Example #1
0
def test_destroy_resources_model_shape():
    gso = GSO("bar")
    gso.set_model("smiley.egg")
    gso.init_resources()
    gso.destroy_resources()
    gnodes = gso.descendants(depths=slice(1, None))
    pso = RBSO("bar")
    pso.set_shape("Box")
    pso.init_resources()
    pso.destroy_resources()
    assert not any(isinstance(n.node(), resource_types) for n in gnodes)
    assert pso.node().getNumShapes() == 0
Example #2
0
def test_res_tags():
    sso = SSO("sso")
    gso = GSO("gso")
    brso = RBSO("pso")
    assert set(sso.res_tags) == set(SSO._res_tags)
    assert set(gso.res_tags) == set(SSO._res_tags + GSO._res_tags)
    assert set(brso.res_tags) == set(SSO._res_tags + PSO._res_tags +
                                     RBSO._res_tags)
Example #3
0
def test_cpso_add():
    c = 3.
    n = 3
    cpso = CPSO("foo")
    objs = [RBSO(str(i)) for i in xrange(n)]
    for obj in objs:
        obj.setPos((c * i - c, 0, 0))
        obj.set_shape("Box")
    cpso.add(objs)
    assert len(cpso.getChildren()) == n
Example #4
0
def test_cpso_remove():
    c = 3.
    n = 4
    cpso = CPSO("foo")
    objs = [RBSO(str(i)) for i in xrange(n)]
    for obj in objs:
        obj.setPos((c * (i - np.floor(n / 2.)), 0, 0))
        obj.set_shape("Box")
    cpso.add(objs)
    assert len(cpso.getChildren()) == n
    cpso.remove(objs[:-2])
    assert len(cpso.getChildren()) == 2
Example #5
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
Example #6
0
def test_cpso_destroy_component_shapes():
    c = 3.
    n = 4
    cpso = CPSO("foo")
    objs = [RBSO(str(i)) for i in xrange(n)]
    for obj in objs:
        obj.setPos((c * (i - np.floor(n / 2.)), 0, 0))
        obj.set_shape("Box")
        obj.init_resources(tags=("shape", ))
    cpso.add(objs)
    for obj in cpso.components:
        assert obj.node().getNumShapes() == 1
    cpso.destroy_component_shapes()
    for obj in cpso.components:
        assert obj.node().getNumShapes() == 0
Example #7
0
def test_cpso_init_tree():
    c = 3.
    n = 4
    sso = SSO("parent")
    cpso = CPSO("foo")
    cpso.reparentTo(sso)
    objs = [RBSO(str(i)) for i in xrange(n)]
    for obj in objs:
        obj.setPos((c * (i - np.floor(n / 2.)), 0, 0))
        obj.set_shape("Box")
    cpso.add(objs)
    sso.init_tree(tags=("shape", ))
    assert cpso.node().getNumShapes() == n
    for obj in cpso.components:
        assert obj.node().getNumShapes() == 0
Example #8
0
def test_cast():
    sso = SSO.cast(NodePath("sso"))
    gso = GSO.cast(NodePath("gso"))
    pso = PSO.cast(NodePath("pso"))
    ghso = GHSO.cast(NodePath("ghso"))
    rbso = RBSO.cast(NodePath("rbso"))
    assert isinstance(sso, NodePath)
    assert isinstance(sso, SSO)
    assert isinstance(gso, NodePath)
    assert isinstance(gso, SSO)
    assert isinstance(gso, GSO)
    assert isinstance(ghso, NodePath)
    assert isinstance(ghso, SSO)
    assert isinstance(ghso, PSO)
    assert isinstance(ghso, GHSO)
    assert isinstance(rbso, NodePath)
    assert isinstance(rbso, SSO)
    assert isinstance(rbso, PSO)
    assert isinstance(rbso, RBSO)
Example #9
0
def test_rbso():
    obj = RBSO("rbso")
    assert isinstance(obj.node(), BulletRigidBodyNode)
Example #10
0
def test_pso_delete_shape():
    obj = RBSO("rso")
    obj.set_shape("Box")
    obj.create_shape()
    obj.delete_shape()
    assert obj.node().getNumShapes() == 0
Example #11
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
Example #12
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