How to use the pythreejs.LineSegments function in pythreejs

To help you get started, we’ve selected a few pythreejs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github materialsproject / crystaltoolkit / crystal_toolkit / helpers / pythreejs_renderer.py View on Github external
surf_indices = BufferAttribute(
        array=np.array(index_list, dtype=np.uint16).ravel(),
        normalized=False)
    geometry = BufferGeometry(
        attributes={
            'position': surf_vertices,
            'index': surf_indices,
        })
    new_surface = Mesh(geometry=geometry,
                       material=MeshLambertMaterial(color=obj_args['color'],
                                                    side='DoubleSide',
                                                    transparent=transparent,
                                                    opacity=obj_args['opacity']))
    if draw_edges == True: 
        edges = EdgesGeometry(geometry)
        edges_lines = LineSegments(edges, LineBasicMaterial(color = obj_args['color']))
        return new_surface, edges_lines
    else:
        return new_surface, None
github skoch9 / meshplot / meshplot / Viewer.py View on Github external
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)
github tpaviot / pythonocc-core / src / Display / WebGl / jupyter_renderer.py View on Github external
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)
github nickc92 / ViewSCAD / viewscad / renderer.py View on Github external
pt3[ax1] += pt[0]
                    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
github nickc92 / ViewSCAD / viewscad / renderer.py View on Github external
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,
                                   children=[pjs.DirectionalLight(color='#ffffff',
github skoch9 / meshplot / meshplot / Viewer.py View on Github external
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
        mesh_obj["type"] = "Mesh"