EdgeShapes

Hi, I have 2 questions about edgeshapes.

1. Can they be dynamic? I have tried, but they don't rotate and fall through other objects.
If they can't, should I use make a custom build of Jbox2d that allows more than 8 vertices in a polygon?

2. Can they be dynamically edited?
I am trying to make destructible terrain. I have my edgeshape, and would like to move vertices in the shape at any time. When I do this, if I move them too far away from their original position, the shape no longer works. Or could I replace single fixtures?

Or is there another way, that doesn't involve deleting the shape and creating a new one?

Thanks,
r_bewick
1. Yes, but to be dynamic properly the body they are attached to must have some mass. By themselves edge shapes have no mass, so you would either need to put them on a body that already has a circle or polygon shape, or set the mass data of the body manually with SetMassData. You can add a polygon/circle first to let the engine calculate the appropriate values for the mass data, use GetMassData to get the values, then remove the polygon/circle and SetMassData back (never tried but I think it should work).

Also, note that edge shapes do not collide with other edge shapes.

2. Not really, but they can be replaced. If you are simply moving the existing vertices of an edge shape on a static body the AABB may not be getting updated - try replacing the shape completely. Is there a problem with deleting and creating a new one?
Thanks for the reply, irresistible force.

irresistible force wrote:
2. Not really, but they can be replaced. If you are simply moving the existing vertices of an edge shape on a static body the AABB may not be getting updated - try replacing the shape completely. Is there a problem with deleting and creating a new one?


It just is a bit slow (my edgeshape say has 1000 points), so replacing it takes about 100ms, which is too slow.
The edge shapes I am thinking of (b2EdgeShape) have only two points. Is this what takes 100ms or you mean replacing all 1000 points takes 100ms? There must be some way you can replace only the section of the ground that got changed...
irresistible force wrote:
The edge shapes I am thinking of (b2EdgeShape) have only two points. Is this what takes 100ms or you mean replacing all 1000 points takes 100ms? There must be some way you can replace only the section of the ground that got changed...


Yes, sorry I mean replacing all 1000 edgeshapes in an object.

I don't know how I can edit single fixtures. It seems like they have to be all deleted and replaced, because when one is created it is set at the end of the fixture list
Yes, that's true. You would have to keep your own references to the fixtures from when you created them, to use for replacing specific segments.
irresistible force wrote:
Yes, that's true. You would have to keep your own references to the fixtures from when you created them, to use for replacing specific segments.


How do I use the references to replace specific segments?

Code:
               PolygonShape shape = new PolygonShape();
               shape.setAsEdge(new Vec2(v1.x, v1.y), new Vec2(v2.x, v2.y));
              
               FixtureDef def = new FixtureDef();
             ...
             m_listFixtures.add(m_body.createFixture(def));



If I now have all my fixtures in an arraylist or something, so I can search and find the ones I want to change, how do I change them without creating a new one? before I tried to edit the shapes inside the fixture but the collision stopped working. I also tried to recalculate the AABB for the shapes I edited but that didn't seem to do anything.
Yeah, I think static shapes assume that their AABB will never change. I would just DestroyFixture and CreateFixture again to replace them completely. As long as you are not doing the whole 1000 then I don't think you will see the slowdown.
irresistible force wrote:
Yeah, I think static shapes assume that their AABB will never change. I would just DestroyFixture and CreateFixture again to replace them completely. As long as you are not doing the whole 1000 then I don't think you will see the slowdown.



How Can I create a fixture in the middle of the body's fixture list? it always puts it at the end?

Thanks
You can't - but why does it matter where it is in the body's fixture list?

Original thread: https://box2d.org/forum/viewtopic.php?t=7902