Custom objects and dependencies
Global THREE and GLTFExporter, custom Selectable classes, adding geometry, and persistence and export boundaries for plugin objects.
A plugin can create custom geometry and explore the editor’s internals.
Use the stable editorAPI for built-in operations. The global editor
and editor classes provide deeper access, but their implementation may
change between versions.
A visible Three.js object, an editable BDEngine object, and a Minecraft entity have different contracts. Adding a mesh to the scene addresses only the first.
THREE and GLTFExporter
The following globals are available when the plugin system initializes:
| Global value | Purpose |
|---|---|
window.editorAPI |
Public plugin API |
window.editor |
Current editor instance and its internal subsystems |
window.THREE |
Three.js from the editor build |
window.THREE.GLTFExporter |
glTF exporter class added to THREE |
window.Selectable |
Base class for editor objects, extending THREE.Group |
window.libs.JSZip |
JSZip provided by the editor |
gT |
Retrieves translated text by key |
Here, GLTFExporter is specifically available as THREE.GLTFExporter;
a separate global GLTFExporter is not created. Use the editor’s Three.js
instance so that objects, materials, and the exporter use the same version.
console.log('Three.js revision:', THREE.REVISION);const exporter = new THREE.GLTFExporter();const zip = new window.libs.JSZip();Library versions are tied to the BDEngine build. Do not extend editorAPI’s stability guarantees to every internal class or dependency method. Available globals do not necessarily mean that the UI is ready: see Plugin startup order. Dictionary registration and gT are covered in the Translations reference.
Selectable and a custom class
The new Selectable(editor) constructor creates a group with transform
methods, selection state, and a link to the editor. It does not create
a Minecraft display, load a model, or assign a serializer to a custom type.
The following example creates a temporary visual marker. It is custom Three.js geometry for the current session, not an exportable Minecraft block.
class PreviewMarker extends Selectable { constructor(editor) { super(editor); this.name = 'Plugin marker'; this.markerMesh = new THREE.Mesh( new THREE.BoxGeometry(0.25, 0.25, 0.25), new THREE.MeshBasicMaterial({ color: 0xffaa00 }) ); this.add(this.markerMesh); }
disposePreview() { if (this.parent) this.delete(); this.markerMesh.geometry.dispose(); this.markerMesh.material.dispose(); }}Selectable provides basic selection, but does not include every feature
of a built-in type: a custom group does not automatically get an entry in
the object panel, Minecraft export, or support from every tool. For that
integration, explore the relevant editor subsystem and verify its contract.
Position, rotation, and scale of built-in displays and custom objects are covered in Position, rotation, and scale. For programmatic selection, see the selected property.
Add an object to the scene
Add the instance through editorAPI.addObject. This example uses the PreviewMarker class above:
const marker = new PreviewMarker(editor);marker.setPosition({ x: 0, y: 1, z: 0 });editorAPI.addObject(marker);marker.selected = true;editorAPI.update(true);
// When the preview is no longer needed:// marker.disposePreview();// editorAPI.update(true);Selectable itself has add(...objects) and remove(...objects),
inherited from the group and extended to update the editor’s internal indices.
They change the hierarchy and return the parent object, but do not create
history. object.delete() deselects descendants and detaches the object
from its parent; it returns undefined and requires the parent to exist.
Direct removal in this example is appropriate for a temporary preview. For standard project objects, use the editorAPI deletion operations.
Persistence, export, and resources
The project saves types known to the editor using their own representation.
Extending Selectable is not enough to serialize an arbitrary class,
load it again, or restore it through Undo. In particular, addObject
does not register a format or add a history command.
THREE.Mesh geometry does not automatically become a Minecraft display either. For a custom export format, you can obtain a mesh snapshot and process it with your own logic. Fully integrating a type into the project requires additional editor mechanisms and separate checks for saving and restoring it.
The plugin is responsible for disposing of resources it creates: geometry, materials, its own textures, event handlers, and timers. Removing a DOM window or detaching a Three.js object does not clean up all of them. Dispose only of resources you own; shared editor textures and materials may still be used by other objects.
When to use a built-in object
If the result must remain an editable display and export to Minecraft,
start with editorAPI.add for BlockDisplay, ItemDisplay, or TextDisplay.
The editor already implements their loading and standard serialization.
Custom geometry is useful for previews, visual tools, and other plugin features where persistence and in-game export are handled separately. For a practical approach, see Create a generator of built-in objects.
Object methods are now covered in Position, rotation, and scale and selected: selection state.