Compound Shape for CollisionSolid

I am aware that Bullet supports compound shape. Does CollisionSolid also support it?
I could set TransformState to a CollisionNode, but cannot set TransformState to a CollisionSolid. A CollisionNode cannot host several CollisionSolids with different tranformations.

Ah, but it can support multiple CollisionSolids (just call “addSolid” more than once, passing in the desired solids), and such solids can be set up to effectively have transformations.

For example, let’s say that you wanted to have a CollisionNode that contained two spheres, one atop the other. That might look something like this, I believe:

node = CollisionNode("kitten")

# Create a sphere at location (0, 0, 0), of radius 2
solid1 = CollisionSphere(0, 0, 0, 2)
node.addSolid(solid1)

# Create a sphere at location (0, 0, 2), of radius 1
# --i.e. smaller, and located vertically higher than the other
solid2 = CollisionSphere(0, 0, 2, 1)
node.addSolid(solid2)

Thanks. I am trying to combine multiple CollisionBox.
The following code might be a solution, but if I want to change the collisionmasks later, I have to get down to each of the node() and update them separately. That is annoying.

 collision_primitive = CollisionBox(center=LPoint3(0, 0, 0),
                                       x=x_side,
                                       y=math.tan(angles[1] / 2) * x_side,
                                       z=cyl.height / 2.0)
    pdcndp = NodePath("auto")
    for angle in angles:
        homomat = cyl.homomat @ rm.homomat_from_posrot(rot=rm.rotmat_from_axangle(np.array([0, 0, 1]), angle))
        pdcnd = CollisionNode("auto")
        pdcnd.addSolid(collision_primitive)
        pdcnd.setTransform(TransformState.makeMat(da.npmat4_to_pdmat4(homomat)))
        pdcndp.attachNewNode(pdcnd).show()

I’m… not sure that it would work with a single collision-solid being shared by multiple collision-nodes–I was thinking of something the other way around! (But maybe it will–I don’t know that I’ve tried it!)

Hum–but if you do require more than just the positioning of your solids–if you require rotation, too–and if it’s boxes–i.e. not spheres or capsules–that you want to rotate, then indeed, the “multiple solids in a single node” solution might not work…

Otherwise, let me ask: what are you trying to achieve here? Perhaps another solution might be found…

And if not… then perhaps Bullet will work better for you!

Yes, Bullet works. Essentially, I am trying to build a CollisionCylinder using multiple boxes… It is an invalid CollisionSolid.

When you say “cylinder”, do you mean a circular tube with flat ends?

If so, would a CollisionCapsule perhaps be close enough? That would, I suspect, make things a lot simpler…

[edit]
If you have the time to wait, you could perhaps request a cylinder-solid via the issue-tracker.

1 Like

I think you don’t need to modify the existing CollisionNode, you can always create a new one.

That is a possibility–depending of course on how often one wants to do it.

(If it’s infrequent, and the process of building up this model is quick, then indeed: why not just throw away the old one and build a new one?)

I have to disagree with you, changing the transformation always costs more.

Not necessarily: it would depend I daresay on the process involved in making new nodes for the given purpose.

The problem is CollisionBox always aligns with axes. It cannot be rotated. I guess the problem is irrelavent to how many new CollisionNodes are created.