I've used demo application from github to vizualise physics world and get strange behaviour:
1) Manually generated terrain mesh looks fine, except strange alignment (looks like it's up axis is X or Z, not Y) and application renders it fine;
2) Game models looks totally messed and unrecognizable;
Both terrain and game objects meshes use same rendering code, there's no mistake in models itself, I've checked them with Noesis viewer. This also can't be bullet wrapper problem because terrain looks ok.
What am I doing wrong? I'm using latest BulletSharp from github (CSharp wrapper)
Creation of game objects in code (C#):
Code: Select all
foreach (int key in FixtureInfos.Keys)
{
FixtureInfo info = FixtureInfos[key]; //getting info about game model
//safe checks
if (!ModelInfos.ContainsKey(info.NifID))
{
Console.WriteLine($"Missing fixture info: {info.NifID} - {info.Name} in {path}");
continue;
}
if (!BulletOcclusion.Fixtures.ContainsKey(ModelInfos[info.NifID].ModelName))
{
Console.WriteLine($"Missing model: {ModelInfos[info.NifID].ModelName}");
continue;
}
//
//creating bvh from pre loaded model
BvhTriangleMeshShape shape = BulletOcclusion.Fixtures[ModelInfos[info.NifID].ModelName];
//translating it and rotating
Matrix startTransform = Matrix.Translation(new BulletSharp.Vector3( //translation
(float)info.X,
(float)info.Y,
(float)info.Z
));
startTransform = Matrix.Add(startTransform, Matrix.RotationQuaternion(BulletSharp.Quaternion.RotationAxis(new BulletSharp.Vector3((float)info.XAxis, (float)info.YAxis, (float)info.ZAxis), info.Angle3D)));
//creating rigidbody itself
myMotionState = new DefaultMotionState(startTransform);
rbInfo = new RigidBodyConstructionInfo(0.0f, myMotionState, shape);
rigid = new FixtureRigidBody(rbInfo, info.ID, info.NifID, info.Name);
rigid.CollisionFlags |= CollisionFlags.StaticObject;
AddRigidBody(rigid);
rbInfo.Dispose();
}
FixtureInfos.Clear();
Code: Select all
ObjModel model = new ObjModel();
model.Deserialize(bytes);
if (model.Vertices.Length > 0 && model.Polygons.Length > 0)
{
TriangleIndexVertexArray indexVertexArray = new TriangleIndexVertexArray(model.Polygons, model.Vertices);
BvhTriangleMeshShape shape = new BvhTriangleMeshShape(indexVertexArray, true, true);
Fixtures.TryAdd(name, shape);
Console.WriteLine($"Loaded model: {name}");
}
else
{
Console.WriteLine($"Model {name} has no faces or polygons!");
}