Exemplo n.º 1
0
        public IndexedFaceSet Clone()
        {
            IndexedFaceSet clone = new IndexedFaceSet();

            clone.Index             = Index;
            clone.CoordIndex        = CoordIndex;
            clone.TextCoordIndex    = TextCoordIndex;
            clone.Normal            = Normal == null ? null : Normal.Clone();
            clone.Coordinate        = Coordinate == null ? null : Coordinate.Clone();
            clone.TextureCoordinate = TextureCoordinate == null ? null : TextureCoordinate.Clone();
            foreach (var text2d in MultiTextureCoordinate)
            {
                clone.MultiTextureCoordinate.Add(text2d.Clone());
            }
            return(clone);
        }
Exemplo n.º 2
0
        static int[] getCoordIndex(IndexedFaceSet indexedFaceSet)
        {
            string cistr = indexedFaceSet.CoordIndex;

            if (!string.IsNullOrEmpty(indexedFaceSet.Index))
            {
                cistr = indexedFaceSet.Index;
            }
            string[] ci = cistr.Split(fChop, StringSplitOptions.RemoveEmptyEntries);
            int      j  = 0;

            for (int i = 0; i < ci.Length; i++)
            {
                if (!ci[i].Equals("-1"))
                {
                    j = j + 1;
                }
            }

            int[] coordIndex = new int[j];
            j = 0;
            for (int i = 0; i < ci.Length; i++)
            {
                if (!ci[i].Equals("-1"))
                {
                    coordIndex[j] = Int32.Parse(ci[i]);
                    j             = j + 1;
                }
            }

            j = 0;
            while (j < coordIndex.Length)
            {
                int t = coordIndex[j];
                int k = j + 2;
                coordIndex[j] = coordIndex[k];
                coordIndex[k] = t;
                j             = j + 3;
            }
            return(coordIndex);
        }
Exemplo n.º 3
0
        public static Mesh HandleVertexShapeNode(IndexedFaceSet indexedFaceSet)
        {
            StartMeshParsing();
            Mesh mesh = new Mesh();

            try
            {
                mesh.vertices  = getCoordinates(indexedFaceSet.Coordinate);
                mesh.triangles = getCoordIndex(indexedFaceSet);
                if (indexedFaceSet.Normal != null)
                {
                    mesh.normals = getNormals(indexedFaceSet.Normal);
                }
                // mesh.SetIndices()

                // Vector3[] x3dMaterial = getX3DMatValues(ref xpni);
                Vector2[][] maps = getUVMaps(indexedFaceSet);
                if (maps[0].Length > 0)
                {
                    mesh.uv = maps[0];
                }
                if (maps[1] != null && maps[1].Length > 0)
                {
                    mesh.uv2 = maps[1];
                }
                if (maps[2] != null && maps[2].Length > 0)
                {
                    mesh.uv3 = maps[2];
                }
            }
            catch (Exception x)
            {
                var a = x.Message;
                Debug.LogWarning(a);
            }
            finally
            {
                FinishMeshParsing();
            }
            return(mesh);
        }
Exemplo n.º 4
0
        //        private char[] cChop = { '\'', ' ' };
        //        private char[] urlChop = { ' ', '\t', '\'', '\"' };

        static Vector2[][] getUVMaps(IndexedFaceSet indexedFaceCet)
        {
            string[] textureCoords = { "", "", "" };
            var      n             = 0;

            if (indexedFaceCet.MultiTextureCoordinate.Count > 0)
            {
                foreach (var texturecord in indexedFaceCet.MultiTextureCoordinate)
                {
                    if (n < 3)
                    {
                        textureCoords[n] = texturecord.Point;
                        n = n + 1;
                    }
                }
            }
            else if (indexedFaceCet.TextureCoordinate != null && !string.IsNullOrEmpty(indexedFaceCet.TextureCoordinate.Point))
            {
                textureCoords[0] = indexedFaceCet.TextureCoordinate.Point;
            }

            Vector2[][] maps = new Vector2[3][];
            if (indexedFaceCet.TextCoordIndex == null)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (textureCoords[i].Length > 0)
                    {
                        string[] vecs = textureCoords[i].Split(fChop, StringSplitOptions.RemoveEmptyEntries);
                        maps[i] = new Vector2[(int)Math.Floor((double)vecs.Length / 2.0)];
                        int j = 0;
                        int m = 0;
                        while (j < vecs.Length && m < maps[i].Length)
                        {
                            int k = j + 1;
                            maps[i][m].x = (float)Double.Parse(vecs[j]);
                            maps[i][m].y = (float)Double.Parse(vecs[k]);
                            j            = j + 2;
                            m            = m + 1;
                        }
                    }
                    else
                    {
                        maps[i] = new Vector2[0];
                    }
                }
            }
            else
            {
                //               string[] vecs = indexedFaceCet.TextCoordIndex.Split(fChop, StringSplitOptions.RemoveEmptyEntries);
                int[] textIndices = ToIntArray(indexedFaceCet.TextCoordIndex);
                //int[] faces = ToIntArray(indexedFaceCet.CoordIndex);
                float[] textureCoordFloat = ToFloatArray(indexedFaceCet.TextureCoordinate.Point);
                maps[0] = new Vector2[(int)Math.Floor((double)textureCoordFloat.Length / 2.0)];
                int j = 0;
                int m = 0;
                while (j < textureCoordFloat.Length && m < maps[0].Length)
                {
                    int k = j + 1;
                    maps[0][m].x = textureCoordFloat[textIndices[j]];
                    maps[0][m].y = textureCoordFloat[textIndices[k]];
                    j            = j + 2;
                    m            = m + 1;
                }
            }
            return(maps);
        }