How to use the pythreejs.MeshLambertMaterial 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
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 materialsproject / crystaltoolkit / crystal_toolkit / helpers / pythreejs_renderer.py View on Github external
render spheres
    """

    if ctk_scene.phiEnd and ctk_scene.phiStart:
        phi_length = ctk_scene.phiEnd - ctk_scene.phiStart
    else:
        phi_length = np.pi * 2

    return [
        Mesh(
            geometry=SphereBufferGeometry(radius=ctk_scene.radius,
                                          phiStart=ctk_scene.phiStart or 0,
                                          phiLength=phi_length,
                                          widthSegments=32,
                                          heightSegments=32),
            material=MeshLambertMaterial(color=ctk_scene.color),
            position=tuple(ipos),
        ) for ipos in ctk_scene.positions
    ]
github materialsproject / crystaltoolkit / crystal_toolkit / helpers / pythreejs_renderer.py View on Github external
index_list = [[itr*3, itr*3+1, itr*3+2] for itr in range(num_triangle)]
    # Vertex ositions as a list of lists
    surf_vertices = BufferAttribute(
        array=positions,
        normalized=False)
    # Indices
    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 materialsproject / crystaltoolkit / crystal_toolkit / helpers / pythreejs_renderer.py View on Github external
v1 = np.array(v1)
    vec = v1 - v0
    mid_point = (v0 + v1) / 2.0
    rot_vec = np.cross([0, 1, 0], vec)
    rot_vec_len = np.linalg.norm(rot_vec)
    rot_vec = rot_vec / rot_vec_len
    rot_arg = np.arccos(np.dot([0, 1, 0], vec) / np.linalg.norm(vec))
    new_bond = Mesh(
        geometry=CylinderBufferGeometry(
            radiusTop=obj_args['radius'],
            radiusBottom=obj_args['radius'],
            height=np.linalg.norm(v1 - v0),
            radialSegments=12,
            heightSegments=10,
        ),
        material=MeshLambertMaterial(color=obj_args['color']),
        position=tuple(mid_point),
    )
    rot = R.from_rotvec(rot_arg * rot_vec)
    quat = tuple(rot.as_quat())
    if any(isnan(itr_q) for itr_q in quat):
        new_bond.quaternion = (0, 0, 0, 0)
    else:
        new_bond.quaternion = quat

    return new_bond
github hassony2 / obman_train / mano_train / visualize / visualizemeshes.py View on Github external
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 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)]
github nickc92 / ViewSCAD / viewscad / renderer.py View on Github external
z_rot = np.arccos(v_norm.dot(np.array([0.0, 1.0, 0.0])))
    y_rot = np.arctan2(v[2], v[0])
    
    cyl_center = start_vec + cyl_height/2 * v_norm
    head_center = start_vec + (cyl_height + head_length/2) * v_norm
    cyl_geom = pjs.CylinderGeometry(radiusTop=width, radiusBottom=width, height=cyl_height)
    cyl_mesh.geometry = cyl_geom
    cyl_mesh.material = pjs.MeshLambertMaterial(color=color)
    cyl_mesh.position = cyl_center.tolist()
    cyl_mesh.setRotationFromMatrix([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0])
    cyl_mesh.rotateY(-y_rot)
    cyl_mesh.rotateZ(-z_rot)
    
    head_geom = pjs.CylinderGeometry(radiusTop=0.0, radiusBottom=head_width, height=head_length)
    head_mesh.geometry = head_geom
    head_mesh.material = pjs.MeshLambertMaterial(color=color)
    head_mesh.position = head_center.tolist()
    head_mesh.setRotationFromMatrix([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0])
    head_mesh.rotateY(-y_rot)
    head_mesh.rotateZ(-z_rot)