Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBlackJoker

Posted 28 March 2013 - 06:15 AM

Problem was solved. The algoritm for that is:

public Mesh OptimizeMesh(Mesh constructedMesh)
        {
            Mesh optimizedMesh;
            optimizedMesh = constructedMesh;


            for (int i = 0; i < constructedMesh.Vertices.Count; i++)
            {
                for (int j = i + 1; j < constructedMesh.Vertices.Count; j++)
                {
                    if (Equals(constructedMesh.Vertices[i], constructedMesh.Vertices[j]) &&
                        (Equals(constructedMesh.Textures[i], constructedMesh.Textures[j]) &&
                         (Equals(constructedMesh.Normals[i], constructedMesh.Normals[j]))
                        ))
                    {
                        optimizedMesh.Vertices.RemoveAt(j);
                        optimizedMesh.Normals.RemoveAt(j);
                        optimizedMesh.Textures.RemoveAt(j);

                        Decrement(ref optimizedMesh, i, j);
                        j--;
                    }
                }
            }
            return optimizedMesh;
        }

 

public void Decrement(ref Mesh mesh, int i, int j)
        {
            for (int k = 0; k < mesh.IndexBuffer.Count; k++)
            {
                if (mesh.IndexBuffer[k] == j)
                {
                    mesh.IndexBuffer[k] = i;
                }
                if (mesh.IndexBuffer[k] > j)
                {
                    mesh.IndexBuffer[k]--;
                }
            }
        }

 

Thats work for C#. If you will need some comments, please, feel free to ask me by private message. 


#2BlackJoker

Posted 26 March 2013 - 01:04 PM

I cannot see nothing simple in your code. Itы very hard to understand what is going on there.

What I want is the simplest way to create indices array for DX index buffer.

I know that I must have 3 loops for and in that cycles I must compare vertexes, normals and textcoords, but what next? Any mesh, even simplest cube doesn`t create when Iuse that algorithm. What I missing? Could someone tell me that? Should I delete also normals and texture coordinates or not, for ex?

 

I don`t understand what I am doing wrong! Help please!


#1BlackJoker

Posted 26 March 2013 - 12:50 PM

I cannot see nothing simple in your code. Ita very hard to understand what is going on there.

What I want is the simplest way to create indices array for DX index buffer.

I know that I must have 3 loops for and in that cycles I must compare vertexes, normals and textcoords, but what next? Any mesh, even simplest cube doesn`t create when Iuse that algorithm. What I missing? Could someone tell me that? Should I delete also normals and texture coordinates or not, for ex?

 

I don`t understand what I am doing wrong! Help please!


PARTNERS