コード例 #1
0
ファイル: MeshStructs.cs プロジェクト: Gemi-Games/QMap2Unity
        public CMesh(AMesh lMesh)
        {
            V = new CVertex[lMesh.V.Length];
            for (int i = 0; i < lMesh.V.Length; i++)
            {
                V[i] = new CVertex(lMesh.V[i].Position);
            }

            E = new CEdge[lMesh.E.Length];
            for (int i = 0; i < lMesh.E.Length; i++)
            {
                int[] lVerts = new int[2] {
                    lMesh.E[i].Vertices[0], lMesh.E[i].Vertices[1]
                };
                int[] lFaces = new int[2] {
                    lMesh.E[i].Faces[0], lMesh.E[i].Faces[1]
                };
                E[i] = new CEdge(lVerts, lFaces);
            }

            F = new CFace[lMesh.F.Length];
            for (int i = 0; i < lMesh.F.Length; i++)
            {
                int[] lEdges = new int[lMesh.F[i].Edges.Length];

                for (int j = 0; j < lMesh.F[i].Edges.Length; j++)
                {
                    lEdges[j] = lMesh.F[i].Edges[j];
                }

                F[i] = new CFace(lEdges, lMesh.F[i].Plane);
            }
        }
コード例 #2
0
ファイル: ClipMesh.cs プロジェクト: Gemi-Games/QMap2Unity
        public static CMesh CreateConvexPolyhedron(Plane[] lPlanes, Vector3 lCentre, Vector3 lSize)
        {
            AMesh lMeshToClip = CreateAMeshBox(lCentre, lSize);

            CMesh lClippedMesh = new CMesh(lMeshToClip);

            for (int i = 0; i < lPlanes.Length; i++)
            {
                ClipOperationResult lResult = Clip(ref lClippedMesh, lPlanes[i]);

                if (lResult == ClipOperationResult.AllNegative)
                {
                    break;
                }
            }

            return(lClippedMesh);
        }
コード例 #3
0
ファイル: ClipMesh.cs プロジェクト: Gemi-Games/QMap2Unity
        private static AMesh CreateAMeshBox(Vector3 lCentre, Vector3 lSize)
        {
            Vector3 lHalfSize = lSize * 0.5f;
            Vector3 lMin      = lCentre - lHalfSize;
            Vector3 lMax      = lCentre + lHalfSize;

            AVertex[] lVerts = new AVertex[8];
            lVerts[0] = new AVertex(new Vector3(lMin.x, lMax.y, lMin.z));
            lVerts[1] = new AVertex(new Vector3(lMax.x, lMax.y, lMin.z));
            lVerts[2] = new AVertex(new Vector3(lMax.x, lMin.y, lMin.z));
            lVerts[3] = new AVertex(new Vector3(lMin.x, lMin.y, lMin.z));

            lVerts[4] = new AVertex(new Vector3(lMin.x, lMax.y, lMax.z));
            lVerts[5] = new AVertex(new Vector3(lMax.x, lMax.y, lMax.z));
            lVerts[6] = new AVertex(new Vector3(lMax.x, lMin.y, lMax.z));
            lVerts[7] = new AVertex(new Vector3(lMin.x, lMin.y, lMax.z));

            AEdge[] lEdges = new AEdge[12];
            lEdges[0] = new AEdge(new int[2] {
                0, 1
            }, new int[2] {
                0, 1
            });
            lEdges[1] = new AEdge(new int[2] {
                1, 2
            }, new int[2] {
                0, 2
            });
            lEdges[2] = new AEdge(new int[2] {
                2, 3
            }, new int[2] {
                0, 3
            });
            lEdges[3] = new AEdge(new int[2] {
                3, 0
            }, new int[2] {
                0, 4
            });

            lEdges[4] = new AEdge(new int[2] {
                0, 4
            }, new int[2] {
                4, 1
            });
            lEdges[5] = new AEdge(new int[2] {
                1, 5
            }, new int[2] {
                1, 2
            });
            lEdges[6] = new AEdge(new int[2] {
                2, 6
            }, new int[2] {
                2, 3
            });
            lEdges[7] = new AEdge(new int[2] {
                3, 7
            }, new int[2] {
                3, 4
            });

            lEdges[8] = new AEdge(new int[2] {
                4, 5
            }, new int[2] {
                1, 5
            });
            lEdges[9] = new AEdge(new int[2] {
                5, 6
            }, new int[2] {
                2, 5
            });
            lEdges[10] = new AEdge(new int[2] {
                6, 7
            }, new int[2] {
                3, 5
            });
            lEdges[11] = new AEdge(new int[2] {
                7, 4
            }, new int[2] {
                4, 5
            });

            AFace[] lFaces = new AFace[6];
            lFaces[0] = new AFace(new int[4] {
                0, 1, 2, 3
            }, new Plane(Vector3.forward, lMin.z));
            lFaces[1] = new AFace(new int[4] {
                0, 4, 8, 5
            }, new Plane(Vector3.down, -lMax.y));
            lFaces[2] = new AFace(new int[4] {
                1, 6, 9, 5
            }, new Plane(Vector3.left, -lMax.x));
            lFaces[3] = new AFace(new int[4] {
                2, 7, 10, 6
            }, new Plane(Vector3.up, lMin.y));
            lFaces[4] = new AFace(new int[4] {
                3, 7, 11, 4
            }, new Plane(Vector3.right, lMin.x));
            lFaces[5] = new AFace(new int[4] {
                8, 9, 10, 11
            }, new Plane(Vector3.back, -lMax.z));

            AMesh lMesh = new AMesh();

            lMesh.V = lVerts;
            lMesh.E = lEdges;
            lMesh.F = lFaces;

            return(lMesh);
        }