Skip to content

Commit

Permalink
Fix body.AddShape(IEnumerable<RigidBodyShape> shapes) for one-time us…
Browse files Browse the repository at this point in the history
…e iterators.
  • Loading branch information
notgiven688 committed Jan 21, 2025
1 parent 4511598 commit eaa4abc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Jitter2/Dynamics/RigidBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ public void AddShape(IEnumerable<RigidBodyShape> shapes, bool setMassInertia = t
foreach (RigidBodyShape shape in shapes)
{
AttachToShape(shape);
this.shapes.Add(shape);
}

this.shapes.AddRange(shapes);
if (setMassInertia) SetMassInertia();
}

Expand Down
8 changes: 2 additions & 6 deletions src/JitterDemo/Demos/Demo05.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ public class Demo05 : IDemo

private bool debugDraw = false;

public List<RigidBodyShape> CreateShapes()
public IEnumerable<RigidBodyShape> CreateShapes()
{
var indices = tm.mesh.Indices;
var vertices = tm.mesh.Vertices;

List<RigidBodyShape> shapesToAdd = new();
List<JTriangle> triangles = new();

foreach (var tvi in indices)
Expand All @@ -56,11 +55,8 @@ public List<RigidBodyShape> CreateShapes()

for (int i = 0; i < jtm.Indices.Length; i++)
{
FatTriangleShape ts = new FatTriangleShape(jtm, i);
shapesToAdd.Add(ts);
yield return new FatTriangleShape(jtm, i);
}

return shapesToAdd;
}

public void Build()
Expand Down

0 comments on commit eaa4abc

Please sign in to comment.