from pythreejs import *
from ipywidgets.widgets import HBox, VBox, Layout
import time
# Setup our objects
mat1 = MeshStandardMaterial(color='#ff0000')
mat2 = MeshStandardMaterial(color='#00ff00')
mat3 = MeshStandardMaterial(color='#0000ff')
mat4 = MeshStandardMaterial(color='#ffff00')
mat5 = MeshStandardMaterial(color='#ff00ff')
mat6 = MeshStandardMaterial(color='#00ffff')
torus = TorusGeometry(radius=12, tube=3, radialSegments=16, tubularSegments=100)
mesh1 = Mesh(geometry=torus, material=mat1, _width=75, _height=75)
mesh2 = Mesh(geometry=torus, material=mat2, _width=75, _height=75)
mesh3 = Mesh(geometry=torus, material=mat3, _width=75, _height=75)
mesh4 = Mesh(geometry=torus, material=mat4, _width=75, _height=75)
mesh5 = Mesh(geometry=torus, material=mat5, _width=75, _height=75)
mesh6 = Mesh(geometry=torus, material=mat6, _width=75, _height=75)
# This will render our meshes, each multiple times, resulting in 30 different renderings
# Each of the 30 is a separate widget.
# This test demonstrates:
# - rendering shared objects in multiple places
# - maintaining interactivity for all renderings
# - no prior image is lost because of subsequent renderings
VBox(children=[
HBox(children=[
Preview(mesh, _width=150, _height=150, layout=Layout(padding='2px'))
for mesh in [mesh1, mesh2, mesh3, mesh4, mesh5, mesh6]])
for _ in range(5)
])
# Test using raw WebGLRenderer
# Need a scene, cam, and lights to do so
scene = Scene()
scene.add(mesh1)
cam = PerspectiveCamera(position=[0, 0, 50], fov=75)
cam.lookAt([0, 0, 0])
scene.add(cam)
amb = AmbientLight(color="#ffffff", intensity=0.5)
point = PointLight(color="#ffffff", intensity=1.0, distance=0.0)
point.position = [ -100, 100, 100 ]
point.lookAt([0, 0, 0])
cam.add(amb)
cam.add(point)
Renderer(camera=cam, scene=scene, controls=[OrbitControls(cam)])
renderer = WebGLRenderer(width=50, height=50)
r = renderer
hboxes = []
for i in range(5):
views = []
for j in range(5):
views.append(r)
hbox = HBox(children=views)
hboxes.append(hbox)
vbox = VBox(children=hboxes)
r.layout.padding = '5px'
vbox
for _ in range(10):
renderer.render(scene, cam)
time.sleep(1)