private void RemoveUnderPlane() { if (numPicks == 0) { voxelPlane = voxelizer.GetAllVoxelOnPlane(pickedVoxel[0], pickedVoxel[1], pickedVoxel[2], true); startPlane = voxelPlane; voxelizer.RemoveVoxelPlane(ref voxelPlane, pickedVoxel[0], pickedVoxel[1], pickedVoxel[2]); List <STLLoader.Vec3> localCorners = voxelizer.CalculateLocalCorners(); voxelizer.CalculateCenterOfMass(); Transform[] ts = gameObject.GetComponentsInChildren <Transform>(); for (int i = 1; i < ts.Length; ++i) { Destroy(ts[i].gameObject); } STLLoader.Quickhull quickhull = new STLLoader.Quickhull(); List <int> convexFaces = new List <int>(); quickhull.CalculateQuickhull(localCorners, ref convexFaces); convexHullOutline.Clear(); quickhull.CalculatePolygonEdges(ref convexHullOutline); voxelMesh = new STLLoader.Mesh[1]; voxelMesh[0] = voxelizer.GenerateMesh(0, resolution); float voxelSize = voxelizer.GetVoxelSize(); STLLoader.Vec3 offset = voxelizer.GetMinOffset(); convexHull.ConfigureConvexHull(ref localCorners, ref convexFaces, voxelSize, new Vector3(offset.x, offset.y, offset.z), ref convexHullOutline); CreateIndexedMesh(ref voxelMesh, (int)resolution); } }
public void VoxelizeMesh() { if (mesh[0] == null) { return; } if (!objectHasChanged) { return; } Transform[] ts = gameObject.GetComponentsInChildren <Transform>(); for (int i = 1; i < ts.Length; ++i) { Destroy(ts[i].gameObject); } STLLoader.Vec3[] direction = new STLLoader.Vec3[3]; direction[0] = new STLLoader.Vec3(1, 0, 0); direction[1] = new STLLoader.Vec3(0, 1, 0); direction[2] = new STLLoader.Vec3(0, 0, 1); voxelizer = new STLLoader.Voxelizer(xResolution, yResolution, zResolution); voxelizer.MultiyDirectionsVoxelize(mesh[0], direction); List <STLLoader.Vec3> localCorners = voxelizer.CalculateLocalCorners(); STLLoader.Quickhull quickhull = new STLLoader.Quickhull(); List <int> convexFaces = new List <int>(); quickhull.CalculateQuickhull(localCorners, ref convexFaces); convexHullOutline.Clear(); quickhull.CalculatePolygonEdges(ref convexHullOutline); STLLoader.Vec3 centerOfMass = voxelizer.GetCenterOfMass(); //voxelizer.SafeLayer(fileName, 0); voxelMesh = new STLLoader.Mesh[1]; voxelMesh[0] = voxelizer.GenerateMesh(0, resolution); float voxelSize = voxelizer.GetVoxelSize(); STLLoader.Vec3 offset = voxelizer.GetMinOffset(); convexHull.ConfigureConvexHull(ref localCorners, ref convexFaces, voxelSize, new Vector3(offset.x, offset.y, offset.z), ref convexHullOutline); CreateIndexedMesh(ref voxelMesh, (int)resolution); transform.localScale = new Vector3(voxelSize, voxelSize, voxelSize); transform.position = new Vector3(offset.x, offset.y, offset.z); objectHasChanged = false; voxelMeshHasChanged = false; }