Skip to content

Meshes

Updated

Meshes are the visible, solid things of a world: built-in shapes, ground, models loaded from 3D files, photoreal captures, landscapes and water. Every mesh entity draws something; most can also take materials, colliders, shadows, animation and interaction components, so the same entity is both what players see and what they touch.

Graphics is everything a MIRA world puts on screen: the shapes of objects, the look of their surfaces, the effects layered on top, and the final image a camera produces. Each of these is a component you add to an entity, and every one of them can be read and changed from a Behavior script while the world runs. This section explains how drawing works, which component to reach for, and how to change what players see without slowing the world down on phones and headsets. Effects that are entities of their own (decals, fire and masks) are in Effects, and effects on the whole image in Post-processing.

Mesh. A surface made of triangles. Everything solid you see is a mesh: either a loaded model (a glTF, FBX, OBJ, Collada or USDZ file, or one piece of a modular kit) or a primitive (a built-in box, sphere, cylinder and so on, described by a Geometry component).

Material. How a mesh’s surface looks: its colour, how it takes light, whether it is see-through, shiny or glowing. An entity holds one material, and each kind (Basic, Standard, Glass, Reflector, …) is its own component.

Shader. The small program the graphics card runs to draw a surface. The Shader Material draws with a ready-made preset (hologram, toon, frozen, lava, …) or with GLSL code you write.

Draw call. One request from the engine to the graphics card to draw one mesh with one material. Each draw call has a fixed cost, so the number of them matters more than the number of triangles in many scenes. LOD and Cache Mesh exist to keep it low.

Effect components. Some components add a visual effect to an entity instead of a shape: an Outline around it, a Decal stamped on it, Fire, Water, Grass, a Mask that turns it into a portal.

Post-processing. Effects applied to the whole rendered image, such as bloom, vignette or film grain. Each is a component on a camera.

Props and setProps. Every component’s settings are its props. Scripts read component.props and change values with component.setProps({ … }), which validates them and updates what is drawn.

Each frame, MIRA draws the scene from the active camera. For every visible entity it takes the entity’s mesh (from its loader or its Geometry), draws it with the entity’s material, and adds any effect components on top. Post-processing components on the camera then transform the finished image.

Two principles shape how scripts should work with graphics:

  • Built on change, not per frame. Geometry, materials and most effect components rebuild their GPU data only when their props change. A setProps call costs one rebuild, so a few discrete changes are cheap, while calling setProps every frame on a material or a Geometry is not. Where smooth animation is needed, animate the entity’s transform, a shader’s uniform values, or the props a page lists as cheap to change live.
  • Shared wherever possible. A model file is parsed once and shared by every copy. Identical materials share one GPU program. With a Cache Mesh, identical copies share one draw call; every fire shares one draw call; cached water shares one simulation.

Components announce what happens to them (a model finished loading, a load failed) through a Signal Emitter on their entity. A script listens with on(signal, callback) and compares event.eventType with an EventType constant such as EventType.GLTF.Ready.

Scripts usually reach graphics components in one of three ways:

  • self.parent.getComponent(StandardMaterialComponent): the Behavior entity sits under the object it drives.
  • findEntity('Statue').getComponent(ModelLoaderComponent): look the object up by name, once, in startup.
  • getComponent(MaterialComponent) or getComponent(ModelLoaderComponent): family base classes that find a material or a model loader of any kind.

Model entities (glTF, FBX, OBJ, Collada, USDZ and Kit Piece) share one way of working. A loader component names the file in src, and the model loads in the background. When it is in place the loader sends a ready event, and when the file cannot load an error event with a message, both through a Signal Emitter on the entity (EventType.GLTF.Ready, EventType.KitPiece.Error, and so on). Changing src keeps the current model on screen until the new one is ready. getComponent(ModelLoaderComponent) returns the loader whatever the format, and a material component added to a model overrides the materials stored in its file.

Primitive Meshes and Floors are built from a Geometry and a material instead of a file, so they appear at once and a script can reshape them. Splats, terrain and water each have their own component and their own cost rules. To draw many identical copies cheaply, add a Cache Mesh; see LOD and caching.

This walkthrough turns a plain box into a glowing crystal that switches to a hologram when clicked.

  1. In your scene, add a Primitive Mesh and name it Crystal. It starts as a green box with a Standard material.

  2. Add a Selectable component to Crystal, so it can be clicked, and a Signal Emitter with the signal crystal/clicked, so its events reach scripts.

  3. Add a Behavior entity as a child of Crystal, and give it this script:

    Crystal.jx
    #pragma lifecycle(startup, update)
    let crystal;
    let hologram = false;
    function startup() {
    crystal = self.parent;
    crystal.getComponent(GeometryComponent).setProps({
    shape: 'octahedron',
    params: { radius: 0.6, detail: 0 },
    });
    crystal.getComponent(MaterialComponent).setProps({
    color: '#f59e0b',
    emissive: '#fbbf24',
    emissiveIntensity: 0.6,
    roughness: 0.2,
    });
    on('crystal/clicked', (event) => {
    if (event.eventType !== EventType.Selectable.Select) return;
    findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again
    hologram = !hologram;
    if (hologram) {
    crystal.addComponent(new ShaderMaterialComponent({ preset: 'hologram' }));
    } else {
    crystal.addComponent(new StandardMaterialComponent({ color: '#f59e0b', emissive: '#fbbf24', emissiveIntensity: 0.6, roughness: 0.2 }));
    }
    });
    }
    function update(dt) {
    crystal.rotation.y += dt * 0.6;
    }
  4. Press Play. The box becomes a slowly turning amber crystal. Click it to switch between the glowing Standard material and the hologram preset.

What each part does:

  • GeometryComponent.setProps swaps the box for an octahedron, rebuilding the mesh once.
  • getComponent(MaterialComponent) returns the material whatever its kind. emissive and emissiveIntensity make it glow; emission stays off until the intensity is above 0.
  • addComponent(new ShaderMaterialComponent({ preset: 'hologram' })) replaces the material, because an entity holds one material at a time. Adding a Standard material back replaces the hologram.
  • update(dt) turns the crystal a little every frame. Rotating the entity costs nothing extra: no material or geometry is rebuilt.
If you want … Use … Read
A simple built-in shape (box, sphere, cylinder…) built in the editor or by a script, to block out a level or build at run time A Primitive Mesh with Geometry Models and meshes
Flat, solid, walkable ground with a collider already set up Floor Models and meshes
To show a 3D model made in a modelling tool A glTF mesh (or FBX, OBJ, Collada, USDZ) Models and meshes
A model from a glTF or GLB file, the recommended format, with animation Mesh Gltf Models and meshes
A model that only exists as FBX Mesh Fbx Models and meshes
Static geometry from an OBJ file and its MTL materials Mesh Obj Models and meshes
A model from a Collada .dae file Mesh Collada Models and meshes
A model from a USDZ file, as used by mobile AR tools Mesh Usdz Models and meshes
One part of a modular building kit, placed from the catalog Kit Piece Models and meshes
To change an object’s colour, shininess or transparency A material component Materials
A stylized or animated surface (hologram, toon, lava, your own code) The Shader Material Shaders
Many identical objects, or detail that drops with distance Cache Mesh, LOD Group LOD and caching
Doors, windows and holes cut into solid shapes CSG CSG
To highlight an object, or see it through walls Outline, Silhouette Outline and silhouette
Pools, lakes, rivers and seas: a real-time water surface Water Mesh Water
A procedural landscape with hills and paths, which you can paint and sculpt Terrain Terrain
Wind-blown grass on any ground Grass Grass
A photoreal Gaussian splat capture of a real place or object Splat Mesh Splats
A portal, a decal stamped onto surfaces, or a campfire Effect entities Effects
Bloom, vignette, glitch or retro looks on the whole image Post-processing effects on a camera Post-processing

Each kind of mesh is an entity type, with a page of its components, props, events and a first script:

EntityTypeWhat it is
Floorent-floorLets the entity's meshes cast and/or receive shadows from lights.
Kit Pieceent-kit-piecePlaces one piece chosen from a modular building kit.
Mesh Colladaent-mesh-colladaLets the entity's meshes cast and/or receive shadows from lights.
Mesh Fbxent-mesh-fbxLets the entity's meshes cast and/or receive shadows from lights.
Mesh Gltfent-mesh-gltfLets the entity's meshes cast and/or receive shadows from lights.
Mesh Objent-mesh-objLets the entity's meshes cast and/or receive shadows from lights.
Mesh Usdzent-mesh-usdzLets the entity's meshes cast and/or receive shadows from lights.
Primitive Meshent-primitive-meshLets the entity's meshes cast and/or receive shadows from lights.
Splat Meshent-splat-meshShows a Gaussian splat capture.
Terrainent-terrainProcedural terrain from one displaced grid, paintable with textures.
Water Meshent-water-meshReal-time water surface with waves, foam, rain, reflections and caustics.

These globals are the ones graphics scripts use most. Every component class is also a global, so StandardMaterialComponent, GeometryComponent or BloomEffectComponent can be used directly in getComponent and new.

GlobalWhat it is
ShaderPresetThe app's shader presets, by name: ShaderPreset.list(), get(name), register(source); a Shader Material draws one with setProps({ preset: name }).
MaterialComponentBase of every material kind: self.getComponent(MaterialComponent) is the entity's material, whichever kind.
ModelLoaderComponentBase of every model loader: self.getComponent(ModelLoaderComponent).props.src, whatever the format.
ShaderMaterialComponentA material drawn by a shader written like a Behavior script, or by a named preset of one.
GeometryComponent
spawnCopy an entity already in the scene (by name, or the entity itself) and add the copy with options.
findEntityFind an entity in the current scene by id, a map read fine every frame, or else by name among its entities.
findObjectFind any object in the current scene by name, a bone or a mesh inside a model too. Walks the scene: look up once and keep it.
TweenAnimate any object's numbers: Tween.to(mesh.position, { x: 5 }, { duration: 1 }), from, value, stop; awaitable.
THREERaw three.js in a Behavior: meshes, materials, vectors, colours and math.
ComponentTypeWhat it does
Basic Materialcomp-basic-materialUnlit flat color that ignores lights.
Cache Meshcomp-cache-meshDraws this entity and every identical copy of it in one draw call.
Colladacomp-colladaLoads a Collada .dae model.
CSGcomp-csgCuts this primitive mesh out of its parent primitive mesh, joins it on, or keeps only their overlap.
Fbxcomp-fbxLoads an FBX model.
Geometrycomp-geometryA built-in primitive shape: box, sphere, plane, cylinder, ring and more.
Glass Materialcomp-glass-materialReady-made see-through glass.
Gltfcomp-gltfLoads a glTF/GLB model.
Grasscomp-grassWind-blown grass that grows on the entity's surface.
Grass Bendercomp-grass-benderMakes grass bend away as this entity moves through it.
Kit Piececomp-kit-piecePlaces one piece chosen from a modular building kit.
Lambert Materialcomp-lambert-materialCheap matte lit material for non-shiny surfaces.
LOD Groupcomp-lod-groupSwitches between child detail levels based on camera distance.
LOD Meshcomp-lod-meshOne detail level inside a LOD Group, shown from a set distance.
Matte Shadow Materialcomp-matte-shadow-materialAn invisible surface that only shows the shadows cast on it, a shadow catcher.
Normal Materialcomp-normal-materialColors surfaces by the way they face; for debugging or sci-fi looks.
Objcomp-objLoads a Wavefront OBJ model.
Outlinecomp-outlineDraws a colored, optionally animated outline around the entity.
Phong Materialcomp-phong-materialClassic shiny highlights, cheaper than Standard.
Physical Materialcomp-physical-materialStandard plus clearcoat, transmission, sheen and iridescence.
Reflector Materialcomp-reflector-materialA surface with a live mirror reflection of the scene.
Shader Materialcomp-shader-materialDraws its mesh with a shader: a preset, or code written with pragmas and hooks.
Shader Texturecomp-shader-textureOne image a shader material reads through a texture uniform.
Silhouettecomp-silhouetteDraws a colored outline around the parts of the entity hidden behind other objects.
Splat Meshcomp-splat-meshShows a Gaussian splat capture.
Standard Materialcomp-standard-materialPhysically based metal/roughness material; the default for most surfaces.
Terraincomp-terrainProcedural terrain from one displaced grid, paintable with textures.
Terrain Texturecomp-terrain-textureOne texture the terrain can be painted with.
Usdzcomp-usdzLoads a USDZ model.
Water Causticscomp-water-causticsPaints moving caustic light on this entity where it is under the water, seen while the camera is under a Water Volume.
Water Foamcomp-water-foamMakes water foam where this entity meets the water, and in its wake as it moves through it.
Water Meshcomp-water-meshReal-time water surface with waves, foam, rain, reflections and caustics.
Water Volumecomp-water-volumeLets the camera go under this water: water-coloured fog as far as its clarity, the waves seen from below, drifting specks.
Water Wetnesscomp-water-wetnessMakes this entity look wet where the water and its waves meet it, like wet sand on a beach.
Topic Description
Models and meshes Loaded models in every format, their load events, and primitive shapes built with Geometry.
Materials Every material kind, its props, and how to change materials from scripts cheaply.
Shaders The Shader Material, the built-in presets, the shader language, and ShaderPreset.
LOD and caching Detail levels by distance, one draw call for many copies, and hiding off-stage content.
CSG Cut, join and intersect primitive meshes, live.
Outline and silhouette Highlight lines around objects, and lines around parts hidden behind others.
Water Real-time water surfaces, foam, wet shores, underwater volumes and caustics.
Terrain Procedural landscapes you can paint, texture and sculpt.
Grass Wind-blown grass on any ground, and Grass Benders that part it.
Splats Photoreal Gaussian splat captures.