Plane Primitive#

obj files

This example shows you how to construct a plane and have it visible on both sides.

We pass in Plane.material.side=2 to the Plane constructor to make it visible on both sides.

mkdir -p assets
wget -O assets/textured.obj
wget -O assets/textured.mtl
wget -O assets/textured_0_YV3hq55a.jpg

This should produce the following file tree:

├── textured.mtl
├── textured.obj
└── textured_0_YV3hq55a.jpg

1 directory, 3 files

We first setup the vuer app:

from asyncio import sleep

from vuer import Vuer
from import Set, ClientEvent
from vuer.schemas import DefaultScene, Obj

app = Vuer(static_root=f"{Path(__file__).parent}/assets")

Detecting when the assets has been loaded#

Sometimes the 3D assets we want to load can be very large (in the hundreds of MBs). In that case, we want to know when the assets has been loaded so that we can start the simulation and the rendering.

To do so, simply bind a function to the LOAD event, which is emitted if

  1. the component has been loaded

  2. the onLoad attribute is set to a non-empty string.

async def onLoad(event: ClientEvent, _):
    print(f"mesh has been loaded: {event.value}")

This should print out the following message:

mesh has been loaded: textured stairs are loaded
mesh has been loaded: wireframe stairs are loaded
mesh has been loaded: red stairs are loaded

Now to setup the scene, we can bind the main function:

# use `start=True` to start the app immediately
async def main(session):
    session.set @ DefaultScene(
            position=[-4.5, 1.5, -3.5],
            # This component emits a `LOAD` event when the mesh is loaded.
            # this also extends to other 3D asset components.
            onLoad="textured stairs are loaded",
        up=[0, 1, 0],

    session.add @ Obj(
        # you can omit this. See the red stairs below.
        position=[0, 1.5, 0],
        onLoad="wireframe stairs are loaded",

    session.add @ Obj(
        position=[4.5, 1.5, 3.5],
        onLoad="red stairs are loaded",

    while True:
        await sleep(1.0)

Optionally you can omit the material (mtl) file. In that case only the mesh will be loaded.



colored mesh