Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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),
camera
)
renderer = Renderer(
camera=camera,
background="white",
background_opacity=1,
scene=scene2render,
controls=[controls],
width=500,
height=500,
antialias=True,
)
logger.debug("Start drawing to the notebook")
display(renderer)
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()
def on_dblclick(change):
if change['name'] == 'point':
try:
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
to plot.
rot: List of tuples. Each tuple describe an (Rx, Ry, Rz) rotation and
are applied in order to generate the first view of the window.
scale: (float) Scale factor applied to the rendered window
Returns:
pyjs renderer needed to show the image in the jupiter notebook.
"""
width,height=size
light = py3js.DirectionalLight(color='#ffffff',
intensity=.7,
position=[0, 1000,0])
alight = py3js.AmbientLight(color='#777777',)
# Set up a scene and render it:
#cam = py3js.PerspectiveCamera(position=[0, 0, 500], fov=70, children=[light], aspect=width / height)
pos = array((0, 0, 500))
for r in rot:
pos=dot(rot_z(r[2]),pos)
pos=dot(rot_y(r[1]),pos)
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)
renderer: a :class:`pythreejs.pythreejs.Renderer` instance
lines: a :class:`pythreejs.pythreejs.Line` object
Example
-------
>>> from IPython import display
>>> renderer, lines = view_3js(eptm)
>>> display(renderer)
"""
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
width=self.width,
height=self.height
# far=10 * orbit_radius,
# orthoFar=10 * orbit_radius
)
self.camera.up = camera_up
self.camera.mode = 'orthographic'
self.camera.position = camera_position
# Set up lights in every of the 8 corners of the global bounding box
positions = list(itertools.product(*[(-orbit_radius, orbit_radius)] * 3))
key_lights = [
DirectionalLight(color='white', position=position, intensity=0.12) for position in positions
]
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]
self.scene = Scene(children=environment + [self.pickable_objects])
# Set up Controllers
self.controller = OrbitControls(controlling=self.camera, target=camera_target, target0=camera_target)
# Update controller to instantiate camera position
self.camera.zoom = zoom
self._update()
self._camera = CombinedCamera(position=camera_position,
width=self._size[0], height=self._size[1],
far=10 * bb_diag, orthoFar=10 * bb_diag)
self._camera.up = (0.0, 0.0, 1.0)
self._camera.lookAt(camera_target)
self._camera.mode = 'orthographic'
self._camera_target = camera_target
self._camera.position = camera_position
# 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,
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)
display(renderer)