private void Instantiate(int hashkey, GameObject prefab, Transform parent, int gridCellDivisions) { int x, y, z; GetReverseHashKey(hashkey, out x, out y, out z); meshingCube = (GameObject)GameObject.Instantiate(prefab); meshingCube.transform.position = new Vector3(x, y, z); meshingCube.transform.parent = parent; grid = meshingCube.GetComponent <DynamicMeshVolume> (); grid.SetProperties(gridCellDivisions); grid.Key = hashkey; }
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)); } }