def test_geometry_shape_visual(self): viewer = MeshcatViewer() s = Shape.create_sphere(0.5, Material()) import trimesh.creation obj = trimesh.creation.uv_sphere(0.5) geom = viewer._get_shape_geometry(s) self.assertTrue(isinstance(geom, g.Sphere)) s.set_user_data(dict(visual_mesh=obj)) geom = viewer._get_shape_geometry(s) self.assertTrue(isinstance(geom, g.MeshGeometry))
def test_geometry_shape_box(self): viewer = MeshcatViewer() s = Shape.create_box([0.2, 0.1, 0.05], Material()) g = viewer._get_shape_geometry(s) self.assertAlmostEqual(g.lengths[0], 0.2) self.assertAlmostEqual(g.lengths[1], 0.1) self.assertAlmostEqual(g.lengths[2], 0.05)
def test_geometry_shape_convex_shape(self): viewer = MeshcatViewer() points = np.random.randn(10, 3) s = Shape.create_convex_mesh_from_points(points, Material()) g = viewer._get_shape_geometry(s) pmin = np.min(points, axis=0) pmax = np.max(points, axis=0) gmin = np.min(g.vertices, axis=0) gmax = np.max(g.vertices, axis=0) self.assertAlmostEqual(pmin[0], gmin[0], places=5) self.assertAlmostEqual(pmin[1], gmin[1], places=5) self.assertAlmostEqual(pmin[2], gmin[2], places=5) self.assertAlmostEqual(pmax[0], gmax[0], places=5) self.assertAlmostEqual(pmax[1], gmax[1], places=5) self.assertAlmostEqual(pmax[2], gmax[2], places=5)
def test_geometry_shape_sphere(self): viewer = MeshcatViewer() s = Shape.create_sphere(0.5, Material()) g = viewer._get_shape_geometry(s) self.assertAlmostEqual(g.radius, 0.5)