private int dimension = 1000; //supports +/- 500m from origin along each axis public VolumetricHashStorage(VolumetricHashStorage parent, int hashkey) { if (parent == null) { root = this; } else { root = parent; } key = hashkey; }
public void Clear() { if (leftHashTree != null) { leftHashTree.Clear(); leftHashTree = null; } if (rightHashTree != null) { rightHashTree.Clear(); rightHashTree = null; } if (grid != null) { grid.Clear(); } if (meshingCube != null) { GameObject.DestroyImmediate(meshingCube); meshingCube = null; } }
private float InsertPoint(int hashkey, Vector3 p, Vector3 n, float weight, GameObject prefab, Transform parent, int cellDivisions) { if (key == hashkey) { if (meshingCube == null) { Instantiate(hashkey, prefab, parent, cellDivisions); } if (grid == null) { grid = meshingCube.GetComponent <DynamicMeshVolume> (); } //adjust weight of mutiple voxels along observation ray float result = grid.InsertPoint(p, n, weight, ref cellIndex); Vector3 closerPoint = p - n * grid.GridCellSize.x; Vector3 furtherPoint = p + n * grid.GridCellSize.x; //voxel was inside the surface, back out one, and insert in the next closest voxel if (result > 0) { grid.InsertPoint(closerPoint, p, n, weight); } else { grid.InsertPoint(furtherPoint, p, n, weight); } if (cellIndex[0] == 0) { int neighborHashKey = hashkey - 1; result = root.InsertPoint(neighborHashKey, p, n, weight, prefab, parent, cellDivisions); } if (cellIndex[1] == 0) { int neighborHashKey = hashkey - dimension; result = root.InsertPoint(neighborHashKey, p, n, weight, prefab, parent, cellDivisions); } if (cellIndex[2] == 0) { int neighborHashKey = hashkey - dimension * dimension; result = root.InsertPoint(neighborHashKey, p, n, weight, prefab, parent, cellDivisions); } return(result); } if (hashkey < key) { if (leftHashTree == null) { leftHashTree = new VolumetricHashStorage(root, hashkey); } return(leftHashTree.InsertPoint(hashkey, p, n, weight, prefab, parent, cellDivisions)); } else { if (rightHashTree == null) { rightHashTree = new VolumetricHashStorage(root, hashkey); } return(rightHashTree.InsertPoint(hashkey, p, n, weight, prefab, parent, cellDivisions)); } }