Beispiel #1
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
Beispiel #2
0
 def attach_pair(self, pair, f_on):
     """ Adds/removes physical attachment between a pair of nodes."""
     # Get the connected subgroups.
     graph = self.make_attachment_graph()
     sgs = [sg for sg in nx.connected_components(graph) if len(sg) > 1]
     self.reset_compounds()
     # Iterate over subgroups, creating compound shapes.
     for sg in sgs:
         nodes = [self.contact_bodies[i] for i in sg]
         parents = [c.getParent() for c in nodes]
         self.compound_components.extend(zip(nodes, parents))
         cname = "+".join([str(i) for i in sorted(sg)])
         cnode = CPSO(cname)
         cnode.reparentTo(self.scene)
         cnode.add(nodes)
         cnode.init_tree(tags=("shape", ))
         cnode.destroy_component_shapes()
         self.compound_objects.append(cnode)
Beispiel #3
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
Beispiel #4
0
 def attach_pair(self, pair, f_on):
     """ Adds/removes physical attachment between a pair of nodes."""
     # Get the connected subgroups.
     graph = self.make_attachment_graph()
     sgs = [sg for sg in nx.connected_components(graph) if len(sg) > 1]
     self.reset_compounds()
     # Iterate over subgroups, creating compound shapes.
     for sg in sgs:
         nodes = [self.contact_bodies[i] for i in sg]
         parents = [c.getParent() for c in nodes]
         self.compound_components.extend(zip(nodes, parents))
         cname = "+".join([str(i) for i in sorted(sg)])
         cnode = CPSO(cname)
         cnode.reparentTo(self.scene)
         cnode.add(nodes)
         cnode.init_tree(tags=("shape",))
         cnode.destroy_component_shapes()
         self.compound_objects.append(cnode)
Beispiel #5
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
Beispiel #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