public Error Create(IntPtr context) { var error = PhononCore.iplCreateProbeBatch(context, ref probeBatch); if (error != Error.None) { throw new Exception("Unable to create probe batch."); } error = PhononCore.iplCreateProbeManager(context, ref probeManager); if (error != Error.None) { throw new Exception("Unable to create probe batch."); } //Add all probes from all probe boxes to the probe batch. SteamAudioProbeBox[] allProbeBoxes = GameObject.FindObjectsOfType <SteamAudioProbeBox>() as SteamAudioProbeBox[]; foreach (SteamAudioProbeBox probeBox in allProbeBoxes) { var probeBoxData = probeBox.LoadData(); if (probeBoxData == null || probeBoxData.Length == 0) { continue; } IntPtr probeBoxPtr = IntPtr.Zero; try { PhononCore.iplLoadProbeBox(context, probeBoxData, probeBoxData.Length, ref probeBoxPtr); } catch (Exception e) { Debug.LogError(e.Message); } int numProbes = PhononCore.iplGetProbeSpheres(probeBoxPtr, null); for (int i = 0; i < numProbes; ++i) { PhononCore.iplAddProbeToBatch(probeBatch, probeBoxPtr, i); } PhononCore.iplDestroyProbeBox(ref probeBoxPtr); } //Add probe batch to probe manager. PhononCore.iplAddProbeBatch(probeManager, probeBatch); PhononCore.iplFinalizeProbeBatch(probeBatch); return(error); }
public void GenerateProbes() { ProbePlacementParameters placementParameters; placementParameters.placement = placementStrategy; placementParameters.maxNumTriangles = maxNumTriangles; placementParameters.maxOctreeDepth = maxOctreeDepth; placementParameters.horizontalSpacing = horizontalSpacing; placementParameters.heightAboveFloor = heightAboveFloor; // Initialize environment SteamAudioManager steamAudioManager = null; try { steamAudioManager = FindObjectOfType <SteamAudioManager>(); if (steamAudioManager == null) { throw new Exception("Phonon Manager Settings object not found in the scene! Click Window > Phonon"); } steamAudioManager.Initialize(GameEngineStateInitReason.GeneratingProbes); if (steamAudioManager.GameEngineState().Scene().GetScene() == IntPtr.Zero) { Debug.LogError("Scene not found. Make sure to pre-export the scene."); steamAudioManager.Destroy(); return; } } catch (Exception e) { Debug.LogError(e.Message); return; } // Create bounding box for the probe. IntPtr probeBox = IntPtr.Zero; PhononCore.iplCreateProbeBox(steamAudioManager.GameEngineState().Context(), steamAudioManager.GameEngineState().Scene().GetScene(), Common.ConvertMatrix(gameObject.transform.localToWorldMatrix), placementParameters, null, ref probeBox); int numProbes = PhononCore.iplGetProbeSpheres(probeBox, null); probeSpherePoints = new float[3 * numProbes]; probeSphereRadii = new float[numProbes]; Sphere[] probeSpheres = new Sphere[numProbes]; PhononCore.iplGetProbeSpheres(probeBox, probeSpheres); for (int i = 0; i < numProbes; ++i) { probeSpherePoints[3 * i + 0] = probeSpheres[i].centerx; probeSpherePoints[3 * i + 1] = probeSpheres[i].centery; probeSpherePoints[3 * i + 2] = probeSpheres[i].centerz; probeSphereRadii[i] = probeSpheres[i].radius; } // Save probe box into searlized data; int probeBoxSize = PhononCore.iplSaveProbeBox(probeBox, null); probeBoxData = new byte[probeBoxSize]; PhononCore.iplSaveProbeBox(probeBox, probeBoxData); if (steamAudioManager.GameEngineState().Scene().GetScene() != IntPtr.Zero) { Debug.Log("Generated " + probeSpheres.Length + " probes for game object " + gameObject.name + "."); } // Cleanup. PhononCore.iplDestroyProbeBox(ref probeBox); steamAudioManager.Destroy(); ClearProbeDataMapping(); // Redraw scene view for probes to show up instantly. #if UNITY_EDITOR UnityEditor.SceneView.RepaintAll(); #endif }