internal void AddFace(Vector3[] face, int cubeArrayId, ref TempMeshBuffer tempBuffer) { if (cubeArrayId >= _constantBuffer.cubesPerChunk1D * _constantBuffer.cubesPerChunk1D * _constantBuffer.cubesPerChunk1D) { return; } int counter = tempBuffer.counter; tempBuffer.vertices.AddRange(face); tempBuffer.triangles.AddRange(new int[] { counter, counter + 1, counter + 2 }); tempBuffer.counter += 3; }
protected internal void GenerateTriangles(Vector3Int threadId, ref TempMeshBuffer tempBuffer) { if (threadId.x >= _constantInputOutput.cubesPerChunk1D || threadId.y >= _constantInputOutput.cubesPerChunk1D || threadId.z >= _constantInputOutput.cubesPerChunk1D) { return; } _common.March( _common.GenerateCube(tempBuffer.points, threadId), _constantInputOutput.surfaceValue, _common.MatrixId2ArrayId(threadId, _constantInputOutput.cubesPerChunk1D), ref tempBuffer); }
public override MeshData GenerateMeshData(MarchPoint[] points) { TempMeshBuffer tempBuffer = new TempMeshBuffer { points = points, vertices = new List <Vector3>(), triangles = new List <int>(), counter = 0 }; _generator.GenerateMesh(ref tempBuffer); return(new MeshData(tempBuffer.vertices.ToArray(), tempBuffer.triangles.ToArray())); }
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); } }
protected internal void GenerateMesh(ref TempMeshBuffer tempBuffer) { #if BIOSEARCHER_PROFILING Profiler.BeginSample("GenerateMesh"); #endif int x, y, z; int cubesPerChunk1D = _constantInputOutput.cubesPerChunk1D; tempBuffer.counter = 0; for (z = 0; z < cubesPerChunk1D; z++) { for (y = 0; y < cubesPerChunk1D; y++) { for (x = 0; x < cubesPerChunk1D; x++) { GenerateTriangles(new Vector3Int(x, y, z), ref tempBuffer); } } } #if BIOSEARCHER_PROFILING Profiler.EndSample(); #endif }
public override MeshData GenerateMeshData(Vector3Int chunkPosition, int cubeSize) { TempPointsBuffer tempPointsBuffer = new TempPointsBuffer { chunkPosition = chunkPosition, cubeSize = cubeSize, points = new MarchPoint[_constantBuffer.pointsPerChunk1D * _constantBuffer.pointsPerChunk1D * _constantBuffer.pointsPerChunk1D] }; _generator.GeneratePoints(ref tempPointsBuffer); TempMeshBuffer tempMeshBuffer = new TempMeshBuffer { points = tempPointsBuffer.points, vertices = new List <Vector3>(), triangles = new List <int>(), counter = 0 }; _generator.GenerateMesh(ref tempMeshBuffer); return(new MeshData(tempMeshBuffer.vertices.ToArray(), tempMeshBuffer.triangles.ToArray())); }