Get Vertices of b2PolygonShape? #20
-
|
Hello! I'm creating my own renderer, but discovering that the GetVertexCount() and GetVertex() methods seem to be missing from b2PolygonShape. Is there another approach or something I'm missing? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
https://github.com/Birch-san/box2d-wasm/blob/master/docs/iteration.md const square = new b2PolygonShape();
square.SetAsBox(1, 1);
for (let vertexIx = 0; vertexIx < square.get_m_count(); vertexIx++) {
const vertex = square.get_m_vertices(vertexIx);
} |
Beta Was this translation helpful? Give feedback.
-
|
The casting worked with some modification and I'm successfully rendering shapes by looping through the world bodies -> fixtures -> shape -> vertices. I really appreciate the help! In case anyone sees these posts in the future, just want to clarify that the suggested polygonShapes Set lookup approach won't work. If you retrieve a shape from a fixture via b2Fixture.GetShape(), the retrieved shape does not have the same pointer as the original shape used to create the fixture. However, you can still cast the retrieved shape from the fixture and it will have the correct vertices. You can cast it on an as-needed basis as suggested, but if its in a processor intensive loop this may be too cumbersome. I opted to attach a casted shape to every fixture I created so that I could reference the "typedShape" in intensive render loops: |
Beta Was this translation helpful? Give feedback.
b2PolygonShape#get_m_count()andb2PolygonShape#get_m_vertices(index?: number).https://github.com/Birch-san/box2d-wasm/blob/master/docs/iteration.md