public override void UpdateParticles(LPParticle[] partdata)
    {
        if (GetComponent<ParticleEmitter>().particleCount < partdata.Length)
        {
            GetComponent<ParticleEmitter>().Emit(partdata.Length - GetComponent<ParticleEmitter>().particleCount);
            particles = GetComponent<ParticleEmitter>().particles;
        }

        for (int i=0; i < particles.Length; i ++)
        {
            if (i > partdata.Length-1)
            {
                particles[i].energy = 0f;
            }
            else
            {
                particles[i].position  = partdata[i].Position;

                float val = 1- ( curve.Evaluate(partdata[i].Weight/divisor));

                if (val < threshold)
                {
                    particles[i].color = Color.Lerp(partdata[i]._Color - SubtractColor,partdata[i]._Color ,val/threshold) ;
                }
                else
                {
                    particles[i].color = Color.Lerp(partdata[i]._Color,partdata[i]._Color + AddColor,(val-threshold)/(1f-threshold));
                }
            }
        }
        GetComponent<ParticleEmitter>().particles = particles;
    }
    /// <summary>
    /// Redraw the particles in the particle system</summary>
    /// <param name="partdata">An array of LPParticle structs, this is available in LPParticle system</param>
    public virtual void UpdateParticles(LPParticle[] partdata)
    {
        if (GetComponent<ParticleEmitter>().particleCount < partdata.Length)
        {
            GetComponent<ParticleEmitter>().Emit(partdata.Length - GetComponent<ParticleEmitter>().particleCount);
            particles = GetComponent<ParticleEmitter>().particles;
        }

        if (debug && particles.Length > 2)
        {
            Debug.Log ( "part 0 "+ particles[0].rotation +" part 1 "+ particles[1].rotation +" part 2 "+ particles[2].rotation);
        }

        for (int i=0; i < particles.Length; i ++)
        {
            if (i > partdata.Length-1)
            {
                particles[i].energy = 0f;
            }
            else
            {
                particles[i].position  = partdata[i].Position;
                particles[i].color = partdata[i]._Color;
            }
        }

        GetComponent<ParticleEmitter>().particles = particles;
    }
    /// <summary>
    /// Redraw the particles in the particle system, but only ones with a certain userdata value</summary>
    /// <param name="partdata">An array of LPParticle structs, this is available in LPParticle system</param>
    public void UpdateParticles(LPParticle[] allpartdata,bool multi)
    {
        List<LPParticle> partsforme =new List<LPParticle>();

        foreach (LPParticle part in allpartdata)
        {
            if (part.UserData == DrawParticlesWithThisUserData)
            {
                partsforme.Add(part);
            }
        }

        UpdateParticles(partsforme.ToArray());
    }
    public override void UpdateParticles(LPParticle[] partdata)
    {
        if (GetComponent<ParticleEmitter>().particleCount < partdata.Length)
        {
            GetComponent<ParticleEmitter>().Emit(partdata.Length - GetComponent<ParticleEmitter>().particleCount);
            particles = GetComponent<ParticleEmitter>().particles;
        }

        for (int i=0; i < particles.Length; i ++)
        {
            if (i > partdata.Length-1)
            {
                particles[i].energy = 0f;
            }
            else
            {
                particles[i].position  = partdata[i].Position;
                particles[i].color = new Color(0.5f+(partdata[i].Velocity.x*0.3f),(partdata[i].Velocity.y*0.3f),0.5f);
            }
        }

        GetComponent<ParticleEmitter>().particles = particles;
    }
    public override void UpdateParticles(LPParticle[] partdata)
    {
        if (GetComponent<ParticleEmitter>().particleCount < partdata.Length)
        {
            GetComponent<ParticleEmitter>().Emit(partdata.Length - GetComponent<ParticleEmitter>().particleCount);
            particles = GetComponent<ParticleEmitter>().particles;
        }

        for (int i=0; i < particles.Length; i ++)
        {
            if (i > partdata.Length-1)
            {
                particles[i].energy = 0f;
            }
            else
            {
                particles[i].position  = partdata[i].Position;
                particles[i].color = Color.Lerp(Foam,Liquid,curve.Evaluate( partdata[i].Weight));
            }
        }

        GetComponent<ParticleEmitter>().particles = particles;
    }
    public override void UpdateParticles(LPParticle[] partdata)
    {
        if (GetComponent<ParticleEmitter>().particleCount < partdata.Length)
        {
            GetComponent<ParticleEmitter>().Emit(partdata.Length - GetComponent<ParticleEmitter>().particleCount);
            particles = GetComponent<ParticleEmitter>().particles;
        }

        for (int i=0; i < particles.Length; i ++)
        {
            if (i > partdata.Length-1)
            {
                particles[i].energy = 0f;
            }
            else
            {
                particles[i].position  = partdata[i].Position;
                float val =  partdata[i].Weight*Wscale;
                particles[i].color = new Color(1f-val,0f, val);
            }
        }

        GetComponent<ParticleEmitter>().particles = particles;
    }
    /// <summary>
    /// Update the chosen particle data from the simulation and store it in this class</summary>
    public void UpdateData()
    {
        IntPtr particlesPointer = LPAPIParticleSystems.GetParticlesDetails(PartSysPtr,GetPositions,GetColors,GetLifeTimes
        ,GetWeights,GetVelocities,GetUserData);

        float[] particlesArray = new float[1];
        Marshal.Copy (particlesPointer,particlesArray,0,1);
        int partsNum = (int)particlesArray[0];

        Particles = new LPParticle[partsNum];
        if (partsNum > 0)
        {
            int datanum  = 0;

            if (GetPositions) datanum +=2;
            if (GetColors) datanum +=4;
            if (GetLifeTimes) datanum +=1;
            if (GetWeights) datanum +=1;
            if (GetVelocities) datanum +=2;
            if (GetUserData) datanum +=1;

            int numberOfCoordinates = (partsNum*datanum)+1;
            float[] pd = new float[numberOfCoordinates];
            Marshal.Copy(particlesPointer, pd, 0, numberOfCoordinates);

            for (int i=0; i < partsNum; i ++)
            {
                Particles[i] = new LPParticle();
            }

            int curpos = 1;

            if (GetPositions)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i].Position = new Vector3(pd[curpos +(i*2)],pd[curpos +(i*2)+1]);
                }
                curpos += partsNum*2;
            }

            if (GetColors)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i]._Color = new Color(pd[curpos +(i*4)]/255f,pd[curpos +(i*4)+1]/255f
                            ,pd[curpos +(i*4)+2]/255f,pd[curpos +(i*4)+3]/255f);
                }
                curpos += partsNum*4;
            }
            if (GetLifeTimes)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i].LifeTime =  pd[curpos +i];
                }
                curpos += partsNum;
            }
            if (GetWeights)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i].Weight =  pd[curpos +i];
                }
                curpos += partsNum;
            }
            if (GetVelocities)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i].Velocity = new Vector3(pd[curpos +(i*2)],pd[curpos +(i*2)+1]);
                }
                curpos += partsNum*2;
            }
            if (GetUserData)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i].UserData =  (int)pd[curpos +i];
                }
            }
        }
    }
    /// <summary>
    /// Returns an array of LPParticle objects with selected information about selected particles</summary>
    /// <param name="indices">An array of ints indicating the indices of the particles you want to get the details of.
    /// Note that the 1st member of the array must be the total number of indices in the array. ie. the lenght of thr array -1</param>
    public LPParticle[] GetSelectedPartDetails(int[] indices,bool position,bool color,bool age,bool weight,bool velocity,bool userdata)
    {
        LPParticle[] ParticleData = new LPParticle[indices[0]];

        IntPtr particlesPointer = LPAPIParticles.GetSelectedParticlesDetails(PartSysPtr,indices,position,color,age,weight,velocity,userdata);

        float[] particlesArray = new float[1];
        Marshal.Copy (particlesPointer,particlesArray,0,1);
        int partsNum = (int)particlesArray[0];

        if (partsNum > 0)
        {
            int datanum  = 0;

            if (position) datanum +=2;
            if (color) datanum +=4;
            if (age) datanum +=1;
            if (weight) datanum +=1;
            if (velocity) datanum +=2;
            if (userdata) datanum +=1;

            int numberOfCoordinates = (partsNum*datanum)+1;
            float[] pd = new float[numberOfCoordinates];
            Marshal.Copy(particlesPointer, pd, 0, numberOfCoordinates);

            for (int i=0; i < partsNum; i ++)
            {
                ParticleData[i] = new LPParticle();
            }

            int curpos = 1;

            if (position)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i].Position = new Vector3(pd[curpos +(i*2)],pd[curpos +(i*2)+1]);
                }
                curpos += partsNum*2;
            }

            if (color)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i]._Color = new Color(pd[curpos +(i*4)]/255f,pd[curpos +(i*4)+1]/255f
                                                    ,pd[curpos +(i*4)+2]/255f,pd[curpos +(i*4)+3]/255f);
                }
                curpos += partsNum*4;
            }
            if (age)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i].LifeTime =  pd[curpos +i];
                }
                curpos += partsNum;
            }
            if (weight)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i].Weight =  pd[curpos +i];
                }
                curpos += partsNum;
            }
            if (velocity)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i].Velocity = new Vector3(pd[curpos +(i*2)],pd[curpos +(i*2)+1]);
                }
                curpos += partsNum*2;
            }
            if (userdata)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i].UserData =  (int)pd[curpos +i];
                }
            }
        }

        return ParticleData;
    }
Beispiel #9
0
    /// <summary>
    /// Returns an array of LPParticle objects with selected information about selected particles</summary>
    /// <param name="indices">An array of ints indicating the indices of the particles you want to get the details of.
    /// Note that the 1st member of the array must be the total number of indices in the array. ie. the lenght of thr array -1</param>
    public LPParticle[] GetSelectedPartDetails(int[] indices, bool position, bool color, bool age, bool weight, bool velocity, bool userdata)
    {
        LPParticle[] ParticleData = new LPParticle[indices[0]];

        IntPtr particlesPointer = LPAPIParticles.GetSelectedParticlesDetails(PartSysPtr, indices, position, color, age, weight, velocity, userdata);

        float[] particlesArray = new float[1];
        Marshal.Copy(particlesPointer, particlesArray, 0, 1);
        int partsNum = (int)particlesArray[0];

        if (partsNum > 0)
        {
            int datanum = 0;

            if (position)
            {
                datanum += 2;
            }
            if (color)
            {
                datanum += 4;
            }
            if (age)
            {
                datanum += 1;
            }
            if (weight)
            {
                datanum += 1;
            }
            if (velocity)
            {
                datanum += 2;
            }
            if (userdata)
            {
                datanum += 1;
            }

            int     numberOfCoordinates = (partsNum * datanum) + 1;
            float[] pd = new float[numberOfCoordinates];
            Marshal.Copy(particlesPointer, pd, 0, numberOfCoordinates);

            for (int i = 0; i < partsNum; i++)
            {
                ParticleData[i] = new LPParticle();
            }

            int curpos = 1;

            if (position)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i].Position = new Vector3(pd[curpos + (i * 2)], pd[curpos + (i * 2) + 1]);
                }
                curpos += partsNum * 2;
            }

            if (color)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i]._Color = new Color(pd[curpos + (i * 4)] / 255f, pd[curpos + (i * 4) + 1] / 255f
                                                       , pd[curpos + (i * 4) + 2] / 255f, pd[curpos + (i * 4) + 3] / 255f);
                }
                curpos += partsNum * 4;
            }
            if (age)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i].LifeTime = pd[curpos + i];
                }
                curpos += partsNum;
            }
            if (weight)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i].Weight = pd[curpos + i];
                }
                curpos += partsNum;
            }
            if (velocity)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i].Velocity = new Vector3(pd[curpos + (i * 2)], pd[curpos + (i * 2) + 1]);
                }
                curpos += partsNum * 2;
            }
            if (userdata)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    ParticleData[i].UserData = (int)pd[curpos + i];
                }
            }
        }

        return(ParticleData);
    }
Beispiel #10
0
    /// <summary>
    /// Update the chosen particle data from the simulation and store it in this class</summary>
    public void UpdateData()
    {
        IntPtr particlesPointer = LPAPIParticleSystems.GetParticlesDetails(PartSysPtr, GetPositions, GetColors, GetLifeTimes
                                                                           , GetWeights, GetVelocities, GetUserData);

        float[] particlesArray = new float[1];
        Marshal.Copy(particlesPointer, particlesArray, 0, 1);
        int partsNum = (int)particlesArray[0];

        Particles = new LPParticle[partsNum];
        if (partsNum > 0)
        {
            int datanum = 0;

            if (GetPositions)
            {
                datanum += 2;
            }
            if (GetColors)
            {
                datanum += 4;
            }
            if (GetLifeTimes)
            {
                datanum += 1;
            }
            if (GetWeights)
            {
                datanum += 1;
            }
            if (GetVelocities)
            {
                datanum += 2;
            }
            if (GetUserData)
            {
                datanum += 1;
            }

            int     numberOfCoordinates = (partsNum * datanum) + 1;
            float[] pd = new float[numberOfCoordinates];
            Marshal.Copy(particlesPointer, pd, 0, numberOfCoordinates);

            for (int i = 0; i < partsNum; i++)
            {
                Particles[i] = new LPParticle();
            }

            int curpos = 1;

            if (GetPositions)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i].Position = new Vector3(pd[curpos + (i * 2)], pd[curpos + (i * 2) + 1]);
                }
                curpos += partsNum * 2;
            }

            if (GetColors)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i]._Color = new Color(pd[curpos + (i * 4)] / 255f, pd[curpos + (i * 4) + 1] / 255f
                                                    , pd[curpos + (i * 4) + 2] / 255f, pd[curpos + (i * 4) + 3] / 255f);
                }
                curpos += partsNum * 4;
            }
            if (GetLifeTimes)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i].LifeTime = pd[curpos + i];
                }
                curpos += partsNum;
            }
            if (GetWeights)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i].Weight = pd[curpos + i];
                }
                curpos += partsNum;
            }
            if (GetVelocities)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i].Velocity = new Vector3(pd[curpos + (i * 2)], pd[curpos + (i * 2) + 1]);
                }
                curpos += partsNum * 2;
            }
            if (GetUserData)
            {
                for (int i = 0; i < partsNum; i++)
                {
                    Particles[i].UserData = (int)pd[curpos + i];
                }
            }
        }
    }