コード例 #1
0
 def test_geometry_material2(self):
     viewer = MeshcatViewer()
     box = Shape.create_box([0.2] * 3, Material())
     box.set_user_data(dict(color='#00ff0000'))
     mat = viewer._get_shape_material(box)
     self.assertEqual(mat.color, int('00ff00', base=16))
     self.assertAlmostEqual(mat.opacity, 0.)
コード例 #2
0
 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)
コード例 #3
0
 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))
コード例 #4
0
 def test_geometry_material_texture(self):
     viewer = MeshcatViewer()
     box = Shape.create_box([0.2] * 3, Material())
     texture = g.ImageTexture(
         image=g.PngImage.from_file(Path(os.path.realpath(__file__)).parent.joinpath('data/texture.png'))
     )
     box.set_user_data(dict(visual_mesh_texture=texture))
     mat = viewer._get_shape_material(box)
     self.assertEqual(mat.map, texture)
     self.assertAlmostEqual(mat.opacity, 1.)
コード例 #5
0
ファイル: test_meshcat.py プロジェクト: HenryJk/pyphysx
    def test_render_to_animation(self):
        scene = Scene()
        actor = RigidDynamic()
        actor.attach_shape(Shape.create_box([0.2] * 3, Material()))
        scene.add_actor(actor)

        viewer = MeshcatViewer(render_to_animation=True, animation_fps=2)
        viewer.add_physx_scene(scene)
        viewer.update()
        viewer.update()
        actor.set_global_pose([1., 2., 3.])
        viewer.update()
        self.assertEqual(
            len(
                list(list(viewer.animation.clips.values())[0].tracks.values())
                [0].frames), 3)
        self.assertEqual(
            len(
                list(list(viewer.animation.clips.values())[0].tracks.values())
                [1].frames), 3)
        pos0 = list(list(
            viewer.animation.clips.values())[0].tracks.values())[0].values[0]
        pos2 = list(list(
            viewer.animation.clips.values())[0].tracks.values())[0].values[2]
        self.assertAlmostEqual(pos0[0], 0.)
        self.assertAlmostEqual(pos0[1], 0.)
        self.assertAlmostEqual(pos0[2], 0.)
        self.assertAlmostEqual(pos2[0], 1.)
        self.assertAlmostEqual(pos2[1], 2.)
        self.assertAlmostEqual(pos2[2], 3.)
コード例 #6
0
 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)
コード例 #7
0
    def test_scene_size(self):
        scene = Scene()
        actor = RigidDynamic()
        actor.attach_shape(Shape.create_box([0.2] * 3, Material()))
        scene.add_actor(actor)

        viewer = MeshcatViewer()
        viewer.add_physx_scene(scene)
        self.assertEqual(len(viewer.actors_and_offsets), 1)
        viewer.clear_physx_scenes()
        self.assertEqual(len(viewer.actors_and_offsets), 0)
コード例 #8
0
 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)
コード例 #9
0
 def test_vis_group(self):
     viewer = MeshcatViewer(object_prefix='asdf')
     self.assertEqual(viewer.vis_group.path.entries[-1], 'asdf')
コード例 #10
0
 def test_animation_fps(self):
     viewer = MeshcatViewer(render_to_animation=True, animation_fps=43)
     self.assertEqual(viewer.animation.default_framerate, 43)
コード例 #11
0
 def test_no_animation_default(self):
     viewer = MeshcatViewer()
     self.assertIsNone(viewer.animation)
コード例 #12
0
ファイル: 07_meshcat_viewer.py プロジェクト: HenryJk/pyphysx
        s.set_user_data(dict(color='tab:grey'))
    elif i in [0, 1, 4, 5]:
        s.set_user_data(dict(color='tab:green'))
    else:
        s.set_user_data(dict(color='green'))

actor.set_global_pose([0.5, -0.5, 1.0])
actor.set_mass(1.)
scene.add_actor(actor)

robot = URDFRobot("franka_panda/panda.urdf", kinematic=False, use_random_collision_colors=True)
robot.attach_root_node_to_pose([0.0, 0.0, 1.0])
q = dict()
for i, value in enumerate([0, -np.pi / 4, 0, -3 * np.pi / 4, 0, np.pi / 2, np.pi / 4]):
    q['panda_joint{}'.format(i + 1)] = value
robot.reset_pose(q)  # reset pose of all links based on default values for joints (0 m or 0 deg)
scene.add_aggregate(robot.get_aggregate())  # add robot into the scene, robot is an aggregate of actors with self


""" Create a viewer and add the scene into it. """
render = MeshcatViewer(wait_for_open=True, open_meshcat=True, show_frames=False)
render.add_physx_scene(scene)

""" Simulate forever. Note, that meschat viewer is always active. """
rate = Rate(120)
while render.is_active:
    robot.update(rate.period())
    scene.simulate(rate.period())
    render.update()
    rate.sleep()