Jump to content
  • Advertisement
Sign in to follow this  
UsingBytes

C# gathering position and normal data only from .X file

This topic is 4279 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, Just wanted to post some code regarding gathering only the position and normal data from an .X file becuase this is a question I had here, but figured out how to do this. I originally thought I was going to need to write my own .X parser specificaly for this job, but turns out its not needed. I'm using C# with MDX 1.1 So I basically load up an .X file as a mesh object and then gather the data I need from that mesh object. I still need to refactor the code a little bit, but it does what i need it to.

// Get the base mesh position & normal information
        private CustomVertex.PositionNormal[] meshVertices;

        // Position holder
        private float[] x;
        private float[] y;
        private float[] z;

        // Normals holder
        private float[] nx;
        private float[] ny;
        private float[] nz;



private void CopyData()
        {
            int[] numberVertices = new int[1];
            numberVertices[0] = mesh.NumberVertices;
            Array getPoints;
            CustomVertex.PositionNormal pointMover = new CustomVertex.PositionNormal();

            meshVertices = new CustomVertex.PositionNormal[mesh.NumberVertices];
            x = new float[mesh.NumberVertices];
            y = new float[mesh.NumberVertices];
            z = new float[mesh.NumberVertices];

            nx = new float[mesh.NumberVertices];
            ny = new float[mesh.NumberVertices];
            nz = new float[mesh.NumberVertices];

            getPoints = mesh.LockVertexBuffer(pointMover.GetType(), LockFlags.None, numberVertices);

            for (int i = 0; i < mesh.NumberVertices; i++)
            {
                pointMover = (CustomVertex.PositionNormal)getPoints.GetValue(i);

                meshVertices.Normal = pointMover.Normal;
                meshVertices.Position = pointMover.Position;

                x.SetValue(meshVertices.Position.X, i);
                y.SetValue(meshVertices.Position.Y, i);
                z.SetValue(meshVertices.Position.Z, i);

                nx.SetValue(meshVertices.Normal.X, i);
                ny.SetValue(meshVertices.Normal.Y, i);
                nz.SetValue(meshVertices.Normal.Z, i);
            }

            mesh.UnlockVertexBuffer();
            mesh.Dispose();
        }

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!