Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numpy type bug #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions urdfpy/urdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -3221,14 +3221,15 @@ 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:
if visual.geometry.mesh.scale is not 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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand All @@ -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()

Expand Down