MCPcopy Create free account
hub / github.com/BerkeleyAutomation/meshrender / InstancedSceneObject

Class InstancedSceneObject

meshrender/scene_object.py:80–149  ·  view source on GitHub ↗

A scene object which consists as a set of identical objects.

Source from the content-addressed store, hash-verified

78 self._T_obj_world = T
79
80class InstancedSceneObject(SceneObject):
81 """A scene object which consists as a set of identical objects.
82 """
83 def __init__(self, mesh, poses=None, raw_pose_data=None, colors=None,
84 T_obj_world=None,
85 material=None,
86 enabled=True):
87 """Initialize a scene object with the given mesh, pose, and material.
88
89 Parameters
90 ----------
91 mesh : trimesh.Trimesh
92 A mesh representing the object's geometry.
93 poses : list of autolab_core.RigidTransform
94 A set of poses, one for each instance of the scene object,
95 relative to the full object's origin.
96 raw_pose_data : (4*n,4) float or None
97 A numpy array containing raw pose data, where each row is a column of a point's
98 homogenous transform matrix. If not present, poses must be present.
99 colors : (n,3) float or None
100 A set of colors for each instanced object. If None, the color specified in material
101 properties is used for all instances.
102 T_obj_world : autolab_core.RigidTransform
103 A rigid transformation from the object's frame to the world frame.
104 material : MaterialProperties
105 A set of material properties for the object.
106 enabled : bool
107 If False, the object will not be rendered.
108 """
109
110 super(InstancedSceneObject, self).__init__(mesh, T_obj_world, material, enabled)
111 self._poses = poses
112 self._raw_pose_data = raw_pose_data
113
114 if self._raw_pose_data is None:
115 if self._poses is None:
116 raise ValueError('Either poses or raw_pose_data must be specified')
117 self._raw_pose_data = np.zeros((4*len(self._poses), 4))
118 for i, pose in enumerate(self._poses):
119 self._raw_pose_data[i*4:(i+1)*4,:] = pose.matrix.T
120
121 self._n_instances = self._raw_pose_data.shape[0] // 4
122
123 self._colors = colors
124 if self._colors is None:
125 self._colors = np.tile(material.color, (self._n_instances,1))
126
127 @property
128 def poses(self):
129 """list of autolab_core.RigidTransform: A set of poses for each instance relative to the object's origin.
130 """
131 return self._poses
132
133 @property
134 def raw_pose_data(self):
135 """(4*n,4) float: Raw data for pose matrices.
136 """
137 return self._raw_pose_data

Callers 1

test_viewer.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected