コード例 #1
0
ファイル: Common.cs プロジェクト: unknownMusician/Biosearcher
        internal int GetPointsHash(MarchCube cube, float surfaceValue)
        {
            int cubeIndex = 0;

            // Find which vertices are inside of the surface and which are outside
            for (int i = 0; i < 8; i++)
            {
                if (cube.points[i].value <= surfaceValue)
                {
                    cubeIndex |= 1 << i;
                }
            }
            return(cubeIndex);
        }
コード例 #2
0
ファイル: Common.cs プロジェクト: unknownMusician/Biosearcher
        internal void March(MarchCube cube, float surfaceValue, int cubeArrayId, ref TempMeshBuffer tempBuffer)
        {
            int pointsHash = GetPointsHash(cube, surfaceValue);

            // Find which edges are intersected by the surface
            int edgesHash = _constantBuffer.pointsHash2EdgesHash[pointsHash];

            // If the cube is entirely inside or outside of the surface, then there will be no intersections
            if (edgesHash == 0)
            {
                return;
            }

            // Save the triangles that were found. There can be up to five per cube
            for (int i = 0; i < 5; i++)
            {
                if (_constantBuffer.pointsHash2EdgesIndexes[pointsHash, 3 * i] == 20.0f)
                {
                    break;
                }

                var face = new Vector3[3];

                for (int j = 0; j < 3; j++)
                {
                    int edgeIndex = _constantBuffer.pointsHash2EdgesIndexes[pointsHash, 3 * i + j];

                    int edgePoint1Index = _constantBuffer.edgeIndex2PointIndexes[edgeIndex, 0];
                    int edgePoint2Index = _constantBuffer.edgeIndex2PointIndexes[edgeIndex, 1];

                    MarchPoint edgePoint1 = cube.points[edgePoint1Index];
                    MarchPoint edgePoint2 = cube.points[edgePoint2Index];

                    face[j] = Interpolate(edgePoint1, edgePoint2, surfaceValue);
                }

                AddFace(face, cubeArrayId, ref tempBuffer);
            }
        }