Esempio n. 1
0
        static void DealWithAlreadyProcessedVertex(OBJVertex vertex, int newTexId, int newNormalId,
                                                   List <uint> indexes, List <OBJVertex> vertices)
        {
            // If it is the same, just add it's index
            if (vertex.HasSameTextureAndNormal(newTexId, newNormalId))
            {
                indexes.Add((uint)vertex.Index);
            }
            else
            {
                OBJVertex prevDupeVertex = vertex.DuplicateVertex;
                if (prevDupeVertex != null)
                {
                    // Handle that vertex's duplicate
                    DealWithAlreadyProcessedVertex(prevDupeVertex, newTexId, newNormalId, indexes, vertices);
                }
                else
                {
                    // Create the duplicated vertex of the previous vertex
                    OBJVertex dupeVertex = new OBJVertex(vertices.Count, vertex.Position);
                    dupeVertex.UVIndex     = newTexId;
                    dupeVertex.NormalIndex = newNormalId;

                    vertex.DuplicateVertex = dupeVertex;

                    vertices.Add(dupeVertex);
                    indexes.Add((uint)dupeVertex.Index);
                }
            }
        }
Esempio n. 2
0
        static void ProcessVertex(string[] vertexData, List <OBJVertex> vertices, List <uint> indexes)
        {
            // Get vertex
            uint index;

            if (!uint.TryParse(vertexData[0], out index))
            {
                LogFloatParseError(-1, "");
            }
            index--;
            // Get the ObjVertex
            OBJVertex currentVertex = vertices[(int)index];
            // Get UV
            int texId;

            if (!int.TryParse(vertexData[1], out texId))
            {
                LogFloatParseError(-1, "");
            }
            texId--;
            // Get normal
            int normalId;

            if (!int.TryParse(vertexData[2], out normalId))
            {
                LogFloatParseError(-1, "");
            }
            normalId--;

            // Setup current vertex if it is not set
            if (!currentVertex.IsSet())
            {
                currentVertex.UVIndex     = texId;
                currentVertex.NormalIndex = normalId;
                indexes.Add(index);
            }
            else
            {
                // Deal with the already processed vertex
                DealWithAlreadyProcessedVertex(currentVertex, texId, normalId, indexes, vertices);
            }
        }
Esempio n. 3
0
        static float ConvertDataToArrays(List <OBJVertex> vertices, List <Vector2> uvs, List <Vector3> normals,
                                         float[] finalVertices, float[] finalUVs, float[] finalNormals)
        {
            float furthestPoint = 0;

            for (int i = 0; i < vertices.Count; i++)
            {
                OBJVertex vertex = vertices[i];
                // Handle furthest point
                if (vertex.Length > furthestPoint)
                {
                    furthestPoint = vertex.Length;
                }

                // Get position, uv, and normal
                Vector3 position = vertex.Position;
                Vector2 uv       = uvs[vertex.UVIndex];
                Vector3 normal   = normals[vertex.NormalIndex];

                // Set final vertices
                finalVertices[i * 3]     = position.X;
                finalVertices[i * 3 + 1] = position.Y;
                finalVertices[i * 3 + 2] = position.Z;

                // Set final uvs
                finalUVs[i * 2]     = uv.X;
                finalUVs[i * 2 + 1] = 1 - uv.Y;

                // Set final normals
                finalNormals[i * 3]     = normal.X;
                finalNormals[i * 3 + 1] = normal.Y;
                finalNormals[i * 3 + 2] = normal.Z;
            }

            return(furthestPoint);
        }