Rotating Cube¶
Smallest 3D scene.
▶ Run in browserTags: getting_started
A textured cube spinning on two axes. Demonstrates MeshInstance3D,
Camera3D, Material, and per-frame rotation via on_process().
Source¶
1"""Rotating Cube: Smallest 3D scene.
2
3A textured cube spinning on two axes. Demonstrates `MeshInstance3D`,
4`Camera3D`, `Material`, and per-frame rotation via `on_process()`.
5"""
6
7from simvx.core import Camera3D, Material, Mesh, MeshInstance3D, Node, Vec3
8from simvx.graphics import App
9
10
11class RotatingCube(Node):
12 def on_ready(self):
13 self.add_child(Camera3D(name="Camera", position=Vec3(0, 2, 5), look_at=Vec3(0, 0, 0), fov=60.0))
14 self.cube = self.add_child(MeshInstance3D(name="Cube"))
15 self.cube.mesh = Mesh.cube()
16 self.cube.material = Material(colour=(0.2, 0.6, 1.0, 1.0), roughness=0.4)
17
18 def on_process(self, dt: float):
19 self.cube.rotate_y(1.0 * dt)
20 self.cube.rotate_x(0.5 * dt)
21
22
23if __name__ == "__main__":
24 App(title="Rotating Cube", width=800, height=600).run(RotatingCube())