2

I'm trying to find some way to iterate over the constraints dependent on a specific body in pymunk. There seem to be multiple ways to do so in Chipmunk, but I can't find an equivalent in pymunk. I would like to see some way to detect constraints such that I don't have to manually keep track of all of them.

I'd also like to see a way to detect the shapes associated with a body. In general, I'd like to be able to automatically remove a body's shapes and constraints when I remove the body from a space. Is that possible?

desophos
  • 207
  • 1
  • 9
  • Right now theres no built in way to do that in pymunk. In Chipmunk the iterator functions loops over shapes & constraints that are both attached to a body and added to a space. I do wonder if thats the way you want it in pymunk as well, or if it should be enough that the shape or constraint is attached to the body? – viblo Mar 03 '13 at 01:18
  • I think it would be enough to iterate over shapes and constraints attached to a specific body, because one could easily check for membership in the space. – desophos Mar 03 '13 at 02:08

1 Answers1

1

Latest trunk version of pymunk has two new (as of today) shapes and constraints properties on the Body class. I went with always return the shapes/constraints regardless of if they are added to the space or not.

So now you can just do:

>>> import pymunk
>>> b = pymunk.Body()
>>> b2 = pymunk.Body()
>>> j = pymunk.PivotJoint(b,b2,(0,0))
>>> s = pymunk.Circle(b,3)
>>> b.constraints
set([<pymunk.constraint.PivotJoint object at 0x02521890>])
>>> b.shapes
set([<pymunk.Circle object at 0x025218F0>])

(This will be included in pymunk 3.1.)

viblo
  • 4,159
  • 4
  • 20
  • 28