Beispiel #1
0
def test_pso_create_shape():
    ts1 = TransformState.makePos((1, 3, 5))
    ts2 = TransformState.makePos((2, 4, 6))
    par2 = (Vec3(4, 1, 7), )
    obj0 = RBSO("0")
    obj1 = RBSO("1")
    obj2 = RBSO("2")
    obj0.set_shape("Box")
    obj1.set_shape(("Box", (), ts1))
    obj2.set_shape(("Box", par2, ts2))
    obj0.create_shape()
    obj1.create_shape()
    obj2.create_shape()
    sh0 = obj0.node().getShape(0)
    sh1 = obj1.node().getShape(0)
    sh2 = obj2.node().getShape(0)
    assert isinstance(sh0, BulletBoxShape)
    assert isinstance(sh1, BulletBoxShape)
    assert isinstance(sh2, BulletBoxShape)
    assert obj0.node().getShapeMat(0) == Mat4.identMat()
    assert obj1.node().getShapeMat(0) == ts1.getMat()
    assert obj2.node().getShapeMat(0) == ts2.getMat()
    assert sh0.getHalfExtentsWithMargin() == Vec3(0.5, 0.5, 0.5)
    assert sh1.getHalfExtentsWithMargin() == Vec3(0.5, 0.5, 0.5)
    assert sh2.getHalfExtentsWithMargin() == par2
Beispiel #2
0
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)
Beispiel #3
0
 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
Beispiel #4
0
 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
Beispiel #5
0
 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
Beispiel #6
0
 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
Beispiel #7
0
def test_boxshape_shift():
    S0 = BoxShape()
    args = Vec3(1, 2, 3)
    S1 = BoxShape([args])
    pos = Vec3(10, 20, 30)
    quat = Quat(1, 1, 0, 0)
    quat.normalize()
    ones = Vec3(1, 1, 1)
    T = TransformState.makePosQuatScale(pos, quat, ones)
    S0.shift(pos=pos, quat=quat)
    S1.shift(pos=pos, quat=quat)
    S1.shift(pos=pos, quat=quat)
    assert S0[1] == T
    assert S1[1] == T.compose(T)
Beispiel #8
0
def test_boxshape_transform():
    args = Vec3(1, 2, 3)
    S0 = BoxShape([args])
    scale = Vec3(5, 6, 7)
    pos = Vec3(10, 20, 30)
    quat = Quat(1, 1, 0, 0)
    quat.normalize()
    ones = Vec3(1, 1, 1)
    rbso = RBSO("rbso")
    rbso.set_scale(scale)
    rbso.set_pos(pos)
    rbso.set_quat(quat)
    S0.transform(rbso)
    T = TransformState.makePosQuatScale(pos, quat, ones)
    assert S0[0][0] == Vec3(*imap(mul, args, scale))
    assert S0[1] == T
Beispiel #9
0
 def shift(self, pos=(0, 0, 0), quat=(1, 0, 0, 0)):
     """ Translate and rotate shape's transform."""
     ones = Vec3(1, 1, 1)
     T = TransformState.makePosQuatScale(pos, quat, ones)
     xform = T.compose(self[1])
     self[1] = xform
Beispiel #10
0
def test_pso_get_shape():
    shape = ("Box", (Vec3(4, 1, 7), ), TransformState.makePos((2, 4, 6)))
    obj = RBSO("rso")
    obj.set_shape(shape)
    assert obj.get_shape() == shape
Beispiel #11
0
 def shift(self, pos=(0, 0, 0), quat=(1, 0, 0, 0)):
     """ Translate and rotate shape's transform."""
     ones = Vec3(1, 1, 1)
     T = TransformState.makePosQuatScale(pos, quat, ones)
     xform = T.compose(self[1])
     self[1] = xform