Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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],
ba_dict["position"] = p3s.BufferAttribute(v, normalized=False)
if type(uv) != type(None):
uv = (uv - np.min(uv)) / (np.max(uv) - np.min(uv))
tex = p3s.DataTexture(data=gen_checkers(20, 20), format="RGBFormat", type="FloatType")
material = p3s.MeshStandardMaterial(map=tex, reflectivity=sh["reflectivity"], side=sh["side"],
roughness=sh["roughness"], metalness=sh["metalness"], flatShading=sh["flat"],
polygonOffset=True, polygonOffsetFactor= 1, polygonOffsetUnits=5)
ba_dict["uv"] = p3s.BufferAttribute(uv.astype("float32", copy=False))
else:
material = p3s.MeshStandardMaterial(vertexColors=coloring, reflectivity=sh["reflectivity"],
side=sh["side"], roughness=sh["roughness"], metalness=sh["metalness"],
flatShading=sh["flat"],
polygonOffset=True, polygonOffsetFactor= 1, polygonOffsetUnits=5)
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)
[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)
if shape_mesh is not None or edge_lines is not None or points is not None:
index_mapping = {"mesh": None, "edges": None, "shape": shape_index}
if shape_mesh is not None:
for j in range(3):
node = face.GetNode(j)
#print('Coordinates of node %i:(%f,%f,%f)'%(i, node.X(), node.Y(), node.Z()))
vertices_position.append(node.X())
vertices_position.append(node.Y())
vertices_position.append(node.Z())
number_of_vertices = len(vertices_position)
# 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')
# set geometry properties
buffer_geometry_properties = {'position': BufferAttribute(np_vertices),
'index' : BufferAttribute(np_faces)}
# build a BufferGeometry instance
mesh_geometry = BufferGeometry(attributes=buffer_geometry_properties)
mesh_geometry.exec_three_obj_method('computeVertexNormals')
# then a default material
mesh_material = MeshPhongMaterial(color=color,
polygonOffset=True,
polygonOffsetFactor=1,
polygonOffsetUnits=1,
shininess=0.5,
wireframe=False,
side='DoubleSide')
edges_material = MeshPhongMaterial(color='black',
polygonOffset=True,
polygonOffsetFactor=1,
polygonOffsetUnits=1,
shininess=0.5,
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)