Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# and to the dict of shapes, to have a mapping between meshes and shapes
self._shapes[mesh_id] = shp
# edge rendering, if set to True
edge_lines = None
if render_edges:
edges = list(map(lambda i_edge: [tess.GetEdgeVertex(i_edge, i_vert) for i_vert in range(tess.ObjEdgeGetVertexCount(i_edge))], range(tess.ObjGetEdgeCount())))
edges = list(filter(lambda edge: len(edge) == 2, edges))
np_edge_vertices = np.array(edges, dtype=np.float32).reshape(-1, 3)
np_edge_indices = np.arange(np_edge_vertices.shape[0], dtype=np.uint32)
edge_geometry = BufferGeometry(attributes={
'position': BufferAttribute(np_edge_vertices),
'index' : BufferAttribute(np_edge_indices)
})
edge_material = LineBasicMaterial(color=edge_color, linewidth=1)
edge_lines = LineSegments(geometry=edge_geometry, material=edge_material)
# Add geometries to pickable or non pickable objects
self._displayed_pickable_objects.add(shape_mesh)
if render_edges:
self._displayed_non_pickable_objects.add(edge_lines)
def lines_children(origins, targets, color="blue"):
material = p3js.LineBasicMaterial(color=color, linewidth=4)
scene_children = []
# For each 24 joint
for origin, target in zip(origins, targets):
geometry = p3js.Geometry(vertices=np.array([origin, target]).tolist())
line = p3js.Line(geometry, material)
scene_children.append(line)
return scene_children
def _render_obj(self, rendered_obj, **kw):
obj_geometry = pjs.BufferGeometry(attributes=dict(position=pjs.BufferAttribute(rendered_obj.plot_verts),
color=pjs.BufferAttribute(rendered_obj.base_cols),
normal=pjs.BufferAttribute(rendered_obj.face_normals.astype('float32'))))
vertices = rendered_obj.vertices
# Create a mesh. Note that the material need to be told to use the vertex colors.
my_object_mesh = pjs.Mesh(
geometry=obj_geometry,
material=pjs.MeshLambertMaterial(vertexColors='VertexColors'),
position=[0, 0, 0],
)
line_material = pjs.LineBasicMaterial(color='#ffffff', transparent=True, opacity=0.3, linewidth=1.0)
my_object_wireframe_mesh = pjs.LineSegments(
geometry=obj_geometry,
material=line_material,
position=[0, 0, 0],
)
n_vert = vertices.shape[0]
center = vertices.mean(axis=0)
extents = self._get_extents(vertices)
max_delta = np.max(extents[:, 1] - extents[:, 0])
camPos = [center[i] + 4 * max_delta for i in range(3)]
light_pos = [center[i] + (i+3)*max_delta for i in range(3)]
# Set up a scene and render it:
camera = pjs.PerspectiveCamera(position=camPos, fov=20,
pt3[ax2] += pt[1]
grid_verts.append(pt3)
grid_cols.append('#000000')
for seg in char_lns:
for pt in seg:
pt3 = [0, 0, 0]
pt3[iaxis] += ends[iaxis] + 2 * char_width
pt3[ax1] += pt[0] * char_width
pt3[ax2] += 1.2 * (pt[1] - 0.5) * char_width
grid_verts.append(pt3)
grid_cols.append('#000000')
lines_geom = pjs.Geometry(vertices=grid_verts, colors =grid_cols)
lines = pjs.LineSegments(geometry=lines_geom,
material=pjs.LineBasicMaterial(linewidth=self.grid_lines_width, transparent=True,
opacity=0.5, dashSize=10,
gapSize=10, vertexColors='VertexColors'),
type='LinePieces')
return lines, space
def __add_line_geometry(self, lines, shading, obj=None):
lines = lines.astype("float32", copy=False)
mi = np.min(lines, axis=0)
ma = np.max(lines, axis=0)
geometry = p3s.BufferGeometry(attributes={'position': p3s.BufferAttribute(lines, normalized=False)})
material = p3s.LineBasicMaterial(linewidth=shading["line_width"], color=shading["line_color"])
#, vertexColors='VertexColors'),
lines = p3s.LineSegments(geometry=geometry, material=material) #type='LinePieces')
line_obj = {"geometry": geometry, "mesh": lines, "material": material,
"max": ma, "min": mi, "type": "Lines", "wireframe": None}
if obj:
return self.__add_object(line_obj, obj), line_obj
else:
return self.__add_object(line_obj)
geometry = p3s.BufferGeometry(attributes=ba_dict)
if coloring == "VertexColors":
geometry.exec_three_obj_method('computeVertexNormals')
else:
geometry.exec_three_obj_method('computeFaceNormals')
# Mesh setup
mesh = p3s.Mesh(geometry=geometry, material=material)
# Wireframe setup
mesh_obj["wireframe"] = None
if sh["wireframe"]:
wf_geometry = p3s.WireframeGeometry(mesh.geometry) # WireframeGeometry
wf_material = p3s.LineBasicMaterial(color=sh["wire_color"], linewidth=sh["wire_width"])
wireframe = p3s.LineSegments(wf_geometry, wf_material)
mesh.add(wireframe)
mesh_obj["wireframe"] = wireframe
# Bounding box setup
if sh["bbox"]:
v_box, f_box = self.__get_bbox(v)
_, bbox = self.add_edges(v_box, f_box, sh, mesh)
mesh_obj["bbox"] = [bbox, v_box, f_box]
# Object setup
mesh_obj["max"] = np.max(v, axis=0)
mesh_obj["min"] = np.min(v, axis=0)
mesh_obj["geometry"] = geometry
mesh_obj["mesh"] = mesh
mesh_obj["material"] = material