// Use this for initialization void Start() { float voxelSize = 1.0f; int size = 33; Array3 <Voxel> voxels = WorldGenerator.CreateVoxels(size, 0, voxelSize, Vector3.zero); MeshData data = MarchingCubes.CalculateMeshData(voxels, voxelSize); data.CalculateNormals(); Mesh mesh = null; if (data != null) { mesh = data.CreateMesh(); } ChunkObject obj = SplitManager.GetObject(); obj.ov.shouldDraw = true; obj.mr.material = mat; obj.mf.mesh = mesh; Vector3 center = Vector3.one * (size - 1) / 2.0f; Bounds area = new Bounds(center, Vector3.one * voxelSize * (size - 1)); obj.ov.init(0, 0, center, area, null, Color.red); }
void Start() { miner = GameObject.Find("Player").GetComponent <VoxelMining>(); Array3 <Voxel> voxels = WorldGenerator.CreateVoxels(33, 0, 1.0f, Vector3.zero); //Array3<Voxel> voxels = WorldGenerator.CreateVoxels(64, 0, 1.0f, Vector3.zero); MeshData data = MarchingCubes.CalculateMeshData(voxels, 1.0f); Mesh mesh = data.CreateMesh(); go = SplitManager.GetObject(); go.mr.enabled = false; go.mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.TwoSided; go.mf.sharedMesh = mesh; go.mr.material = testMat; MeshData data2 = MarchingTetrahedra.CalculateMeshData(voxels, 1.0f); data2.CalculateSharedNormals(); Mesh mesh2 = data2.CreateMesh(); go2 = SplitManager.GetObject(); go2.mf.sharedMesh = mesh2; go2.mr.material = testMat; go2.mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.TwoSided; miner.forceDrawChunk = go2; }
void Start() { voxels = WorldGenerator.CreateVoxels(65, 0, 1, Vector3.zero); data = MarchingCubes.CalculateMeshData(voxels, 1); data.CalculateVertexSharing(); data.CalculateNormals(); simp = new Simplification(data.vertices, data.triangles); mesh = data.CreateMesh(); go = SplitManager.GetObject(); go.mr.material = mat; go.mf.sharedMesh = mesh; }
public MeshData GenerateMesh(bool createVoxels) { // so while SIZE is 16, which means theres 16 cells/blocks in grid // you need 17 values to be able to construct those blocks // (think of 17 points in a grid and the blocks are the 16 spaces in between) // if smoothing then need a buffer of 2 around (front and back so +4) for smoothing and normal calculation // (so mesh goes from 2-19 basically (0, 1, 20, 21) are not visible in final result) #if (SMOOTH_SHADING) if (createVoxels) { voxels = WorldGenerator.CreateVoxels(SIZE + 5, depth, voxelSize, pos); } MeshData data = MarchingCubes.CalculateMeshData(voxels, voxelSize, 2, 2); data.CalculateVertexSharing(); //Simplification simp = new Simplification(data.vertices, data.triangles); //data.normals = VoxelUtils.CalculateSmoothNormals(voxels, voxelSize, data.vertices); //data.SplitEdgesCalcSmoothness(); data.CalculateSharedNormals(); // todo figure out why this doesnt make it smoothed... #else if (createVoxels) { voxels = WorldGenerator.CreateVoxels(SIZE + 1, depth, voxelSize, worldPos); } //if (!needsMesh) { // return null; //} //MeshData data = MarchingTetrahedra.CalculateMeshData(voxels, voxelSize); MeshData data = MarchingCubes.CalculateMeshData(voxels, voxelSize); data.CalculateNormals(); #endif //data.CalculateColorsByDepth(depth); return(data); }