Sign in to follow this  
TheMaskedFace

[MDX] Subset of meshes

Recommended Posts

I am trying to develop some 3D application. I have a model class that loads a mesh from a file.What I want is this: For example the model that I am loading have some other parts(subset),I want to sepearete them and consider each of them as DirectX.Direct3D.Mesh.My code snippet is like that.I hope that I had describes what I want.
ranges = mesh.GetAttributeTable();
            //Mesh array for subsets
            meshes = new Mesh[ranges.Length];
            vertexBuffers = new VertexBuffer[ranges.Length];
            for (int i = 0; i < meshes.Length; i++)
            {

                meshes[i] = new Mesh(ranges[i].VertexCount * 3, ranges[i].VertexCount, MeshFlags.Managed, CustomVertex.PositionNormalTextured.Format, device);

                rangeVertices = (CustomVertex.PositionNormalTextured[])mesh.VertexBuffer.Lock(ranges[i].VertexStart * sizeof(CustomVertex.PositionNormalTextured), typeof(CustomVertex.PositionNormalTextured), LockFlags.None, ranges[i].VertexCount);

                using (VertexBuffer vb = meshes[i].VertexBuffer)
                {
                    GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                    data.Write(rangeVertices);

                    vb.Unlock();
                }



            }

But when I do my rendering,I can not see any thing or with some changes in Vertexformats I have some StackOverFlow or FatalEngine errors. Is this code snippet is ok for what I want? I am waiting for some more info

Share this post


Link to post
Share on other sites
Yes it is possible to do so. What you need to do is lock the Attribute buffer of the mesh and separate the mesh out using what attribute index the mesh is. Usually if the mesh has n materials applied to it, there will be n attribute buffers.

Share this post


Link to post
Share on other sites
I can't see what's wrong with your code at first glance, but maybe our sample on splitting a mesh (1st sample on page) might be of help. We split the mesh's vertices into seperate vertexbuffers, but you could also create a new Mesh object for each subset and fill the vertexbuffer of these mesh objects using the same technique.

Hope his helps :)

Share this post


Link to post
Share on other sites
I had been looked at mdxinfo tutorial. I had tried to develop some more things releated with it and also my own code above. I do not get any debug errors but can not see anything on renderscreen.When I debug my code, it seems good.I mean information that is set seems ok.What can cause my problem?Nothing is rendered.

Share this post


Link to post
Share on other sites
It could be a number of things, are you refreshing the sene every time, are the meshes in the correct world view?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this