Exemple #1
0
    private void LateUpdate()
    {
        if (system == null)
        {
            system = GetComponent <ParticleSystem>();
            system.simulationSpace = ParticleSystemSimulationSpace.World;
        }
        if (particles == null || particles.Length < system.maxParticles)
        {
            particles = new ParticleSystem.Particle[system.maxParticles];
        }
        int particleCount = system.GetParticles(particles);

        if (!m_NoCurl)
        {
            Bounds b = system.GetComponent <ParticleSystemRenderer>().bounds;

            if (b.Intersects(m_CurlVolume.GetComponent <Renderer>().bounds))
            {
                NoisePluginWrapper.UpdateCurlSettings(false, frequency, octaves, lacunarity, persistence);
                UpdateParticleVelocity();
                system.SetParticles(particles, particleCount);
            }
        }
    }
Exemple #2
0
    private void UpdateParticleVelocity()
    {
        Int32  numColliders = m_Spheres.Length;
        IntPtr ptr          = pColliders;

        foreach (Transform t in m_Spheres)
        {
            Volume obstacle = new Volume();

            obstacle.mShape         = Volume.eShape.kSphere;
            obstacle.mExtent        = t.lossyScale * 0.5f;
            obstacle.mWorldToObject = Matrix4x4.TRS(t.position, t.rotation, Vector3.one);

            Marshal.StructureToPtr(obstacle, ptr, false);
            //Debug.Log("Marshal.SizeOf(typeof(Volume) = " + Marshal.SizeOf(typeof(Volume)));
            ptr = (IntPtr)((int)ptr + Marshal.SizeOf(typeof(Volume)));
        }


        for (int i = 0; i < particles.Length; i++)
        {
            Vector3 ppos = particles[i].position;

            Vector3 p_to_c = ppos - m_CurlVolume.transform.position;
            float   r      = m_CurlVolume.transform.lossyScale.x * 0.5f;
            if (p_to_c.sqrMagnitude < r * r)
            {
                Vector3 v = new Vector3();

                if (m_CurlWithoutBoundaries)
                {
                    Profiler.BeginSample("CC-NoBoundaries");
                    Vector3 curl = NoisePluginWrapper.ComputeCurlA(ppos);
                    v = strength * curl;
                    Profiler.EndSample();
                }
                else
                {
                    Profiler.BeginSample("CC-YesBoundaries");
                    if (m_BruteForce)
                    {
                        Vector3 curl = NoisePluginWrapper.ComputeCurlB(ppos, pColliders, numColliders);
                        v = strength * curl;
                    }
                    else
                    {
                        Vector3 curl = NoisePluginWrapper.ComputeCurlC(ppos, pColliders, numColliders);
                        v = strength * curl;
                        //particles[i].velocity = new Vector3(0f, 0.5f, 0f);
                    }
                    Profiler.EndSample();
                }

                particles[i].velocity = new Vector3(0f, 0.04f, 0f) + v;
            }
        }
    }