private unsafe DynamicUnstructureGeometry DoCreateMesh(DynamicUnstructuredGridderSource src)
        {
            MatrixPositionBuffer   matrixPositions         = null;
            IndexBuffer            matrixIndicesBuffer     = null;
            FracturePositionBuffer fractionPositionsBuffer = null;

            //生成母体
            if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT4_TETRAHEDRON)
            {
                matrixPositions = new TetrahedronMatrixPositionBuffer();
                //matrixPositions.Shape = MatrixPositionBufferData.SHAPE_TETRAHEDRON;

                //int memSize = src.ElementNum * sizeof(TetrahedronPositions);
                //matrixPositions.AllocMem(memSize);
                matrixPositions.AllocMem(src.ElementNum);

                TetrahedronPosition *tets = (TetrahedronPosition *)matrixPositions.Data;
                int[][]  matrixIndices    = src.Elements;
                Vertex[] positions        = src.Nodes;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    tets[i].p1 = src.Transform * positions[matrixIndices[i][0] - 1];
                    tets[i].p2 = src.Transform * positions[matrixIndices[i][1] - 1];
                    tets[i].p3 = src.Transform * positions[matrixIndices[i][2] - 1];
                    tets[i].p4 = src.Transform * positions[matrixIndices[i][3] - 1];
                }

                matrixIndicesBuffer = new TetrahedronMatrixIndexBuffer();
                //int triangleCount = src.ElementNum * 4;
                //matrixIndicesBuffer.AllocMem(triangleCount * sizeof(TriangleIndex));
                matrixIndicesBuffer.AllocMem(src.ElementNum);
                TetrahedronIndex *header = (TetrahedronIndex *)matrixIndicesBuffer.Data;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    header[i].dot0         = (uint)(i * 4 + 0);
                    header[i].dot1         = (uint)(i * 4 + 1);
                    header[i].dot2         = (uint)(i * 4 + 2);
                    header[i].dot3         = (uint)(i * 4 + 3);
                    header[i].dot4         = (uint)(i * 4 + 0);
                    header[i].dot5         = (uint)(i * 4 + 1);
                    header[i].restartIndex = uint.MaxValue;
                }
            }

            if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT3_TRIANGLE)
            {
                matrixPositions = new TriangleMatrixPositionBuffer();
                //matrixPositions.Shape = MatrixPositionBufferData.SHAPE_TRIANGLE;
                matrixPositions.AllocMem(src.ElementNum);
                int[][]           matrixIndices = src.Elements;
                Vertex[]          positions     = src.Nodes;
                TrianglePosition *triangles     = (TrianglePosition *)matrixPositions.Data;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    triangles[i].P1 = src.Transform * positions[matrixIndices[i][0] - 1];
                    triangles[i].P2 = src.Transform * positions[matrixIndices[i][1] - 1];
                    triangles[i].P3 = src.Transform * positions[matrixIndices[i][2] - 1];
                }
            }

            if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT6_TRIANGULAR_PRISM)
            {
                matrixPositions = new TriangularPrismMatrixPositionBuffer();
                //matrixPositions.Shape = MatrixPositionBufferData.SHAPE_TRIANGLE;
                matrixPositions.AllocMem(src.ElementNum);
                int[][]  matrixIndices         = src.Elements;
                Vertex[] positions             = src.Nodes;
                TriangularPrismPosition *prism = (TriangularPrismPosition *)matrixPositions.Data;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    try
                    {
                        prism[i].P1 = src.Transform * positions[matrixIndices[i][0] - 1];
                        prism[i].P2 = src.Transform * positions[matrixIndices[i][1] - 1];
                        prism[i].P3 = src.Transform * positions[matrixIndices[i][2] - 1];
                        prism[i].P4 = src.Transform * positions[matrixIndices[i][3] - 1];
                        prism[i].P5 = src.Transform * positions[matrixIndices[i][4] - 1];
                        prism[i].P6 = src.Transform * positions[matrixIndices[i][5] - 1];
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        throw new IndexOutOfRangeException(String.Format("Maxtrix positions row:{0},out of range", i + 1));
                    }
                }

                matrixIndicesBuffer = new TetrahedronMatrixTriangularPrismIndexBuffer();
                //int triangleCount = src.ElementNum * 4;
                //matrixIndicesBuffer.AllocMem(triangleCount * sizeof(TriangleIndex));
                matrixIndicesBuffer.AllocMem(src.ElementNum);
                TetrahedronTriangularPrismIndex *indexes = (TetrahedronTriangularPrismIndex *)matrixIndicesBuffer.Data;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    indexes[i].dot0         = (uint)(i * 6 + 0);
                    indexes[i].dot1         = (uint)(i * 6 + 3);
                    indexes[i].dot2         = (uint)(i * 6 + 1);
                    indexes[i].dot3         = (uint)(i * 6 + 4);
                    indexes[i].dot4         = (uint)(i * 6 + 2);
                    indexes[i].dot5         = (uint)(i * 6 + 5);
                    indexes[i].dot6         = (uint)(i * 6 + 0);
                    indexes[i].dot7         = (uint)(i * 6 + 3);
                    indexes[i].restartIndex = uint.MaxValue;
                }
            }

            //生成裂缝
            if (src.FractureFormat == DynamicUnstructuredGridderSource.FRACTURE_FORMAT3_TRIANGLE)
            {
                fractionPositionsBuffer = new TriangleFracturePositionBuffer();

                //fractionPositionsBuffer.Shape = FracturePositionBufferData.SHAPE_TRIANGLE;

                int triangleCount = src.FractureNum;

                //fractionPositionsBuffer.AllocMem(triangleCount * sizeof(TrianglePositions));
                fractionPositionsBuffer.AllocMem(triangleCount);

                int[][]           triangleIndices = src.Fractures;
                Vertex[]          positions       = src.Nodes;
                TrianglePosition *triangles       = (TrianglePosition *)fractionPositionsBuffer.Data;
                for (int i = 0; i < triangleCount; i++)
                {
                    triangles[i].P1 = src.Transform * positions[triangleIndices[i][0] - 1];
                    triangles[i].P2 = src.Transform * positions[triangleIndices[i][1] - 1];
                    triangles[i].P3 = src.Transform * positions[triangleIndices[i][2] - 1];
                }
            }

            if (src.FractureFormat == DynamicUnstructuredGridderSource.FRACTURE_FORMAT2_LINE)
            {
                fractionPositionsBuffer = new LineFracturePositionBuffer();

                //fractionPositionsBuffer.Shape = FracturePositionBufferData.SHAPE_LINE;

                int lineCount = src.FractureNum;

                //fractionPositionsBuffer.AllocMem(lineCount * sizeof(LinePositions));
                fractionPositionsBuffer.AllocMem(lineCount);

                LinePosition *lines       = (LinePosition *)fractionPositionsBuffer.Data;
                Vertex[]      positions   = src.Nodes;
                int[][]       lineIndices = src.Fractures;
                for (int i = 0; i < lineCount; i++)
                {
                    lines[i].P1 = src.Transform * positions[lineIndices[i][0] - 1];
                    lines[i].P2 = src.Transform * positions[lineIndices[i][1] - 1];
                }
            }

            if (src.FractureFormat == DynamicUnstructuredGridderSource.FRACTURE_FORMAT4_QUAD)
            {
                fractionPositionsBuffer = new QuadFracturePositionBuffer();
                int fractureCount = src.FractureNum;
                fractionPositionsBuffer.AllocMem(fractureCount);
                QuadPosition *quad        = (QuadPosition *)fractionPositionsBuffer.Data;
                Vertex[]      positions   = src.Nodes;
                int[][]       quadIndices = src.Fractures;
                for (int i = 0; i < fractureCount; i++)
                {
                    quad[i].P1 = src.Transform * positions[quadIndices[i][0] - 1];
                    quad[i].P2 = src.Transform * positions[quadIndices[i][1] - 1];
                    quad[i].P3 = src.Transform * positions[quadIndices[i][3] - 1];
                    quad[i].P4 = src.Transform * positions[quadIndices[i][2] - 1];
                }
            }

            DynamicUnstructureGeometry geometry = new DynamicUnstructureGeometry(matrixPositions);

            geometry.MatrixIndices     = matrixIndicesBuffer;
            geometry.FracturePositions = fractionPositionsBuffer;
            geometry.Min = src.TransformedActiveBounds.Min;
            geometry.Max = src.TransformedActiveBounds.Max;
            return(geometry);
        }
        private unsafe DynamicUnstructureGeometry DoCreateMesh(DynamicUnstructuredGridderSource src)
        {
            MatrixPositionBuffer matrixPositions = null;
            IndexBuffer matrixIndicesBuffer = null;
            FracturePositionBuffer fractionPositionsBuffer = null;

            //生成母体
            if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT4_TETRAHEDRON)
            {
                matrixPositions = new TetrahedronMatrixPositionBuffer();
                //matrixPositions.Shape = MatrixPositionBufferData.SHAPE_TETRAHEDRON;

                //int memSize = src.ElementNum * sizeof(TetrahedronPositions);
                //matrixPositions.AllocMem(memSize);
                matrixPositions.AllocMem(src.ElementNum);

                TetrahedronPosition* tets = (TetrahedronPosition*)matrixPositions.Data;
                int[][] matrixIndices = src.Elements;
                vec3[] positions = src.Nodes;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    tets[i].p1 = src.TranslateMatrix*positions[matrixIndices[i][0]-1];
                    tets[i].p2 = src.TranslateMatrix*positions[matrixIndices[i][1]-1];
                    tets[i].p3 = src.TranslateMatrix*positions[matrixIndices[i][2]-1];
                    tets[i].p4 = src.TranslateMatrix*positions[matrixIndices[i][3]-1];
                }

                matrixIndicesBuffer = new TetrahedronMatrixIndexBuffer();
                //int triangleCount = src.ElementNum * 4;
                //matrixIndicesBuffer.AllocMem(triangleCount * sizeof(TriangleIndex));
                matrixIndicesBuffer.AllocMem(src.ElementNum);
                TetrahedronIndex* header = (TetrahedronIndex*)matrixIndicesBuffer.Data;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    header[i].dot0 = (uint)(i * 4 + 0);
                    header[i].dot1 = (uint)(i * 4 + 1);
                    header[i].dot2 = (uint)(i * 4 + 2);
                    header[i].dot3 = (uint)(i * 4 + 3);
                    header[i].dot4 = (uint)(i * 4 + 0);
                    header[i].dot5 = (uint)(i * 4 + 1);
                    header[i].restartIndex = uint.MaxValue;
                }
            }

            if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT3_TRIANGLE)
            {
                matrixPositions = new TriangleMatrixPositionBuffer();
                //matrixPositions.Shape = MatrixPositionBufferData.SHAPE_TRIANGLE;
                matrixPositions.AllocMem(src.ElementNum);
                int[][] matrixIndices = src.Elements;
                vec3[] positions = src.Nodes;
                var triangles = (TrianglePosition*)matrixPositions.Data;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    triangles[i].P1 = src.TranslateMatrix*positions[matrixIndices[i][0]-1];
                    triangles[i].P2 = src.TranslateMatrix*positions[matrixIndices[i][1]-1];
                    triangles[i].P3 = src.TranslateMatrix*positions[matrixIndices[i][2]-1];
                }
            }

            if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT6_TRIANGULAR_PRISM)
            {
                matrixPositions = new TriangularPrismMatrixPositionBuffer();
                //matrixPositions.Shape = MatrixPositionBufferData.SHAPE_TRIANGLE;
                matrixPositions.AllocMem(src.ElementNum);
                int[][] matrixIndices = src.Elements;
                vec3[] positions = src.Nodes;
                TriangularPrismPosition* prism = (TriangularPrismPosition*)matrixPositions.Data;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    try
                    {
                        prism[i].P1 = src.TranslateMatrix*positions[matrixIndices[i][0]-1];
                        prism[i].P2 = src.TranslateMatrix*positions[matrixIndices[i][1]-1];
                        prism[i].P3 = src.TranslateMatrix*positions[matrixIndices[i][2]-1];
                        prism[i].P4 = src.TranslateMatrix*positions[matrixIndices[i][3]-1];
                        prism[i].P5 = src.TranslateMatrix*positions[matrixIndices[i][4]-1];
                        prism[i].P6 = src.TranslateMatrix*positions[matrixIndices[i][5]-1];
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        throw new IndexOutOfRangeException(String.Format("Maxtrix positions row:{0},out of range", i + 1));
                    }
                }

                matrixIndicesBuffer = new TetrahedronMatrixTriangularPrismIndexBuffer();
                //int triangleCount = src.ElementNum * 4;
                //matrixIndicesBuffer.AllocMem(triangleCount * sizeof(TriangleIndex));
                matrixIndicesBuffer.AllocMem(src.ElementNum);
                TetrahedronTriangularPrismIndex* indexes = (TetrahedronTriangularPrismIndex*)matrixIndicesBuffer.Data;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    indexes[i].dot0 = (uint)(i * 6 + 0);
                    indexes[i].dot1 = (uint)(i * 6 + 3);
                    indexes[i].dot2 = (uint)(i * 6 + 1);
                    indexes[i].dot3 = (uint)(i * 6 + 4);
                    indexes[i].dot4 = (uint)(i * 6 + 2);
                    indexes[i].dot5 = (uint)(i * 6 + 5);
                    indexes[i].dot6 = (uint)(i * 6 + 0);
                    indexes[i].dot7 = (uint)(i * 6 + 3);
                    indexes[i].restartIndex = uint.MaxValue;
                }
            }

            //生成裂缝
            if (src.FractureFormat == DynamicUnstructuredGridderSource.FRACTURE_FORMAT3_TRIANGLE)
            {
                fractionPositionsBuffer = new TriangleFracturePositionBuffer();

                //fractionPositionsBuffer.Shape = FracturePositionBufferData.SHAPE_TRIANGLE;

                int triangleCount = src.FractureNum;

                //fractionPositionsBuffer.AllocMem(triangleCount * sizeof(TrianglePositions));
                fractionPositionsBuffer.AllocMem(triangleCount);

                int[][] triangleIndices = src.Fractures;
                vec3[] positions = src.Nodes;
                TrianglePosition* triangles = (TrianglePosition*)fractionPositionsBuffer.Data;
                for (int i = 0; i < triangleCount; i++)
                {
                    triangles[i].P1 = src.TranslateMatrix*positions[triangleIndices[i][0]-1];
                    triangles[i].P2 = src.TranslateMatrix*positions[triangleIndices[i][1]-1];
                    triangles[i].P3 = src.TranslateMatrix*positions[triangleIndices[i][2]-1];
                }
            }

            if (src.FractureFormat == DynamicUnstructuredGridderSource.FRACTURE_FORMAT2_LINE)
            {
                fractionPositionsBuffer = new LineFracturePositionBuffer();

                //fractionPositionsBuffer.Shape = FracturePositionBufferData.SHAPE_LINE;

                int lineCount = src.FractureNum;

                //fractionPositionsBuffer.AllocMem(lineCount * sizeof(LinePositions));
                fractionPositionsBuffer.AllocMem(lineCount);

                LinePosition* lines = (LinePosition*)fractionPositionsBuffer.Data;
                vec3[] positions = src.Nodes;
                int[][] lineIndices = src.Fractures;
                for (int i = 0; i < lineCount; i++)
                {
                    lines[i].P1 = src.TranslateMatrix*positions[lineIndices[i][0]-1];
                    lines[i].P2 = src.TranslateMatrix*positions[lineIndices[i][1]-1];
                }
            }

            if (src.FractureFormat == DynamicUnstructuredGridderSource.FRACTURE_FORMAT4_QUAD)
            {
                fractionPositionsBuffer = new QuadFracturePositionBuffer();
                int fractureCount = src.FractureNum;
                fractionPositionsBuffer.AllocMem(fractureCount);
                QuadPosition* quad = (QuadPosition*)fractionPositionsBuffer.Data;
                vec3[] positions = src.Nodes;
                int[][] quadIndices = src.Fractures;
                for (int i = 0; i < fractureCount; i++)
                {
                    quad[i].P1 = src.TranslateMatrix*positions[quadIndices[i][0]-1];
                    quad[i].P2 = src.TranslateMatrix*positions[quadIndices[i][1]-1];
                    quad[i].P3 = src.TranslateMatrix*positions[quadIndices[i][3]-1];
                    quad[i].P4 = src.TranslateMatrix*positions[quadIndices[i][2]-1];
                }
            }

            DynamicUnstructureGeometry geometry = new DynamicUnstructureGeometry(matrixPositions);
            geometry.MatrixIndices = matrixIndicesBuffer;
            geometry.FracturePositions = fractionPositionsBuffer;
            geometry.Min = src.TransformedActiveBounds.Min;
            geometry.Max = src.TransformedActiveBounds.Max;
            return geometry;
        }
Пример #3
0
        private unsafe DynamicUnstructureGeometry DoCreateMesh(DynamicUnstructuredGridderSource src)
        {
            MatrixPositionBuffer         matrixPositions         = null;
            TetrahedronMatrixIndexBuffer matrixIndicesBuffer     = null;
            FracturePositionBuffer       fractionPositionsBuffer = null;

            //生成母体
            if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT4_TETRAHEDRON)
            {
                matrixPositions = new TetrahedronMatrixPositionBuffer();
                //matrixPositions.Shape = MatrixPositionBufferData.SHAPE_TETRAHEDRON;

                //int memSize = src.ElementNum * sizeof(TetrahedronPositions);
                //matrixPositions.AllocMem(memSize);
                matrixPositions.AllocMem(src.ElementNum);

                TetrahedronPosition *tets = (TetrahedronPosition *)matrixPositions.Data;
                int[][]  matrixIndices    = src.Elements;
                Vertex[] positions        = src.Nodes;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    tets[i].p1 = positions[matrixIndices[i][0] - 1];
                    tets[i].p2 = positions[matrixIndices[i][1] - 1];
                    tets[i].p3 = positions[matrixIndices[i][2] - 1];
                    tets[i].p4 = positions[matrixIndices[i][3] - 1];
                }

                matrixIndicesBuffer = new TetrahedronMatrixIndexBuffer();
                //int triangleCount = src.ElementNum * 4;
                //matrixIndicesBuffer.AllocMem(triangleCount * sizeof(TriangleIndex));
                matrixIndicesBuffer.AllocMem(src.ElementNum);
                TetrahedronIndex *header = (TetrahedronIndex *)matrixIndicesBuffer.Data;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    header[i].dot0         = (uint)(i * 4 + 0);
                    header[i].dot1         = (uint)(i * 4 + 1);
                    header[i].dot2         = (uint)(i * 4 + 2);
                    header[i].dot3         = (uint)(i * 4 + 3);
                    header[i].dot4         = (uint)(i * 4 + 0);
                    header[i].dot5         = (uint)(i * 4 + 1);
                    header[i].restartIndex = uint.MaxValue;
                }
            }
            if (src.ElementFormat == DynamicUnstructuredGridderSource.MATRIX_FORMAT3_TRIANGLE)
            {
                matrixPositions = new TriangleMatrixPositionBuffer();
                //matrixPositions.Shape = MatrixPositionBufferData.SHAPE_TRIANGLE;
                matrixPositions.AllocMem(src.ElementNum);
                int[][]           matrixIndices = src.Elements;
                Vertex[]          positions     = src.Nodes;
                TrianglePosition *triangles     = (TrianglePosition *)matrixPositions.Data;
                for (int i = 0; i < src.ElementNum; i++)
                {
                    triangles[i].P1 = positions[matrixIndices[i][0] - 1];
                    triangles[i].P2 = positions[matrixIndices[i][1] - 1];
                    triangles[i].P3 = positions[matrixIndices[i][2] - 1];
                }
            }

            //生成裂缝
            if (src.FractureFormat == DynamicUnstructuredGridderSource.FRACTURE_FORMAT3_TRIANGLE)
            {
                fractionPositionsBuffer = new TriangleFracturePositionBuffer();

                //fractionPositionsBuffer.Shape = FracturePositionBufferData.SHAPE_TRIANGLE;

                int triangleCount = src.FractureNum;

                //fractionPositionsBuffer.AllocMem(triangleCount * sizeof(TrianglePositions));
                fractionPositionsBuffer.AllocMem(triangleCount);

                int[][]           triangleIndices = src.Fractures;
                Vertex[]          positions       = src.Nodes;
                TrianglePosition *triangles       = (TrianglePosition *)fractionPositionsBuffer.Data;
                for (int i = 0; i < triangleCount; i++)
                {
                    triangles[i].P1 = positions[triangleIndices[i][0] - 1];
                    triangles[i].P2 = positions[triangleIndices[i][1] - 1];
                    triangles[i].P3 = positions[triangleIndices[i][2] - 1];
                }
            }

            if (src.FractureFormat == DynamicUnstructuredGridderSource.FRACTURE_FORMAT2_LINE)
            {
                fractionPositionsBuffer = new LineFracturePositionBuffer();

                //fractionPositionsBuffer.Shape = FracturePositionBufferData.SHAPE_LINE;

                int lineCount = src.FractureNum;

                //fractionPositionsBuffer.AllocMem(lineCount * sizeof(LinePositions));
                fractionPositionsBuffer.AllocMem(lineCount);

                LinePosition *lines       = (LinePosition *)fractionPositionsBuffer.Data;
                Vertex[]      positions   = src.Nodes;
                int[][]       lineIndices = src.Fractures;
                for (int i = 0; i < lineCount; i++)
                {
                    lines[i].P1 = positions[lineIndices[i][0] - 1];
                    lines[i].P2 = positions[lineIndices[i][1] - 1];
                }
            }

            DynamicUnstructureGeometry geometry = new DynamicUnstructureGeometry(matrixPositions);

            geometry.MatrixIndices     = matrixIndicesBuffer;
            geometry.FracturePositions = fractionPositionsBuffer;
            geometry.Min = src.Min;
            geometry.Max = src.Max;
            return(geometry);
        }