Inverted obj import in BulletSharp?

vbprogr
Posts: 5
Joined: Tue Jan 28, 2014 11:38 am

Inverted obj import in BulletSharp?

Post by vbprogr »

Wavefront.cs

Left: bullet imported version, right: correct 3ds max version.
1391559433-clip-2001kb.png
It's somehow inverted. If you think that left part is just 180 degrees rotated you are wrong. Just rotate it yourself in paint and you'll see - they will be different.

What's wrong with the bullet importer?

Usage:

Code: Select all

        var wo = new WavefrontObj();

        int tcount = wo.LoadObj(path);

        Vector3 localScaling = new Vector3(1, 1, 1) * 1f;

        var vertices = wo.Vertices.Select(v => Vector3.Modulate(new Vector3(v.X, v.Y, v.Z), localScaling)).ToArray();
        var indices = wo.Indices;

        if (tcount > 0)
        {
            var trimesh = new TriangleMesh();
            int i;
            for (i = 0; i < tcount; i++)
            {
                int index0 = indices[i * 3];
                int index1 = indices[i * 3 + 1];
                int index2 = indices[i * 3 + 2];

                Vector3 vertex0 = vertices[index0];
                Vector3 vertex1 = vertices[index1];
                Vector3 vertex2 = vertices[index2];

                trimesh.AddTriangle(vertex0, vertex1, vertex2);
            }
            CollisionShape concaveShape = new BvhTriangleMeshShape(trimesh, false);
            CreateRigidbody(transform.Position, transform.Rotation, concaveShape);
        }
You do not have the required permissions to view the files attached to this post.
vbprogr
Posts: 5
Joined: Tue Jan 28, 2014 11:38 am

Re: Inverted obj import in BulletSharp?

Post by vbprogr »

I tried to import with Assimp and got the same result. So the importer is correct but something inside bullet mirrors it.
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Inverted obj import in BulletSharp?

Post by c6burns »

Just flip the one axis that's getting inverted
vbprogr
Posts: 5
Joined: Tue Jan 28, 2014 11:38 am

Re: Inverted obj import in BulletSharp?

Post by vbprogr »

Thanks, already fixed. For 3dsMax exported obj models with flipped YZ (poser like) setting (checked by default) I should invert Z axis and swap vertices (like 0 1 2 to 2 1 0).