private static SerializableVolume[] GetVolumeDataAuto(int volumeSubdivisions) { // Create initial volume var sceneBounds = GetSceneBounds(); var volumeData = new VolumeData() { positionWS = sceneBounds.center, scaleWS = sceneBounds.size }; // Recursively generate hierarchy int currentDepth = 0; if (currentDepth < volumeSubdivisions) { GetVolumeDataAutoRecursive(currentDepth + 1, volumeSubdivisions, ref volumeData); } // Serialize return(volumeData.Serialize()); }
private static void GetVolumeDataAutoRecursive(int currentDepth, int volumeSubdivisions, ref VolumeData parentVolume) { parentVolume.children = new VolumeData[8]; for (int i = 0; i < parentVolume.children.Length; i++) { // Get offset values from index // TODO // - Math this var signX = (float)(i + 1) % 2 == 0 ? 1 : -1; var signY = i == 2 || i == 3 || i == 6 || i == 7 ? 1 : -1; var signZ = i == 4 || i == 5 || i == 6 || i == 7 ? 1 : -1; //(float)(i + 1) * 0.5f > 4 ? 1 : -1; // Calculate transformations var scale = new Vector3(parentVolume.scaleWS.x * 0.5f, parentVolume.scaleWS.y * 0.5f, parentVolume.scaleWS.z * 0.5f); var position = parentVolume.positionWS + new Vector3(signX * scale.x * 0.5f, signY * scale.y * 0.5f, signZ * scale.z * 0.5f); // Create new child VolumeData parentVolume.children[i] = new VolumeData() { positionWS = position, scaleWS = scale }; // Continue down hierarchy if (currentDepth < volumeSubdivisions) { GetVolumeDataAutoRecursive(currentDepth + 1, volumeSubdivisions, ref parentVolume.children[i]); } } }