def _test_cannon(): scene = Scene() scene.add(PointLight(color=0xffffff, intensity=1, distance=100, position=[-2, 20, 4])) scene.add(Mesh(geometry=SphereBufferGeometry(radius=0.25), material=MeshPhongMaterial(color=0xff0000, shading=FlatShading), cannonData={'mass': 1, 'shapes': ['Sphere']}, position=[0, 2, -4])) scene.add(Mesh(geometry=BoxGeometry(width=1, height=1, depth=1), material=MeshPhongMaterial(color=0x00ff00, shading=FlatShading), cannonData={'mass': 1, 'shapes': ['Box']}, position=[-2, 3, -4])) scene.add(Mesh(geometry=CylinderGeometry(radiusTop=0.5, radiusBottom=0.5, height=1, radialSegments=8), material=MeshPhongMaterial(color=0x0000ff, shading=FlatShading), position=[2, 4, -6], cannonData={'mass': 1, 'shapes': ['Cylinder']})) scene.add(Mesh(geometry=PlaneBufferGeometry(width=8, height=8), material=MeshBasicMaterial(color=0x5555ff), position=[0, -2, -4], rotation=[-np.pi/2, 0, 0], cannonData={'mass': 0, 'shapes': ['Plane']})) return render_template('index.html', json_config=Markup(r"""<script> var THREE_PY_CONFIG = %s; var JSON_SCENE = %s; </script>""" % (json.dumps({'controls': request.args.get('controls')}, indent=2), json.dumps(scene.export(), indent=2))))
def _test_heightfield(): scene = Scene() scene.add(PointLight(color=0xffffff, intensity=1, distance=800, position=[10, 0, 0])) heightfieldImage = Image(url='../images/terrain128.png') scene.add(HeightfieldMesh(heightfieldImage=heightfieldImage, heightfieldScale=32, material=MeshLambertMaterial(color=0xff0000), rotation=[-np.pi/4, 0, 0], position=[0, -24, -32], cannonData={'mass': 0, 'shapes': ['Heightfield']})) scene.add(Mesh(geometry=SphereBufferGeometry(radius=1), material=MeshPhongMaterial(color=0xffff00, shading=FlatShading), position=[0, 10, -40], cannonData={'mass': 1, 'shapes': ['Sphere']})) scene.add(Mesh(geometry=BoxGeometry(width=1, height=1, depth=1), material=MeshPhongMaterial(color=0xff00ff, shading=FlatShading), position=[4, 10, -40], cannonData={'mass': 1, 'shapes': ['Box']})) return render_template('index.html', json_config=Markup(r"""<script> var THREE_PY_CONFIG = %s; var JSON_SCENE = %s; </script>""" % (json.dumps({'controls': request.args.get('controls')}, indent=2), json.dumps(scene.export(), indent=2))))
def _test_skybox(): scene = Scene() scene.add(Skybox(cube_images=['../images/%s.png' % side for side in ('px', 'nx', 'py', 'ny', 'pz', 'nz')])) return render_template('index.html', json_config=Markup(r"""<script> var THREE_PY_CONFIG = %s; var JSON_SCENE = %s; </script>""" % (json.dumps({'controls': request.args.get('controls')}, indent=2), json.dumps(scene.export(), indent=2))))
def _test_text(): scene = Scene() scene.add(Mesh(geometry=TextGeometry(text='test text', size=0.1, height=0), material=MeshBasicMaterial(color=0xff00ff), position=[0, 0, -4])) return render_template('index.html', json_config=Markup(r"""<script> var THREE_PY_CONFIG = %s; var JSON_SCENE = %s; </script>""" % (json.dumps({'controls': request.args.get('controls')}, indent=2), json.dumps(scene.export(), indent=2))))
def _test_page(): scene = Scene() scene.add(Mesh(geometry=PlaneBufferGeometry(width=8, height=8), material=MeshBasicMaterial(color=0x5555ff), position=[0, -2, -4], rotation=[-np.pi/2, 0, 0], cannonData={'mass': 0, 'shapes': ['Plane']})) return render_template('test.html', links=Markup('\n<br>\n'.join([r"<a href='%s'>%s</a>" % (endpoint, endpoint) for endpoint in ('test/cannon', 'test/heightfield', 'test/skybox')])), json_config=Markup(r"""<script> var THREE_PY_CONFIG = %s; var JSON_SCENE = %s; </script>""" % (json.dumps({'controls': request.args.get('controls')}, indent=2), json.dumps(scene.export(), indent=2))))