EdgeShapes (aka Thin Line Segments)

EDIT: The post below is outdated. EdgeShapes are now merged into the main Box2DFlash SVN repository. Get them from there:
http://sourceforge.net/scm/?type=svn&group_id=210232
The new EdgeShapes are a direct port of the version I made for C++:
viewtopic.php?f=3&t=1577&hilit=edgeshapes



OLD POST:

DEMO!

I have (re)implemented shapes composed of infinitely-thin line segments in Box2D. I've decided to call my implementation "Static Edges".

This is a beta. The API is subject to change. A C++ port is possible, eventually, though whether or not it will be integrated into the main branch of Box2D is still uncertain, and this branch will be updated at my whim. 🙂 However, I welcome bug reports and feedback.

The way you create Static Edges differs from the norm. You start by creating a definition of a "chain" of connected edges:
Code:
var chainDef: b2StaticEdgeChainDef = new b2StaticEdgeChainDef();
chainDef.vertexCount = 3;
chainDef.vertices.push(new b2Vec2(x1,y1));
chainDef.vertices.push(new b2Vec2(x2,y2));
chainDef.vertices.push(new b2Vec2(x3,y3));
chainDef.isALoop = true; // connect the first and last vertices
Line Segments are only allowed to be static. So you can only attach them to the ground body:
Code:
world.CreateGroundShape(chainDef);
In this example, this one function call will create 3 line segments, each of type "b2StaticEdgeShape", and it will return one object of type "b2StaticEdgeChain".

Static Edges have an "inside" and an "outside". Which is which depends on your coordinate system. If up is positive on the Y axis, floors go from right to left, and ceilings go from left to right. If up is negative, floors go from left to right and ceilings go from right to left. This is consistent with the vertex order of Polygons.

As a bonus, you can find a super-barebones SVG parser in TestBed/TestEdges.as, so that you can draw paths in Inkscape and import them into Box2D. Inkscape was my level editor for Planet of the Forklift Kid.
Ohmigod, that is sweet. And you've done an SVG parser too, I was considering that, though less with the XML, and more with the robust path parsing. Damn, now I need adapt b2ConcaveArc into a thin version, too.

You say the lines are "one-sided". They seem to let stuff through the other way, but with "popping". Is that intentional/usable, or did you just mean they are intended to be used a particular way around to do convexity test etc.
This is actually based on your concave arc code, mostly because it sort of laid the foundation for adding new types of shapes. Thank you! The concave arcs are still in there, though they do not collide with static edges. If you make any updates to your concave arcs or the SVG parser, I'll offer to merge them in with any of my updates to the static edges, but I do not offer to write collision detection between the two. 😛 I'm assuming they'll both be used as static level geometry most of the time anyway.
The only problem is that the physics solver seems to "push" an object as it penetrates the shape.

This is was what I was looking for
Are you referring to when objects approach a Static Edge from the "wrong" side? If so, what is the behavior you would expect in this situation? Do you want it to collide with the "wrong" side just like it collides with the "right" side, or do you want it to pass through freely instead of being forced through?
shaktool wrote:
it to pass through freely instead of being forced through?

That would be best in my books, but I after seeing that Tinger game, I'm no longer concerned as it seems pretty easy to do with filters instead, and would rather what ever gives the best performance, which is probably what you have at the moment.
shaktool wrote:
do you want it to pass through freely instead of being forced through?

Yes! I got all excited about this until I realized that this is not the case.

Just wondering... is there any advantage to using this (besides easier authoring) over building static level shapes out of a bunch of polygons or even thin rectangles? Is it better performance-wise?
One advantage these lines have over polygons already is that this will never happen:
viewtopic.php?f=3&t=906

I have not yet attempted to compare their performance, though theoretically my static edges should be faster in many cases, as they are simpler to evaluate for contacts. However, they result in separate AABBs for each edge. If you have a large shape whose AABB overlaps the AABBs of eight static edges with convex corners all at once, it would be faster to use one static polygon with eight sides, resulting in one contact test with a polygon instead of eight contact tests with static edges.
shaktool wrote:
This is actually based on your concave arc code, mostly because it sort of laid the foundation for adding new types of shapes. Thank you! The concave arcs are still in there, though they do not collide with static edges. If you make any updates to your concave arcs or the SVG parser, I'll offer to merge them in with any of my updates to the static edges, but I do not offer to write collision detection between the two. 😛 I'm assuming they'll both be used as static level geometry most of the time anyway.



Thx both of you for the great additions ot box2d as3.

Do you mean that we can already define a concave arc line within the thin line segment shape ?
If you download the code attached to my first post, you'll get a version of Box2DAS3 that contains both b2ConcaveArcShapes and b2StaticEdgeShapes. They are separate, unrelated shapes, and they will never collide with each other, but you can use them both as static level geometry.

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