How to use the pythreejs.Scene 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 tpaviot / pythonocc-core / src / Display / WebGl / jupyter_renderer.py View on Github external
# Set up lights in every of the 8 corners of the global bounding box
        key_lights = [
            DirectionalLight(color='white', position=position, intensity=0.12)
            for position in list(itertools.product((-bb_diag, bb_diag), (-bb_diag, bb_diag), (-bb_diag, bb_diag)))
        ]
        ambient_light = AmbientLight(intensity=1.0)

        # Set up Helpers
        self.axes = Axes(bb_center=self._bb.center, length=bb_max * 1.1)
        self.grid = Grid(bb_center=self._bb.center, maximum=bb_max, colorCenterLine='#aaa', colorGrid='#ddd')

        # Set up scene
        environment = self.axes.axes + key_lights + [ambient_light, self.grid.grid, self._camera]

        scene_shp = Scene(children=[self._displayed_pickable_objects,
                                    self._displayed_non_pickable_objects] + environment)

        # Set up Controllers
        self._controller = OrbitControls(controlling=self._camera, target=camera_target)

        self._renderer = Renderer(camera=self._camera,
                                  background=self._background,
                                  background_opacity=self._background_opacity,
                                  scene=scene_shp,
                                  controls=[self._controller, self._picker],
                                  width=self._size[0],
                                  height=self._size[1],
                                  antialias=True)

        # needs to be done after setup of camera
        self.grid.set_rotation((math.pi / 2.0, 0, 0, "XYZ"))
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
github nickc92 / ViewSCAD / viewscad / renderer.py View on Github external
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()
        
        
        def on_dblclick(change):    
            if change['name'] == 'point':                
                try:
                    point = np.array(change['new'])
                    face = click_picker.faceIndex
                    face_points = rendered_obj.face_verts[face]                    
                    face_vecs = face_points - np.roll(face_points, 1, axis=0)
                    edge_lens = np.sqrt((face_vecs**2).sum(axis=1))
                    point_vecs = face_points - point[np.newaxis, :]
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 materialsproject / crystaltoolkit / crystal_toolkit / helpers / pythreejs_renderer.py View on Github external
def display_scene(scene):
    """Render the scene in the pythreeJS
    
    Arguments:
        scene {Object3D} -- Root node of the PythreeJS object we want to plot
    """
    obs = traverse_scene_object(scene)

    logger.debug(type(obs))
    scene2render = Scene(children=list(obs.children))
    logger.debug(len(scene2render.children))
    # cannot use the setFromObject function because the function call is asyncronous
    # https://github.com/jupyter-widgets/pythreejs/issues/282
    bounding_box = scene.bounding_box
    extent = max([p[1]-p[0] for p in zip(*bounding_box)]) * 1.2
    logger.debug(f"extent : {extent}")
    camera = OrthographicCamera(
        -extent, +extent, extent, -extent, -2000, 2000, position=[0,0,10]
    )
    cam_target = tuple(-i for i in scene.origin)
    controls = OrbitControls(target=cam_target, controlling=camera)
    camera.lookAt(cam_target)

    scene2render.children = scene2render.children + (
        AmbientLight(color="#cccccc", intensity=0.75),
        DirectionalLight(color="#ccaabb", position=[0, 20, 10], intensity=0.5),
github cihologramas / pyoptools / pyoptools / gui / ipywidgets.py View on Github external
pos=dot(rot_x(r[0]),pos)
    
    cam = py3js.OrthographicCamera(-width/2*scale,width/2*scale, height/2*scale,
                                   -height/2*scale,children=[light],
                                   position=list(pos),
                                   zoom=scale)

    if isinstance(S,System):
        c=sys2mesh(S)
    elif isinstance(S,Component):
        c=comp2mesh(S,(0,0,0),(0,0,0))
    else:
        c=surf2mesh(S,(0,0,0),(0,0,0))

        
    scene = py3js.Scene(children=[c, alight,cam],background="#000000")
    oc=py3js.OrbitControls(controlling=cam)
    oc.target=center
    renderer = py3js.Renderer(camera=cam, background='black', background_opacity=1,
                          scene=scene, controls=[oc],width=width*scale, height=height*scale)

    return(renderer)
github solvcon / solvcon / solvcon / vis / viewer.py View on Github external
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)