Rotating Cube¶
Demonstrates: MeshInstance3D, Camera3D, Material, process() rotation. Run: uv run python packages/graphics/examples/start_rotating_cube.py
Source Code¶
1#!/usr/bin/env python3
2"""Rotating cube -- simple 3D demo using the node system.
3
4Demonstrates: MeshInstance3D, Camera3D, Material, process() rotation.
5Run: uv run python packages/graphics/examples/start_rotating_cube.py
6"""
7
8from simvx.core import Camera3D, Material, Mesh, MeshInstance3D, Node, Vec3
9from simvx.graphics import App
10
11
12class RotatingCube(Node):
13 def ready(self):
14 self.add_child(Camera3D(name="Camera", position=Vec3(0, 2, 5), look_at=Vec3(0, 0, 0), fov=60.0))
15
16 self.cube = self.add_child(MeshInstance3D(name="Cube"))
17 self.cube.mesh = Mesh.cube()
18 self.cube.material = Material(colour=(0.2, 0.6, 1.0, 1.0), roughness=0.4)
19
20 def process(self, dt: float):
21 self.cube.rotate_y(1.0 * dt)
22 self.cube.rotate_x(0.5 * dt)
23
24
25if __name__ == "__main__":
26 App(title="Rotating Cube", width=800, height=600).run(RotatingCube())