Skip to content

Commit

Permalink
Fix SlimDX SoftBody rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresTraks committed Jul 23, 2017
1 parent 3bd89f7 commit d9d87d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,22 +251,21 @@ public void RenderSoftBody(SoftBody softBody)

if (faceCount > 0)
{
PositionedNormal[] vectors = new PositionedNormal[faceCount * 6];
PositionedNormal[] vectors = new PositionedNormal[faceCount * 3];
int v = 0;

int i;
for (i = 0; i < faceCount; i++)
for (int i = 0; i < faceCount; i++)
{
NodePtrArray nodes = faces[i].Nodes;
Node n0 = nodes[0];
Node n1 = nodes[1];
Node n2 = nodes[2];
n0.Position = vectors[v].Position;
n0.Normal = vectors[v].Normal;
n1.Position = vectors[v + 1].Position;
n1.Normal = vectors[v + 1].Normal;
n2.Position = vectors[v + 2].Position;
n2.Normal = vectors[v + 2].Normal;
vectors[v].Position = n0.Position;
vectors[v].Normal = n0.Normal;
vectors[v + 1].Position = n1.Position;
vectors[v + 1].Normal = n1.Normal;
vectors[v + 2].Position = n2.Position;
vectors[v + 2].Normal = n2.Normal;
v += 3;
}

Expand Down
36 changes: 23 additions & 13 deletions BulletSharpPInvoke/test/SerializationTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Linq;
using BulletSharp;
using NUnit.Framework;
using System.Reflection;
using System.IO;

namespace BulletSharpTest
{
Expand All @@ -20,14 +22,14 @@ public void SerializeTest()
var fileLoader = new BulletWorldImporter(_world);
var objects = _world.CollisionObjectArray;

Assert.True(fileLoader.LoadFile("data\\bsp.bullet"));
Assert.True(LoadFile(fileLoader, "data\\bsp.bullet"));
Assert.AreEqual(127, objects.Count);
Assert.AreEqual(127, fileLoader.NumCollisionShapes);
Assert.True(objects.All(o => o.CollisionShape is ConvexHullShape));
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);

Assert.True(fileLoader.LoadFile("data\\concaveCompound.bullet"));
Assert.True(LoadFile(fileLoader, "data\\concaveCompound.bullet"));
Assert.AreEqual(1, fileLoader.NumBvhs);
Assert.AreEqual(6, fileLoader.NumCollisionShapes);
Assert.AreEqual(11, objects.Count);
Expand All @@ -40,50 +42,50 @@ public void SerializeTest()
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);

Assert.True(fileLoader.LoadFile("data\\constraints.bullet"));
Assert.True(LoadFile(fileLoader, "data\\constraints.bullet"));
Assert.AreEqual(10, fileLoader.NumConstraints);
Assert.AreEqual(10, _world.NumConstraints);
Assert.AreEqual(17, objects.Count);
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);

Assert.True(fileLoader.LoadFile("data\\convex_decomposition.bullet"));
Assert.True(LoadFile(fileLoader, "data\\convex_decomposition.bullet"));
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);

Assert.True(fileLoader.LoadFile("data\\cylinders.bullet"));
Assert.True(LoadFile(fileLoader, "data\\cylinders.bullet"));
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);

Assert.True(fileLoader.LoadFile("data\\multibody.bullet"));
Assert.True(LoadFile(fileLoader, "data\\multibody.bullet"));
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);
/*
Assert.True(fileLoader.LoadFile("data\\r2d2_multibody.bullet"));
Assert.True(LoadFile(fileLoader, "data\\r2d2_multibody.bullet"));
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);
*/
Assert.True(fileLoader.LoadFile("data\\ragdoll_6dof.bullet"));
Assert.True(LoadFile(fileLoader, "data\\ragdoll_6dof.bullet"));
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);

Assert.True(fileLoader.LoadFile("data\\ragdoll_conetwist.bullet"));
Assert.True(LoadFile(fileLoader, "data\\ragdoll_conetwist.bullet"));
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);

Assert.True(fileLoader.LoadFile("data\\slope.bullet"));
Assert.True(LoadFile(fileLoader, "data\\slope.bullet"));
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);

Assert.True(fileLoader.LoadFile("data\\spider.bullet"));
Assert.True(LoadFile(fileLoader, "data\\spider.bullet"));
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);
/*
Assert.True(fileLoader.LoadFile("data\\testFile.bullet"));
Assert.True(LoadFile(fileLoader, "data\\testFile.bullet"));
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);
*/
Assert.True(fileLoader.LoadFile("data\\testFileFracture.bullet"));
Assert.True(LoadFile(fileLoader, "data\\testFileFracture.bullet"));
fileLoader.DeleteAllData();
Assert.AreEqual(0, objects.Count);
}
Expand All @@ -107,5 +109,13 @@ public void TearDown()
_dispatcher.Dispose();
_conf.Dispose();
}

private static bool LoadFile(BulletWorldImporter fileLoader, string fileName)
{
string path = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
fileName);
return fileLoader.LoadFile(path);
}
}
}

0 comments on commit d9d87d5

Please sign in to comment.