public void Traversal()
 {
     pecies.Clear();
     foreach (var target in breakable.ModelInfos)
     {
         for (int i = 0; i < target.triangles.Count; i += 3)
         {
             TriangleFace breakableFace;
             if (target.normals != null && target.normals.Count > 0)
             {
                 VertexData[] vertexData;
                 if (target.uvs != null && target.uvs.Count > 0)
                 {
                     vertexData = new VertexData[] {
                         new VertexData(target.vertices[target.triangles[i]], target.normals[target.triangles[i]], target.uvs[target.triangles[i]]),
                         new VertexData(target.vertices[target.triangles[i + 1]], target.normals[target.triangles[i + 1]], target.uvs[target.triangles[i + 1]]),
                         new VertexData(target.vertices[target.triangles[i + 2]], target.normals[target.triangles[i + 2]], target.uvs[target.triangles[i + 2]])
                     };
                 }
                 else
                 {
                     vertexData = new VertexData[]
                     {
                         new VertexData(target.vertices[target.triangles[i]], target.normals[target.triangles[i]]),
                         new VertexData(target.vertices[target.triangles[i + 1]], target.normals[target.triangles[i + 1]]),
                         new VertexData(target.vertices[target.triangles[i + 2]], target.normals[target.triangles[i + 2]])
                     };
                 }
                 breakableFace = new TriangleFace(vertexData[0], vertexData[1], vertexData[2]);
             }
             else
             {
                 breakableFace = new TriangleFace(target.vertices[target.triangles[i]], target.vertices[target.triangles[i + 1]], target.vertices[target.triangles[i + 2]]);
             }
             pecies.AddRange(genPieces.GenModelData(breakableFace));
         }
     }
 }
Beispiel #2
0
        private void SplitTwoPart(ref TriangleFace triangleFace, ref Stack <TriangleFace> faceStack)
        {
            Vector3    ab = triangleFace.pointB.vertex - triangleFace.pointA.vertex;
            Vector3    ca = triangleFace.pointA.vertex - triangleFace.pointC.vertex;
            Vector3    bc = triangleFace.pointC.vertex - triangleFace.pointB.vertex;
            Vector3    maxLenVec;
            VertexData startPointData;
            VertexData endPointData;
            VertexData leftPointData;

            if (ab.magnitude > ca.magnitude)
            {
                maxLenVec      = ab;
                startPointData = triangleFace.pointA;
                endPointData   = triangleFace.pointB;
                leftPointData  = triangleFace.pointC;
            }
            else
            {
                maxLenVec      = ca;
                startPointData = triangleFace.pointC;
                endPointData   = triangleFace.pointA;
                leftPointData  = triangleFace.pointB;
            }
            if (maxLenVec.magnitude < bc.magnitude)
            {
                maxLenVec      = bc;
                startPointData = triangleFace.pointB;
                endPointData   = triangleFace.pointC;
                leftPointData  = triangleFace.pointA;
            }
            Vector3    newPoint     = startPointData.vertex + maxLenVec * 0.5f;
            VertexData newPointData = triangleFace.Interlopation(newPoint, true, true);

            faceStack.Push(new TriangleFace(leftPointData, startPointData, newPointData));
            faceStack.Push(new TriangleFace(leftPointData, newPointData, endPointData));
        }