Example #1
0
		private void AddFace(GameObject parent, X3DIndexedFaceSet preparedFaceSet, bool frontFace) {

			List<Vector3> vertices = null;
			int?[] vertexMapping = null;
			List<Vector3> normals = null;
			List<Color> colors = null;
			List<int> triangles = null;

			int partCount = 0;

			for (int i = 0; i < preparedFaceSet.Faces.Count; i++) {
				if (vertices != null && vertices.Count + 3 > MAX_VERTEX_PER_MESH_COUNT) {
					AddPart (parent, vertices, normals, colors, triangles, (frontFace ? "Front_" : "Back_") + partCount);
					partCount++;
					vertices = null;
				}
				if (vertices == null) {
					vertices = new List<Vector3> (preparedFaceSet.Vertices.Count);
					vertexMapping = new int?[preparedFaceSet.Vertices.Count];
					if (preparedFaceSet.Normals != null) {
						normals = new List<Vector3> (preparedFaceSet.Normals.Count);
					}
					if (preparedFaceSet.Colors != null) {
						colors = new List<Color> (preparedFaceSet.Colors.Count);
					}
					triangles = new List<int>(preparedFaceSet.Faces.Count * 3);
				}
					
				int vertexA;
				int vertexB;
				int vertexC;

				if (frontFace) {
					vertexA = preparedFaceSet.Faces [i] [0];
					vertexB = preparedFaceSet.Faces [i] [1];
					vertexC = preparedFaceSet.Faces [i] [2];
				} else {
					vertexA = preparedFaceSet.Faces [i] [2];
					vertexB = preparedFaceSet.Faces [i] [1];
					vertexC = preparedFaceSet.Faces [i] [0];
				}

				foreach (int vertexId in new int[]{vertexA, vertexB, vertexC}) {
					if (vertexMapping [vertexId] == null) {
						vertexMapping [vertexId] = vertices.Count;
						vertices.Add (preparedFaceSet.Vertices[vertexId]);
						if (preparedFaceSet.Normals != null) {
							normals.Add (preparedFaceSet.Normals[vertexId]);
						}
						if (preparedFaceSet.Colors != null) {
							colors.Add (preparedFaceSet.Colors[vertexId]);
						}
					}
					triangles.Add (vertexMapping [vertexId].Value);
				}
			}
			AddPart (parent, vertices, normals, colors, triangles, (frontFace ? "Front_" : "Back_") + partCount);
		}
        override public void Convert(GameObject parent)
        {
            X3DIndexedFaceSet preparedFaceSet = this.ToTriangulatedFaceSet().
                                                ToVertexOrientedFaceSet();

            AddFace(parent, preparedFaceSet, true);
            if (!this.Solid)
            {
                AddFace(parent, preparedFaceSet, false);
            }
        }
        private void AddFace(GameObject parent, X3DIndexedFaceSet preparedFaceSet, bool frontFace)
        {
            List <Vector3> vertices = null;

            int?[]         vertexMapping = null;
            List <Vector3> normals       = null;
            List <Color>   colors        = null;
            List <int>     triangles     = null;

            int partCount = 0;

            for (int i = 0; i < preparedFaceSet.Faces.Count; i++)
            {
                if (vertices != null && vertices.Count + 3 > MAX_VERTEX_PER_MESH_COUNT)
                {
                    AddPart(parent, vertices, normals, colors, triangles, (frontFace ? "Front_" : "Back_") + partCount);
                    partCount++;
                    vertices = null;
                }
                if (vertices == null)
                {
                    vertices      = new List <Vector3> (preparedFaceSet.Vertices.Count);
                    vertexMapping = new int?[preparedFaceSet.Vertices.Count];
                    if (preparedFaceSet.Normals != null)
                    {
                        normals = new List <Vector3> (preparedFaceSet.Normals.Count);
                    }
                    if (preparedFaceSet.Colors != null)
                    {
                        colors = new List <Color> (preparedFaceSet.Colors.Count);
                    }
                    triangles = new List <int>(preparedFaceSet.Faces.Count * 3);
                }

                int vertexA;
                int vertexB;
                int vertexC;

                if (frontFace)
                {
                    vertexA = preparedFaceSet.Faces [i] [0];
                    vertexB = preparedFaceSet.Faces [i] [1];
                    vertexC = preparedFaceSet.Faces [i] [2];
                }
                else
                {
                    vertexA = preparedFaceSet.Faces [i] [2];
                    vertexB = preparedFaceSet.Faces [i] [1];
                    vertexC = preparedFaceSet.Faces [i] [0];
                }

                foreach (int vertexId in new int[] { vertexA, vertexB, vertexC })
                {
                    if (vertexMapping [vertexId] == null)
                    {
                        vertexMapping [vertexId] = vertices.Count;
                        vertices.Add(preparedFaceSet.Vertices[vertexId]);
                        if (preparedFaceSet.Normals != null)
                        {
                            normals.Add(preparedFaceSet.Normals[vertexId]);
                        }
                        if (preparedFaceSet.Colors != null)
                        {
                            colors.Add(preparedFaceSet.Colors[vertexId]);
                        }
                    }
                    triangles.Add(vertexMapping [vertexId].Value);
                }
            }
            AddPart(parent, vertices, normals, colors, triangles, (frontFace ? "Front_" : "Back_") + partCount);
        }