diff --git a/urdfpy/urdf.py b/urdfpy/urdf.py index 14b0216..68ca7bf 100644 --- a/urdfpy/urdf.py +++ b/urdfpy/urdf.py @@ -895,7 +895,7 @@ def color(self): @color.setter def color(self, value): if value is not None: - value = np.asanyarray(value).astype(np.float) + value = np.asanyarray(value).astype(float) value = np.clip(value, 0.0, 1.0) if value.shape != (4,): raise ValueError('Color must be a (4,) float') @@ -3221,6 +3221,7 @@ def visual_trimesh_fk(self, cfg=None, links=None): fk = OrderedDict() for link in lfk: for visual in link.visuals: + material = visual.material for mesh in visual.geometry.meshes: pose = lfk[link].dot(visual.origin) if visual.geometry.mesh is not None: @@ -3228,7 +3229,7 @@ def visual_trimesh_fk(self, cfg=None, links=None): S = np.eye(4, dtype=np.float64) S[:3,:3] = np.diag(visual.geometry.mesh.scale) pose = pose.dot(S) - fk[mesh] = pose + fk[mesh] = pose, material return fk def visual_trimesh_fk_batch(self, cfgs=None, links=None): @@ -3361,7 +3362,7 @@ def collision_trimesh_fk(self, cfg=None, links=None): pose = lfk[link] cm = link.collision_mesh if cm is not None: - fk[cm] = pose + fk[cm] = pose, None return fk def collision_trimesh_fk_batch(self, cfgs=None, links=None): @@ -3511,9 +3512,14 @@ def animate(self, cfg_trajectory=None, loop_time=3.0, use_collision=False): node_map = {} scene = pyrender.Scene() - for tm in fk: - pose = fk[tm] - mesh = pyrender.Mesh.from_trimesh(tm, smooth=False) + for tm, (pose, material) in fk.items(): + render_mat = pyrender.material.MetallicRoughnessMaterial( + alphaMode='BLEND', + baseColorFactor=material.color, + metallicFactor=1.0, + roughnessFactor=0.8, + ) + mesh = pyrender.Mesh.from_trimesh(tm, smooth=False, material=render_mat) node = scene.add(mesh, pose=pose) node_map[tm] = node @@ -3537,8 +3543,7 @@ def animate(self, cfg_trajectory=None, loop_time=3.0, use_collision=False): fk = self.visual_trimesh_fk(cfg=cfg) v.render_lock.acquire() - for mesh in fk: - pose = fk[mesh] + for mesh, (pose, material) in fk.items(): node_map[mesh].matrix = pose v.render_lock.release()