- Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathhello_cube.py
More file actions
Latest commit
66 lines (48 loc) · 1.72 KB
/
Copy pathhello_cube.py
File metadata and controls
66 lines (48 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""The three.js 'hello world' — spinning, lit cubes you can orbit — in Python.
python hello_cube.py
Opens a window. Drag to orbit, scroll to zoom, Esc to quit.
"""
importos
importsys
# Make the built `threepp` module (in the parent python/ dir) importable.
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
importthreeppastp
canvas=tp.Canvas("threepp — hello cube", width=900, height=600, antialiasing=4)
renderer=tp.GLRenderer(canvas)
renderer.shadow_map_enabled=True
scene=tp.Scene()
scene.background=0x202830
camera=tp.PerspectiveCamera(70, canvas.aspect(), 0.1, 100)
camera.position.set(0, 2, 6)
controls=tp.OrbitControls(camera, canvas)
controls.enable_damping=True
scene.add(tp.HemisphereLight(0xffffff, 0x333344, 1.0))
key_light=tp.DirectionalLight(0xffffff, 2.5)
key_light.position.set(5, 10, 7)
key_light.cast_shadow=True
scene.add(key_light)
cubes=tp.Group()
fori, colorinenumerate((0xff5555, 0x55ff66, 0x5599ff)):
material=tp.MeshStandardMaterial()
material.color=color# hex int converts straight to a Color
material.roughness=0.35
material.metalness=0.1
cube=tp.Mesh(tp.BoxGeometry(), material)
cube.position.x= (i-1) *1.7
cube.cast_shadow=True
cubes.add(cube)
scene.add(cubes)
defon_resize(w, h):
camera.aspect=w/max(h, 1)
camera.update_projection_matrix()
renderer.set_size(w, h)
canvas.on_window_resize(on_resize)
clock=tp.Clock()
defanimate():
t=clock.get_elapsed_time()
cubes.rotation.y=t*0.5
fori, cubeinenumerate(cubes.children):
cube.rotation.x=t* (1.0+0.3*i)
controls.update()
renderer.render(scene, camera)
canvas.animate(animate)