How to use the pythreejs.Geometry 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 cihologramas / pyoptools / pyoptools / gui / ipywidgets.py View on Github external
# Map the normals
    nfaces=[]
    for f in faces:
        p0 = points[f[0]]
        p1 = points[f[1]]
        p2 = points[f[2]]
        v0 = array(p1)-array(p0)
        v1 = array(p2)-array(p0)
        v3 = cross(v0, v1)
        v3 = tuple(v3 / sqrt(v3[0]**2 + v3[1]**2 + v3[2]**2))
        
        nfaces.append(f + [v3, color, None])
        
    # Create the geometry:
    
    surfaceGeometry = py3js.Geometry(vertices=vertices,
        faces=nfaces,
        #colors=vertexcolors
                           )
    
    
    #surfaceGeometry = py3js.SphereGeometry(radius=300, widthSegments=32, heightSegments=24)
    
    if wire:
        surfaceGeometry = py3js.WireframeGeometry(surfaceGeometry)
        
    # Calculate normals per face, for nice crisp edges:
    surfaceGeometry.exec_three_obj_method('computeFaceNormals')

    surfaceMaterial=py3js.MeshPhongMaterial( color=color,
                                             ambient="#050505", 
                                             specular="#ffffff",
github nickc92 / ViewSCAD / viewscad / renderer.py View on Github external
pt3 = [0, 0, 0]
                    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 hassony2 / obman_train / mano_train / visualize / visualizemeshes.py View on Github external
back_color = "red"
        mat_bak = p3js.MeshLambertMaterial(
            color=back_color, side="BackSide", transparent=True
        )
        mat_bak.opacity = obj_opacity
        surf_obj_back = p3js.Mesh(geometry=geo_obj, material=mat_bak)
        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 gt_obj_verts is not None:
        geo_obj = p3js.Geometry(
            vertices=gt_obj_verts.tolist(), faces=gt_obj_faces.tolist()
        )
        geo_obj.exec_three_obj_method("computeFaceNormals")
        mat = p3js.MeshLambertMaterial(
            color="orange", side="FrontSide", transparent=True
        )
        mat.opacity = obj_opacity
        surf_obj = p3js.Mesh(geometry=geo_obj, material=mat)
        mat_back = p3js.MeshLambertMaterial(
            color="#a91818", side="BackSide", transparent=True
        )
        mat_back.opacity = obj_opacity
        surf_obj_back = p3js.Mesh(geometry=geo_obj, material=mat_bak)
        scene_children.append(surf_obj)
        scene_children.append(surf_obj_back)
        if display_wireframe:
github cihologramas / pyoptools / pyoptools / gui / ipywidgets.py View on Github external
def ray2mesh(ray):
    rays=py3js.Group()

    w = ray.wavelength
    rc, gc, bc = wavelength2RGB(w)
    rc=int(255*rc)
    gc=int(255*gc)
    bc=int(255*bc)
    material = py3js.LineBasicMaterial(color = "#{:02X}{:02X}{:02X}".format(rc,gc,bc))



    rl = ray2list(ray)

    for r in rl:
        geometry = py3js.Geometry()
        geometry.vertices =  r
        line = py3js.Line( geometry, material)
        rays.add(line)

    return rays