Spinning Cube
The smallest complete @domphy/three scene: a single mesh built from a tag + args, animated every frame with onFrame, lit by two lights against a deep slate backdrop. Start here before the grammar reference.
How it works
- Tags:
boxGeometryandmeshStandardMaterialare the camelCase names ofTHREE.BoxGeometry/THREE.MeshStandardMaterial, resolved by reflection — see Grammar keys. Theirattachtarget ("geometry"/"material") is inferred automatically from the.isBufferGeometry/.isMaterialflags. args:{ boxGeometry: null, args: [1.4, 1.4, 1.4] }passes constructor arguments tonew THREE.BoxGeometry(1.4, 1.4, 1.4)— seeargsreconstruction.onFrame: theuseFrame()analog, called every rendered frame as(root, delta, self)—selfis the mesh'sTHREE.Meshinstance. See Animation & Loop.root.clock: the float bob readsroot.clock.getElapsedTime()from the sharedRootStateclock instead of a local time accumulator, so it stays correct across re-renders.onCreated: runs once after the renderer and scene exist, used here to setroot.scene.background, add a matchingTHREE.Fogfor depth (even at this small scale, fog keeps the cube from reading flat), and toroot.camera.lookAt(0, 0, 0)— the camera never gets an explicitrotation, so it must be aimed at the cube by hand. A fixed background color inside the canvas is fine; Domphy's theme/doctor rules govern the DOM around the canvas, not the rendered scene itself.- Two-point lighting: a warm
directionalLightkey from the front-right and a coolpointLightrim from behind separate the cube from the backdrop —colorandintensityon both are applied directly (color.set(...)under the hood) — see Duck-typed props.