def cdmesh_type(self, cdmesh_type): if cdmesh_type is not None and cdmesh_type not in [ 'aabb', 'obb', 'convex_hull', 'triangles' ]: raise ValueError("Wrong mesh collision model type name!") self._cdmesh_type = cdmesh_type self._cdmesh = mcd.gen_cdmesh_vvnf(*self.extract_rotated_vvnf())
def __init__(self, initor, cdprimit_type='box', cdmesh_type='triangles', expand_radius=None, name="auto", userdefined_cdprimitive_fn=None, btransparency=True, btwosided=False): """ :param initor: :param btransparency: :param cdprimit_type: box, ball, cylinder, point_cloud, user_defined :param cdmesh_type: aabb, obb, convex_hull, triangulation :param expand_radius: :param name: :param userdefined_cdprimitive_fn: the collision primitive will be defined in the provided function if cdprimitive_type = external; protocal for the callback function: return CollisionNode, may have multiple CollisionSolid date: 201290312, 20201212 """ if isinstance(initor, CollisionModel): self._name = copy.deepcopy(initor.name) self._objpath = copy.deepcopy(initor.objpath) self._objtrm = copy.deepcopy(initor.objtrm) self._objpdnp = copy.deepcopy(initor.objpdnp) self._localframe = copy.deepcopy(initor.localframe) self._cdprimitive_type = copy.deepcopy(initor.cdprimitive_type) self._cdmesh_type = copy.deepcopy(initor.cdmesh_type) # TODO exceptions where both initor and types were set needs to be considered # also, copy.deepcopy is not used because it invokes a deprecated getdata method, # see my question&comments at https://discourse.panda3d.org/t/ode-odetrimeshdata-problem/28232 for details # weiwei, 20220105 self._cdmesh = mcd.copy_cdmesh(initor.cdmesh) else: super().__init__(initor=initor, name=name, btransparency=btransparency, btwosided=btwosided) self._cdprimitive_type, collision_node = self._update_cdprimit( cdprimit_type, expand_radius, userdefined_cdprimitive_fn) # use pdnp.getChild instead of a new self._cdnp variable as collision nodepath is not compatible with deepcopy self._objpdnp.attachNewNode(collision_node) self._objpdnp.getChild(1).setCollideMask(BitMask32(2**31)) self._cdmesh_type = cdmesh_type self._cdmesh = mcd.gen_cdmesh_vvnf(*self.extract_rotated_vvnf()) self._localframe = None
def __init__(self, initor, cdprimit_type='box', cdmesh_type='triangles', expand_radius=None, name="auto", userdefined_cdprimitive_fn=None, btransparency=True, btwosided=False): """ :param initor: :param btransparency: :param cdprimit_type: box, ball, cylinder, point_cloud, user_defined :param cdmesh_type: aabb, obb, convex_hull, triangulation :param expand_radius: :param name: :param userdefined_cdprimitive_fn: the collision primitive will be defined in the provided function if cdprimitive_type = external; protocal for the callback function: return CollisionNode, may have multiple CollisionSolid date: 201290312, 20201212 """ if isinstance(initor, CollisionModel): self._name = copy.deepcopy(initor.name) self._objpath = copy.deepcopy(initor.objpath) self._objtrm = copy.deepcopy(initor.objtrm) self._objpdnp = copy.deepcopy(initor.objpdnp) self._localframe = copy.deepcopy(initor.localframe) self._cdprimitive_type = copy.deepcopy(initor.cdprimitive_type) self._cdmesh_type = copy.deepcopy(initor.cdmesh_type) else: super().__init__(initor=initor, name=name, btransparency=btransparency, btwosided=btwosided) self._cdprimitive_type, collision_node = self._update_cdprimit( cdprimit_type, expand_radius, userdefined_cdprimitive_fn) # use pdnp.getChild instead of a new self._cdnp variable as collision nodepath is not compatible with deepcopy self._objpdnp.attachNewNode(collision_node) self._objpdnp.getChild(1).setCollideMask(BitMask32(2**31)) self._cdmesh_type = cdmesh_type self._localframe = None # reinit self._cdmesh while ignoring the initor types. # The reinit helps to avoid the annoying ode warning caused by deepcopy. self._cdmesh = mcd.gen_cdmesh_vvnf(*self.extract_rotated_vvnf())
def cdmesh(self): vertices = [] vertex_normals = [] faces = [] for objcm in self._cm_list: if objcm.cdmesh_type == 'aabb': objtrm = objcm.objtrm.bounding_box elif objcm.cdmesh_type == 'obb': objtrm = objcm.objtrm.bounding_box_oriented elif objcm.cdmesh_type == 'convexhull': objtrm = objcm.objtrm.convex_hull elif objcm.cdmesh_type == 'triangles': objtrm = objcm.objtrm homomat = objcm.get_homomat() vertices += rm.homomat_transform_points(homomat, objtrm.vertices) vertex_normals += rm.homomat_transform_points(homomat, objtrm.vertex_normals) faces += (objtrm.faces+len(faces)) return mcd.gen_cdmesh_vvnf(vertices, vertex_normals, faces)
def cdmesh(self): return mcd.gen_cdmesh_vvnf(*self.extract_rotated_vvnf())
def set_scale(self, scale=[1, 1, 1]): self._objpdnp.setScale(scale[0], scale[1], scale[2]) self._objtrm.apply_scale(scale) self._cdmesh = mcd.gen_cdmesh_vvnf(*self.extract_rotated_vvnf())