public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(mAsset); var scene = (target as SteamAudioStaticMesh).gameObject.scene; if (mAsset.objectReferenceValue == null) { EditorGUILayout.HelpBox( "This scene has not been exported. Click Steam Audio > Export Active Scene to export.", MessageType.Warning); } else if (mSceneNameWhenExported.stringValue != scene.name) { EditorGUILayout.HelpBox( string.Format("This geometry was last exported for the scene {0}. If this is not what you " + "intended, click Export As New Asset below.", mSceneNameWhenExported.stringValue), MessageType.Warning); if (GUILayout.Button("Export As New Asset")) { mAsset.objectReferenceValue = SerializedData.PromptForNewAsset(scene.name); mSceneNameWhenExported.stringValue = scene.name; serializedObject.ApplyModifiedProperties(); SteamAudioManager.ExportScene(scene, false); } } serializedObject.ApplyModifiedProperties(); }
public void DeleteBakedDataByName(string name, string prefix) { SteamAudioManager steamAudioManager = null; IntPtr probeBox = IntPtr.Zero; try { steamAudioManager = FindObjectOfType <SteamAudioManager>(); if (steamAudioManager == null) { throw new Exception("Phonon Manager Settings object not found in the scene! Click Window > Phonon"); } var context = steamAudioManager.GameEngineState().Context(); PhononCore.iplLoadProbeBox(context, probeBoxData, probeBoxData.Length, ref probeBox); PhononCore.iplDeleteBakedDataByName(probeBox, Common.HashStringForIdentifierWithPrefix(name, prefix)); UpdateProbeDataMapping(name, prefix, -1); int probeBoxSize = PhononCore.iplSaveProbeBox(probeBox, null); probeBoxData = new byte[probeBoxSize]; PhononCore.iplSaveProbeBox(probeBox, probeBoxData); } catch (Exception e) { Debug.LogError(e.Message); } }
void DisplayProgressBarAndCancel() { SteamAudioManager phononManager = serializedObject.targetObject as SteamAudioManager; phononManager.phononBaker.DrawProgressBar(); Repaint(); }
public void DeleteBakedDataByIdentifier(BakedDataIdentifier identifier) { SteamAudioManager steamAudioManager = null; IntPtr probeBox = IntPtr.Zero; 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.EditingProbes); var context = steamAudioManager.GameEngineState().Context(); byte[] probeBoxData = LoadData(); PhononCore.iplLoadProbeBox(context, probeBoxData, probeBoxData.Length, ref probeBox); PhononCore.iplDeleteBakedDataByIdentifier(probeBox, identifier); RemoveLayer(identifier); int probeBoxSize = PhononCore.iplSaveProbeBox(probeBox, null); probeBoxData = new byte[probeBoxSize]; PhononCore.iplSaveProbeBox(probeBox, probeBoxData); SaveData(probeBoxData); steamAudioManager.Destroy(); } catch (Exception e) { Debug.LogError(e.Message); } }
public bool BakedReverbGUI(SteamAudioManager phononManager) { SteamAudioListener bakedReverb = GameObject.FindObjectOfType <SteamAudioListener>(); if (bakedReverb == null) { return(false); } EditorGUILayout.LabelField("Baked Reverb", EditorStyles.boldLabel); GUI.enabled = !Baker.IsBakeActive() && !EditorApplication.isPlayingOrWillChangePlaymode; EditorGUILayout.BeginHorizontal(); bakedReverb.UpdateBakedDataStatistics(); bool previousValues = bakedReverb.bakeToggle; bool newValue = GUILayout.Toggle(bakedReverb.bakeToggle, " reverb"); if (previousValues != newValue) { Undo.RecordObject(bakedReverb, "Toggled reverb in Phonon Manager"); bakedReverb.bakeToggle = newValue; } EditorGUILayout.LabelField((bakedReverb.bakedDataSize / 1000.0f).ToString("0.0") + " KB"); EditorGUILayout.EndHorizontal(); GUI.enabled = true; return(true); }
public static void EndBake() { if (sThread != null) { sThread.Join(); } SerializedObject.FlushAllWrites(); #if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) if (sProgressCallbackHandle.IsAllocated) { sProgressCallbackHandle.Free(); } #endif SteamAudioManager.ShutDown(); UnityEngine.Object.DestroyImmediate(SteamAudioManager.Singleton.gameObject); #if UNITY_EDITOR sProgress = 0.0f; #endif sCurrentObjectIndex = 0; sTotalObjects = 0; sCurrentObjectName = null; sCurrentProbeBatchIndex = 0; sTotalProbeBatches = 0; sStatus = BakeStatus.Ready; #if UNITY_EDITOR EditorApplication.update -= InEditorUpdate; #endif }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(mAsset); if (mAsset.objectReferenceValue == null) { EditorGUILayout.HelpBox( "This Dynamic Object has not been exported to an asset yet. Please click Export Dynamic Object " + "to do so.", MessageType.Warning); } EditorGUILayout.Space(); if (GUILayout.Button("Export Dynamic Object")) { if (mAsset.objectReferenceValue == null) { var name = (target as SteamAudioDynamicObject).gameObject.scene.name + "_" + target.name; mAsset.objectReferenceValue = SerializedData.PromptForNewAsset(name); serializedObject.ApplyModifiedProperties(); } SteamAudioManager.ExportDynamicObject(target as SteamAudioDynamicObject, false); } if (GUILayout.Button("Export Dynamic Object as OBJ")) { SteamAudioManager.ExportDynamicObject(target as SteamAudioDynamicObject, true); } serializedObject.ApplyModifiedProperties(); }
private void OnEnable() { if (applyReverb) { mSource.AddToSimulator(mSimulator); SteamAudioManager.AddListener(this); SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource); } }
private void OnDisable() { if (applyReverb) { SteamAudioManager.RemoveListener(this); mSource.RemoveFromSimulator(mSimulator); SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource); } }
private void OnDestroy() { SteamAudioManager.UnloadDynamicObject(this); if (mInstancedMesh != null) { mInstancedMesh.Release(); } }
private void Awake() { mSimulator = SteamAudioManager.Simulator; var settings = SteamAudioManager.GetSimulationSettings(false); mSource = new Source(SteamAudioManager.Simulator, settings); SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource); }
private void OnDisable() { SteamAudioManager.RemoveSource(this); mSource.RemoveFromSimulator(mSimulator); if (mAudioEngineSource != null) { mAudioEngineSource.UpdateParameters(this); } }
private void OnEnable() { mSource.AddToSimulator(mSimulator); SteamAudioManager.AddSource(this); if (mAudioEngineSource != null) { mAudioEngineSource.UpdateParameters(this); } }
public bool BakedSourcesGUI(SteamAudioManager phononManager) { SteamAudioSource[] bakedSources = GameObject.FindObjectsOfType <SteamAudioSource>(); bool showBakedSources = false; foreach (SteamAudioSource bakedSource in bakedSources) { if (bakedSource.reflections && bakedSource.uniqueIdentifier.Length != 0 && bakedSource.simulationType == SourceSimulationType.BakedStaticSource) { showBakedSources = true; break; } } if (showBakedSources) { EditorGUILayout.LabelField("Baked Sources", EditorStyles.boldLabel); } else { return(false); } foreach (SteamAudioSource bakedSource in bakedSources) { if (!bakedSource.reflections || bakedSource.uniqueIdentifier.Length == 0 || bakedSource.simulationType != SourceSimulationType.BakedStaticSource) { continue; } GUI.enabled = !Baker.IsBakeActive() && !EditorApplication.isPlayingOrWillChangePlaymode; EditorGUILayout.BeginHorizontal(); bakedSource.UpdateBakedDataStatistics(); bool previousValue = bakedSource.bakeToggle; bool newValue = GUILayout.Toggle(bakedSource.bakeToggle, " " + bakedSource.uniqueIdentifier); if (previousValue != newValue) { Undo.RecordObject(bakedSource, "Toggled " + bakedSource.uniqueIdentifier + " in Phonon Manager"); bakedSource.bakeToggle = newValue; } EditorGUILayout.LabelField((bakedSource.bakedDataSize / 1000.0f).ToString("0.0") + " KB"); EditorGUILayout.EndHorizontal(); GUI.enabled = true; } return(true); }
static MaterialValue GetMaterialForGameObject(GameObject gameObject) { // todo: report error if there's a dynamic object component between gameobject and material. var steamAudioMaterial = gameObject.GetComponentInParent <SteamAudioMaterial>(); if (steamAudioMaterial == null) { return(SteamAudioManager.GetSingleton().materialValue); } else { return(steamAudioMaterial.Value); } }
void Awake() { manager = SteamAudioManager.GetSingleton(); if (manager == null) { throw new Exception(); } manager.Initialize(GameEngineStateInitReason.Playing); if (assetFileName != null && assetFileName.Length > 0) { manager.CreateInstancedMesh(assetFileName, transform, ref instancedMesh); } }
private void Update() { if (mInstancedMesh == null && asset != null) { mInstancedMesh = SteamAudioManager.LoadDynamicObject(this, SteamAudioManager.CurrentScene, SteamAudioManager.Context); if (enabled) { mInstancedMesh.AddToScene(SteamAudioManager.CurrentScene); } } mInstancedMesh.UpdateTransform(SteamAudioManager.CurrentScene, transform); }
public static void BeginBake(BakedDataTask[] tasks) { SteamAudioManager.Initialize(ManagerInitReason.Baking); SteamAudioManager.LoadScene(SceneManager.GetActiveScene(), SteamAudioManager.Context, false); SteamAudioStaticMesh staticMeshComponent = null; var rootObjects = SceneManager.GetActiveScene().GetRootGameObjects(); foreach (var rootObject in rootObjects) { staticMeshComponent = rootObject.GetComponent <SteamAudioStaticMesh>(); if (staticMeshComponent) { break; } } if (staticMeshComponent == null || staticMeshComponent.asset == null) { Debug.LogError(string.Format("Scene {0} has not been exported. Click Steam Audio > Export Active Scene to do so.", SceneManager.GetActiveScene().name)); return; } var staticMesh = new StaticMesh(SteamAudioManager.Context, SteamAudioManager.CurrentScene, staticMeshComponent.asset); staticMesh.AddToScene(SteamAudioManager.CurrentScene); SteamAudioManager.CurrentScene.Commit(); staticMesh.Release(); sTasks = tasks; sStatus = BakeStatus.InProgress; sProgressCallback = new ProgressCallback(AdvanceProgress); #if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) sProgressCallbackPointer = Marshal.GetFunctionPointerForDelegate(sProgressCallback); sProgressCallbackHandle = GCHandle.Alloc(sProgressCallbackPointer); GC.Collect(); #endif #if UNITY_EDITOR EditorApplication.update += InEditorUpdate; #endif sThread = new Thread(BakeThread); sThread.Start(); }
public static LayerMask GetSteamAudioLayerMask() { UnityEngine.SceneManagement.Scene activeScene = SceneManager.GetActiveScene(); if (s_activeScene != activeScene) { s_activeScene = activeScene; s_steamAudioManager = GameObject.FindObjectOfType <SteamAudioManager>(); } if (s_steamAudioManager == null) { return(new LayerMask()); } return(s_steamAudioManager.layerMask); }
void Awake() { var steamAudioManager = SteamAudioManager.GetSingleton(); if (steamAudioManager == null) { Debug.LogError("Phonon Manager Settings object not found in the scene! Click Window > Phonon"); return; } steamAudioManager.Initialize(GameEngineStateInitReason.Playing); managerData = steamAudioManager.ManagerData(); audioEngine = steamAudioManager.audioEngine; audioEngineSource = AudioEngineSourceFactory.Create(audioEngine); audioEngineSource.Initialize(gameObject); audioEngineSource.UpdateParameters(this); }
public void DeleteBakedDataForIdentifier(BakedDataIdentifier identifier) { if (asset == null) { return; } SteamAudioManager.Initialize(ManagerInitReason.EditingProbes); var probeBatch = new ProbeBatch(SteamAudioManager.Context, asset); probeBatch.RemoveData(identifier); probeDataSize = probeBatch.Save(asset); SteamAudioManager.ShutDown(); DestroyImmediate(SteamAudioManager.Singleton.gameObject); RemoveLayer(identifier); }
public int GetNumTriangles() { if (exportAllChildren) { var objects = SteamAudioManager.GetGameObjectsForExport(gameObject); var numTriangles = 0; foreach (var obj in objects) { numTriangles += SteamAudioManager.GetNumTriangles(obj); } return(numTriangles); } else { return(SteamAudioManager.GetNumTriangles(gameObject)); } }
private void Awake() { mSimulator = SteamAudioManager.Simulator; var settings = SteamAudioManager.GetSimulationSettings(false); mSource = new Source(SteamAudioManager.Simulator, settings); mAudioEngineSource = AudioEngineSource.Create(SteamAudioSettings.Singleton.audioEngine); if (mAudioEngineSource != null) { mAudioEngineSource.Initialize(gameObject); mAudioEngineSource.UpdateParameters(this); } mAudioSource = GetComponent <AudioSource>(); mThis = GCHandle.Alloc(this); if (SteamAudioSettings.Singleton.audioEngine == AudioEngineType.Unity && distanceAttenuation && distanceAttenuationInput == DistanceAttenuationInput.CurveDriven && reflections && useDistanceCurveForReflections) { mAttenuationData.rolloffMode = mAudioSource.rolloffMode; mAttenuationData.minDistance = mAudioSource.minDistance; mAttenuationData.maxDistance = mAudioSource.maxDistance; mAttenuationData.curve = mAudioSource.GetCustomCurve(AudioSourceCurveType.CustomRolloff); mCurveAttenuationModel.type = DistanceAttenuationModelType.Callback; mCurveAttenuationModel.callback = EvaluateDistanceCurve; mCurveAttenuationModel.userData = GCHandle.ToIntPtr(mThis); mCurveAttenuationModel.dirty = Bool.False; } }
public void Initialize(SimulationSettingsValue settings, ComponentCache componentCache, GameEngineStateInitReason reason) { PhononCore.iplCreateContext(LogMessage, IntPtr.Zero, IntPtr.Zero, ref context); var customSettings = componentCache.SteamAudioCustomSettings(); var useOpenCL = false; var computeDeviceType = ComputeDeviceType.Any; var numComputeUnits = 0; if (customSettings) { convolutionType = customSettings.convolutionOption; if (customSettings.convolutionOption == ConvolutionOption.TrueAudioNext) { useOpenCL = true; computeDeviceType = ComputeDeviceType.GPU; numComputeUnits = customSettings.numComputeUnits; } else if (customSettings.rayTracerOption == SceneType.RadeonRays) { useOpenCL = true; } } try { computeDevice.Create(context, useOpenCL, computeDeviceType, numComputeUnits); } catch (Exception e) { throw e; } var inEditor = !SteamAudioManager.IsAudioEngineInitializing(); simulationSettings = new SimulationSettings { sceneType = (customSettings) ? customSettings.rayTracerOption : SceneType.Phonon, rays = (inEditor) ? settings.BakeRays : settings.RealtimeRays, secondaryRays = (inEditor) ? settings.BakeSecondaryRays : settings.RealtimeSecondaryRays, bounces = (inEditor) ? settings.BakeBounces : settings.RealtimeBounces, irDuration = settings.Duration, ambisonicsOrder = settings.AmbisonicsOrder, maxConvolutionSources = settings.MaxSources }; if (reason != GameEngineStateInitReason.ExportingScene) { scene.Create(computeDevice, simulationSettings, context); } if (reason == GameEngineStateInitReason.Playing) { probeManager.Create(context); } if (reason != GameEngineStateInitReason.ExportingScene && reason != GameEngineStateInitReason.GeneratingProbes) { try { environment.Create(computeDevice, simulationSettings, scene, probeManager, context); } catch (Exception e) { throw e; } } }
public void SetInputs(SimulationFlags flags) { var listener = SteamAudioManager.GetSteamAudioListener(); var inputs = new SimulationInputs { }; inputs.source.origin = Common.ConvertVector(transform.position); inputs.source.ahead = Common.ConvertVector(transform.forward); inputs.source.up = Common.ConvertVector(transform.up); inputs.source.right = Common.ConvertVector(transform.right); if (SteamAudioSettings.Singleton.audioEngine == AudioEngineType.Unity && distanceAttenuation && distanceAttenuationInput == DistanceAttenuationInput.CurveDriven && reflections && useDistanceCurveForReflections) { inputs.distanceAttenuationModel = mCurveAttenuationModel; } else { inputs.distanceAttenuationModel.type = DistanceAttenuationModelType.Default; } inputs.airAbsorptionModel.type = AirAbsorptionModelType.Default; inputs.directivity.dipoleWeight = dipoleWeight; inputs.directivity.dipolePower = dipolePower; inputs.occlusionType = occlusionType; inputs.occlusionRadius = occlusionRadius; inputs.numOcclusionSamples = occlusionSamples; inputs.reverbScaleLow = 1.0f; inputs.reverbScaleMid = 1.0f; inputs.reverbScaleHigh = 1.0f; inputs.hybridReverbTransitionTime = SteamAudioSettings.Singleton.hybridReverbTransitionTime; inputs.hybridReverbOverlapPercent = SteamAudioSettings.Singleton.hybridReverbOverlapPercent / 100.0f; inputs.baked = (reflectionsType != ReflectionsType.Realtime) ? Bool.True : Bool.False; inputs.pathingProbes = (pathingProbeBatch != null) ? pathingProbeBatch.GetProbeBatch() : IntPtr.Zero; inputs.visRadius = SteamAudioSettings.Singleton.bakingVisibilityRadius; inputs.visThreshold = SteamAudioSettings.Singleton.bakingVisibilityThreshold; inputs.visRange = SteamAudioSettings.Singleton.bakingVisibilityRange; inputs.pathingOrder = SteamAudioSettings.Singleton.bakingAmbisonicOrder; inputs.enableValidation = pathValidation ? Bool.True : Bool.False; inputs.findAlternatePaths = findAlternatePaths ? Bool.True : Bool.False; if (reflectionsType == ReflectionsType.BakedStaticSource) { if (currentBakedSource != null) { inputs.bakedDataIdentifier = currentBakedSource.GetBakedDataIdentifier(); } } else if (reflectionsType == ReflectionsType.BakedStaticListener) { if (listener != null && listener.currentBakedListener != null) { inputs.bakedDataIdentifier = listener.currentBakedListener.GetBakedDataIdentifier(); } } inputs.flags = SimulationFlags.Direct; if (reflections) { if ((reflectionsType == ReflectionsType.Realtime) || (reflectionsType == ReflectionsType.BakedStaticSource && currentBakedSource != null) || (reflectionsType == ReflectionsType.BakedStaticListener && listener != null && listener.currentBakedListener != null)) { inputs.flags = inputs.flags | SimulationFlags.Reflections; } } if (pathing) { if (pathingProbeBatch == null) { pathing = false; Debug.LogWarningFormat("Pathing probe batch not set, disabling pathing for source {0}.", gameObject.name); } else { inputs.flags = inputs.flags | SimulationFlags.Pathing; } } inputs.directFlags = 0; if (distanceAttenuation) { inputs.directFlags = inputs.directFlags | DirectSimulationFlags.DistanceAttenuation; } if (airAbsorption) { inputs.directFlags = inputs.directFlags | DirectSimulationFlags.AirAbsorption; } if (directivity) { inputs.directFlags = inputs.directFlags | DirectSimulationFlags.Directivity; } if (occlusion) { inputs.directFlags = inputs.directFlags | DirectSimulationFlags.Occlusion; } if (transmission) { inputs.directFlags = inputs.directFlags | DirectSimulationFlags.Transmission; } mSource.SetInputs(flags, inputs); }
// // Draws the inspector. // public override void OnInspectorGUI() { serializedObject.Update(); // Audio Engine GUI.enabled = !EditorApplication.isPlayingOrWillChangePlaymode; EditorGUILayout.Space(); EditorGUILayout.LabelField("Audio Engine Integration", EditorStyles.boldLabel); string[] engines = { "Unity", "FMOD Studio" }; var audioEngineProperty = serializedObject.FindProperty("audioEngine"); audioEngineProperty.enumValueIndex = EditorGUILayout.Popup("Audio Engine", audioEngineProperty.enumValueIndex, engines); // Scene Settings SteamAudioManager steamAudioManager = ((SteamAudioManager)target); EditorGUILayout.Space(); EditorGUILayout.LabelField("Global Material Settings", EditorStyles.boldLabel); EditorGUILayout.PropertyField(serializedObject.FindProperty("materialPreset")); if (serializedObject.FindProperty("materialPreset").enumValueIndex < 11) { MaterialValue actualValue = steamAudioManager.materialValue; actualValue.CopyFrom(MaterialPresetList.PresetValue( serializedObject.FindProperty("materialPreset").enumValueIndex)); } else { EditorGUILayout.PropertyField(serializedObject.FindProperty("materialValue")); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Scene Export", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button("Export to OBJ")) { steamAudioManager.ExportScene(true); } if (GUILayout.Button("Pre-Export Scene")) { steamAudioManager.ExportScene(false); } EditorGUILayout.EndHorizontal(); // Simulation Settings EditorGUILayout.Space(); EditorGUILayout.LabelField("Simulation Settings", EditorStyles.boldLabel); EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationPreset")); if (serializedObject.FindProperty("simulationPreset").enumValueIndex < 3) { SimulationSettingsValue actualValue = steamAudioManager.simulationValue; actualValue.CopyFrom(SimulationSettingsPresetList.PresetValue( serializedObject.FindProperty("simulationPreset").enumValueIndex)); } else { EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationValue")); SimulationSettingsValue actualValue = steamAudioManager.simulationValue; if (actualValue.AmbisonicsOrder > 2) { var numChannels = (actualValue.AmbisonicsOrder + 1) * (actualValue.AmbisonicsOrder + 1); EditorGUILayout.HelpBox("Ambisonics order " + actualValue.AmbisonicsOrder.ToString() + " uses " + numChannels.ToString() + " channels per source for processing indirect sound. " + "This may significantly increase CPU usage. Consider reducing this value unless necessary.", MessageType.Warning); } if (Application.isEditor && EditorApplication.isPlayingOrWillChangePlaymode) { IntPtr environment = steamAudioManager.GameEngineState().Environment().GetEnvironment(); if (environment != IntPtr.Zero) { PhononCore.iplSetNumBounces(environment, actualValue.RealtimeBounces); } } } // Fold Out for Advanced Settings EditorGUILayout.Space(); EditorGUILayout.LabelField("Advanced Options", EditorStyles.boldLabel); serializedObject.FindProperty("showLoadTimeOptions").boolValue = EditorGUILayout.Foldout(serializedObject.FindProperty("showLoadTimeOptions").boolValue, "Per Frame Query Optimization"); if (steamAudioManager.showLoadTimeOptions) { EditorGUILayout.PropertyField(serializedObject.FindProperty("updateComponents")); var updateComponents = serializedObject.FindProperty("updateComponents").boolValue; if (!updateComponents) { EditorGUILayout.PropertyField(serializedObject.FindProperty("currentAudioListener")); } } serializedObject.FindProperty("showMassBakingOptions").boolValue = EditorGUILayout.Foldout(serializedObject.FindProperty("showMassBakingOptions").boolValue, "Consolidated Baking Options"); if (steamAudioManager.showMassBakingOptions) { bool noSettingMessage = false; noSettingMessage = ProbeGenerationGUI() || noSettingMessage; noSettingMessage = BakeAllGUI() || noSettingMessage; noSettingMessage = BakedSourcesGUI(steamAudioManager) || noSettingMessage; noSettingMessage = BakedStaticListenerNodeGUI(steamAudioManager) || noSettingMessage; noSettingMessage = BakedReverbGUI(steamAudioManager) || noSettingMessage; if (!noSettingMessage) { EditorGUILayout.LabelField("Scene does not contain any baking related components."); } } GUI.enabled = true; EditorGUILayout.HelpBox("Do not manually add Steam Audio Manager component. " + "Click Window > Steam Audio.", MessageType.Info); EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); }
public void BakeSelected() { List <GameObject> gameObjects = new List <GameObject>(); List <BakedDataIdentifier> identifers = new List <BakedDataIdentifier>(); List <string> names = new List <string>(); List <Sphere> influenceSpheres = new List <Sphere>(); List <SteamAudioProbeBox[]> probeBoxes = new List <SteamAudioProbeBox[]>(); SteamAudioSource[] bakedSources = GameObject.FindObjectsOfType <SteamAudioSource>(); foreach (SteamAudioSource bakedSource in bakedSources) { if (bakedSource.reflections && bakedSource.uniqueIdentifier.Length != 0 && bakedSource.simulationType == SourceSimulationType.BakedStaticSource && bakedSource.bakeToggle) { gameObjects.Add(bakedSource.gameObject); identifers.Add(bakedSource.bakedDataIdentifier); names.Add(bakedSource.uniqueIdentifier); Sphere bakeSphere; Vector3 sphereCenter = Common.ConvertVector(bakedSource.transform.position); bakeSphere.centerx = sphereCenter.x; bakeSphere.centery = sphereCenter.y; bakeSphere.centerz = sphereCenter.z; bakeSphere.radius = bakedSource.bakingRadius; influenceSpheres.Add(bakeSphere); if (bakedSource.useAllProbeBoxes) { probeBoxes.Add(FindObjectsOfType <SteamAudioProbeBox>() as SteamAudioProbeBox[]); } else { probeBoxes.Add(bakedSource.probeBoxes); } } } SteamAudioBakedStaticListenerNode[] bakedStaticNodes = GameObject.FindObjectsOfType <SteamAudioBakedStaticListenerNode>(); foreach (SteamAudioBakedStaticListenerNode bakedStaticNode in bakedStaticNodes) { if (bakedStaticNode.uniqueIdentifier.Length != 0 && bakedStaticNode.bakeToggle) { gameObjects.Add(bakedStaticNode.gameObject); identifers.Add(bakedStaticNode.bakedDataIdentifier); names.Add(bakedStaticNode.name); Sphere bakeSphere; Vector3 sphereCenter = Common.ConvertVector(bakedStaticNode.transform.position); bakeSphere.centerx = sphereCenter.x; bakeSphere.centery = sphereCenter.y; bakeSphere.centerz = sphereCenter.z; bakeSphere.radius = bakedStaticNode.bakingRadius; influenceSpheres.Add(bakeSphere); if (bakedStaticNode.useAllProbeBoxes) { probeBoxes.Add(FindObjectsOfType <SteamAudioProbeBox>() as SteamAudioProbeBox[]); } else { probeBoxes.Add(bakedStaticNode.probeBoxes); } } } SteamAudioListener bakedReverb = GameObject.FindObjectOfType <SteamAudioListener>(); if (!(bakedReverb == null) && bakedReverb.bakeToggle) { gameObjects.Add(bakedReverb.gameObject); identifers.Add(bakedReverb.Identifier); names.Add("reverb"); influenceSpheres.Add(new Sphere()); if (bakedReverb.useAllProbeBoxes) { probeBoxes.Add(FindObjectsOfType <SteamAudioProbeBox>() as SteamAudioProbeBox[]); } else { probeBoxes.Add(bakedReverb.probeBoxes); } } if (gameObjects.Count > 0) { SteamAudioManager phononManager = serializedObject.targetObject as SteamAudioManager; phononManager.phononBaker.BeginBake(gameObjects.ToArray(), identifers.ToArray(), names.ToArray(), influenceSpheres.ToArray(), probeBoxes.ToArray()); } else { Debug.LogWarning("No game object selected for baking."); } }
static void BakeThread() { sTotalObjects = sTasks.Length; for (var i = 0; i < sTotalObjects; ++i) { sCurrentObjectIndex = i; if (sTasks[i].identifier.type == BakedDataType.Pathing) { sCurrentObjectName = "pathing"; } else if (sTasks[i].identifier.variation == BakedDataVariation.Reverb) { sCurrentObjectName = "reverb"; } else { sCurrentObjectName = sTasks[i].name; } Debug.Log(string.Format("START: Baking effect for {0}.", sCurrentObjectName)); var probeBatches = sTasks[i].probeBatches; sTotalProbeBatches = probeBatches.Length; for (var j = 0; j < sTotalProbeBatches; ++j) { sCurrentProbeBatchIndex = j; if (sCancel) { return; } if (probeBatches[j] == null) { Debug.LogWarning(string.Format("{0}: Probe Batch at index {1} is null.", sCurrentObjectName, j)); continue; } if (probeBatches[j].GetNumProbes() == 0) { Debug.LogWarning(string.Format("{0}: Probe Batch {1} has no probes, skipping.", sCurrentObjectName, sTasks[i].probeBatchNames[j])); continue; } var probeBatch = new ProbeBatch(SteamAudioManager.Context, sTasks[i].probeBatchAssets[j]); var simulationSettings = SteamAudioManager.GetSimulationSettings(true); if (sTasks[i].identifier.type == BakedDataType.Reflections) { var bakeParams = new ReflectionsBakeParams { }; bakeParams.scene = SteamAudioManager.CurrentScene.Get(); bakeParams.probeBatch = probeBatch.Get(); bakeParams.sceneType = simulationSettings.sceneType; bakeParams.identifier = sTasks[i].identifier; bakeParams.flags = 0; bakeParams.numRays = simulationSettings.maxNumRays; bakeParams.numDiffuseSamples = simulationSettings.numDiffuseSamples; bakeParams.numBounces = SteamAudioSettings.Singleton.bakingBounces; bakeParams.simulatedDuration = simulationSettings.maxDuration; bakeParams.savedDuration = simulationSettings.maxDuration; bakeParams.order = simulationSettings.maxOrder; bakeParams.numThreads = simulationSettings.numThreads; bakeParams.rayBatchSize = simulationSettings.rayBatchSize; bakeParams.irradianceMinDistance = SteamAudioSettings.Singleton.bakingIrradianceMinDistance; bakeParams.bakeBatchSize = 1; if (SteamAudioSettings.Singleton.bakeConvolution) { bakeParams.flags = bakeParams.flags | ReflectionsBakeFlags.BakeConvolution; } if (SteamAudioSettings.Singleton.bakeParametric) { bakeParams.flags = bakeParams.flags | ReflectionsBakeFlags.BakeParametric; } if (simulationSettings.sceneType == SceneType.RadeonRays) { bakeParams.openCLDevice = SteamAudioManager.OpenCLDevice; bakeParams.radeonRaysDevice = SteamAudioManager.RadeonRaysDevice; bakeParams.bakeBatchSize = SteamAudioSettings.Singleton.bakingBatchSize; } API.iplReflectionsBakerBake(SteamAudioManager.Context.Get(), ref bakeParams, sProgressCallback, IntPtr.Zero); } else { var bakeParams = new PathBakeParams { }; bakeParams.scene = SteamAudioManager.CurrentScene.Get(); bakeParams.probeBatch = probeBatch.Get(); bakeParams.identifier = sTasks[i].identifier; bakeParams.numSamples = SteamAudioSettings.Singleton.bakingVisibilitySamples; bakeParams.radius = SteamAudioSettings.Singleton.bakingVisibilityRadius; bakeParams.threshold = SteamAudioSettings.Singleton.bakingVisibilityThreshold; bakeParams.visRange = SteamAudioSettings.Singleton.bakingVisibilityRange; bakeParams.pathRange = SteamAudioSettings.Singleton.bakingPathRange; bakeParams.numThreads = SteamAudioManager.Singleton.NumThreadsForCPUCorePercentage(SteamAudioSettings.Singleton.bakedPathingCPUCoresPercentage); API.iplPathBakerBake(SteamAudioManager.Context.Get(), ref bakeParams, sProgressCallback, IntPtr.Zero); } if (sCancel) { Debug.Log("CANCELLED: Baking."); return; } // Don't flush the writes to disk just yet, because we can only do it from the main thread. probeBatches[j].probeDataSize = probeBatch.Save(sTasks[i].probeBatchAssets[j], false); var dataSize = (int)probeBatch.GetDataSize(sTasks[i].identifier); probeBatches[j].AddOrUpdateLayer(sTasks[i].gameObject, sTasks[i].identifier, dataSize); if (sTasks[i].identifier.type == BakedDataType.Reflections) { switch (sTasks[i].identifier.variation) { case BakedDataVariation.Reverb: (sTasks[i].component as SteamAudioListener).UpdateBakedDataStatistics(); break; case BakedDataVariation.StaticSource: (sTasks[i].component as SteamAudioBakedSource).UpdateBakedDataStatistics(); break; case BakedDataVariation.StaticListener: (sTasks[i].component as SteamAudioBakedListener).UpdateBakedDataStatistics(); break; } } } Debug.Log(string.Format("COMPLETED: Baking effect for {0}.", sCurrentObjectName)); } sStatus = BakeStatus.Complete; }
public void Initialize(SimulationSettingsValue settings, ComponentCache componentCache, GameEngineStateInitReason reason) { PhononCore.iplCreateContext(LogMessage, IntPtr.Zero, IntPtr.Zero, ref context); if (reason != GameEngineStateInitReason.EditingProbes) { var customSettings = componentCache.SteamAudioCustomSettings(); var useOpenCL = false; var computeDeviceType = ComputeDeviceType.Any; var requiresTan = false; var minReservableCUs = 0; var maxCUsToReserve = 0; if (customSettings) { convolutionType = customSettings.ConvolutionType(); if (convolutionType == ConvolutionOption.TrueAudioNext) { useOpenCL = true; requiresTan = true; computeDeviceType = ComputeDeviceType.GPU; minReservableCUs = customSettings.minComputeUnitsToReserve; maxCUsToReserve = customSettings.maxComputeUnitsToReserve; } else if (customSettings.RayTracerType() == SceneType.RadeonRays) { useOpenCL = true; } } try { var deviceFilter = new ComputeDeviceFilter { type = computeDeviceType, requiresTrueAudioNext = (requiresTan) ? Bool.True : Bool.False, minReservableCUs = minReservableCUs, maxCUsToReserve = maxCUsToReserve }; computeDevice.Create(context, useOpenCL, deviceFilter); } catch (Exception e) { Debug.LogWarning(String.Format("Unable to initialize TrueAudio Next: {0}. Using Phonon convolution.", e.Message)); convolutionType = ConvolutionOption.Phonon; } var inEditor = !SteamAudioManager.IsAudioEngineInitializing(); var maxSources = settings.MaxSources; if (customSettings && convolutionType == ConvolutionOption.TrueAudioNext) { maxSources = customSettings.MaxSources; } if (customSettings && customSettings.RayTracerType() == SceneType.RadeonRays && reason == GameEngineStateInitReason.Baking) { maxSources = customSettings.BakingBatchSize; } var rayTracer = SceneType.Phonon; if (customSettings) { if (customSettings.RayTracerType() != SceneType.RadeonRays || reason != GameEngineStateInitReason.Playing) { rayTracer = customSettings.RayTracerType(); } } simulationSettings = new SimulationSettings { sceneType = rayTracer, occlusionSamples = settings.OcclusionSamples, rays = (inEditor) ? settings.BakeRays : settings.RealtimeRays, secondaryRays = (inEditor) ? settings.BakeSecondaryRays : settings.RealtimeSecondaryRays, bounces = (inEditor) ? settings.BakeBounces : settings.RealtimeBounces, threads = (inEditor) ? (int)Mathf.Max(1, (settings.BakeThreadsPercentage * SystemInfo.processorCount) / 100.0f) : (int)Mathf.Max(1, (settings.RealtimeThreadsPercentage * SystemInfo.processorCount) / 100.0f), irDuration = (customSettings && convolutionType == ConvolutionOption.TrueAudioNext) ? customSettings.Duration : settings.Duration, ambisonicsOrder = (customSettings && convolutionType == ConvolutionOption.TrueAudioNext) ? customSettings.AmbisonicsOrder : settings.AmbisonicsOrder, maxConvolutionSources = maxSources, bakingBatchSize = (customSettings && customSettings.RayTracerType() == SceneType.RadeonRays) ? customSettings.BakingBatchSize : 1 }; #if UNITY_EDITOR if (customSettings) { if (customSettings.RayTracerType() == SceneType.Embree) { if (!File.Exists(Directory.GetCurrentDirectory() + "/Assets/Plugins/x86_64/embree.dll")) { throw new Exception( "Steam Audio configured to use Embree, but Embree support package not installed. " + "Please import SteamAudio_Embree.unitypackage in order to use Embree support for " + "Steam Audio."); } } else if (customSettings.RayTracerType() == SceneType.RadeonRays) { if (!File.Exists(Directory.GetCurrentDirectory() + "/Assets/Plugins/x86_64/RadeonRays.dll")) { throw new Exception( "Steam Audio configured to use Radeon Rays, but Radeon Rays support package not " + "installed. Please import SteamAudio_RadeonRays.unitypackage in order to use Radeon " + "Rays support for Steam Audio."); } } if (customSettings.ConvolutionType() == ConvolutionOption.TrueAudioNext) { if (!File.Exists(Directory.GetCurrentDirectory() + "/Assets/Plugins/x86_64/tanrt64.dll")) { throw new Exception( "Steam Audio configured to use TrueAudio Next, but TrueAudio Next support package " + "not installed. Please import SteamAudio_TrueAudioNext.unitypackage in order to use " + "TrueAudio Next support for Steam Audio."); } } } #endif if (reason != GameEngineStateInitReason.ExportingScene) { scene.Create(computeDevice, simulationSettings, context); } if (reason == GameEngineStateInitReason.Playing) { probeManager.Create(context); } if (reason != GameEngineStateInitReason.ExportingScene && reason != GameEngineStateInitReason.GeneratingProbes) { try { environment.Create(computeDevice, simulationSettings, scene, probeManager, context); } catch (Exception e) { throw e; } } } }
public void GenerateProbes() { SteamAudioManager.Initialize(ManagerInitReason.GeneratingProbes); SteamAudioManager.LoadScene(SceneManager.GetActiveScene(), SteamAudioManager.Context, false); var scene = SteamAudioManager.CurrentScene; SteamAudioStaticMesh staticMeshComponent = null; var rootObjects = SceneManager.GetActiveScene().GetRootGameObjects(); foreach (var rootObject in rootObjects) { staticMeshComponent = rootObject.GetComponentInChildren <SteamAudioStaticMesh>(); if (staticMeshComponent) { break; } } if (staticMeshComponent == null || staticMeshComponent.asset == null) { Debug.LogError(string.Format("Scene {0} has not been exported. Click Steam Audio > Export Active Scene to do so.", SceneManager.GetActiveScene().name)); return; } var staticMesh = new StaticMesh(SteamAudioManager.Context, scene, staticMeshComponent.asset); staticMesh.AddToScene(scene); scene.Commit(); var probeArray = new ProbeArray(SteamAudioManager.Context); var probeGenerationParams = new ProbeGenerationParams { }; probeGenerationParams.type = placementStrategy; probeGenerationParams.spacing = horizontalSpacing; probeGenerationParams.height = heightAboveFloor; probeGenerationParams.transform = Common.TransposeMatrix(Common.ConvertTransform(gameObject.transform)); // Probe generation requires a transposed matrix. probeArray.GenerateProbes(scene, probeGenerationParams); var numProbes = probeArray.GetNumProbes(); mProbeSpheres = new Sphere[numProbes]; for (var i = 0; i < numProbes; ++i) { mProbeSpheres[i] = probeArray.GetProbe(i); } var probeBatch = new ProbeBatch(SteamAudioManager.Context); probeBatch.AddProbeArray(probeArray); probeDataSize = probeBatch.Save(GetAsset()); probeBatch.Release(); probeArray.Release(); staticMesh.Release(); SteamAudioManager.ShutDown(); DestroyImmediate(SteamAudioManager.Singleton.gameObject); ResetLayers(); Debug.Log("Generated " + mProbeSpheres.Length + " probes for game object " + gameObject.name + "."); // Redraw scene view for probes to show up instantly. #if UNITY_EDITOR SceneView.RepaintAll(); #endif }