bvhTriangleMesh glitch

Post Reply
Alastar
Posts: 2
Joined: Fri Jan 07, 2022 7:48 pm

bvhTriangleMesh glitch

Post by Alastar »

I've got terrain data as heightmap and converted it to bvhTriangleMesh manually, and I also get some game models (as .obj) for game objects on scene and passed verts and tris to bvhTriangleMesh.
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?
Снимок.JPG
Снимок.JPG (70.39 KiB) Viewed 6466 times
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();
Reading models and creating collision shapes for them:

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!");
        }
Alastar
Posts: 2
Joined: Fri Jan 07, 2022 7:48 pm

Re: bvhTriangleMesh glitch

Post by Alastar »

Stupid mistake, in all .obj models vertexes are indexed from 1, not 0, that caused this stupid behavior
Post Reply