OG3D: developer's guide¶
This page covers OG3D 1.2.1 and OG3D Lite 1.2.0. Items marked Pro exist only in the full plugin with an active licence. Everything else is in both editions.
For the user guide, see OG3D.
Actions¶
| Action | Arguments | When it fires |
|---|---|---|
og3d_editor_rows |
WP_Post $post |
In the scene editor box, just above Scene description (JSON). Print extra editor rows here. |
og3d_settings_fields |
array $settings |
Inside the Settings card, after the built-in fields. Print extra fields named og3d_settings[your_key]. |
Add a settings field and keep its value:
add_action( 'og3d_settings_fields', function ( $s ) {
printf(
'<div class="og-adm-field"><label><input type="checkbox" name="og3d_settings[my_flag]" value="1" %s> My flag</label></div>',
checked( ! empty( $s['my_flag'] ), true, false )
);
} );
add_filter( 'og3d_sanitize_settings', function ( $out, $in ) {
$out['my_flag'] = ! empty( $in['my_flag'] );
return $out;
}, 10, 2 );
Filters¶
| Filter | Arguments | Use |
|---|---|---|
og3d_sanitize_settings |
array $out, array $in |
Keep your own keys in og3d_settings. Clean them yourself. The built-in keys always win. |
og3d_sanitize_spec |
array $out, array $in |
Keep your own top-level keys in a scene. $in is the raw input, so clean what you keep. The built-in keys (v, name, palette, fog, tint, vignette, camera, objects) are always restored. |
og3d_object_types |
string[] $types |
Add object type names. Names must match ^[a-z0-9-]{2,30}$ and must not be a built-in type. |
og3d_sanitize_object |
null $clean, array $object, array $base |
Clean one object of a type you added. $base holds the cleaned pos and scale. Return an array with the same type, or null to drop it. Objects of a type nobody claims are dropped. |
og3d_client_spec |
array $spec, int $scene_id |
Change the scene sent to the browser (front end only; the stored scene is not changed). |
og3d_runtime_scripts |
string[] $urls |
Extra script URLs loaded after the 3D runtime and before the scene starts. Use this to add object builders. |
og3d_script_paths |
string[] $paths |
Path parts of scripts that cache and optimiser plugins are asked not to combine, defer or delay. Add the scripts you load through og3d_runtime_scripts. |
og3d_scenes_buttons |
string $html |
Trusted HTML for extra buttons next to Add new scene on the Scenes tab. |
og3d_ai_text (Pro) |
null $reply, string $prompt |
Answer Design with AI with your own AI provider. Return the reply text; return null to let OG AI Core answer. Hooking it also makes Design with AI available without OG AI Core. |
Add a custom object type (server side):
add_filter( 'og3d_object_types', function ( $types ) {
$types[] = 'my-ring';
return $types;
} );
add_filter( 'og3d_sanitize_object', function ( $clean, $o, $base ) {
if ( 'my-ring' !== $o['type'] ) {
return $clean;
}
return array(
'type' => 'my-ring',
'pos' => $base['pos'],
'scale' => $base['scale'],
'radius' => max( 0.5, min( 10, (float) ( $o['radius'] ?? 3 ) ) ),
);
}, 10, 3 );
add_filter( 'og3d_runtime_scripts', function ( $urls ) {
$urls[] = plugins_url( 'my-ring.js', __FILE__ );
return $urls;
} );
add_filter( 'og3d_script_paths', function ( $paths ) {
$paths[] = 'my-plugin/my-ring.js';
return $paths;
} );
See JavaScript for the builder side.
Shortcodes¶
[og3d]¶
Places a published scene in the content.
| Attribute | Default | Values |
|---|---|---|
scene |
0 |
The scene's post ID. Required. Only published scenes render. |
mode |
section |
section: the scene fills this element and the camera follows the scroll through it. background: the scene goes behind the whole page. |
height |
100vh |
Section height. A number with px, vh, vw, rem, em or %. Anything else falls back to 100vh. |
mode="background" does nothing when a site-wide scene already matches the page, and only the first background per page is used. Up to 8 section scenes play on one page.
Blocks¶
| Block | Attributes | Notes |
|---|---|---|
og3d/scene (OG3D Scene, Design category) |
sceneId (number, default 0), mode (section or background, default section), height (string, default 100vh) |
Server-rendered, the same output as the shortcode. |
core/group, core/cover |
og3dScene (number, default 0) |
Added by OG3D. When set to a published scene, the scene is inserted as the first child of the block wrapper, and the wrapper gets the class og3d-has-bg. |
REST API¶
Namespace og3d/v1. Every route needs the manage_options capability and a REST nonce (X-WP-Nonce).
| Route | Method | Parameters | Returns |
|---|---|---|---|
/random |
POST | seed (int), palette (object) |
{ spec }: a seeded random scene |
/template |
POST | slug |
{ spec }, or 404 if unknown, or 403 for a Pro template without Pro |
/generate (Pro) |
POST | brief (up to 600 characters), palette |
{ spec, source, notice }. source is ai or random. Rate-limited: 429 if called again within a few seconds. |
/still |
POST (multipart) | scene (ID), hand (bool), file field still |
Saves the still image: WebP, JPEG or PNG, up to 3 MB, 100 to 4000 px per side. Returns { id, url, hand }. |
/still/remove |
POST | scene |
{ removed: true } |
/export |
GET | id |
{ file, data }. data is { format: "og3d-scene", version: 1, name, spec }. |
/import |
POST | text (JSON, up to 256 KB), create (bool) |
Without create: { spec, note }. With create: saves a new draft scene and returns { id, edit, note }. |
/demo (Pro) |
POST | none | Makes (or returns) the demo page and scene: { page, scene, view, edit, again } |
/import accepts the export format or a bare scene object. Anything without objects, camera or palette is refused.
AJAX actions¶
OG3D uses no admin-ajax.php actions. The Pro licence form posts to admin-post.php with the actions og3d_licence_activate (field og3d_licence_key) and og3d_licence_deactivate, nonce og3d_licence.
MCP tools¶
Pro. Added to OG AI Core's MCP server when OG AI Core is active and AI assistant tools is ticked in OG3D > Settings (off by default). Only administrators can use them. Write tools refuse to run unless confirm is true, so the assistant must ask you first.
| Tool | Access | Arguments | What it does |
|---|---|---|---|
og3d_list_scenes |
read | none | Scenes with id, title, status, rules and edit link |
og3d_get_scene |
read | id (required) |
One scene's full spec and rules |
og3d_list_templates |
read | none | Template slug and name |
og3d_create_scene |
write | title, template (slug), spec (object), rules (object), confirm (required) |
Makes a draft scene from a scene description, a template, or Grid Terrain if neither is given |
og3d_update_scene |
write | id, confirm (required); title, spec, rules |
Changes a scene. A live scene changes on the site at once. |
og3d_set_scene_status |
write | id, status (publish or draft), confirm (all required) |
Puts a scene live or takes it off |
rules takes target (front, all, pages, types), pages (IDs), types (post type names) and except (IDs). Given keys are merged into the current rules.
A scene made through MCP gets its still image the next time it is opened in the editor.
OG3D Lite has no MCP tools.
WP-CLI¶
OG3D adds no WP-CLI commands. Scenes are ordinary posts, so you can list them with:
Data stored¶
Post type¶
og3d_scene: not public, not in REST, supports a title only. It uses its own capabilities (og3d_scene / og3d_scenes), which OG3D grants to every user with manage_options.
On the front end the first published scene (by menu order, then ID) whose rule matches the page is used.
Post meta¶
| Key | On | Holds |
|---|---|---|
_og3d_spec |
scene | The scene description as JSON |
_og3d_rules |
scene | { target, pages, types, except }. Up to 50 IDs and 20 post types. |
_og3d_still |
scene | Attachment ID of the still image |
_og3d_still_hand |
scene | 1 when the still was picked by hand |
_og3d_still_for |
scene | Hash of the scene the still was taken from |
_og3d_still_of |
attachment | The scene a still image belongs to. The image is deleted with its scene. |
Scene description¶
Top-level keys: v, name, palette (bg, primary, secondary, accent as #rrggbb), fog (0 to 0.2), tint (0 to 0.9, the see-through section strength), vignette (0 to 0.9), camera (fov, fovMobile, mouse, follow, path of up to 16 { t, pos, look } points) and objects (up to 12). Pro adds sync: up to 12 { selector, effect, from, to } scroll effects. Object colours may be a palette name (primary, secondary, accent, bg) or #rrggbb.
Pro object types model (media: attachment ID, spin, bob, tint) and text3d (text up to 60 characters, size, depth, color, glow, spin, sway) are added through the same filters you can use.
Options¶
| Option | Holds |
|---|---|
og3d_settings |
tint_selector, phones (full, lite, still, off), phone_width, min_width (kept for older code), and in Pro mcp |
og3d_demo_page, og3d_demo_scene (Pro) |
IDs of the demo page and scene |
OG3D also uses short-lived transients whose names start with og3d_. It adds no database tables.
On uninstall, og3d_settings, og3d_demo_page and og3d_demo_scene are deleted. Scenes, their meta and still images are kept.
Constants¶
| Constant | Value |
|---|---|
OG3D_VERSION |
Plugin version. Defined by whichever edition loads first; the other edition then stands down. |
OG3D_FILE |
Main plugin file |
OG3D_DIR |
Plugin folder path |
OG3D_URL |
Plugin folder URL |
JavaScript¶
Front end¶
og3d-boot.js reads window.OG3D_BOOT:
{ three, runtime, extra: [urls], phones, phoneWidth,
bg: { spec, still } | null,
sections: [ { id, spec, still } ] }
It picks a mode in the browser, so page caches can keep one copy of the page for everyone:
| Mode | When |
|---|---|
full |
The moving scene |
lite |
Phones with Lighter scene: fewer objects, pixels and frames |
still |
Data saver on, less motion asked for (when a still exists), no WebGL, or phones with Still image |
off |
Phones with Off (plain background) |
The mode is written to <html data-og3d-mode="...">. three.js and the runtime load only for full and lite, after the page has loaded.
Markup and classes you can style:
| Selector | Meaning |
|---|---|
#og3d-bg |
The fixed page background layer |
body.og3d-active |
A page-background scene is on this page |
#og3d-bg.og3d-still, .og3d-off, .og3d-nogl |
Showing the still image, the plain colour, or the fallback without WebGL |
.og3d-section |
A scene inside a section (block, shortcode or Group/Cover background) |
.og3d-has-bg |
A Group or Cover block with a 3D background |
Runtime API¶
og3d-runtime.js sets window.OG3D:
| Member | Use |
|---|---|
OG3D.addType( name, builder ) |
Registers an object type. Built-in names cannot be replaced. |
OG3D.types |
Names of every registered type |
OG3D.mount( host, spec, options ) |
Draws a scene into an element that contains a <canvas> |
OG3D.snapshot |
Used by the editor to take the still image |
OG3D.start( cfg ) |
Called by the boot script |
A builder is function ( object, palette, ctx ) and returns { obj, tick }: obj is a three.js Object3D added to the scene, and tick( seconds ) runs every frame. If your script may load before the runtime, queue it instead:
( function ( w ) {
var ring = function ( o, pal ) {
var g = new THREE.Group();
// ... build meshes with o.radius and the palette ...
return { obj: g, tick: function ( s ) { g.rotation.y = s * 0.2; } };
};
if ( w.OG3D && w.OG3D.addType ) {
w.OG3D.addType( 'my-ring', ring );
} else {
w.OG3D_TYPES = ( w.OG3D_TYPES || [] ).concat( [ [ 'my-ring', ring ] ] );
}
} )( window );
three.js r128 is bundled as window.THREE. Pro also bundles its GLTFLoader. Nothing loads from a CDN.
Admin¶
The scene editor reads window.OG3D_ADMIN and window.OG3D_EDITOR. To change the scene from your own editor row, write JSON into #og3d-json and fire an input event on it: the preview redraws.