How to use the pythreejs.Mesh 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 nickc92 / ViewSCAD / viewscad / renderer.py View on Github external
camera = pjs.PerspectiveCamera(position=camPos, fov=20,
                                   children=[pjs.DirectionalLight(color='#ffffff',
                                   position=light_pos, intensity=0.5)])
        camera.up = (0,0,1)

        v = [0.0, 0.0, 0.0]
        if n_vert > 0: v = vertices[0].tolist()
        select_point_geom = pjs.SphereGeometry(radius=1.0)
        select_point_mesh = pjs.Mesh(select_point_geom,
                 material=pjs.MeshBasicMaterial(color=SELECTED_VERTEX_COLOR),
                 position=v, scale=(0.0, 0.0, 0.0))
        
        #select_edge_mesh = pjs.ArrowHelper(dir=pjs.Vector3(1.0, 0.0, 0.0), origin=pjs.Vector3(0.0, 0.0, 0.0), length=1.0,
        #                                  hex=SELECTED_EDGE_COLOR_INT, headLength=0.1, headWidth=0.05)
        
        arrow_cyl_mesh = pjs.Mesh(geometry=pjs.SphereGeometry(radius=0.01), material=pjs.MeshLambertMaterial())
        arrow_head_mesh = pjs.Mesh(geometry=pjs.SphereGeometry(radius=0.001), material=pjs.MeshLambertMaterial())
        
        scene_things = [my_object_mesh, my_object_wireframe_mesh, select_point_mesh, arrow_cyl_mesh, arrow_head_mesh,
                        camera, pjs.AmbientLight(color='#888888')]
        
        if self.draw_grids:
            grids, space = self._get_grids(vertices)
            scene_things.append(grids)

        scene = pjs.Scene(children=scene_things, background=BACKGROUND_COLOR)
        
        
        click_picker = pjs.Picker(controlling=my_object_mesh, event='dblclick')
        out = Output()
        top_msg = HTML()
github hassony2 / obman_train / mano_train / visualize / visualizemeshes.py View on Github external
scene_children.append(surf_obj)
        scene_children.append(surf_obj_back)
        if display_wireframe:
            obj_edges = p3js.Mesh(
                geometry=geo_obj,
                material=p3js.MeshBasicMaterial(color="black", wireframe=True),
            )
            scene_children.append(obj_edges)
    if hand_verts is not None:
        geo_hand = p3js.Geometry(
            vertices=hand_verts.tolist(), faces=mano_faces_left.tolist()
        )
        geo_hand.exec_three_obj_method("computeFaceNormals")
        mat = p3js.MeshLambertMaterial(color="blue", side="FrontSide", transparent=True)
        mat.opacity = hand_opacity
        surf_hand = p3js.Mesh(geometry=geo_hand, material=mat)
        bak_mat = p3js.MeshLambertMaterial(
            color="blue", side="BackSide", transparent=True
        )
        bak_mat.opacity = hand_opacity
        surf_hand_bak = p3js.Mesh(geometry=geo_hand, material=bak_mat)

        scene_children.append(surf_hand)
        scene_children.append(surf_hand_bak)
        if display_wireframe:
            hand_edges = p3js.Mesh(
                geometry=geo_hand,
                material=p3js.MeshBasicMaterial(color="black", wireframe=True),
            )
            scene_children.append(hand_edges)

    return scene_children
github cihologramas / pyoptools / pyoptools / gui / ipywidgets.py View on Github external
# Calculate normals per face, for nice crisp edges:
    surfaceGeometry.exec_three_obj_method('computeFaceNormals')

    surfaceMaterial=py3js.MeshPhongMaterial( color=color,
                                             ambient="#050505", 
                                             specular="#ffffff",
                                             shininess= 15,
                                             emissive="#000000",
                                             side='DoubleSide',
                                             transparent = True,
                                             opacity=.8)
    #surfaceMaterial = py3js.MeshLambertMaterial(color='red',side='DoubleSide')
    
    # Create a mesh. Note that the material need to be told to use the vertex colors.
    surfaceMesh = py3js.Mesh(
        geometry=surfaceGeometry,
        material= surfaceMaterial,)
    
    surfaceMesh.rotation=*D,"ZYX"
    surfaceMesh.position=tuple(P)
    return surfaceMesh
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)
github DamCB / tyssue / tyssue / draw / threejs_draw.py View on Github external
spec.update(**draw_specs)
    if "visible" in sheet.face_df.columns:
        vis_e = sheet.upcast_face(sheet.face_df["visible"])
        faces = sheet.edge_df[vis_e][["srce", "trgt", "face"]]
    else:
        faces = sheet.edge_df[["srce", "trgt", "face"]].copy()

    vertices = np.vstack([sheet.vert_df[coords], sheet.face_df[coords]])
    vertices = vertices.reshape((-1, 3))
    faces["face"] += sheet.Nv

    facesgeom = py3js.PlainGeometry(
        vertices=[list(v) for v in vertices], faces=[list(f) for f in faces.values]
    )

    return py3js.Mesh(geometry=facesgeom, material=py3js.LambertMaterial())