def edge_lines(sheet, coords, **draw_specs): spec = sheet_spec() spec.update(**draw_specs) up_srce = sheet.upcast_srce(sheet.vert_df[sheet.coords]) up_trgt = sheet.upcast_trgt(sheet.vert_df[sheet.coords]) vertices = np.hstack([up_srce.values, up_trgt.values]) vertices = vertices.reshape(vertices.shape[0] * 2, 3) colors = spec['vert']['color'] if isinstance(colors, str): colors = [colors for v in vertices] else: colors = np.asarray(colors) if (colors.shape == (sheet.Nv, 3)) or (colors.shape == (sheet.Nv, 4)): sheet.vert_df['hex_c'] = [mpl_colors.rgb2hex(c) for c in colors] srce_c = sheet.upcast_srce(sheet.vert_df['hex_c']) trgt_c = sheet.upcast_trgt(sheet.vert_df['hex_c']) colors = np.vstack([srce_c.values, trgt_c.values]).T.reshape(vertices.shape[0]) colors = list(colors) else: raise ValueError linesgeom = py3js.PlainGeometry(vertices=[list(v) for v in vertices], colors=colors) return py3js.Line(geometry=linesgeom, material=py3js.LineBasicMaterial( linewidth=spec['edge']['width'], vertexColors='VertexColors'), type='LinePieces')
def __init__(self, num_cells=5, color='#cccccc', linewidth=1, cellsize=0.5): Group.__init__(self) material = LineBasicMaterial(color=color, linewidth=linewidth) for i in range(num_cells + 1): edge = cellsize * num_cells / 2 position = edge - (i * cellsize) geometry_h = Geometry(vertices=[(-edge, position, 0), (edge, position, 0)]) geometry_v = Geometry(vertices=[(position, -edge, 0), (position, edge, 0)]) self.add(pythreejs.Line(geometry=geometry_h, material=material)) self.add(pythreejs.Line(geometry=geometry_v, material=material))
def add_view_frustum(): position = np.array(lm_camera_params['eye']) center = np.array(lm_camera_params['center']) up = np.array(lm_camera_params['up']) aspect = lm_camera_params['aspect'] fov = math.radians(lm_camera_params['vfov']) M = lookat_matrix(position, center, up) z = 5 half_fov = fov * .5 y = math.tan(half_fov) * z x = aspect * y p = list(position) p1 = list(position + np.dot(M, [-x, -y, -z])) p2 = list(position + np.dot(M, [x, -y, -z])) p3 = list(position + np.dot(M, [x, y, -z])) p4 = list(position + np.dot(M, [-x, y, -z])) # Add mesh geom = three.Geometry( vertices=[p, p1, p2, p, p2, p3, p, p3, p4, p, p4, p1]) mat = three.MeshBasicMaterial(color='#00ff00', wireframe=True, side='DoubleSide') mesh = three.Line(geometry=geom, material=mat) scene.add(mesh)
def display_path(th_scene, vs, **kwargs): """Display path.""" geom = three.Geometry(vertices=vs) mat_line = three.LineBasicMaterial(**kwargs) line = three.Line(geometry=geom, material=mat_line) th_scene.add(line) mat_points = three.PointsMaterial(**kwargs) points = three.Points(geometry=geom, material=mat_points) th_scene.add(points)
def lines_children(origins, targets, color="blue"): material = p3js.LineBasicMaterial(color=color, linewidth=4) scene_children = [] # For each 24 joint for origin, target in zip(origins, targets): geometry = p3js.Geometry(vertices=np.array([origin, target]).tolist()) line = p3js.Line(geometry, material) scene_children.append(line) return scene_children
def get_polylines_pythreejs(polylines): lines = [] for x in polylines: line_geometry = pythreejs.Geometry(vertices=x["vertices"]) line = pythreejs.Line( geometry=line_geometry, material=pythreejs.LineBasicMaterial(color=x["color"]), type='LinePieces') lines.append(line) return lines
def joint_children(joints3D, color="blue", links=None): material = p3js.LineBasicMaterial(color=color, linewidth=4) scene_children = [] # For each 24 joint if links is None: links = [ (0, 1, 2, 3, 4), (0, 5, 6, 7, 8), (0, 9, 10, 11, 12), (0, 13, 14, 15, 16), (0, 17, 18, 19, 20), ] for link in links: for j1, j2 in zip(link[0:-1], link[1:]): geometry = p3js.Geometry(vertices=joints3D[(j1, j2), :].tolist()) line = p3js.Line(geometry, material) scene_children.append(line) return scene_children
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
def axes_1d(x, y, color="#000000", linewidth=1.5): N = len(x) pts = np.zeros([5, 3]) xmin = np.amin(x) xmax = np.amax(x) ymin = np.amin(y) ymax = np.amax(y) pts[:, 0] = x pts[:, 1] = y geometry = p3.BufferGeometry(attributes={ 'position': p3.BufferAttribute(array=pts), }) material = p3.LineBasicMaterial(color=color, linewidth=linewidth) line = p3.Line(geometry=geometry, material=material) width = 800 height = 500
def ray2mesh(ray): rays = py3js.Group() if ray.draw_color is None: color = wavelength2RGB(ray.wavelength) else: color = colors.to_rgb(ray.draw_color) int_colors = [int(255 * c) for c in color] material = py3js.LineBasicMaterial(color="#{:02X}{:02X}{:02X}".format( *int_colors)) rl = ray2list(ray) for r in rl: geometry = py3js.Geometry() geometry.vertices = r line = py3js.Line(geometry, material) rays.add(line) return rays
def plot_1d(x, y, color="blue", linewidth=2, background="#DDDDDD"): if len(x) != len(y): raise RuntimeError("bad shape") N = len(x) dx = config.figure["width"] dy = config.figure["height"] xmin = np.amin(x) ymin = np.amin(y) scale_x = dx / (np.amax(x) - xmin) scale_y = dy / (np.amax(y) - ymin) pts = np.zeros([N, 3], dtype=np.float32) pts[:, 0] = (x - xmin) * scale_x pts[:, 1] = (y - ymin) * scale_y # arr = p3.BufferAttribute(array=pts) geometry = p3.BufferGeometry(attributes={ 'position': p3.BufferAttribute(array=pts), }) material = p3.LineBasicMaterial(color=color, linewidth=linewidth) line = p3.Line(geometry=geometry, material=material) # width = 800 # height= 500 # Create the threejs scene with ambient light and camera # camera = p3.PerspectiveCamera(position=[0.5*dx, 0.5*dy, 0], # aspect=dx / dy) camera = p3.OrthographicCamera(0, dx, dy, 0, 0.5 * dx, -0.5 * dx) return render(objects=line, camera=camera, background=background, enableRotate=False, width=dx, height=dy)
def axes(max_dist): """ Generate X, Y, Z axes of length max_width in the form of a pythreejs Line object. Parameters ---------- max_dist : float maximum extent of grid from origin in each dimension Returns ------- axes : pythreejs.Line a pythreejs Line object representing the xyz axes. """ axes_geom = p3j.Geometry( vertices=[[0, 0, 0], [max_dist, 0, 0], [0, 0, 0], [0, max_dist, 0], [0, 0, 0], [0, 0, max_dist]], colors=['white', 'white', 'white', 'white', 'white', 'white']) return p3j.Line(geometry=axes_geom, material=p3j.LineBasicMaterial( linewidth=1, vertexColors='VertexColors'))