Example #1
0
        private static void ReadVertices(XmlReader xmlTree, List <Vector3> vertices, double scale, ProgressData progressData)
        {
            while (xmlTree.Read())
            {
                if (xmlTree.Name == "vertices")
                {
                    using (XmlReader verticesTree = xmlTree.ReadSubtree())
                    {
                        while (verticesTree.Read())
                        {
                            if (xmlTree.Name == "vertex")
                            {
                                using (XmlReader vertexTree = verticesTree.ReadSubtree())
                                {
                                    while (vertexTree.Read())
                                    {
                                        if (vertexTree.Name == "coordinates")
                                        {
                                            using (XmlReader coordinatesTree = vertexTree.ReadSubtree())
                                            {
                                                Vector3 position = new Vector3();
                                                while (coordinatesTree.Read())
                                                {
                                                    switch (coordinatesTree.Name)
                                                    {
                                                    case "x":
                                                        string x = coordinatesTree.ReadString();
                                                        position.x = double.Parse(x);
                                                        break;

                                                    case "y":
                                                        string y = coordinatesTree.ReadString();
                                                        position.y = double.Parse(y);
                                                        break;

                                                    case "z":
                                                        string z = coordinatesTree.ReadString();
                                                        position.z = double.Parse(z);
                                                        break;

                                                    default:
                                                        break;
                                                    }
                                                }
                                                position *= scale;
                                                vertices.Add(position);
                                            }
                                            bool continueProcessing;
                                            progressData.ReportProgress0To50(out continueProcessing);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        private static List <Vector3> ReadVolume(XmlReader reader, List <Vector3> vertices, Mesh mesh, ProgressData progressData, out string material)
        {
            material = reader["materialid"];

            if (reader.ReadToDescendant("triangle"))
            {
                do
                {
                    var    indices     = new int[3];
                    string nextSibling = null;
                    if (reader.ReadToDescendant("v1"))
                    {
                        do
                        {
                            switch (reader.Name)
                            {
                            case "v1":
                                indices[0]  = reader.ReadElementContentAsInt();
                                nextSibling = "v2";
                                break;

                            case "v2":
                                indices[1]  = reader.ReadElementContentAsInt();
                                nextSibling = "v3";
                                break;

                            case "v3":
                                indices[2]  = reader.ReadElementContentAsInt();
                                nextSibling = null;
                                break;
                            }
                        } while (nextSibling != null && (reader.Name != nextSibling ? reader.ReadToNextSibling(nextSibling) : true));
                    }

                    if (indices[0] != indices[1] &&
                        indices[0] != indices[2] &&
                        indices[1] != indices[2] &&
                        vertices[indices[0]] != vertices[indices[1]] &&
                        vertices[indices[1]] != vertices[indices[2]] &&
                        vertices[indices[2]] != vertices[indices[0]])
                    {
                        var triangle = new IVertex[]
                        {
                            mesh.CreateVertex(vertices[indices[0]], CreateOption.CreateNew, SortOption.WillSortLater),
                            mesh.CreateVertex(vertices[indices[1]], CreateOption.CreateNew, SortOption.WillSortLater),
                            mesh.CreateVertex(vertices[indices[2]], CreateOption.CreateNew, SortOption.WillSortLater),
                        };
                        mesh.CreateFace(triangle, CreateOption.CreateNew);
                    }

                    progressData.ReportProgress0To50();

                    reader.MoveToEndElement("triangle");
                } while (reader.ReadToNextSibling("triangle"));
            }

            return(vertices);
        }
Example #3
0
        private static List <Vector3> ReadAllVertices(XmlReader reader, ProgressData progressData)
        {
            var vertices = new List <Vector3>();

            if (reader.ReadToDescendant("vertex"))
            {
                do
                {
                    if (reader.ReadToDescendant("coordinates"))
                    {
                        var vertex = default(Vector3);

                        string nextSibling = null;
                        if (reader.ReadToDescendant("x"))
                        {
                            do
                            {
                                switch (reader.Name)
                                {
                                case "x":
                                    vertex.X    = reader.ReadElementContentAsDouble();
                                    nextSibling = "y";
                                    break;

                                case "y":
                                    vertex.Y    = reader.ReadElementContentAsDouble();
                                    nextSibling = "z";
                                    break;

                                case "z":
                                    vertex.Z    = reader.ReadElementContentAsDouble();
                                    nextSibling = null;

                                    break;
                                }
                            }while (nextSibling != null && (reader.Name != nextSibling ? reader.ReadToNextSibling(nextSibling) : true));
                        }

                        progressData.ReportProgress0To50();

                        vertices.Add(vertex);
                    }

                    MoveToEndElement(reader, "vertex");
                }while (reader.ReadToNextSibling("vertex"));
            }

            return(vertices);
        }
Example #4
0
        private static Mesh ReadVolume(XmlReader xmlTree, List <Vector3> vertices, ProgressData progressData)
        {
            Mesh newMesh = new Mesh();

            while (xmlTree.Read())
            {
                if (xmlTree.Name == "triangle")
                {
                    using (XmlReader triangleTree = xmlTree.ReadSubtree())
                    {
                        while (triangleTree.Read())
                        {
                            int[] indices = new int[3];
                            while (triangleTree.Read())
                            {
                                switch (triangleTree.Name)
                                {
                                case "v1":
                                    string v1 = triangleTree.ReadString();
                                    indices[0] = int.Parse(v1);
                                    break;

                                case "v2":
                                    string v2 = triangleTree.ReadString();
                                    indices[1] = int.Parse(v2);
                                    break;

                                case "v3":
                                    string v3 = triangleTree.ReadString();
                                    indices[2] = int.Parse(v3);
                                    break;

                                case "map":
                                    using (XmlReader mapTree = triangleTree.ReadSubtree())
                                    {
                                    }
                                    // a texture map, has u1...un and v1...vn
                                    break;

                                default:
                                    break;
                                }
                            }
                            if (indices[0] != indices[1] &&
                                indices[0] != indices[2] &&
                                indices[1] != indices[2] &&
                                vertices[indices[0]] != vertices[indices[1]] &&
                                vertices[indices[1]] != vertices[indices[2]] &&
                                vertices[indices[2]] != vertices[indices[0]])
                            {
                                Vertex[] triangle = new Vertex[]
                                {
                                    newMesh.CreateVertex(vertices[indices[0]], CreateOption.CreateNew, SortOption.WillSortLater),
                                    newMesh.CreateVertex(vertices[indices[1]], CreateOption.CreateNew, SortOption.WillSortLater),
                                    newMesh.CreateVertex(vertices[indices[2]], CreateOption.CreateNew, SortOption.WillSortLater),
                                };
                                newMesh.CreateFace(triangle, CreateOption.CreateNew);
                            }

                            bool continueProcessing;
                            progressData.ReportProgress0To50(out continueProcessing);
                            if (!continueProcessing)
                            {
                                // this is what we should do but it requires a bit more debugging.
                                return(null);
                            }
                        }
                    }
                }
            }
            return(newMesh);
        }
Example #5
0
		private static void ReadVertices(XmlReader xmlTree, List<Vector3> vertices, double scale, ProgressData progressData)
		{
			while (xmlTree.Read())
			{
				if (xmlTree.Name == "vertices")
				{
					using (XmlReader verticesTree = xmlTree.ReadSubtree())
					{
						while (verticesTree.Read())
						{
							if (xmlTree.Name == "vertex")
							{
								using (XmlReader vertexTree = verticesTree.ReadSubtree())
								{
									while (vertexTree.Read())
									{
										if (vertexTree.Name == "coordinates")
										{
											using (XmlReader coordinatesTree = vertexTree.ReadSubtree())
											{
												Vector3 position = new Vector3();
												while (coordinatesTree.Read())
												{
													switch (coordinatesTree.Name)
													{
														case "x":
															string x = coordinatesTree.ReadString();
															position.x = double.Parse(x);
															break;

														case "y":
															string y = coordinatesTree.ReadString();
															position.y = double.Parse(y);
															break;

														case "z":
															string z = coordinatesTree.ReadString();
															position.z = double.Parse(z);
															break;

														default:
															break;
													}
												}
												position *= scale;
												vertices.Add(position);
											}
											bool continueProcessing;
											progressData.ReportProgress0To50(out continueProcessing);
										}
									}
								}
							}
						}
					}
				}
			}
		}
Example #6
0
		private static Mesh ReadVolume(XmlReader xmlTree, List<Vector3> vertices, ProgressData progressData)
		{
			Mesh newMesh = new Mesh();
			while (xmlTree.Read())
			{
				if (xmlTree.Name == "triangle")
				{
					using (XmlReader triangleTree = xmlTree.ReadSubtree())
					{
						while (triangleTree.Read())
						{
							int[] indices = new int[3];
							while (triangleTree.Read())
							{
								switch (triangleTree.Name)
								{
									case "v1":
										string v1 = triangleTree.ReadString();
										indices[0] = int.Parse(v1);
										break;

									case "v2":
										string v2 = triangleTree.ReadString();
										indices[1] = int.Parse(v2);
										break;

									case "v3":
										string v3 = triangleTree.ReadString();
										indices[2] = int.Parse(v3);
										break;

									case "map":
										using (XmlReader mapTree = triangleTree.ReadSubtree())
										{
										}
										// a texture map, has u1...un and v1...vn
										break;

									default:
										break;
								}
							}
							if (indices[0] != indices[1]
								&& indices[0] != indices[2]
								&& indices[1] != indices[2]
								&& vertices[indices[0]] != vertices[indices[1]]
								&& vertices[indices[1]] != vertices[indices[2]]
								&& vertices[indices[2]] != vertices[indices[0]])
							{
								Vertex[] triangle = new Vertex[]
                                {
                                    newMesh.CreateVertex(vertices[indices[0]], CreateOption.CreateNew, SortOption.WillSortLater),
                                    newMesh.CreateVertex(vertices[indices[1]], CreateOption.CreateNew, SortOption.WillSortLater),
                                    newMesh.CreateVertex(vertices[indices[2]], CreateOption.CreateNew, SortOption.WillSortLater),
                                };
								newMesh.CreateFace(triangle, CreateOption.CreateNew);
							}

							bool continueProcessing;
							progressData.ReportProgress0To50(out continueProcessing);
							if (!continueProcessing)
							{
								// this is what we should do but it requires a bit more debugging.
								return null;
							}
						}
					}
				}
			}
			return newMesh;
		}