コード例 #1
0
        //
        // Copies data from another object.
        //
        public void CopyFrom(PhononMaterialValue other)
        {
            LowFreqAbsorption  = other.LowFreqAbsorption;
            MidFreqAbsorption  = other.MidFreqAbsorption;
            HighFreqAbsorption = other.HighFreqAbsorption;

            Scattering = other.Scattering;
        }
コード例 #2
0
        //
        // Draws the inspector.
        //
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            PhononGUI.SectionHeader("Material Preset");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("Preset"));

            if (serializedObject.FindProperty("Preset").enumValueIndex < 11)
            {
                PhononMaterialValue actualValue = ((PhononMaterial)target).Value;
                actualValue.CopyFrom(PhononMaterialPresetList.PresetValue(serializedObject.FindProperty("Preset").enumValueIndex));
            }
            else
            {
                PhononGUI.SectionHeader("Custom Material");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("Value"));
            }

            EditorGUILayout.Space();

            // Save changes.
            serializedObject.ApplyModifiedProperties();
        }
コード例 #3
0
ファイル: Scene.cs プロジェクト: gimoz71/Vertigini-VR---2018
        public Error Export(ComputeDevice computeDevice, SimulationSettings simulationSettings, PhononMaterialValue defaultMaterial, GlobalContext globalContext)
        {
            var error = Error.None;

            var objects = GameObject.FindObjectsOfType <PhononGeometry>();

            simulationSettings.sceneType = SceneType.Phonon;    // Scene type should always be Phonon when exporting the scene.
            error = PhononCore.iplCreateScene(globalContext, computeDevice.GetDevice(), simulationSettings,
                                              objects.Length, ref scene);
            if (error != Error.None)
            {
                throw new Exception("Unable to create scene for export (" + objects.Length.ToString() +
                                    " materials): [" + error.ToString() + "]");
            }

            var materials = new Material[objects.Length];

            for (var i = 0; i < objects.Length; ++i)
            {
                materials[i].absorptionHigh = defaultMaterial.HighFreqAbsorption;
                materials[i].absorptionMid  = defaultMaterial.MidFreqAbsorption;
                materials[i].absorptionLow  = defaultMaterial.LowFreqAbsorption;
                materials[i].scattering     = defaultMaterial.Scattering;

                objects[i].GetMaterial(ref materials[i]);
                PhononCore.iplSetSceneMaterial(scene, i, materials[i]);
            }

            var totalNumVertices = 0;
            var numVertices      = new int[objects.Length];

            var totalNumTriangles = 0;
            var numTriangles      = new int[objects.Length];

            for (var i = 0; i < objects.Length; ++i)
            {
                numVertices[i]    = objects[i].GetNumVertices();
                totalNumVertices += numVertices[i];

                numTriangles[i]    = objects[i].GetNumTriangles();
                totalNumTriangles += numTriangles[i];
            }

            var staticMesh = IntPtr.Zero;

            error = PhononCore.iplCreateStaticMesh(scene, totalNumVertices, totalNumTriangles, ref staticMesh);
            if (error != Error.None)
            {
                throw new Exception("Unable to create static mesh for export (" + totalNumVertices.ToString() +
                                    " vertices, " + totalNumTriangles.ToString() + " triangles): [" + error.ToString() + "]");
            }

            var vertices     = new Vector3[totalNumVertices];
            var vertexOffset = 0;

            var triangles      = new Triangle[totalNumTriangles];
            var triangleOffset = 0;

            var materialIndices = new int[totalNumTriangles];

            for (var i = 0; i < objects.Length; ++i)
            {
                objects[i].GetGeometry(vertices, vertexOffset, triangles, triangleOffset);

                for (var j = 0; j < numTriangles[i]; ++j)
                {
                    materialIndices[triangleOffset + j] = i;
                }

                vertexOffset   += numVertices[i];
                triangleOffset += numTriangles[i];
            }

            PhononCore.iplSetStaticMeshVertices(scene, staticMesh, vertices);
            PhononCore.iplSetStaticMeshTriangles(scene, staticMesh, triangles);
            PhononCore.iplSetStaticMeshMaterials(scene, staticMesh, materialIndices);

            PhononCore.iplFinalizeScene(scene, null);

#if UNITY_EDITOR
            if (!Directory.Exists(Application.streamingAssetsPath))
            {
                UnityEditor.AssetDatabase.CreateFolder("Assets", "StreamingAssets");
            }
#endif

            error = PhononCore.iplSaveFinalizedScene(scene, SceneFileName());
            if (error != Error.None)
            {
                throw new Exception("Unable to save scene to " + SceneFileName() + " [" + error.ToString() + "]");
            }

            PhononCore.iplDestroyStaticMesh(ref staticMesh);
            PhononCore.iplDestroyScene(ref scene);

            Debug.Log("Scene exported to " + SceneFileName() + ".");

            return(error);
        }
コード例 #4
0
 //
 // Copy constructor.
 //
 public PhononMaterialValue(PhononMaterialValue other)
 {
     CopyFrom(other);
 }
コード例 #5
0
        public Error Export(ComputeDevice computeDevice, SimulationSettings simulationSettings,
                            PhononMaterialValue defaultMaterial, GlobalContext globalContext, bool exportOBJ = false)
        {
            var error = Error.None;

            var objects           = GameObject.FindObjectsOfType <PhononGeometry>();
            var totalNumVertices  = 0;
            var totalNumTriangles = 0;
            var totalNumMaterials = 1;  // Global material.

            for (var i = 0; i < objects.Length; ++i)
            {
                totalNumVertices  += objects[i].GetNumVertices();
                totalNumTriangles += objects[i].GetNumTriangles();
                totalNumMaterials += objects[i].GetNumMaterials();
            }

            simulationSettings.sceneType = SceneType.Phonon;    // Scene type should always be Phonon when exporting.

            error = PhononCore.iplCreateScene(globalContext, computeDevice.GetDevice(), simulationSettings,
                                              totalNumMaterials, ref scene);
            if (error != Error.None)
            {
                throw new Exception("Unable to create scene for export (" + objects.Length.ToString() +
                                    " materials): [" + error.ToString() + "]");
            }

            var staticMesh = IntPtr.Zero;

            error = PhononCore.iplCreateStaticMesh(scene, totalNumVertices, totalNumTriangles, ref staticMesh);
            if (error != Error.None)
            {
                throw new Exception("Unable to create static mesh for export (" + totalNumVertices.ToString() +
                                    " vertices, " + totalNumTriangles.ToString() + " triangles): [" + error.ToString() + "]");
            }

            var vertices        = new Vector3[totalNumVertices];
            var triangles       = new Triangle[totalNumTriangles];
            var materialIndices = new int[totalNumTriangles];
            var materials       = new Material[totalNumMaterials + 1]; // Offset added to avoid creating Material
                                                                       // for each object and then copying it.

            var vertexOffset   = 0;
            var triangleOffset = 0;

            var materialOffset = 1;

            materials[0].absorptionHigh   = defaultMaterial.HighFreqAbsorption;
            materials[0].absorptionMid    = defaultMaterial.MidFreqAbsorption;
            materials[0].absorptionLow    = defaultMaterial.LowFreqAbsorption;
            materials[0].scattering       = defaultMaterial.Scattering;
            materials[0].transmissionHigh = defaultMaterial.HighFreqTransmission;
            materials[0].transmissionMid  = defaultMaterial.MidFreqTransmission;
            materials[0].transmissionLow  = defaultMaterial.LowFreqTransmission;

            for (var i = 0; i < objects.Length; ++i)
            {
                objects[i].GetGeometry(vertices, ref vertexOffset, triangles, ref triangleOffset, materials,
                                       materialIndices, ref materialOffset);
            }

            for (var i = 0; i < totalNumMaterials; ++i)
            {
                PhononCore.iplSetSceneMaterial(scene, i, materials[i]);
            }

            PhononCore.iplSetStaticMeshVertices(scene, staticMesh, vertices);
            PhononCore.iplSetStaticMeshTriangles(scene, staticMesh, triangles);
            PhononCore.iplSetStaticMeshMaterials(scene, staticMesh, materialIndices);

            PhononCore.iplFinalizeScene(scene, null);

#if UNITY_EDITOR
            if (!Directory.Exists(Application.streamingAssetsPath))
            {
                UnityEditor.AssetDatabase.CreateFolder("Assets", "StreamingAssets");
            }
#endif

            if (exportOBJ)
            {
                PhononCore.iplDumpSceneToObjFile(scene, Common.ConvertString(ObjFileName()));
                Debug.Log("Scene dumped to " + ObjFileName() + ".");
            }
            else
            {
                error = PhononCore.iplSaveFinalizedScene(scene, Common.ConvertString(SceneFileName()));
                if (error != Error.None)
                {
                    throw new Exception("Unable to save scene to " + SceneFileName() + " [" + error.ToString() + "]");
                }

                Debug.Log("Scene exported to " + SceneFileName() + ".");
            }

            PhononCore.iplDestroyStaticMesh(ref staticMesh);
            PhononCore.iplDestroyScene(ref scene);
            return(error);
        }
コード例 #6
0
        //
        // Draws the inspector.
        //
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Audio Engine
            PhononGUI.SectionHeader("Audio Engine Integration");
            string[] engines             = { "Unity Audio" };
            var      audioEngineProperty = serializedObject.FindProperty("audioEngine");

            audioEngineProperty.enumValueIndex = EditorGUILayout.Popup("Audio Engine", audioEngineProperty.enumValueIndex, engines);

            // Scene Settings
            PhononManager phononManager = ((PhononManager)target);

            PhononGUI.SectionHeader("Global Material Settings");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("materialPreset"));
            if (serializedObject.FindProperty("materialPreset").enumValueIndex < 11)
            {
                PhononMaterialValue actualValue = phononManager.materialValue;
                actualValue.CopyFrom(PhononMaterialPresetList.PresetValue(serializedObject.FindProperty("materialPreset").enumValueIndex));
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("materialValue"));
            }

            PhononGUI.SectionHeader("Scene Export");
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");

            bool exportOBJ   = false;
            bool exportScene = false;

            if (GUILayout.Button("Export to OBJ"))
            {
                exportOBJ = true;
            }
            if (GUILayout.Button("Pre-Export Scene"))
            {
                exportScene = true;
            }

            if (exportOBJ || exportScene)
            {
                if (exportScene)
                {
                    phononManager.ExportScene();
                }
                if (exportOBJ)
                {
                    phononManager.DumpScene();
                }
            }
            EditorGUILayout.EndHorizontal();

            // Simulation Settings
            PhononGUI.SectionHeader("Simulation Settings");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationPreset"));
            if (serializedObject.FindProperty("simulationPreset").enumValueIndex < 3)
            {
                SimulationSettingsValue actualValue = phononManager.simulationValue;
                actualValue.CopyFrom(SimulationSettingsPresetList.PresetValue(serializedObject.FindProperty("simulationPreset").enumValueIndex));
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationValue"));
                if (Application.isEditor && EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    SimulationSettingsValue actualValue = phononManager.simulationValue;
                    IntPtr environment = phononManager.PhononManagerContainer().Environment().GetEnvironment();
                    if (environment != IntPtr.Zero)
                    {
                        PhononCore.iplSetNumBounces(environment, actualValue.RealtimeBounces);
                    }
                }
            }

            EditorGUILayout.Space();
            serializedObject.ApplyModifiedProperties();
        }
コード例 #7
0
        //
        // Draws the inspector.
        //
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Audio Engine
            PhononGUI.SectionHeader("Audio Engine Integration");
            string[] engines             = { "Unity Audio" };
            var      audioEngineProperty = serializedObject.FindProperty("audioEngine");

            audioEngineProperty.enumValueIndex = EditorGUILayout.Popup("Audio Engine", audioEngineProperty.enumValueIndex, engines);

            // Scene Settings
            PhononManager phononManager = ((PhononManager)target);

            PhononGUI.SectionHeader("Global Material Settings");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("materialPreset"));
            if (serializedObject.FindProperty("materialPreset").enumValueIndex < 11)
            {
                PhononMaterialValue actualValue = phononManager.materialValue;
                actualValue.CopyFrom(PhononMaterialPresetList.PresetValue(serializedObject.FindProperty("materialPreset").enumValueIndex));
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("materialValue"));
            }

            PhononGUI.SectionHeader("Scene Export");
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");

            if (GUILayout.Button("Export to OBJ"))
            {
                phononManager.ExportScene(true);
            }
            if (GUILayout.Button("Pre-Export Scene"))
            {
                phononManager.ExportScene(false);
            }

            EditorGUILayout.EndHorizontal();

            // Simulation Settings
            PhononGUI.SectionHeader("Simulation Settings");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationPreset"));
            if (serializedObject.FindProperty("simulationPreset").enumValueIndex < 3)
            {
                SimulationSettingsValue actualValue = phononManager.simulationValue;
                actualValue.CopyFrom(SimulationSettingsPresetList.PresetValue(serializedObject.FindProperty("simulationPreset").enumValueIndex));
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationValue"));
                if (Application.isEditor && EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    SimulationSettingsValue actualValue = phononManager.simulationValue;
                    IntPtr environment = phononManager.PhononManagerContainer().Environment().GetEnvironment();
                    if (environment != IntPtr.Zero)
                    {
                        PhononCore.iplSetNumBounces(environment, actualValue.RealtimeBounces);
                    }
                }
            }

            // Fold Out for Advanced Settings
            PhononGUI.SectionHeader("Advanced Options");
            phononManager.showLoadTimeOptions = EditorGUILayout.Foldout(phononManager.showLoadTimeOptions, "Per Frame Query Optimization");
            if (phononManager.showLoadTimeOptions)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("updateComponents"));
            }

            phononManager.showMassBakingOptions = EditorGUILayout.Foldout(phononManager.showMassBakingOptions, "Consolidated Baking Options");
            if (phononManager.showMassBakingOptions)
            {
                bool noSettingMessage = false;
                noSettingMessage = ProbeGenerationGUI() || noSettingMessage;
                noSettingMessage = BakedSourcesGUI(phononManager) || noSettingMessage;
                noSettingMessage = BakedReverbGUI(phononManager) || noSettingMessage;
                noSettingMessage = BakedStaticListenerNodeGUI(phononManager) || noSettingMessage;

                if (!noSettingMessage)
                {
                    EditorGUILayout.LabelField("Scene does not contain any baking related components.");
                }
            }

            EditorGUILayout.HelpBox("Do not manually add Phonon Manager component. Click Window > Phonon.", MessageType.Info);

            EditorGUILayout.Space();
            serializedObject.ApplyModifiedProperties();
        }