void Solver_OnFluidUpdated(object sender, Obi.ObiSolver.ObiFluidEventArgs e)
 {
     for (int i = 0; i < e.indices.Length; ++i)
     {
         //Debug.DrawRay(solver.renderablePositions[e.indices[i]],e.vorticities[e.indices[i]]*0.05f,Color.red);
         Debug.DrawRay(solver.renderablePositions[e.indices[i]], -e.normals[e.indices[i]] * 0.5f, Color.blue);
     }
 }
        void Solver_OnFluidUpdated(object sender, ObiSolver.ObiFluidEventArgs e)
        {
            if (!isActiveAndEnabled)
            {
                return;
            }

            for (int i = 0; i < emitter.particleIndices.Length; ++i)
            {
                int k = emitter.particleIndices[i];

                float v = e.vorticities[k].z;

                if (v > 0)
                {
                    emitter.colors[i] = Color.Lerp(Color.white, Color.red, v);
                }
                else
                {
                    emitter.colors[i] = Color.Lerp(Color.white, Color.blue, -v);
                }
            }
        }
Esempio n. 3
0
        void Solver_OnFluidUpdated(object sender, ObiSolver.ObiFluidEventArgs e)
        {
            if (!isActiveAndEnabled || advector == null || advector.solver == null)
            {
                return;
            }

            if (emitLocations == null)
            {
                emitLocations = new List <Vector4>(emitter.particleIndices.Length);
            }

            accumTime += Time.deltaTime;

            // calculate emission budget for this frame:
            int emitAmount = Mathf.FloorToInt(emissionRate * accumTime);

            // remove used emission time from accumulator:
            accumTime -= emitAmount / emissionRate;

            if (emitAmount == 0)
            {
                return;
            }

            ParticleSystem.EmitParams param = new ParticleSystem.EmitParams();

            emitLocations.Clear();

            // loop trough particles and decide where we should emit foam from:
            for (int i = 0; i < emitter.particleIndices.Length; ++i)
            {
                int k = emitter.particleIndices[i];

                float vorticity = e.vorticities[k].magnitude;

                if (vorticity > vorticityThreshold && e.densities[k] < densityThreshold)
                {
                    emitLocations.Add(((ObiSolver)sender).renderablePositions[k]);
                }
            }

            // calculate how many particles we must skip each iteration to meet the budget:
            int step = Mathf.Max(1, Mathf.FloorToInt(emitLocations.Count / (float)emitAmount));

            // emit particles:
            if (advector.solver.parameters.mode == Oni.SolverParameters.Mode.Mode3D)
            {
                for (int i = UnityEngine.Random.Range(0, step - 1); i < emitLocations.Count; i += step)
                {
                    param.position = emitLocations[i] + (Vector4)UnityEngine.Random.insideUnitSphere * randomness;
                    advector.Particles.Emit(param, 1);
                }
            }
            else
            {
                for (int i = UnityEngine.Random.Range(0, step - 1); i < emitLocations.Count; i += step)
                {
                    param.position = emitLocations[i] + (Vector4)UnityEngine.Random.insideUnitCircle * randomness;
                    advector.Particles.Emit(param, 1);
                }
            }
        }