Ejemplo n.º 1
0
        private unsafe HexahedronPositionBuffer GeneratePositionBuffer(ref Vertex max, ref Vertex min)
        {
            HexahedronGridderSource  src            = this;
            HexahedronPositionBuffer positionBuffer = new HexahedronPositionBuffer();
            int dimSize = src.DimenSize;
            int I, J, K;

            positionBuffer.AllocMem(dimSize);

            HexahedronPosition *cell = (HexahedronPosition *)positionBuffer.Data;

            for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
            {
                src.InvertIJK(gridIndex, out I, out J, out K);
                cell[gridIndex].FLT = src.PointFLT(I, J, K);
                cell[gridIndex].FRT = src.PointFRT(I, J, K);
                cell[gridIndex].BRT = src.PointBRT(I, J, K);
                cell[gridIndex].BLT = src.PointBLT(I, J, K);
                cell[gridIndex].FLB = src.PointFLB(I, J, K);
                cell[gridIndex].FRB = src.PointFRB(I, J, K);
                cell[gridIndex].BRB = src.PointBRB(I, J, K);
                cell[gridIndex].BLB = src.PointBLB(I, J, K);

                if (!isSet && src.IsActiveBlock(gridIndex))
                {
                    min   = cell[gridIndex].FLT;
                    max   = min;
                    isSet = true;
                }

                if (isSet && src.IsActiveBlock(gridIndex))
                {
                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].FLT);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].FLT);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].FRT);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].FRT);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].BRT);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].BRT);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].BLT);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].BLT);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].FLB);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].FLB);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].FRB);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].FRB);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].BRB);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].BRB);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].BLB);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].BLB);
                }
            }

            return(positionBuffer);
        }
Ejemplo n.º 2
0
        private unsafe void InitVertexBuffers()
        {
            // http://images.cnblogs.com/cnblogs_com/bitzhuwei/482613/o_Cube-small.jpg
            {
                VR03PositionBuffer positionBuffer = new VR03PositionBuffer(strin_Position);
                positionBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronPosition *array = (HexahedronPosition *)positionBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            var x          = ((float)i / (float)xFrameCount - 0.5f) * factor;
                            var y          = ((float)j / (float)yFrameCount - 0.5f) * factor;
                            var z          = (((float)k / (float)zFrameCount - 0.5f) * 109.0f / 256.0f) * factor;
                            var hexahedron = new HexahedronPosition();
                            hexahedron.v0  = new vec3(x + hexahedronHalfLength, y + hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v1  = new vec3(x - hexahedronHalfLength, y + hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v2  = new vec3(x + hexahedronHalfLength, y - hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v3  = new vec3(x - hexahedronHalfLength, y - hexahedronHalfLength, z + hexahedronHalfLength);
                            hexahedron.v4  = new vec3(x + hexahedronHalfLength, y + hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v5  = new vec3(x - hexahedronHalfLength, y + hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v6  = new vec3(x + hexahedronHalfLength, y - hexahedronHalfLength, z - hexahedronHalfLength);
                            hexahedron.v7  = new vec3(x - hexahedronHalfLength, y - hexahedronHalfLength, z - hexahedronHalfLength);
                            array[index++] = hexahedron;
                        }
                    }
                }
                this.positionBufferRenderer = positionBuffer.GetRenderer();
                positionBuffer.Dispose();
            }

            {
                VR03UVBuffer uvBuffer = new VR03UVBuffer(strin_uv);
                uvBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronUV *array = (HexahedronUV *)uvBuffer.FirstElement();
                int           index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            var x     = (float)i / (float)xFrameCount;
                            var y     = (float)j / (float)yFrameCount;
                            var z     = (float)k / (float)zFrameCount;
                            var color = new vec3(x, y, z);
                            var uv    = new HexahedronUV();
                            uv.v0          = color;
                            uv.v1          = color;
                            uv.v2          = color;
                            uv.v3          = color;
                            uv.v4          = color;
                            uv.v5          = color;
                            uv.v6          = color;
                            uv.v7          = color;
                            array[index++] = uv;
                        }
                    }
                }
                this.uvBufferRenderer = uvBuffer.GetRenderer();
                uvBuffer.Dispose();
            }
            {
                var indexBuffer = new VR03IndexBuffer();
                indexBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);
                HexahedronIndex *array = (HexahedronIndex *)indexBuffer.FirstElement();
                int index = 0;
                for (int i = 0; i < xFrameCount; i++)
                {
                    for (int j = 0; j < yFrameCount; j++)
                    {
                        for (int k = 0; k < zFrameCount; k++)
                        {
                            uint centerIndex = (uint)((i * yFrameCount * zFrameCount + j * zFrameCount + k) * 8);
                            array[index++] = new HexahedronIndex(centerIndex);
                        }
                    }
                }
                this.indexBufferRenderer = indexBuffer.GetRenderer();
                indexBuffer.Dispose();
            }

            this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer);
        }
Ejemplo n.º 3
0
        public override MeshBase CreateMesh(GridderSource source)
        {
            HexahedronGridderSource src = (HexahedronGridderSource)source;

            PositionBuffer            positions             = new HexahedronPositionBuffer();
            HalfHexahedronIndexBuffer halfHexahedronIndices = new HalfHexahedronIndexBuffer();
            int dimSize = src.DimenSize;
            int I, J, K;

            unsafe
            {
                positions.AllocMem(dimSize);

                HexahedronPosition *cell = (HexahedronPosition *)positions.Data;
                for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
                {
                    src.InvertIJK(gridIndex, out I, out J, out K);
                    cell[gridIndex].FLT = src.Transform * src.PointFLT(I, J, K);
                    cell[gridIndex].FRT = src.Transform * src.PointFRT(I, J, K);
                    cell[gridIndex].BRT = src.Transform * src.PointBRT(I, J, K);
                    cell[gridIndex].BLT = src.Transform * src.PointBLT(I, J, K);
                    cell[gridIndex].FLB = src.Transform * src.PointFLB(I, J, K);
                    cell[gridIndex].FRB = src.Transform * src.PointFRB(I, J, K);
                    cell[gridIndex].BRB = src.Transform * src.PointBRB(I, J, K);
                    cell[gridIndex].BLB = src.Transform * src.PointBLB(I, J, K);
                }

                //网格个数*每个六面体的面数*描述每个六面体的三角形个数
                int halfHexahedronIndexCount = dimSize * 2;
                //int memorySizeInBytes = halfHexahedronIndexCount * sizeof(HalfHexahedronIndex);
                //halfHexahedronIndices.AllocMem(memorySizeInBytes);
                halfHexahedronIndices.AllocMem(halfHexahedronIndexCount);

                HalfHexahedronIndex *array = (HalfHexahedronIndex *)halfHexahedronIndices.Data;
                for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
                {
                    array[gridIndex * 2].dot0         = (uint)(8 * gridIndex + 6);
                    array[gridIndex * 2].dot1         = (uint)(8 * gridIndex + 2);
                    array[gridIndex * 2].dot2         = (uint)(8 * gridIndex + 7);
                    array[gridIndex * 2].dot3         = (uint)(8 * gridIndex + 3);
                    array[gridIndex * 2].dot4         = (uint)(8 * gridIndex + 4);
                    array[gridIndex * 2].dot5         = (uint)(8 * gridIndex + 0);
                    array[gridIndex * 2].dot6         = (uint)(8 * gridIndex + 5);
                    array[gridIndex * 2].dot7         = (uint)(8 * gridIndex + 1);
                    array[gridIndex * 2].restartIndex = uint.MaxValue;

                    array[gridIndex * 2 + 1].dot0         = (uint)(8 * gridIndex + 3);
                    array[gridIndex * 2 + 1].dot1         = (uint)(8 * gridIndex + 0);
                    array[gridIndex * 2 + 1].dot2         = (uint)(8 * gridIndex + 2);
                    array[gridIndex * 2 + 1].dot3         = (uint)(8 * gridIndex + 1);
                    array[gridIndex * 2 + 1].dot4         = (uint)(8 * gridIndex + 6);
                    array[gridIndex * 2 + 1].dot5         = (uint)(8 * gridIndex + 5);
                    array[gridIndex * 2 + 1].dot6         = (uint)(8 * gridIndex + 7);
                    array[gridIndex * 2 + 1].dot7         = (uint)(8 * gridIndex + 4);
                    array[gridIndex * 2 + 1].restartIndex = uint.MaxValue;
                }

                HexahedronMeshGeometry3D mesh = new HexahedronMeshGeometry3D(positions, halfHexahedronIndices);
                mesh.Max = source.TransformedActiveBounds.Min;
                mesh.Min = source.TransformedActiveBounds.Max;
                return(mesh);
            }
        }
Ejemplo n.º 4
0
        public override MeshBase CreateMesh(GridderSource source)
        {
            HexahedronGridderSource src                     = (HexahedronGridderSource)source;
            Vertex                    minVertex             = new Vertex();
            Vertex                    maxVertex             = new Vertex();
            bool                      isSet                 = false;
            PositionBuffer            positions             = new HexahedronPositionBuffer();
            HalfHexahedronIndexBuffer halfHexahedronIndices = new HalfHexahedronIndexBuffer();
            int dimSize = src.DimenSize;
            int I, J, K;

            unsafe
            {
                positions.AllocMem(dimSize);

                HexahedronPosition *cell = (HexahedronPosition *)positions.Data;
                for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
                {
                    src.InvertIJK(gridIndex, out I, out J, out K);
                    cell[gridIndex].FLT = src.PointFLT(I, J, K);
                    cell[gridIndex].FRT = src.PointFRT(I, J, K);
                    cell[gridIndex].BRT = src.PointBRT(I, J, K);
                    cell[gridIndex].BLT = src.PointBLT(I, J, K);
                    cell[gridIndex].FLB = src.PointFLB(I, J, K);
                    cell[gridIndex].FRB = src.PointFRB(I, J, K);
                    cell[gridIndex].BRB = src.PointBRB(I, J, K);
                    cell[gridIndex].BLB = src.PointBLB(I, J, K);

                    if (!isSet && src.IsActiveBlock(gridIndex))
                    {
                        minVertex = cell[gridIndex].FLT;
                        maxVertex = minVertex;
                        isSet     = true;
                    }

                    if (isSet && src.IsActiveBlock(gridIndex))
                    {
                        minVertex = SimLab.SimGrid.helper.VertexHelper.MinVertex(minVertex, cell[gridIndex].FLT);
                        maxVertex = SimLab.SimGrid.helper.VertexHelper.MaxVertex(maxVertex, cell[gridIndex].FLT);

                        minVertex = SimLab.SimGrid.helper.VertexHelper.MinVertex(minVertex, cell[gridIndex].FRT);
                        maxVertex = SimLab.SimGrid.helper.VertexHelper.MaxVertex(maxVertex, cell[gridIndex].FRT);

                        minVertex = SimLab.SimGrid.helper.VertexHelper.MinVertex(minVertex, cell[gridIndex].BRT);
                        maxVertex = SimLab.SimGrid.helper.VertexHelper.MaxVertex(maxVertex, cell[gridIndex].BRT);

                        minVertex = SimLab.SimGrid.helper.VertexHelper.MinVertex(minVertex, cell[gridIndex].BLT);
                        maxVertex = SimLab.SimGrid.helper.VertexHelper.MaxVertex(maxVertex, cell[gridIndex].BLT);

                        minVertex = SimLab.SimGrid.helper.VertexHelper.MinVertex(minVertex, cell[gridIndex].FLB);
                        maxVertex = SimLab.SimGrid.helper.VertexHelper.MaxVertex(maxVertex, cell[gridIndex].FLB);

                        minVertex = SimLab.SimGrid.helper.VertexHelper.MinVertex(minVertex, cell[gridIndex].FRB);
                        maxVertex = SimLab.SimGrid.helper.VertexHelper.MaxVertex(maxVertex, cell[gridIndex].FRB);

                        minVertex = SimLab.SimGrid.helper.VertexHelper.MinVertex(minVertex, cell[gridIndex].BRB);
                        maxVertex = SimLab.SimGrid.helper.VertexHelper.MaxVertex(maxVertex, cell[gridIndex].BRB);

                        minVertex = SimLab.SimGrid.helper.VertexHelper.MinVertex(minVertex, cell[gridIndex].BLB);
                        maxVertex = SimLab.SimGrid.helper.VertexHelper.MaxVertex(maxVertex, cell[gridIndex].BLB);
                    }
                }

                //网格个数*每个六面体的面数*描述每个六面体的三角形个数
                int halfHexahedronIndexCount = dimSize * 2;
                //int memorySizeInBytes = halfHexahedronIndexCount * sizeof(HalfHexahedronIndex);
                //halfHexahedronIndices.AllocMem(memorySizeInBytes);
                halfHexahedronIndices.AllocMem(halfHexahedronIndexCount);

                HalfHexahedronIndex *array = (HalfHexahedronIndex *)halfHexahedronIndices.Data;
                for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
                {
                    array[gridIndex * 2].dot0         = (uint)(8 * gridIndex + 6);
                    array[gridIndex * 2].dot1         = (uint)(8 * gridIndex + 2);
                    array[gridIndex * 2].dot2         = (uint)(8 * gridIndex + 7);
                    array[gridIndex * 2].dot3         = (uint)(8 * gridIndex + 3);
                    array[gridIndex * 2].dot4         = (uint)(8 * gridIndex + 4);
                    array[gridIndex * 2].dot5         = (uint)(8 * gridIndex + 0);
                    array[gridIndex * 2].dot6         = (uint)(8 * gridIndex + 5);
                    array[gridIndex * 2].dot7         = (uint)(8 * gridIndex + 1);
                    array[gridIndex * 2].restartIndex = uint.MaxValue;

                    array[gridIndex * 2 + 1].dot0         = (uint)(8 * gridIndex + 3);
                    array[gridIndex * 2 + 1].dot1         = (uint)(8 * gridIndex + 0);
                    array[gridIndex * 2 + 1].dot2         = (uint)(8 * gridIndex + 2);
                    array[gridIndex * 2 + 1].dot3         = (uint)(8 * gridIndex + 1);
                    array[gridIndex * 2 + 1].dot4         = (uint)(8 * gridIndex + 6);
                    array[gridIndex * 2 + 1].dot5         = (uint)(8 * gridIndex + 5);
                    array[gridIndex * 2 + 1].dot6         = (uint)(8 * gridIndex + 7);
                    array[gridIndex * 2 + 1].dot7         = (uint)(8 * gridIndex + 4);
                    array[gridIndex * 2 + 1].restartIndex = uint.MaxValue;
                }

                HexahedronMesh mesh = new HexahedronMesh(positions, halfHexahedronIndices);
                mesh.Max = maxVertex;
                mesh.Min = minVertex;
                return(mesh);
            }
        }