Beispiel #1
0
        /**
         * Generates the particle based physical representation of the emitter. This is the initialization method for the rope object
         * and should not be called directly once the object has been created.
         */
        protected override IEnumerator Initialize()
        {
            initialized  = false;
            initializing = true;

            RemoveFromSolver(null);

            active         = new bool[numParticles];
            life           = new float[numParticles];
            positions      = new Vector3[numParticles];
            velocities     = new Vector3[numParticles];
            invMasses      = new float[numParticles];
            principalRadii = new Vector3[numParticles];
            phases         = new int[numParticles];
            colors         = new Color[numParticles];

            orientations        = new Quaternion[numParticles];
            angularVelocities   = new Vector3[numParticles];
            invRotationalMasses = new float[numParticles];
            restOrientations    = new Quaternion[numParticles];

            activeParticleCount = 0;

            float restDistance = (emitterMaterial != null) ? emitterMaterial.GetParticleSize(solver.parameters.mode) : 0.1f;
            float pmass        = (emitterMaterial != null) ? emitterMaterial.GetParticleMass(solver.parameters.mode) : 0.1f;

            for (int i = 0; i < numParticles; i++)
            {
                active[i] = false;
                life[i]   = 0;
                invRotationalMasses[i] = invMasses[i] = 1.0f / pmass;
                positions[i]           = Vector3.zero;

                orientations[i] = restOrientations[i] = Quaternion.identity;

                if (emitterMaterial != null && !(emitterMaterial is ObiEmitterMaterialFluid))
                {
                    float randomRadius = UnityEngine.Random.Range(0, restDistance / 100.0f * (emitterMaterial as ObiEmitterMaterialGranular).randomness);
                    principalRadii[i] = Vector3.one * Mathf.Max(0.001f + restDistance * 0.5f - randomRadius);
                }
                else
                {
                    principalRadii[i] = Vector3.one * restDistance * 0.5f;
                }

                colors[i] = Color.white;

                phases[i] = Oni.MakePhase(fluidPhase, (selfCollisions?Oni.ParticlePhase.SelfCollide:0) |
                                          ((emitterMaterial != null && (emitterMaterial is ObiEmitterMaterialFluid))?Oni.ParticlePhase.Fluid:0));
            }

            initializing = false;
            initialized  = true;

            yield return(null);
        }
Beispiel #2
0
        /**
         * Sets all particle masses in accordance to the fluid's rest density.
         */
        public void CalculateParticleMass()
        {
            float pmass = (emitterMaterial != null) ? emitterMaterial.GetParticleMass(solver.parameters.mode) : 0.1f;

            for (int i = 0; i < invMasses.Length; i++)
            {
                invMasses[i] = 1.0f / pmass;
            }

            this.PushDataToSolver(ParticleData.INV_MASSES);
        }
        public override void OnInspectorGUI()
        {
            serializedObject.UpdateIfRequiredOrScript();

            Editor.DrawPropertiesExcluding(serializedObject, "m_Script");

            EditorGUILayout.HelpBox("Particle mass (kg):\n" +
                                    "2D:" + material.GetParticleMass(Oni.SolverParameters.Mode.Mode2D) + "\n" +
                                    "3D;" + material.GetParticleMass(Oni.SolverParameters.Mode.Mode3D) + "\n\n" +
                                    "Particle size:\n" +
                                    "2D:" + material.GetParticleSize(Oni.SolverParameters.Mode.Mode2D) + "\n" +
                                    "3D;" + material.GetParticleSize(Oni.SolverParameters.Mode.Mode3D), MessageType.Info);

            // Apply changes to the serializedProperty
            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();

                material.CommitChanges();
            }
        }