コード例 #1
0
    public int CalcMemory()
    {
        int mem = 0;

        int skip = 1;

        if (optimized)
        {
            for (int i = 0; i < optparticles.Count; i++)
            {
                MegaCacheParticleHistoryOpt ph = optparticles[i];

                mem += ph.pos.Length;
                mem += ph.vels.Length;
                mem += ph.rots.Length;
                mem += ph.scale.Length;
                mem += ph.spin.Length;
            }
        }
        else
        {
            for (int i = 0; i < particles.Count; i++)
            {
                MegaCacheParticleHistory ph = particles[i];

                mem += ph.positions.Count * 12;
                mem += ph.vels.Count * 12;
                mem += ph.rots.Count * 12;
                mem += ph.scale.Count * 4;
                mem += ph.spin.Count * 4;
            }
        }

        return(mem / skip);
    }
コード例 #2
0
    void OnDrawGizmosSelected()
    {
        if (showpaths && image)
        {
            Gizmos.color  = Color.red;
            Gizmos.matrix = transform.localToWorldMatrix;
            Color col = showcolor;

            float len = image.frames / fps;

            float t = 0.0f;

            if (time < 0.0f)
            {
                time = 0.0f;
            }

            switch (loopmode)
            {
            case MegaCacheRepeatMode.Loop: t = Mathf.Repeat(time, len); break;

            case MegaCacheRepeatMode.Clamp: t = Mathf.Clamp(time, 0.0f, len); break;

            case MegaCacheRepeatMode.PingPong: t = Mathf.PingPong(time, len); break;
            }

            float alpha = t / len;

            float fn = alpha * (image.frames - 1);
            framenum = (int)fn;

            if (image.optimized)
            {
                MegaCacheParticleHistoryOpt ph = image.optparticles[framenum];

                for (int j = 0; j < ph.count; j += showparticlestep)
                {
                    Vector3 lpos = DecodeV3(ph.pos, j * 6, ph.posmin, ph.possize) * scaleall * emitscale;
                    float   scl  = DecodeFloat(ph.scale, j, ph.scalemin, ph.scalesize);

                    Gizmos.color = col;
                    Gizmos.DrawSphere(lpos, scl * scaleall * sizescale);
                }
            }
            else
            {
                MegaCacheParticleHistory ph = image.particles[framenum];

                for (int j = 0; j < ph.positions.Count; j += showparticlestep)
                {
                    Vector3 lpos = ph.positions[j] * scaleall * emitscale;

                    Gizmos.color = col;
                    Gizmos.DrawSphere(lpos, ph.scale[j] * scaleall * sizescale);
                }
            }
            Gizmos.matrix = Matrix4x4.identity;
        }
    }
コード例 #3
0
    void UpdateParticlesOpt(float dt)
    {
        if (dt > 0.01f)
        {
            dt = 0.01f;
        }

        if (particle && image && image.optparticles.Count > 0)
        {
            //int count = particle.particleCount;
            particles = particle.particles;

            time += Time.deltaTime * speed;

            float len = image.frames / fps;

            float t = 0.0f;

            switch (loopmode)
            {
            case MegaCacheRepeatMode.Loop: t = Mathf.Repeat(time, len); break;

            case MegaCacheRepeatMode.Clamp: t = Mathf.Clamp(time, 0.0f, len); break;

            case MegaCacheRepeatMode.PingPong: t = Mathf.PingPong(time, len); break;
            }

            float alpha = t / len;

            float fn = alpha * image.frames;
            framenum = (int)fn;

            int ix = 0;

            Matrix4x4 tm = transform.localToWorldMatrix;

            MegaCacheParticleHistoryOpt ph = image.optparticles[framenum];

            for (int i = 0; i < ph.count; i++)
            {
                Vector3 pos = DecodeV3(ph.pos, i * 6, ph.posmin, ph.possize);
                float   scl = DecodeFloat(ph.scale, i, ph.scalemin, ph.scalesize);
                Vector3 rot = DecodeV3b(ph.rots, i * 3, ph.rotmin, ph.rotsize);

                particles[ix].position    = tm.MultiplyPoint3x4(pos);
                particles[ix].energy      = alpha * len;
                particles[ix].startEnergy = len;
                particles[ix].size        = scl;
                particles[ix].rotation    = rot[(int)axis];                     // * Mathf.Rad2Deg;
                ix++;
            }

            particle.particles = particles;
        }
    }
コード例 #4
0
    // Should be in another class
    void UpdateParticlesOpt(float dt)
    {
        if (dt > 0.01f)
        {
            dt = 0.01f;
        }

        if (particle && image && image.optparticles.Count > 0)
        {
            InitStates();

            if (useemit)
            {
                emittime += dt * emitrate;

                int ecount = (int)emittime;
                if (ecount > 0)
                {
                    particle.Emit(ecount);
                    emittime -= 1.0f;
                }
            }

            int count = particle.particleCount;
            particles = particle.particles;

            int ix = 0;

            Matrix4x4 tm = transform.localToWorldMatrix;

            removeparticles.Clear();

            float pscl = scaleall * sizescale * particle.minSize;

            for (int i = 0; i < activeparticles.Count; i++)
            {
                MegaCacheParticleHistoryOpt ph = image.optparticles[activeparticles[i]];
                MegaCacheParticleState      ps = states[activeparticles[i]];

                ps.time += Time.deltaTime * speed * ps.locspeed;

                if (ps.time >= ph.life || ps.time < 0.0f)
                {
                    removeparticles.Add(i);
                }
                else
                {
                    float alpha = ps.time / ph.life;

                    float fn = alpha * (ph.count - 1);
                    framenum = (int)fn;
                    float subalpha = fn - framenum;

                    Vector3 pos  = DecodeV3(ph.pos, framenum * 6, ph.posmin, ph.possize);
                    Vector3 pos1 = DecodeV3(ph.pos, (framenum + 1) * 6, ph.posmin, ph.possize);
                    float   scl  = DecodeFloat(ph.scale, framenum, ph.scalemin, ph.scalesize);
                    float   scl1 = DecodeFloat(ph.scale, framenum + 1, ph.scalemin, ph.scalesize);
                    Vector3 rot  = DecodeV3b(ph.rots, framenum * 3, ph.rotmin, ph.rotsize);
                    Vector3 rot1 = DecodeV3b(ph.rots, (framenum + 1) * 3, ph.rotmin, ph.rotsize);

                    Vector3 lpos = Vector3.Lerp(pos, pos1, subalpha) * scaleall * ps.locscale;

                    particles[ix].position    = ps.tm.MultiplyPoint3x4(lpos);
                    particles[ix].energy      = ph.life - ps.time;
                    particles[ix].startEnergy = ph.life;
                    particles[ix].size        = Mathf.Lerp(scl, scl1, subalpha) * pscl * ps.locscale;
                    //particles[ix].rotation = Mathf.Lerp(rot[(int)axis], rot1[(int)axis], subalpha) * Mathf.Rad2Deg;
                    particles[ix].rotation = Mathf.Lerp(rot[(int)axis], rot1[(int)axis], subalpha);

                    ix++;
                }
            }

            for (int i = removeparticles.Count - 1; i >= 0; i--)
            {
                activeparticles.RemoveAt(removeparticles[i]);
            }

            if (activeparticles.Count < image.optparticles.Count)
            {
                if (count > activeparticles.Count)
                {
                    int emit = count - activeparticles.Count;

                    for (int i = 0; i < emit; i++)
                    {
                        MegaCacheParticleHistoryOpt ph = image.optparticles[particleindex];
                        MegaCacheParticleState      ps = states[particleindex];

                        int px = 0;
                        if (emitspeed * speed >= 0.0f)
                        {
                            ps.time = 0.0f;
                            particles[ix].energy = ph.life;
                        }
                        else
                        {
                            ps.time = ph.life;
                            particles[ix].energy = 0.0f;
                            px = ph.pos.Length - 1;
                        }

                        ps.locscale = emitscale;
                        ps.locspeed = emitspeed;
                        ps.tm       = tm;

                        activeparticles.Add(particleindex++);

                        Vector3 pos = DecodeV3(ph.pos, px * 6, ph.posmin, ph.possize);
                        Vector3 rot = DecodeV3b(ph.rots, px * 3, ph.rotmin, ph.rotsize);
                        particles[ix].position    = tm.MultiplyPoint3x4(pos * scaleall);
                        particles[ix].startEnergy = ph.life;
                        //particles[ix].rotation = rot[(int)axis] * Mathf.Rad2Deg;
                        particles[ix].rotation = rot[(int)axis];                                // * Mathf.Rad2Deg;

                        particles[ix].size = 0.0f;

                        if (particleindex >= image.optparticles.Count)
                        {
                            particleindex = 0;
                        }

                        ix++;
                    }
                }
            }
            else
            {
                //Debug.Log("No available particles");
            }

            particle.particles = particles;
        }
    }
コード例 #5
0
    void OnDrawGizmosSelected()
    {
        int sfn = framenum;

        if (showpaths && image)
        {
            Gizmos.color  = Color.red;
            Gizmos.matrix = transform.localToWorldMatrix;

            if (image.optimized)
            {
                for (int i = showstart; i < image.optparticles.Count; i += showparticlestep)
                {
                    Vector3 lastpos = Vector3.zero;

                    Color col = showcolor;

                    MegaCacheParticleHistoryOpt ph = image.optparticles[i];

                    for (int j = 0; j < ph.count; j += showposstep)
                    {
                        float alpha = (float)j / (float)ph.count;

                        float fn = alpha * (ph.count - 1);
                        framenum = (int)fn;

                        Vector3 lpos = DecodeV3(ph.pos, framenum * 6, ph.posmin, ph.possize) * scaleall * emitscale;

                        if (j > 0)
                        {
                            col.a        = 1.0f - alpha;
                            Gizmos.color = col;
                            Gizmos.DrawLine(lastpos, lpos);
                        }

                        lastpos = lpos;
                    }
                }
            }
            else
            {
                for (int i = showstart; i < image.particles.Count; i += showparticlestep)
                {
                    Vector3 lastpos = Vector3.zero;

                    Color col = showcolor;

                    MegaCacheParticleHistory ph = image.particles[i];

                    for (int j = 0; j < ph.positions.Count; j += showposstep)
                    {
                        float alpha = (float)j / (float)ph.positions.Count;

                        float fn = alpha * (ph.positions.Count - 1);
                        framenum = (int)fn;

                        Vector3 lpos = ph.positions[framenum] * scaleall * emitscale;

                        if (j > 0)
                        {
                            col.a        = 1.0f - alpha;
                            Gizmos.color = col;
                            Gizmos.DrawLine(lastpos, lpos);
                        }

                        lastpos = lpos;
                    }
                }
            }
            Gizmos.matrix = Matrix4x4.identity;
        }

        framenum = sfn;
    }
コード例 #6
0
    // Should be in another class
    void UpdateParticlesOpt(float dt)
    {
        if (dt > 0.01f)
        {
            dt = 0.01f;
        }

        if (particle && image && image.optparticles.Count > 0)
        {
            particle.GetParticles(particles);

            time += Time.deltaTime * speed;

            float len = image.frames / fps;

            float t = 0.0f;

            switch (loopmode)
            {
            case MegaCacheRepeatMode.Loop: t = Mathf.Repeat(time, len); break;

            case MegaCacheRepeatMode.Clamp: t = Mathf.Clamp(time, 0.0f, len); break;

            case MegaCacheRepeatMode.PingPong: t = Mathf.PingPong(time, len); break;
            }

            float alpha = t / len;

            float fn = alpha * image.frames;
            framenum = (int)fn;

            int ix = 0;

            Matrix4x4 tm = transform.localToWorldMatrix;

            MegaCacheParticleHistoryOpt ph = image.optparticles[framenum];

            for (int i = 0; i < ph.count; i++)
            {
                Vector3 pos = DecodeV3(ph.pos, i * 6, ph.posmin, ph.possize);
                float   scl = DecodeFloat(ph.scale, i, ph.scalemin, ph.scalesize);
                Vector3 rot = DecodeV3b(ph.rots, i * 3, ph.rotmin, ph.rotsize);

                particles[ix].position = tm.MultiplyPoint3x4(pos);
#if UNITY_2017 || UNITY_2018
                particles[ix].remainingLifetime = alpha * len;
#else
                particles[ix].lifetime = alpha * len;
#endif
                particles[ix].startLifetime = len;
#if UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_2017 || UNITY_2018
                particles[ix].startSize = scl;
#else
                particles[ix].size = scl;
#endif
#if UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_2017 || UNITY_2018
                particles[ix].rotation3D = rot;
#else
                particles[ix].rotation = rot[(int)axis];                        // * Mathf.Rad2Deg;
#endif

                ix++;
            }

            particle.SetParticles(particles, ix);
        }
    }
コード例 #7
0
    public void ReadData(BinaryReader br)
    {
        int version = br.ReadInt32();

        if (version < 2)
        {
            int pcount = br.ReadInt32();

            bool optimize = br.ReadBoolean();
            bool hasrot   = br.ReadBoolean();
            bool hasvel   = br.ReadBoolean();
            bool hasscale = br.ReadBoolean();
            bool hasspin  = br.ReadBoolean();

            if (version == 1)
            {
                frames       = br.ReadInt32();
                maxparticles = br.ReadInt32();
            }

            optimized = optimize;

            if (optimize)
            {
                //Debug.Log("v " + version);
                //Debug.Log("frames " + frames);
                //Debug.Log("max " + maxparticles);
                for (int i = 0; i < pcount; i++)
                {
                    int count = br.ReadInt32();

                    MegaCacheParticleHistoryOpt ph = new MegaCacheParticleHistoryOpt();

                    ph.count = count;
                    ph.life  = br.ReadSingle();
                    ph.id    = br.ReadInt32();

                    // load pos
                    ph.posmin.x = br.ReadSingle();
                    ph.posmin.y = br.ReadSingle();
                    ph.posmin.z = br.ReadSingle();

                    ph.possize.x = br.ReadSingle();
                    ph.possize.y = br.ReadSingle();
                    ph.possize.z = br.ReadSingle();

                    ph.possize *= 1.0f / 65535.0f;

                    ph.pos = br.ReadBytes(count * 6);

                    if (hasvel)
                    {
                        ph.velmin.x = br.ReadSingle();
                        ph.velmin.y = br.ReadSingle();
                        ph.velmin.z = br.ReadSingle();

                        ph.velsize.x = br.ReadSingle();
                        ph.velsize.y = br.ReadSingle();
                        ph.velsize.z = br.ReadSingle();

                        ph.vels = br.ReadBytes(count * 3);
                    }

                    if (hasscale)
                    {
                        ph.scalemin  = br.ReadSingle();
                        ph.scalesize = br.ReadSingle();

                        ph.scalesize *= 1.0f / 255.0f;

                        ph.scale = br.ReadBytes(count);
                    }

                    if (hasrot)
                    {
                        ph.rotmin.x = br.ReadSingle();
                        ph.rotmin.y = br.ReadSingle();
                        ph.rotmin.z = br.ReadSingle();

                        ph.rotsize.x = br.ReadSingle();
                        ph.rotsize.y = br.ReadSingle();
                        ph.rotsize.z = br.ReadSingle();

                        ph.rotsize *= 1.0f / 255.0f;

                        ph.rots = br.ReadBytes(count * 3);
                    }

                    if (hasspin)
                    {
                        ph.spinmin  = br.ReadSingle();
                        ph.spinsize = br.ReadSingle();

                        ph.spinsize *= 1.0f / 255.0f;

                        ph.spin = br.ReadBytes(count);
                    }

                    optparticles.Add(ph);
                }
            }
            else
            {
                for (int i = 0; i < pcount; i++)
                {
                    int count = br.ReadInt32();

                    MegaCacheParticleHistory ph = new MegaCacheParticleHistory();

                    Vector3 p3 = Vector3.zero;

                    // load pos
                    for (int v = 0; v < count; v++)
                    {
                        p3.x = br.ReadSingle();
                        p3.y = br.ReadSingle();
                        p3.z = br.ReadSingle();

                        ph.positions.Add(p3);
                    }

                    if (hasvel)
                    {
                        for (int v = 0; v < count; v++)
                        {
                            p3.x = br.ReadSingle();
                            p3.y = br.ReadSingle();
                            p3.z = br.ReadSingle();

                            ph.vels.Add(p3);
                        }
                    }

                    if (hasscale)
                    {
                        for (int v = 0; v < count; v++)
                        {
                            ph.scale.Add(br.ReadSingle());
                        }
                    }

                    if (hasrot)
                    {
                        for (int v = 0; v < count; v++)
                        {
                            p3.x = br.ReadSingle();
                            p3.y = br.ReadSingle();
                            p3.z = br.ReadSingle();

                            ph.rots.Add(p3);
                        }
                    }

                    if (hasspin)
                    {
                        for (int v = 0; v < count; v++)
                        {
                            ph.spin.Add(br.ReadSingle());
                        }
                    }

                    particles.Add(ph);
                }
            }
        }
    }