def draw_box(self, box, color=None): geo = p3js.BoxBufferGeometry(width=box.xsize, height=box.zsize, depth=box.ysize, widthSegments=box.xsize, heightSegments=box.zsize, depthSegments=box.ysize) mat = material_from_color(color) mesh = p3js.Mesh(geometry=geo, material=mat) Tinit = Translation([box.xsize/2, box.ysize/2, box.zsize/2]) Sc, Sh, R, T, P = (Transformation.from_frame(box.frame) * Tinit).decompose() mesh.quaternion = R.quaternion.xyzw mesh.position = list(T.translation) self.geometry.append(mesh) return mesh
def _create_outline(self, axparams): """ Make a wireframe cube with tick labels """ box_geometry = p3.BoxBufferGeometry( axparams['x']["lims"][1] - axparams['x']["lims"][0], axparams['y']["lims"][1] - axparams['y']["lims"][0], axparams['z']["lims"][1] - axparams['z']["lims"][0]) edges = p3.EdgesGeometry(box_geometry) self.outline = p3.LineSegments( geometry=edges, material=p3.LineBasicMaterial(color='#000000'), position=axparams["centre"]) self.axticks = self._generate_axis_ticks_and_labels(axparams)
def test_box(): box = Box(10.0, 20.0, 30.0, name='box', color='blue', material="WATER") assert box.name == 'box' assert box.__str__() == 'Box box color:blue material:WATER depth:30.0 height:20.0 width:10.0' assert box.__repr__() == 'Box' assert box.width == 10.0 assert box.height == 20.0 assert box.depth == 30.0 assert box.color == 'blue' if p3js is not None: mesh = box._p3js_mesh() expected_mesh = p3js.Mesh(p3js.BoxBufferGeometry(width=10.0, height=20.0, depth=30.0), p3js.MeshStandardMaterial(color='blue'), name='box') assert repr(mesh) == repr(expected_mesh)
def create_outline(self): """ Make a wireframe cube with tick labels """ box_geometry = p3.BoxBufferGeometry( self.xminmax['x'][1] - self.xminmax['x'][0], self.xminmax['y'][1] - self.xminmax['y'][0], self.xminmax['z'][1] - self.xminmax['z'][0]) edges = p3.EdgesGeometry(box_geometry) outline = p3.LineSegments( geometry=edges, material=p3.LineBasicMaterial(color='#000000'), position=[ 0.5 * np.sum(self.xminmax['x']), 0.5 * np.sum(self.xminmax['y']), 0.5 * np.sum(self.xminmax['z']) ]) ticks_and_labels = self.generate_axis_ticks_and_labels() return outline, ticks_and_labels
def test_cube(): cube = Cube(10.0, name='cube', color='blue', material="WATER") assert cube.name == 'cube' assert cube.__str__() == 'Cube cube color:blue material:WATER length:10.0' assert cube.__repr__() == 'Cube' assert cube.length == 10.0 assert cube.color == 'blue' if p3js is not None: mesh = cube._p3js_mesh() expected_mesh = p3js.Mesh(p3js.BoxBufferGeometry(width=10.0, height=10.0, depth=10.0), p3js.MeshStandardMaterial(color='blue'), name='cube') assert repr(mesh) == repr(expected_mesh) cube.name = 'cube1' assert cube.name == 'cube1' cube.length = 16.0 assert cube.length == 16.0 cube.color = 'red' assert cube.color == 'red' assert cube.generate_dict() == { "color": "red", "type": "Cube", "name": "cube1", "length": 16.0, "material": "WATER" } assert isinstance(cube, Shape) if p3js is not None: mesh = cube._p3js_mesh() expected_mesh = p3js.Mesh(p3js.BoxBufferGeometry(width=16.0, height=16.0, depth=16.0), p3js.MeshStandardMaterial(color='red'), name='cube1') assert repr(mesh) == repr(expected_mesh) # testing unnamed cube = Cube(10.0, color='blue') assert cube.name == 'unnamed' expected = 'Cube unnamed color:blue material:default length:10.0' assert cube.__str__() == expected assert cube.__repr__() == 'Cube' cube = Cube(symbols('V')**(1.0 / 3.0)) actual = cube.generate_dict(constant_map={symbols('V'): 27.0}) assert actual == { "color": "grey", "type": "Cube", "name": "unnamed", "length": 3.0, "material": "default" } if p3js is not None: mesh = cube._p3js_mesh(constant_map={symbols('V'): 27.0}) expected_mesh = p3js.Mesh(p3js.BoxBufferGeometry(width=3.0, height=3.0, depth=3.0), p3js.MeshStandardMaterial(color='gray'), name='unnamed') assert repr(mesh) == repr(expected_mesh)