I’m making an attempt to create a CompoundShape utilizing BulletSharp and Assimp for my 3D physics engine. The collider works completely when the scaling is uniform throughout all axes (e.g., 1,1,1 or 2,2,2). Nonetheless, after I apply non-uniform scaling (e.g., 1,2,1), the collider behaves incorrectly.
Right here is the related a part of my code:
utilizing Assimp;
utilizing BulletSharp;
utilizing Genesis.Core.GameElements;
utilizing Genesis.Math;
utilizing Genesis.Physics;
public class CompoundMeshCollider2 : ColliderBehavior3D
{
public CompoundMeshCollider2(PhysicHandler physicHandler) : base(physicHandler) { }
public void CreateCollider(String path, int collisionGroup = -1, int collisionMask = -1)
{
var ingredient = (Element3D)this.Mum or dad;
var compoundShape = new CompoundShape(false);
var btTranslation = BulletSharp.Math.Matrix.Translation(ingredient.Location.ToBulletVec3());
var btScale = BulletSharp.Math.Matrix.Scaling(1.0f);
var btRotation = BulletSharp.Math.Matrix.RotationX(ingredient.Rotation.X) *
BulletSharp.Math.Matrix.RotationY(ingredient.Rotation.Y) *
BulletSharp.Math.Matrix.RotationZ(ingredient.Rotation.Z);
var btStartTransform = btTranslation * btRotation * btScale;
Assimp.AssimpContext importer = new Assimp.AssimpContext();
var mannequin = importer.ImportFile(path, Assimp.PostProcessPreset.TargetRealTimeQuality | Assimp.PostProcessSteps.Triangulate);
foreach (var mesh in mannequin.Meshes)
{
int[] indicies = mesh.GetIndices();
float[] verticies = mesh.Vertices.SelectMany(v => new float[] { v.X, v.Y, v.Z }).ToArray();
var meshScale = BulletSharp.Math.Matrix.Scaling(ingredient.Dimension.ToBulletVec3());
var node = FindMeshNode(mannequin.RootNode, mesh.Identify);
var remodel = GetMatrix(mannequin.RootNode.Rework) * GetMatrix(node.Rework);
TriangleIndexVertexArray triangle = new TriangleIndexVertexArray(indicies, verticies);
BvhTriangleMeshShape form = new BvhTriangleMeshShape(triangle, true);
form.LocalScaling = new BulletSharp.Math.Vector3(1, 1, 1);
compoundShape.AddChildShape(remodel, form);
}
compoundShape.LocalScaling = TransformVector(ingredient.Dimension);
compoundShape.CalculateLocalInertia(0);
Collider = new BulletSharp.CollisionObject
{
CollisionShape = compoundShape,
UserObject = this.Mum or dad,
WorldTransform = btStartTransform
};
PhysicHandler.ManageElement(this, collisionGroup, collisionMask);
}
non-public static Node FindMeshNode(Node root, String meshname)
{
return root.FindNode(meshname);
}
non-public static BulletSharp.Math.Matrix GetMatrix(Assimp.Matrix4x4 matrix)
{
return new BulletSharp.Math.Matrix(
matrix.A1, matrix.B1, matrix.C1, matrix.D1,
matrix.A2, matrix.B2, matrix.C2, matrix.D2,
matrix.A3, matrix.B3, matrix.C3, matrix.D3,
matrix.A4, matrix.B4, matrix.C4, matrix.D4
);
}
non-public static BulletSharp.Math.Vector3 TransformVector(Vec3 vec)
{
return new BulletSharp.Math.Vector3(vec.X, vec.Y, vec.Z);
}
}
Noticed Concern:
Uniform scaling (1,1,1 or 2,2,2) works appropriately.
Non-uniform scaling (1,2,1) causes incorrect conduct.
I think that the problem is expounded to how scaling transformations are utilized both to particular person meshes or to the CompoundShape. I’ve tried adjusting form.LocalScaling and compoundShape.LocalScaling, however the outcomes are nonetheless incorrect.
What I’m Wanting For:
Ideas for debugging this situation.
Insights into the right approach to deal with non-uniform scaling with CompoundShape in BulletSharp.
Any identified pitfalls when integrating Assimp and BulletSharp with non-uniform scaling.
Thanks upfront in your assist!