public override void OnInspectorGUI()
        {
            serializedObject.Update();

            /*GUI.enabled = emitter.Initialized;
             * EditorGUI.BeginChangeCheck();
             * editMode = GUILayout.Toggle(editMode,new GUIContent("Edit particles",EditorGUIUtility.Load("Obi/EditParticles.psd") as Texture2D),"LargeButton");
             * if (EditorGUI.EndChangeCheck()){
             *      SceneView.RepaintAll();
             * }
             * GUI.enabled = true;*/

            EditorGUILayout.HelpBox("Active particles:" + emitter.ActiveParticles, MessageType.Info);

            EditorGUI.BeginChangeCheck();
            ObiSolver solver = EditorGUILayout.ObjectField("Solver", emitter.Solver, typeof(ObiSolver), true) as ObiSolver;

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(emitter, "Set solver");
                emitter.Solver = solver;
            }

            EditorGUI.BeginChangeCheck();
            ObiCollisionMaterial material = EditorGUILayout.ObjectField("Collision Material", emitter.CollisionMaterial, typeof(ObiCollisionMaterial), false) as ObiCollisionMaterial;

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(emitter, "Set collision material");
                emitter.CollisionMaterial = material;
            }

            EditorGUI.BeginChangeCheck();
            ObiEmitterMaterial emitterMaterial = EditorGUILayout.ObjectField(new GUIContent("Emitter Material", "Emitter material used. This controls the behavior of the emitted particles."),
                                                                             emitter.EmitterMaterial, typeof(ObiEmitterMaterial), false) as ObiEmitterMaterial;

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(emitter, "Set emitter material");
                emitter.EmitterMaterial = emitterMaterial;
            }

            EditorGUI.BeginChangeCheck();
            int numParticles = EditorGUILayout.IntField(new GUIContent("Num particles", "Amount of pooled particles used by this emitter."), emitter.NumParticles);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(emitter, "Set num particles");
                emitter.NumParticles = numParticles;
            }

            Editor.DrawPropertiesExcluding(serializedObject, "m_Script");

            // Apply changes to the serializedProperty
            if (GUI.changed)
            {
                emitter.UpdateParticlePhases();                 //TODO: only do this when changing material.
                serializedObject.ApplyModifiedProperties();
            }
        }
Exemple #2
0
        public void Initialize()
        {
            // Tear everything down first:
            Teardown();

            try{
                // Create a default material:
                defaultFluidMaterial           = ScriptableObject.CreateInstance <ObiEmitterMaterialFluid>();
                defaultFluidMaterial.hideFlags = HideFlags.HideAndDontSave;

                // Create the Oni solver:
                oniSolver = Oni.CreateSolver(maxParticles, MAX_NEIGHBOURS);

                actors               = new List <ObiActor>();
                activeParticles      = new int[maxParticles];
                particleToActor      = new ParticleInActor[maxParticles];
                materialIndices      = new int[maxParticles];
                fluidMaterialIndices = new int[maxParticles];
                renderablePositions  = new Vector4[maxParticles];

                // Initialize materials:
                UpdateEmitterMaterials();

                // Initialize parameters:
                UpdateParameters();
            }catch (Exception exception) {
                Debug.LogException(exception);
            }finally{
                initialized = true;
            };
        }
Exemple #3
0
        public void Initialize()
        {
            // Tear everything down first:
            Teardown();

            try{
                // Create a default material (TODO: maybe expose this to the user?)
                defaultMaterial           = ScriptableObject.CreateInstance <ObiCollisionMaterial>();
                defaultMaterial.hideFlags = HideFlags.HideAndDontSave;

                defaultFluidMaterial           = ScriptableObject.CreateInstance <ObiEmitterMaterial>();
                defaultFluidMaterial.hideFlags = HideFlags.HideAndDontSave;

                // Create the Oni solver:
                oniSolver = Oni.CreateSolver(maxParticles, maxDiffuseParticles, 92);

                actors               = new List <ObiActor>();
                allocatedParticles   = new HashSet <int>();
                activeParticles      = new HashSet <int>();
                materialIndices      = new int[maxParticles];
                fluidMaterialIndices = new int[maxParticles];
                renderablePositions  = new Vector4[maxParticles];

                // Initialize materials:
                UpdateSolverMaterials();
                //UpdateEmitterMaterials();

                // Initialize parameters:
                UpdateParameters();
            }catch (Exception exception) {
                Debug.LogException(exception);
            }finally{
                initialized = true;
            };
        }
Exemple #4
0
        private void emitterMaterial_OnChangesMade(object sender, ObiEmitterMaterial.MaterialChangeEventArgs e)
        {
            ObiEmitterMaterial material = sender as ObiEmitterMaterial;
            int index = emitterMaterials.IndexOf(material);

            if (index >= 0)
            {
                Oni.SetFluidMaterials(oniSolver, new Oni.FluidMaterial[] { material.GetEquivalentOniMaterial(parameters.mode) }, 1, index);
            }
        }
        public void OnEnable()
        {
            material = (ObiEmitterMaterial)target;

            isFluid        = serializedObject.FindProperty("isFluid");
            randomRadius   = serializedObject.FindProperty("randomRadius");
            restDensity    = serializedObject.FindProperty("restDensity");
            viscosity      = serializedObject.FindProperty("viscosity");
            surfaceTension = serializedObject.FindProperty("surfaceTension");

            buoyancy            = serializedObject.FindProperty("buoyancy");
            atmosphericDrag     = serializedObject.FindProperty("atmosphericDrag");
            atmosphericPressure = serializedObject.FindProperty("atmosphericPressure");
            vorticity           = serializedObject.FindProperty("vorticity");
        }
        public void Initialize()
        {
            // Tear everything down first:
            Teardown();

            try{
                // Create a default material:
                defaultFluidMaterial           = ScriptableObject.CreateInstance <ObiEmitterMaterialFluid>();
                defaultFluidMaterial.hideFlags = HideFlags.HideAndDontSave;

                // Create the Oni solver:
                oniSolver = Oni.CreateSolver(maxParticles);

                // Initialize moving transform:
                InitializeTransformFrame();

                actors               = new List <ObiActor>();
                activeParticles      = new int[maxParticles];
                particleToActor      = new ParticleInActor[maxParticles];
                materialIndices      = new int[maxParticles];
                fluidMaterialIndices = new int[maxParticles];

                positions = new AlignedVector4Array(maxParticles);
                Oni.SetParticlePositions(oniSolver, positions.GetIntPtr());

                startPositions = new AlignedVector4Array(maxParticles);
                Oni.SetParticleStartPositions(oniSolver, startPositions.GetIntPtr());

                prevPositions = new AlignedVector4Array(maxParticles);
                Oni.SetParticlePreviousPositions(oniSolver, prevPositions.GetIntPtr());

                restPositions = new AlignedVector4Array(maxParticles);
                Oni.SetRestPositions(oniSolver, restPositions.GetIntPtr());

                velocities = new AlignedVector4Array(maxParticles);
                Oni.SetParticleVelocities(oniSolver, velocities.GetIntPtr());

                orientations = new AlignedQuaternionArray(maxParticles, Quaternion.identity);
                Oni.SetParticleOrientations(oniSolver, orientations.GetIntPtr());

                startOrientations = new AlignedQuaternionArray(maxParticles, Quaternion.identity);
                Oni.SetParticleStartOrientations(oniSolver, startOrientations.GetIntPtr());

                prevOrientations = new AlignedQuaternionArray(maxParticles, Quaternion.identity);
                Oni.SetParticlePreviousOrientations(oniSolver, prevOrientations.GetIntPtr());

                restOrientations = new AlignedQuaternionArray(maxParticles, Quaternion.identity);
                Oni.SetRestOrientations(oniSolver, restOrientations.GetIntPtr());

                angularVelocities = new AlignedVector4Array(maxParticles);
                Oni.SetParticleAngularVelocities(oniSolver, angularVelocities.GetIntPtr());

                invMasses = new AlignedFloatArray(maxParticles);
                Oni.SetParticleInverseMasses(oniSolver, invMasses.GetIntPtr());

                invRotationalMasses = new AlignedFloatArray(maxParticles);
                Oni.SetParticleInverseRotationalMasses(oniSolver, invRotationalMasses.GetIntPtr());

                principalRadii = new AlignedVector4Array(maxParticles);
                Oni.SetParticlePrincipalRadii(oniSolver, principalRadii.GetIntPtr());

                phases = new AlignedIntArray(maxParticles);
                Oni.SetParticlePhases(oniSolver, phases.GetIntPtr());

                renderablePositions = new AlignedVector4Array(maxParticles);
                Oni.SetRenderableParticlePositions(oniSolver, renderablePositions.GetIntPtr());

                renderableOrientations = new AlignedQuaternionArray(maxParticles, Quaternion.identity);
                Oni.SetRenderableParticleOrientations(oniSolver, renderableOrientations.GetIntPtr());

                anisotropies = new AlignedVector4Array(maxParticles * 3);
                Oni.SetParticleAnisotropies(oniSolver, anisotropies.GetIntPtr());

                smoothingRadii = new AlignedFloatArray(maxParticles);
                Oni.SetParticleSmoothingRadii(oniSolver, smoothingRadii.GetIntPtr());

                buoyancies = new AlignedFloatArray(maxParticles);
                Oni.SetParticleBuoyancy(oniSolver, buoyancies.GetIntPtr());

                restDensities = new AlignedFloatArray(maxParticles);
                Oni.SetParticleRestDensities(oniSolver, restDensities.GetIntPtr());

                viscosities = new AlignedFloatArray(maxParticles);
                Oni.SetParticleViscosities(oniSolver, viscosities.GetIntPtr());

                surfaceTension = new AlignedFloatArray(maxParticles);
                Oni.SetParticleSurfaceTension(oniSolver, surfaceTension.GetIntPtr());

                vortConfinement = new AlignedFloatArray(maxParticles);
                Oni.SetParticleVorticityConfinement(oniSolver, vortConfinement.GetIntPtr());

                atmosphericDrag     = new AlignedFloatArray(maxParticles);
                atmosphericPressure = new AlignedFloatArray(maxParticles);
                Oni.SetParticleAtmosphericDragPressure(oniSolver, atmosphericDrag.GetIntPtr(), atmosphericPressure.GetIntPtr());

                diffusion = new AlignedFloatArray(maxParticles);
                Oni.SetParticleDiffusion(oniSolver, diffusion.GetIntPtr());

                vorticities = new AlignedVector4Array(maxParticles);
                Oni.SetParticleVorticities(oniSolver, vorticities.GetIntPtr());

                fluidData = new AlignedVector4Array(maxParticles);
                Oni.SetParticleFluidData(oniSolver, fluidData.GetIntPtr());

                userData = new AlignedVector4Array(maxParticles);
                Oni.SetParticleUserData(oniSolver, userData.GetIntPtr());

                externalForces = new AlignedVector4Array(maxParticles);
                Oni.SetParticleExternalForces(oniSolver, externalForces.GetIntPtr());

                externalTorques = new AlignedVector4Array(maxParticles);
                Oni.SetParticleExternalTorques(oniSolver, externalTorques.GetIntPtr());

                wind = new AlignedVector4Array(maxParticles);
                Oni.SetParticleWinds(oniSolver, wind.GetIntPtr());

                positionDeltas = new AlignedVector4Array(maxParticles);
                Oni.SetParticlePositionDeltas(oniSolver, positionDeltas.GetIntPtr());

                orientationDeltas = new AlignedQuaternionArray(maxParticles, new Quaternion(0, 0, 0, 0));
                Oni.SetParticleOrientationDeltas(oniSolver, orientationDeltas.GetIntPtr());

                positionConstraintCounts = new AlignedIntArray(maxParticles);
                Oni.SetParticlePositionConstraintCounts(oniSolver, positionConstraintCounts.GetIntPtr());

                orientationConstraintCounts = new AlignedIntArray(maxParticles);
                Oni.SetParticleOrientationConstraintCounts(oniSolver, orientationConstraintCounts.GetIntPtr());

                normals = new AlignedVector4Array(maxParticles);
                Oni.SetParticleNormals(oniSolver, normals.GetIntPtr());

                invInertiaTensors = new AlignedVector4Array(maxParticles);
                Oni.SetParticleInverseInertiaTensors(oniSolver, invInertiaTensors.GetIntPtr());

                // Initialize parameters:
                UpdateParameters();
            }catch (Exception exception) {
                Debug.LogException(exception);
            }finally{
                initialized = true;
            };
        }
Exemple #7
0
        public void Initialize()
        {
            // Tear everything down first:
            Teardown();

            try{
                // Create a default material (TODO: maybe expose this to the user?)
                defaultMaterial           = ScriptableObject.CreateInstance <ObiCollisionMaterial>();
                defaultMaterial.hideFlags = HideFlags.HideAndDontSave;

                defaultFluidMaterial           = ScriptableObject.CreateInstance <ObiEmitterMaterial>();
                defaultFluidMaterial.hideFlags = HideFlags.HideAndDontSave;

                // Create the Oni solver:
                oniSolver = Oni.CreateSolver(maxParticles, 92, interactionRadius);

                actors               = new List <ObiActor>();
                allocatedParticles   = new HashSet <int>();
                activeParticles      = new HashSet <int>();
                materialIndices      = new int[maxParticles];
                fluidMaterialIndices = new int[maxParticles];
                renderablePositions  = new Vector3[maxParticles];
                positions            = new Vector3[maxParticles];
                previousPositions    = new Vector3[maxParticles];
                predictedPositions   = new Vector3[maxParticles];
                velocities           = new Vector3[maxParticles];
                inverseMasses        = new float[maxParticles];
                solidRadii           = new float[maxParticles];
                phases               = new int[maxParticles];

                // Create constraint groups:
                distanceConstraints    = new ObiDistanceConstraintGroup(this);
                bendingConstraints     = new ObiBendingConstraintGroup(this);
                skinConstraints        = new ObiSkinConstraintGroup(this);
                aerodynamicConstraints = new ObiAerodynamicConstraintGroup(this);
                volumeConstraints      = new ObiVolumeConstraintGroup(this);
                tetherConstraints      = new ObiTetherConstraintGroup(this);
                pinConstraints         = new ObiPinConstraintGroup(this);

                // Register constraint groups:
                RegisterConstraintGroup(typeof(ObiDistanceConstraints), distanceConstraints);
                RegisterConstraintGroup(typeof(ObiBendingConstraints), bendingConstraints);
                RegisterConstraintGroup(typeof(ObiSkinConstraints), skinConstraints);
                RegisterConstraintGroup(typeof(ObiAerodynamicConstraints), aerodynamicConstraints);
                RegisterConstraintGroup(typeof(ObiVolumeConstraints), volumeConstraints);
                RegisterConstraintGroup(typeof(ObiTetherConstraints), tetherConstraints);
                RegisterConstraintGroup(typeof(ObiPinConstraints), pinConstraints);

                // Pin all memory so that the GC won't deallocate it before we are done.
                materialIndicesHandle      = Oni.PinMemory(materialIndices);
                fluidMaterialIndicesHandle = Oni.PinMemory(fluidMaterialIndices);
                renderablePositionsHandle  = Oni.PinMemory(renderablePositions);
                positionsHandle            = Oni.PinMemory(positions);
                predictedHandle            = Oni.PinMemory(predictedPositions);
                previousHandle             = Oni.PinMemory(previousPositions);
                velocitiesHandle           = Oni.PinMemory(velocities);
                inverseMassesHandle        = Oni.PinMemory(inverseMasses);
                solidRadiiHandle           = Oni.PinMemory(solidRadii);
                phasesHandle = Oni.PinMemory(phases);

                // Send all pointers to pinned memory to the solver:
                Oni.SetMaterialIndices(oniSolver, materialIndicesHandle.AddrOfPinnedObject());
                Oni.SetFluidMaterialIndices(oniSolver, fluidMaterialIndicesHandle.AddrOfPinnedObject());
                Oni.SetRenderableParticlePositions(oniSolver, renderablePositionsHandle.AddrOfPinnedObject());
                Oni.SetParticlePositions(oniSolver, positionsHandle.AddrOfPinnedObject());
                Oni.SetPredictedParticlePositions(oniSolver, predictedHandle.AddrOfPinnedObject());
                Oni.SetPreviousParticlePositions(oniSolver, previousHandle.AddrOfPinnedObject());
                Oni.SetParticleVelocities(oniSolver, velocitiesHandle.AddrOfPinnedObject());
                Oni.SetParticleInverseMasses(oniSolver, inverseMassesHandle.AddrOfPinnedObject());
                Oni.SetParticleSolidRadii(oniSolver, solidRadiiHandle.AddrOfPinnedObject());
                Oni.SetParticlePhases(oniSolver, phasesHandle.AddrOfPinnedObject());

                // Initialize materials:
                UpdateSolverMaterials();
                UpdateFluidMaterials();

                // Initialize parameters:
                UpdateParameters();

                boundsHandle = Oni.PinMemory(bounds);
            }catch (Exception exception) {
                Debug.LogException(exception);
            }finally{
                initialized = true;
            };
        }
 public void OnEnable()
 {
     material = (ObiEmitterMaterial)target;
 }