Пример #1
0
def gen_frame(pos=np.array([0, 0, 0]),
              rotmat=np.eye(3),
              length=.1,
              thickness=.005,
              rgbmatrix=None,
              alpha=None,
              plotname="frame"):
    """
    gen an axis for attaching
    :param pos:
    :param rotmat:
    :param length:
    :param thickness:
    :param rgbmatrix: each column indicates the color of each base
    :param plotname:
    :return:
    author: weiwei
    date: 20161212tsukuba, 20191228osaka
    """
    endx = pos + rotmat[:, 0] * length
    endy = pos + rotmat[:, 1] * length
    endz = pos + rotmat[:, 2] * length
    if rgbmatrix is None:
        rgbx = np.array([1, 0, 0])
        rgby = np.array([0, 1, 0])
        rgbz = np.array([0, 0, 1])
    else:
        rgbx = rgbmatrix[:, 0]
        rgby = rgbmatrix[:, 1]
        rgbz = rgbmatrix[:, 2]
    if alpha is None:
        alphax = alphay = alphaz = 1
    elif isinstance(alpha, np.ndarray):
        alphax = alpha[0]
        alphay = alpha[1]
        alphaz = alpha[2]
    else:
        alphax = alphay = alphaz = alpha
    # TODO 20201202 change it to StaticGeometricModelCollection
    frame_nodepath = NodePath(plotname)
    arrowx_trm = trihelper.gen_arrow(spos=pos, epos=endx, thickness=thickness)
    arrowx_nodepath = da.trimesh_to_nodepath(arrowx_trm)
    arrowx_nodepath.setTransparency(TransparencyAttrib.MDual)
    arrowx_nodepath.setColor(rgbx[0], rgbx[1], rgbx[2], alphax)
    arrowy_trm = trihelper.gen_arrow(spos=pos, epos=endy, thickness=thickness)
    arrowy_nodepath = da.trimesh_to_nodepath(arrowy_trm)
    arrowy_nodepath.setTransparency(TransparencyAttrib.MDual)
    arrowy_nodepath.setColor(rgby[0], rgby[1], rgby[2], alphay)
    arrowz_trm = trihelper.gen_arrow(spos=pos, epos=endz, thickness=thickness)
    arrowz_nodepath = da.trimesh_to_nodepath(arrowz_trm)
    arrowz_nodepath.setTransparency(TransparencyAttrib.MDual)
    arrowz_nodepath.setColor(rgbz[0], rgbz[1], rgbz[2], alphaz)
    arrowx_nodepath.reparentTo(frame_nodepath)
    arrowy_nodepath.reparentTo(frame_nodepath)
    arrowz_nodepath.reparentTo(frame_nodepath)
    frame_sgm = StaticGeometricModel(frame_nodepath)
    return frame_sgm
Пример #2
0
def drawanySingleSurface(base, vertices, color):
    '''
    draw a surface using a calculated fourth point to creat a hull
    :param base:
    :param vertices:
    :param faces:
    :param color:
    :return:
    '''
    # print("faces in plotsurface",faces)

    surface_vertices = vertices
    # surface = humath.centerPoftrangle(surface_vertices[0][:3], surface_vertices[1][:3], surface_vertices[2][:3])
    surface = trimesh.Trimesh(surface_vertices)
    surface = surface.convex_hull
    surface = da.trimesh_to_nodepath(surface)
    surface.set_color(color)
    surface.reparentTo(base.render)
Пример #3
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