Hello all! I really need some help with "Single edge shapes". What I am trying to do is make a "blob" body (a.k.a a soft-body) by connecting single-edges together with joints. Right now I just have a circle made of 20 edges, and am aiming at connecting each edge to the neighboring edge with a joint. Well, it seams Box2D doesn't like single edge shapes. I am using a masked circle to determine the mass of the edge. When I start my program the edges fall like they should, but when they hit the ground they "try" to react (bounce) but end up just falling through the floor. Any ideas what I am doing wrong? I am using the latest version of pyBox2D. Here is the code I am using to construct the bodies/shapes:
Please please help!
Code:
def build_body(World, Body):
for Index1 in range(len(Body.Verts)):
Index2 = (Index1 + 1) % len(Body.Verts)
Index3 = (Index1 + 2) % len(Body.Verts)
#Set up the edge
EdgeVerts = [(Body.Verts[Index1].X, Body.Verts[Index1].Y), (Body.Verts[Index2].X, Body.Verts[Index2].Y)]
EdgeVerts.reverse()
#Calculate the center of the edge
X1 = EdgeVerts[0][0]
Y1 = EdgeVerts[0][1]
X2 = EdgeVerts[1][0]
Y2 = EdgeVerts[1][1]
X3 = ((X2 - X1) / 2.0)
Y3 = ((Y2 - Y1) / 2.0)
#Recompute an edge with vertecies stemming from center point
FinalEdgeVerts = [(-X3, -Y3), (X3, Y3)]
#Make my program body
TempBody = Base.GameBody(World)
#The bodies in my program are drawn with my own data... not the Box2D data
for V in FinalEdgeVerts:
TempBody.Verts.append(Base.GameBodyVertex(V[0], V[1], 1.0, 1.0, 1.0, 1.0))
#Create the Box2D body
World.CreatePhysicsBody(TempBody)
TempBody.PhysicsBody.SetBullet(True)
#Create a small circle at the center of the edge to compute mass
Weight = b2CircleDef()
Weight.filter.categoryBits = 0x0001
Weight.filter.maskBits = 0x0000
Weight.density = 1.0
Weight.radius = 0.50
Weight.localPosition = (0.0, 0.0)
TempBody.PhysicsBody.CreateShape(Weight)
#Build said edge
EdgeDef = b2EdgeChainDef()
EdgeDef.setVertices(FinalEdgeVerts)
EdgeDef.isALoop = False
EdgeDef.mass = Body.Mass
EdgeDef.density = Body.Density
EdgeDef.restitution = Body.Restitution
EdgeDef.friction = Body.Friction
EdgeDef.filter.categoryBits = Body.Category
EdgeDef.filter.maskBits = Body.Mask
Shape = TempBody.PhysicsBody.CreateShape(EdgeDef)
TempBody.PhysicsBody.SetMassFromShapes()
TempBody.PhysicsBody.SetXForm((X1 + X3, Y1 + Y3), 0.0)
World.AddBody(TempBody)
#Destroy the incoming circle (only used as a template to build the edges)
Body.Destroy = True
for Index1 in range(len(Body.Verts)):
Index2 = (Index1 + 1) % len(Body.Verts)
Index3 = (Index1 + 2) % len(Body.Verts)
#Set up the edge
EdgeVerts = [(Body.Verts[Index1].X, Body.Verts[Index1].Y), (Body.Verts[Index2].X, Body.Verts[Index2].Y)]
EdgeVerts.reverse()
#Calculate the center of the edge
X1 = EdgeVerts[0][0]
Y1 = EdgeVerts[0][1]
X2 = EdgeVerts[1][0]
Y2 = EdgeVerts[1][1]
X3 = ((X2 - X1) / 2.0)
Y3 = ((Y2 - Y1) / 2.0)
#Recompute an edge with vertecies stemming from center point
FinalEdgeVerts = [(-X3, -Y3), (X3, Y3)]
#Make my program body
TempBody = Base.GameBody(World)
#The bodies in my program are drawn with my own data... not the Box2D data
for V in FinalEdgeVerts:
TempBody.Verts.append(Base.GameBodyVertex(V[0], V[1], 1.0, 1.0, 1.0, 1.0))
#Create the Box2D body
World.CreatePhysicsBody(TempBody)
TempBody.PhysicsBody.SetBullet(True)
#Create a small circle at the center of the edge to compute mass
Weight = b2CircleDef()
Weight.filter.categoryBits = 0x0001
Weight.filter.maskBits = 0x0000
Weight.density = 1.0
Weight.radius = 0.50
Weight.localPosition = (0.0, 0.0)
TempBody.PhysicsBody.CreateShape(Weight)
#Build said edge
EdgeDef = b2EdgeChainDef()
EdgeDef.setVertices(FinalEdgeVerts)
EdgeDef.isALoop = False
EdgeDef.mass = Body.Mass
EdgeDef.density = Body.Density
EdgeDef.restitution = Body.Restitution
EdgeDef.friction = Body.Friction
EdgeDef.filter.categoryBits = Body.Category
EdgeDef.filter.maskBits = Body.Mask
Shape = TempBody.PhysicsBody.CreateShape(EdgeDef)
TempBody.PhysicsBody.SetMassFromShapes()
TempBody.PhysicsBody.SetXForm((X1 + X3, Y1 + Y3), 0.0)
World.AddBody(TempBody)
#Destroy the incoming circle (only used as a template to build the edges)
Body.Destroy = True
Please please help!