jupyter-widgets / pythreejs

A Jupyter - Three.js bridge
https://pythreejs.readthedocs.io
Other
951 stars 188 forks source link

simple triangle #61

Closed uddipan closed 7 years ago

uddipan commented 8 years ago

I am new to 3js. I have tried all the examples and they work fine. I want to render a simple triangle as shown in http://jsfiddle.net/yomotsu/gyPJQ/

and I have the following code: geom = Geometry(vertices=[[0,0,0],[30,0,0],[30,30,0]], faces=[[0,1,2]], colors = ['red', 'blue', 'green']) mesh = Mesh(geometry=geom, material=BasicMaterial(vertexColors='VertexColors')) scene = Scene(children=[mesh,AmbientLight(color='#cccccc')]) c = PerspectiveCamera(position=[0, 0, 100], fov = 40, aspect = 6/4, near = 1, far = 1000) renderer = Renderer(camera=c, scene = scene, controls=[OrbitControls(controlling=c)]) display(renderer)

It compiles fine but I do not see anything. Can someone please let me know what might be wrong here?

nlooije commented 8 years ago

I am also having a similar problem for a geometry where i want to specify the vertices and faces.

misolietavec commented 7 years ago

Use PlainGeometry instead of (abstract class) Geometry. Always choose the appropriate geometry for given object.

jasongrout commented 7 years ago

Indeed. Also, vertexColors is a bit confusing. This works for me:

from pythreejs import *
from IPython.display import display
geom = PlainGeometry(vertices=[[0,0,0],[30,0,0],[30,30,0]],
faces=[[0,1,2]],
colors = ['red', 'blue', 'green'])
mesh = Mesh(geometry=geom, material=BasicMaterial(color='blue'))
scene = Scene(children=[mesh,AmbientLight(color='#cccccc')])
c = PerspectiveCamera(position=[0, 0, 100], fov = 40, aspect = 6/4, near = 1, far = 1000)
renderer = Renderer(camera=c, scene = scene, controls=[OrbitControls(controlling=c)])
display(renderer)

I also added some examples in the example file showing how to use PlainGeometry with vertexColors (which may require the current dev version of pythreejs).

jasongrout commented 7 years ago

Thanks @misolietavec for answering this!