Commit d950e0e6 authored by Dario Seyb's avatar Dario Seyb

drawing edges and vertices

parent 9e7cbedf
This diff is collapsed.
......@@ -8,52 +8,85 @@ class Context(object):
children=[three.DirectionalLight(color='#ffffff', position=[-3, 5, 1], intensity=0.5)])
self.scene = three.Scene(children=[three.AmbientLight(color='#dddddd')])
self.scene.background = '#dddddd'
self.orbit_controls = three.OrbitControls(controlling=self.camera)
self.renderer = three.Renderer(camera=self.camera, background='black', background_opacity=1,
scene=self.scene, controls=[self.orbit_controls],
width=600, height=400 )
def draw_faces(self, vertices, face_indices, normals=None, per_vertex_colors=None, per_face_colors=None, shading='flat', z_offset=0):
face_indices = np.asarray(face_indices, dtype='uint16').ravel()
def draw_faces(self, vertices, face_indices, normals=None, per_vertex_colors=None, per_face_colors=None,
hidden=False, shading='flat', z_offset=0.5):
mesh_geom = three.BufferGeometry(attributes=dict(
position = three.BufferAttribute(vertices, normalized=False),
index = three.BufferAttribute(face_indices, normalized=False),
position = three.BufferAttribute(np.asarray(vertices, dtype=np.float32), normalized=False),
index = three.BufferAttribute(np.asarray(face_indices, dtype='uint16').ravel(), normalized=False),
))
mesh_obj = three.Mesh(geometry=mesh_geom, material=three.MeshLambertMaterial(color='#dddddd'))
mat = three.MeshLambertMaterial(color='#dddddd', colorWrite=not hidden)
if z_offset is not 0:
mat.polygonOffset = True
mat.polygonOffsetFactor = z_offset
mat.polygonOffsetUnits = 0.1
mesh_obj = three.Mesh(geometry=mesh_geom, material=mat)
self.scene.add(mesh_obj)
return self
def draw_edges(self, vertices, edge_indices=None, per_vertex_colors=None, per_edge_colors=None, z_offset=1e-3):
def draw_edges(self, vertices, edge_indices=None, per_vertex_colors=None, per_edge_colors=None, z_offset=0):
if edge_indices is None:
edge_indices = np.arange(0, len(vertices)-1)
edge_indices = zip(np.arange(0, len(vertices)-1), np.arange(1, len(vertices)))
attributes=dict(
position = three.BufferAttribute(np.asarray(vertices, dtype=np.float32), normalized=False),
index = three.BufferAttribute(np.asarray(edge_indices, dtype=np.uint16).ravel(), normalized=False),
)
edge_indices = np.asarray(edge_indices, dtype='uint16')
mat = three.LineBasicMaterial(color='#000000')
geom = three.BufferGeometry(attributes=dict(
position = three.BufferAttribute(vertices, normalized=False),
index = three.BufferAttribute(edge_indices, normalized=False),
))
if z_offset is not 0:
mat.polygonOffset = True
mat.polygonOffsetFactor = z_offset
mat.polygonOffsetUnits = 0.1
material = three.LineBasicMaterial(color='#000000')
geom = three.BufferGeometry(attributes = attributes)
mesh_obj = three.Line(geometry=geom, material=material)
mesh_obj = three.LineSegments(geometry=geom, material=mat)
self.scene.add(mesh_obj)
return self
def draw_vertices(self, vertices, per_vertex_colors=None, point_size=1, z_offset=0):
geometry = three.Geometry(vertices=vertices)
if per_vertex_colors is not None:
geometry.colors = per_vertex_colors
def draw_vertices(self, vertices, colors=None, point_size=1, z_offset=0, perspective=False):
material = three.PointsMaterial(color='#000000', sizeAttenuation=False, size=point_size)
matColor = colors
if colors is None:
matColor = 'black'
elif hasattr(colors, '__len__') and (not isinstance(colors, str)):
matColor = '#dddddd'
else:
colors = None
attributes = dict(
position = three.BufferAttribute(np.asarray(vertices, dtype=np.float32), normalized=False),
)
mat = three.PointsMaterial(color=matColor, sizeAttenuation=perspective, size=point_size)
if z_offset is not 0:
mat.polygonOffset = True
mat.polygonOffsetFactor = z_offset
mat.polygonOffsetUnits = 0.1
if colors is not None:
attributes['color'] = three.BufferAttribute(np.asarray(colors, dtype=np.float32))
mat.vertexColors = 'VertexColors'
mesh_obj = three.Points(geometry=geometry, material=material)
geom = three.BufferGeometry(attributes=attributes)
mesh_obj = three.Points(geometry=geom, material=mat)
self.scene.add(mesh_obj)
return self
......
......@@ -6,5 +6,5 @@ def display_faces(vertices, face_indices, normals=None, per_vertex_colors=None,
def display_edges(vertices, edge_indices=None, per_vertex_colors=None, per_edge_colors=None, z_offset=1e-3):
Context().draw_edges(vertices, edge_indices, per_vertex_colors, per_edge_colors, z_offset).display()
def display_vertices(vertices, per_vertex_colors=None, point_size=1, z_offset=0):
Context().draw_vertices(vertices, per_vertex_colors, point_size, z_offset).display()
def display_vertices(vertices, colors=None, point_size=1, z_offset=0):
Context().draw_vertices(vertices, colors, point_size, z_offset).display()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment