+1

Texture coordinates from ObjReader

Anonymous 10 years ago updated by Kong Lee 2 years ago 15
This discussion was imported from CodePlex

Lolligeir wrote at 2013-03-22 18:08:

Hey! Thanks for an awesome tool.

I am reading some obj files for a ray tracer and I have managed to read the Points of each triangle and the normals but the texture coordinate don´t seem to be working correctly. This is how I am reading the file:
            ObjReader r = new ObjReader();
            Model3DGroup model = r.Read(modelUrl);
            GeometryModel3D gm1 = (GeometryModel3D)model.Children[0];
            MeshGeometry3D mg1 = (MeshGeometry3D)gm1.Geometry;
            Vector3DCollection normals = mg1.Normals;     
            System.Windows.Media.PointCollection textureCoordinates = mg1.TextureCoordinates;
            System.Windows.Media.Int32Collection indices = mg1.TriangleIndices;
            Point3DCollection points = mg1.Positions;
            
            

            for (int index = 0; index < indices.Count; index += 3)
            {
                Point3D p0 = points[indices[index]];
                Point3D p1 = points[indices[index + 1]];
                Point3D p2 = points[indices[index + 2]];          
                
                Vector3D n0 = normals[indices[index]];
                Vector3D n1 = normals[indices[index + 1]];
                Vector3D n2 = normals[indices[index + 2]];

                System.Windows.Point t0 = textureCoordinates[indices[index]];
                System.Windows.Point t1 = textureCoordinates[indices[index + 1]];
                System.Windows.Point t2 = textureCoordinates[indices[index + 2]];
}
      
This loads the correct points and normals but the texture coordinates come out wrong. Am I approacing this incorrectly? How do you read the correct texture coordinate for every face?

The obj file I have been using (Removed text after vertices to get the objReader to read it) : http://cs.wellesley.edu/~cs307/tw/objects/cube-textures.obj

Best regards,
Viktor

You seemed to have thought of everything in this topic! I will save your site and come back here real soon to read more informative post from you.

รูเล็ตออนไลน์

เล่นรูเล็ตเว็บไหนดี

เล่นเกมรูเล็ตเว็บไหนดี

You seemed to have thought of everything in this topic! I will save your site and come back here real soon to read more informative post from you.

cash or crash

เล่นcash or crashเว็บไหนดี

สมัครสมาชิกเล่นเกมcash or crashเว็บไหนดี