Ejemplo n.º 1
0
def gen_pointcloud(points, rgbas=[[0, 0, 0, .7]], pntsize=3):
    """
    do not use this raw function directly
    use environment.collisionmodel to call it
    gen objmnp
    :param points: nx3 list
    :param rgbas: None; Specify for each point; Specify a unified color
    :return:
    """
    pointcloud_nodepath = da.nodepath_from_points(points, rgbas)
    pointcloud_nodepath.setRenderMode(RenderModeAttrib.MPoint, pntsize)
    pointcloud_sgm = StaticGeometricModel(pointcloud_nodepath)
    return pointcloud_sgm
Ejemplo n.º 2
0
 def __init__(self,
              initor=None,
              name="defaultname",
              btransparency=True,
              btwosided=False):
     """
     :param initor: path type defined by os.path or trimesh or nodepath
     :param btransparency
     :param name
     """
     if isinstance(initor, StaticGeometricModel):
         self._objpath = copy.deepcopy(initor.objpath)
         self._objtrm = copy.deepcopy(initor.objtrm)
         self._objpdnp = copy.deepcopy(initor.objpdnp)
         self._name = copy.deepcopy(initor.name)
         self._localframe = copy.deepcopy(initor.localframe)
     else:
         # make a grandma nodepath to separate decorations (-autoshader) and raw nodepath (+autoshader)
         self._name = name
         self._objpdnp = NodePath(name)
         if isinstance(initor, str):
             self._objpath = initor
             self._objtrm = da.trm.load(self._objpath)
             objpdnp_raw = da.trimesh_to_nodepath(self._objtrm,
                                                  name='pdnp_raw')
             objpdnp_raw.reparentTo(self._objpdnp)
         elif isinstance(initor, da.trm.Trimesh):
             self._objpath = None
             self._objtrm = initor
             objpdnp_raw = da.trimesh_to_nodepath(self._objtrm)
             objpdnp_raw.reparentTo(self._objpdnp)
         elif isinstance(initor, o3d.geometry.PointCloud
                         ):  # TODO should pointcloud be pdnp or pdnp_raw
             self._objpath = None
             self._objtrm = da.trm.Trimesh(np.asarray(initor.points))
             objpdnp_raw = da.nodepath_from_points(self._objtrm.vertices,
                                                   name='pdnp_raw')
             objpdnp_raw.reparentTo(self._objpdnp)
         elif isinstance(
                 initor,
                 np.ndarray):  # TODO should pointcloud be pdnp or pdnp_raw
             self._objpath = None
             if initor.shape[1] == 3:
                 self._objtrm = da.trm.Trimesh(initor)
                 objpdnp_raw = da.nodepath_from_points(
                     self._objtrm.vertices)
             elif initor.shape[1] == 7:
                 self._objtrm = da.trm.Trimesh(initor[:, :3])
                 objpdnp_raw = da.nodepath_from_points(
                     self._objtrm.vertices, initor[:, 3:].tolist())
                 objpdnp_raw.setRenderMode(RenderModeAttrib.MPoint, 3)
             else:
                 # TODO depth UV?
                 raise NotImplementedError
             objpdnp_raw.reparentTo(self._objpdnp)
         elif isinstance(initor, o3d.geometry.TriangleMesh):
             self._objpath = None
             self._objtrm = da.trm.Trimesh(
                 vertices=initor.vertices,
                 faces=initor.triangles,
                 face_normals=initor.triangle_normals)
             objpdnp_raw = da.trimesh_to_nodepath(self._objtrm,
                                                  name='pdnp_raw')
             objpdnp_raw.reparentTo(self._objpdnp)
         elif isinstance(initor, NodePath):
             self._objpath = None
             self._objtrm = None  # TODO nodepath to trimesh?
             objpdnp_raw = initor
             objpdnp_raw.reparentTo(self._objpdnp)
         else:
             self._objpath = None
             self._objtrm = None
             objpdnp_raw = NodePath("pdnp_raw")
             objpdnp_raw.reparentTo(self._objpdnp)
         if btransparency:
             self._objpdnp.setTransparency(TransparencyAttrib.MDual)
         if btwosided:
             self._objpdnp.getChild(0).setTwoSided(True)
         self._localframe = None