def read(cls, node): """ Get shape list from Bullet*Shape(s).""" # Get valid node. try: node = node.node() except AttributeError: pass # Get shapes. n_shapes = node.getNumShapes() if n_shapes == 0: # For no shape, return "". shapes = [] else: # For 1+ shapes. parent = node.getParent() node.detachNode() shapes = [] for i in xrange(n_shapes): # Get shape and shape's matrix. bshape = node.getShape(i) # Get name. name = cls.read_name(bshape) # Get params. Shape = cls._name2shape[name] params = Shape.read_params(bshape) # Get xform. xform = TransformState.makeMat(node.getShapeMat(i)) # Store. shapes.append((name, params, xform)) node.reparentTo(parent) return shapes
def test_boxshape_fix_xform(): # _fix_xform ident_T = TransformState.makeIdentity() X = None assert BoxShape._fix_xform(X) == ident_T X = () assert BoxShape._fix_xform(X) == ident_T X = Mat4.identMat() * 3 assert BoxShape._fix_xform(X) == TransformState.makeMat(X)
def _fix_xform(T): """ Converts T into a valid xform. Returns None on fail.""" # If T has "flat" attribute, it is an ndarray and that should # be returned. Otherwise just return T. if not T: xform = TransformState.makeIdentity() else: if not isinstance(T, TransformState): mat = Mat4(*T.flat) if hasattr(T, "flat") else Mat4(T) xform = TransformState.makeMat(mat) else: xform = T return xform