Ejemplo n.º 1
0
		// Return a new CSG solid representing space in either this solid or in the
		// solid `csg`. Neither this solid nor the solid `csg` are modified.
		//
		//     +-------+            +-------+
		//     |       |            |       |
		//     |   A   |            |       |
		//     |    +--+----+   =   |       +----+
		//     +----+--+    |       +----+       |
		//          |   B   |            |       |
		//          |       |            |       |
		//          +-------+            +-------+
		//
		public static Mesh Union(Mesh a1, Mesh b1)
		{
			CsgAcceleratedMesh a = new CsgAcceleratedMesh(a1);
			CsgAcceleratedMesh b = new CsgAcceleratedMesh(b1);
			a.SplitOnAllEdgeIntersections(b);
			b.SplitOnAllEdgeIntersections(a);

			a.MarkInternalVertices(b);
			b.MarkInternalVertices(a);

			a.RemoveAllInternalEdges();
			b.RemoveAllInternalEdges();

			a.MergeWith(b);

			return a.mesh;
		}
Ejemplo n.º 2
0
        // Return a new CSG solid representing space in either this solid or in the
        // solid `csg`. Neither this solid nor the solid `csg` are modified.
        //
        //     +-------+            +-------+
        //     |       |            |       |
        //     |   A   |            |       |
        //     |    +--+----+   =   |       +----+
        //     +----+--+    |       +----+       |
        //          |   B   |            |       |
        //          |       |            |       |
        //          +-------+            +-------+
        //
        public static Mesh Union(Mesh a1, Mesh b1)
        {
            CsgAcceleratedMesh a = new CsgAcceleratedMesh(a1);
            CsgAcceleratedMesh b = new CsgAcceleratedMesh(b1);

            a.SplitOnAllEdgeIntersections(b);
            b.SplitOnAllEdgeIntersections(a);

            a.MarkInternalVertices(b);
            b.MarkInternalVertices(a);

            a.RemoveAllInternalEdges();
            b.RemoveAllInternalEdges();

            a.MergeWith(b);

            return(a.mesh);
        }
Ejemplo n.º 3
0
        public void SplitOnAllEdgeIntersections(CsgAcceleratedMesh meshWidthEdges)
        {
            AxisAlignedBoundingBox boundsForFaces             = this.mesh.GetAxisAlignedBoundingBox();
            AxisAlignedBoundingBox boundsForEdges             = meshWidthEdges.mesh.GetAxisAlignedBoundingBox();
            AxisAlignedBoundingBox faceEdgeBoundsIntersection = AxisAlignedBoundingBox.Intersection(boundsForEdges, boundsForFaces);

            foreach (var meshEdge in meshWidthEdges.GetMeshEdgesTouching(faceEdgeBoundsIntersection))
            {
                // Check the mesh edge bounds agains all polygons. If there is an intersection
                // subdivide the mesh edge and if the face that is hit. If hit face on an edge only split the edge.
                Vector3 end0 = meshEdge.VertexOnEnd[0].Position;
                Vector3 end1 = meshEdge.VertexOnEnd[1].Position;
                Ray     ray  = new Ray(end0, (end1 - end0).GetNormal());
                AxisAlignedBoundingBox edgeBounds = new AxisAlignedBoundingBox(Vector3.ComponentMin(end0, end1), Vector3.ComponentMax(end0, end1));

                foreach (Face face in GetFacesTouching(edgeBounds))
                {
                    Vector3 intersectionPosition;
                    // intersect the face with the edge
                    switch (face.Intersection(ray, out intersectionPosition))
                    {
                    case FaceHelper.IntersectionType.Vertex:
                        break;

                    case FaceHelper.IntersectionType.MeshEdge:
                    {
                        SplitMeshEdge(meshEdge, intersectionPosition);
                        // split the face at intersectionPosition
                        SplitMeshEdgeAtPosition(face, intersectionPosition);
                    }
                    break;

                    case FaceHelper.IntersectionType.Face:
                    {
                        SplitMeshEdge(meshEdge, intersectionPosition);
                        // split the face at intersectionPosition
                        SplitFaceAtPosition(face, intersectionPosition);
                    }
                    break;
                    }
                }
            }
        }
Ejemplo n.º 4
0
		public void SplitOnAllEdgeIntersections(CsgAcceleratedMesh meshWidthEdges)
		{
			foreach (var meshEdge in meshWidthEdges.mesh.MeshEdges)
			{
				// Check the mesh edge bounds agains all polygons. If there is an intersection
				// subdivide the mesh edge and if the face that is hit. If hit face on an edge only split the edge.
				Vector3 end0 = meshEdge.VertexOnEnd[0].Position;
				Vector3 end1 = meshEdge.VertexOnEnd[1].Position;
				AxisAlignedBoundingBox edgeBounds = new AxisAlignedBoundingBox(Vector3.ComponentMin(end0, end1), Vector3.ComponentMax(end0, end1));

				foreach (Face face in GetFacesTouching(edgeBounds))
				{
					Vector3 intersectionPosition;
					// intersect the face with the edge
					switch (face.Intersection(end0, end1, out intersectionPosition))
					{
						case FaceHelper.IntersectionType.Vertex:
							break;

						case FaceHelper.IntersectionType.MeshEdge:
							{
								SplitMeshEdgeIfRequired(meshEdge, intersectionPosition);
								// split the face at intersectionPosition
								SplitMeshEdgeAtPosition(face, intersectionPosition);
							}
							break;

						case FaceHelper.IntersectionType.Face:
							{
								SplitMeshEdgeIfRequired(meshEdge, intersectionPosition);
								// split the face at intersectionPosition
								SplitFaceAtPosition(face, intersectionPosition);
							}
							break;
					}
				}
			}
		}
Ejemplo n.º 5
0
 internal void MergeWith(CsgAcceleratedMesh b)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
 internal void MarkInternalVertices(CsgAcceleratedMesh b)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 7
0
		internal void MergeWith(CsgAcceleratedMesh b)
		{
			throw new NotImplementedException();
		}
Ejemplo n.º 8
0
		internal void MarkInternalVertices(CsgAcceleratedMesh b)
		{
			throw new NotImplementedException();
		}