Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
edge_list = list(
map(
lambda i_edge:
[tess.GetEdgeVertex(i_edge, i_vert) for i_vert in range(tess.ObjEdgeGetVertexCount(i_edge))],
range(tess.ObjGetEdgeCount())))
# END copy
if vertices is not None:
vertices_list = []
for vertex in vertices:
p = BRep_Tool.Pnt(vertex)
vertices_list.append((p.X(), p.Y(), p.Z()))
vertices_list = np.array(vertices_list, dtype=np.float32)
attributes = {"position": BufferAttribute(vertices_list, normalized=False)}
mat = PointsMaterial(color=vertex_color, sizeAttenuation=False, size=vertex_width)
geom = BufferGeometry(attributes=attributes)
points = Points(geometry=geom, material=mat)
if edges is not None:
start_discretize_time = self._start_timer()
edge_list = [discretize_edge(edge, self.edge_accuracy) for edge in edges]
self._stop_timer("discretize time",start_discretize_time)
if edge_list is not None:
edge_list = _flatten(list(map(_explode, edge_list)))
lines = LineSegmentsGeometry(positions=edge_list)
mat = LineMaterial(linewidth=edge_width, color=edge_color)
edge_lines = LineSegments2(lines, mat, name="edges_%d" % shape_index)
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],
)
def AddCurveToScene(self, shp, color):
""" shp is either a TopoDS_Wire or a TopodS_Edge.
"""
if is_edge(shp):
pnts = discretize_edge(shp)
elif is_wire(shp):
pnts = discretize_wire(shp)
np_edge_vertices = np.array(pnts, dtype=np.float32)
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=color, linewidth=2, fog=True)
edge_lines = LineSegments(geometry=edge_geometry, material=edge_material)
# Add geometries to pickable or non pickable objects
self._displayed_pickable_objects.add(edge_lines)
# then we build the vertex and faces collections as numpy ndarrays
np_vertices = np.array(vertices_position, dtype='float32')\
.reshape(int(number_of_vertices / 3), 3)
# Note: np_faces is just [0, 1, 2, 3, 4, 5, ...], thus arange is used
np_faces = np.arange(np_vertices.shape[0], dtype='uint32')
# compute normals
np_normals = np.array(tess.GetNormalsAsTuple(), dtype='float32').reshape(-1, 3)
if np_normals.shape != np_vertices.shape:
raise AssertionError("Wrong number of normals/shapes")
# build a BufferGeometry instance
shape_geometry = BufferGeometry(
attributes={
'position': BufferAttribute(np_vertices),
'index': BufferAttribute(np_faces),
'normal': BufferAttribute(np_normals)
})
shp_material = self._material(mesh_color, transparent=True, opacity=opacity)
shape_mesh = Mesh(geometry=shape_geometry, material=shp_material, name="mesh_%d" % shape_index)
if render_edges:
edge_list = list(
map(
lambda i_edge:
[tess.GetEdgeVertex(i_edge, i_vert) for i_vert in range(tess.ObjEdgeGetVertexCount(i_edge))],
range(tess.ObjGetEdgeCount())))
# END copy
if v.shape[1] == 2:
v = np.append(v, np.zeros([v.shape[0], 1]), 1)
# Type adjustment vertices
v = v.astype("float32", copy=False)
# Color setup
colors, coloring = self.__get_colors(v, f, c, sh)
# Type adjustment faces and colors
c = colors.astype("float32", copy=False)
# Material and geometry setup
ba_dict = {"color": p3s.BufferAttribute(c)}
if coloring == "FaceColors":
verts = np.zeros((f.shape[0]*3, 3), dtype="float32")
for ii in range(f.shape[0]):
#print(ii*3, f[ii])
verts[ii*3] = v[f[ii,0]]
verts[ii*3+1] = v[f[ii,1]]
verts[ii*3+2] = v[f[ii,2]]
v = verts
else:
f = f.astype("uint32", copy=False).ravel()
ba_dict["index"] = p3s.BufferAttribute(f, normalized=False)
ba_dict["position"] = p3s.BufferAttribute(v, normalized=False)
if type(uv) != type(None):
uv = (uv - np.min(uv)) / (np.max(uv) - np.min(uv))
np_vertices = np.array(vertices_position, dtype='float32')\
.reshape(int(number_of_vertices / 3), 3)
# Note: np_faces is just [0, 1, 2, 3, 4, 5, ...], thus arange is used
np_faces = np.arange(np_vertices.shape[0], dtype='uint32')
# compute normals
np_normals = np.array(tess.GetNormalsAsTuple(), dtype='float32').reshape(-1, 3)
if np_normals.shape != np_vertices.shape:
raise AssertionError("Wrong number of normals/shapes")
# build a BufferGeometry instance
shape_geometry = BufferGeometry(
attributes={
'position': BufferAttribute(np_vertices),
'index': BufferAttribute(np_faces),
'normal': BufferAttribute(np_normals)
})
shp_material = self._material(mesh_color, transparent=True, opacity=opacity)
shape_mesh = Mesh(geometry=shape_geometry, material=shp_material, name="mesh_%d" % shape_index)
if render_edges:
edge_list = list(
map(
lambda i_edge:
[tess.GetEdgeVertex(i_edge, i_vert) for i_vert in range(tess.ObjEdgeGetVertexCount(i_edge))],
range(tess.ObjGetEdgeCount())))
# END copy
if vertices is not None: