How to use the pythreejs.PerspectiveCamera 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 DamCB / tyssue / tyssue / draw / threejs_draw.py View on Github external
spec = sheet_spec()
    spec.update(**draw_specs)
    children = [
        py3js.DirectionalLight(color="#ccaabb", position=[0, 5, 0]),
        py3js.AmbientLight(color="#cccccc"),
    ]

    if spec["edge"]["visible"]:
        lines = edge_lines(sheet, coords, **spec)
        children.append(lines)
    if spec["face"]["visible"]:
        faces = triangular_faces(sheet, coords, **spec)
        children.append(faces)

    scene = py3js.Scene(children=children)
    cam = py3js.PerspectiveCamera(position=[0, 5, 5])
    renderer = py3js.Renderer(
        camera=cam, scene=scene, controls=[py3js.OrbitControls(controlling=cam)]
    )
    return renderer, scene
github solvcon / solvcon / solvcon / vis / viewer.py View on Github external
def __init__(self, *args, **kw):

        camera = kw.pop('camera', None)
        if not camera:
            position = kw.pop('position', [0,0,0])
            up = kw.pop('up', [0,1,0])
            camera = ptjs.PerspectiveCamera(position=position, up=up)
        kw['camera'] = camera

        controls = kw.pop('controls', None)
        if not controls:
            controls = ptjs.TrackballControls(controlling=kw['camera'])
        kw['controls'] = [controls]

        scene = kw.pop('scene', None)
        if not scene:
            scene = ptjs.Scene()
        kw['scene'] = scene

        super(Viewer, self).__init__(*args, **kw)
github nickc92 / ViewSCAD / viewscad / renderer.py View on Github external
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',
                                   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())
github tpaviot / pythonocc-core / src / Display / WebGl / jupyter_renderer.py View on Github external
# create a mesh unique id
        mesh_id = uuid.uuid4().hex

        # finally create the mash
        shape_mesh = Mesh(geometry=mesh_geometry,
                          material=mesh_material,
                          name=mesh_id)
        edges_mesh = Mesh(geometry=mesh_geometry,
                          material=edges_material,
                          name=mesh_id)


        # a special display for the mesh
        camera_target = [0., 0., 0.]  # the point to look at
        camera_position = [0, 0., 100.]  # the camera initial position
        camera = PerspectiveCamera(position=camera_position,
                                   lookAt=camera_target,
                                   up=[0, 0, 1],
                                   fov=50,
                                   children=[DirectionalLight(color='#ffffff',
                                                              position=[50, 50, 50],
                                                              intensity=0.9)])
        scene_shp = Scene(children=[shape_mesh, edges_mesh, camera, AmbientLight(color='#101010')])

        renderer = Renderer(camera=camera,
                            background=self._background,
                            background_opacity=self._background_opacity,
                            scene=scene_shp,
                            controls=[OrbitControls(controlling=camera, target=camera_target)],
                            width=self._size[0],
                            height=self._size[1],
                            antialias=True)
github skoch9 / meshplot / meshplot / Viewer.py View on Github external
def __init__(self, settings):
        self.__update_settings(settings)
        self._light = p3s.DirectionalLight(color='white', position=[0, 0, 1], intensity=0.6)
        self._light2 = p3s.AmbientLight(intensity=0.5)
        self._cam = p3s.PerspectiveCamera(position=[0, 0, 1], lookAt=[0, 0, 0], fov=self.__s["fov"],
                                     aspect=self.__s["width"]/self.__s["height"], children=[self._light])
        self._orbit = p3s.OrbitControls(controlling=self._cam)
        self._scene = p3s.Scene(children=[self._cam, self._light2], background=self.__s["background"])#"#4c4c80"
        self._renderer = p3s.Renderer(camera=self._cam, scene = self._scene, controls=[self._orbit],
                    width=self.__s["width"], height=self.__s["height"], antialias=self.__s["antialias"])

        self.__objects = {}
        self.__cnt = 0