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 BakeEffectThread() { BakingSettings bakeSettings; bakeSettings.bakeConvolution = bakeConvolution ? Bool.True : Bool.False; bakeSettings.bakeParametric = bakeParameteric ? Bool.True : Bool.False; #if UNITY_EDITOR totalObjects = duringBakeObjects.Length; objectBakingCurrently = 0; #endif for (int i = 0; i < duringBakeObjects.Length; ++i) { bakingGameObjectName = "reverb"; if (duringBakeIdentifiers[i].type == BakedDataType.StaticListener) { bakingGameObjectName = duringBakeObjectNames[i]; } else if (duringBakeIdentifiers[i].type == BakedDataType.StaticSource) { bakingGameObjectName = duringBakeObjectNames[i]; } Debug.Log("START: Baking effect for " + bakingGameObjectName + "."); ++objectBakingCurrently; #if UNITY_EDITOR totalProbeBoxes = duringBakeProbeBoxes[i].Length; #endif probeBoxBakingCurrently = 0; var atLeastOneProbeBoxHasProbes = false; foreach (SteamAudioProbeBox probeBox in duringBakeProbeBoxes[i]) { if (cancelBake) { return; } if (probeBox == null) { Debug.LogError("Probe Box specified in list of Probe Boxes to bake is null."); continue; } var probeBoxData = probeBox.LoadData(); if (probeBoxData == null || probeBoxData.Length == 0) { Debug.LogError("Skipping probe box, because probes have not been generated for it."); probeBoxBakingCurrently++; continue; } atLeastOneProbeBoxHasProbes = true; var context = steamAudioManager.GameEngineState().Context(); IntPtr probeBoxPtr = IntPtr.Zero; try { PhononCore.iplLoadProbeBox(context, probeBoxData, probeBoxData.Length, ref probeBoxPtr); probeBoxBakingCurrently++; } catch (Exception e) { Debug.LogError(e.Message); } var environment = steamAudioManager.GameEngineState().Environment().GetEnvironment(); if (duringBakeIdentifiers[i].type == BakedDataType.Reverb) { PhononCore.iplBakeReverb(environment, probeBoxPtr, bakeSettings, bakeCallback); } else if (duringBakeIdentifiers[i].type == BakedDataType.StaticListener) { PhononCore.iplBakeStaticListener(environment, probeBoxPtr, duringBakeSpheres[i], duringBakeIdentifiers[i], bakeSettings, bakeCallback); } else if (duringBakeIdentifiers[i].type == BakedDataType.StaticSource) { PhononCore.iplBakePropagation(environment, probeBoxPtr, duringBakeSpheres[i], duringBakeIdentifiers[i], bakeSettings, bakeCallback); } if (cancelBake) { PhononCore.iplDestroyProbeBox(ref probeBoxPtr); Debug.Log("CANCELLED: Baking."); return; } int probeBoxSize = PhononCore.iplSaveProbeBox(probeBoxPtr, null); probeBoxData = new byte[probeBoxSize]; PhononCore.iplSaveProbeBox(probeBoxPtr, probeBoxData); probeBox.SaveData(probeBoxData); int probeBoxEffectSize = PhononCore.iplGetBakedDataSizeByIdentifier(probeBoxPtr, duringBakeIdentifiers[i]); probeBox.AddOrUpdateLayer(duringBakeIdentifiers[i], duringBakeNames[i], probeBoxEffectSize); PhononCore.iplDestroyProbeBox(ref probeBoxPtr); } if (duringBakeProbeBoxes[i].Length == 0) { Debug.LogError("Probe Box component not attached or no probe boxes selected for " + bakingGameObjectName); } else if (atLeastOneProbeBoxHasProbes) { Debug.Log("COMPLETED: Baking effect for " + bakingGameObjectName + "."); } } bakeStatus = BakeStatus.Complete; }
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 }