コード例 #1
0
    public MegaCachePCFrame LoadFrame(string filename)
    {
        StreamReader stream     = File.OpenText(filename);
        string       entireText = stream.ReadToEnd();

        stream.Close();

        char[] splitIdentifier = { ',' };

        //StringReader reader = new StringReader(entireText);
        MegaCacheParticle.offset = 0;
        List <Vector3> pos   = new List <Vector3>();
        List <float>   inten = new List <float>();

        Vector3 p  = Vector3.zero;
        float   it = 0.0f;

        MegaCachePCFrame frame = new MegaCachePCFrame();

        while (true)
        {
            //string ps = reader.ReadLine();
            string ps = MegaCacheParticle.ReadLine(entireText);
            if (ps == null || ps.Length == 0)
            {
                break;
            }

            string[] brokenString = ps.Split(splitIdentifier, 50);

            p.x = float.Parse(brokenString[0]);
            p.y = float.Parse(brokenString[1]);
            p.z = float.Parse(brokenString[2]);

            if (yupimport)
            {
                p = AdjustYUp(p);
            }

            it = float.Parse(brokenString[3]) / 255.0f;
            pos.Add(p * importscale);
            inten.Add(it * sizescale);
        }

        frame.points    = pos.ToArray();
        frame.intensity = inten.ToArray();

        //mod.image.frames.Add(frame);
        return(frame);
    }
コード例 #2
0
    public MegaCachePCXYZFrame LoadFrame(string filename)
    {
        StreamReader stream = File.OpenText(filename);

        if (stream == null)
        {
            return(null);
        }

        string entireText = stream.ReadToEnd();

        stream.Close();

        entireText.Replace('\n', '\r');

        char[] splitIdentifier = { ' ' };

        //StringReader reader = new StringReader(entireText);
        MegaCacheParticle.offset = 0;

        List <Vector3> pos = new List <Vector3>();
        List <Color32> col = new List <Color32>();

        Vector3 p = Vector3.zero;
        Color32 c = new Color32(255, 255, 255, 255);

        MegaCachePCXYZFrame frame = new MegaCachePCXYZFrame();

        int sk = 0;

        while (true)
        {
            //string ps = reader.ReadLine();
            string ps = MegaCacheParticle.ReadLine(entireText);
            if (ps == null || ps.Length == 0)
            {
                break;
            }

            sk--;
            if (sk < 0)
            {
                string[] brokenString = ps.Split(splitIdentifier, 50);

                if (brokenString.Length == 6)
                {
                    p.x = float.Parse(brokenString[0]);
                    p.y = float.Parse(brokenString[1]);
                    p.z = float.Parse(brokenString[2]);

                    if (yupimport)
                    {
                        p = MegaCachePointCloud.AdjustYUp(p);
                    }

                    c.r = byte.Parse(brokenString[3]);
                    c.g = byte.Parse(brokenString[4]);
                    c.b = byte.Parse(brokenString[5]);

                    pos.Add(p * importscale);
                    col.Add(c);
                }
                sk = particleskip;
            }
        }

        frame.points = pos.ToArray();
        frame.color  = col.ToArray();

        //mod.image.frames.Add(frame);
        return(frame);
    }
コード例 #3
0
    void LoadPDAFile(MegaCacheParticle mod, MegaCacheParticleImage img, string filename, bool remove)
    {
        StreamReader stream     = File.OpenText(filename);
        string       entireText = stream.ReadToEnd();

        stream.Close();

        char[] splitIdentifier = { ' ' };

        //StringReader reader = new StringReader(entireText);

        MegaCacheParticle.offset = 0;
        //reader.ReadLine();	// ATTRIBUTES
        MegaCacheParticle.ReadLine(entireText);

        //string[] attribs = reader.ReadLine().Split(splitIdentifier, System.StringSplitOptions.RemoveEmptyEntries);
        string[] attribs = MegaCacheParticle.ReadLine(entireText).Split(splitIdentifier, System.StringSplitOptions.RemoveEmptyEntries);

        //reader.ReadLine();	// TYPES
        MegaCacheParticle.ReadLine(entireText);
        //string[] types = reader.ReadLine().Split(splitIdentifier, System.StringSplitOptions.RemoveEmptyEntries);	// actual values
        string[] types = MegaCacheParticle.ReadLine(entireText).Split(splitIdentifier, System.StringSplitOptions.RemoveEmptyEntries);           // actual values

        int[] attriboff = new int[attribs.Length];

        int off = 0;

        for (int i = 0; i < types.Length; i++)
        {
            attriboff[i] = off;

            switch (types[i])
            {
            case "V":       off += 3;       break;

            case "I":       off += 1;       break;

            case "R":       off += 1;       break;

            default:        Debug.Log("Unknown Type " + types[i]);  off += 1;       break;
            }
        }

        //string[] vals = reader.ReadLine().Split(splitIdentifier, 2);
        string[] vals         = MegaCacheParticle.ReadLine(entireText).Split(splitIdentifier, 2);
        int      numParticles = int.Parse(vals[1]);

        //reader.ReadLine();	// BEGIN DATA
        MegaCacheParticle.ReadLine(entireText);

        MegaCacheParticleHistory ph = new MegaCacheParticleHistory();

        for (int j = 0; j < numParticles; j++)
        {
            Vector3 pos = Vector3.zero;
            Vector3 rot = Vector3.zero;
            Vector3 vel = Vector3.zero;
            //int id = 0;
            float life  = 0.0f;
            float scale = 1.0f;
            float spin  = 0.0f;

            //string ps = reader.ReadLine();
            string   ps     = MegaCacheParticle.ReadLine(entireText);
            string[] values = ps.Split(splitIdentifier, 50);

            for (int a = 0; a < attribs.Length; a++)
            {
                int of = attriboff[a];

                switch (attribs[a])
                {
                case "position":
                    pos.x = float.Parse(values[of]);
                    pos.y = float.Parse(values[of + 1]);
                    pos.z = float.Parse(values[of + 2]);
                    break;

                case "velocity":
                    vel.x = float.Parse(values[of]);
                    vel.y = float.Parse(values[of + 1]);
                    vel.z = float.Parse(values[of + 2]);
                    break;

                case "id":
                    //id = int.Parse(values[of]);
                    break;

                case "lifespanPP":
                    life = (float)double.Parse(values[of]);
                    break;

                //case "age":
                //age = float.Parse(values[of]);
                //break;

                case "radiusPP":
                    scale = float.Parse(values[of]);
                    break;

                default:
                    break;
                }
            }

            if (mod.vel)
            {
                ph.vels.Add(vel * mod.importscale);
            }

            if (mod.rot)
            {
                ph.rots.Add(rot);
            }

            if (mod.scale)
            {
                ph.scale.Add(scale * mod.importscale);
            }

            if (mod.spin)
            {
                ph.spin.Add(spin);
            }

            ph.life = life;
            ph.positions.Add(pos * mod.importscale);
        }

        img.particles.Add(ph);
    }
コード例 #4
0
    public static void LoadFilePlayBack(MegaCacheParticle mod, string filename)
    {
        MegaCacheParticle.offset = 0;
        StreamReader stream     = File.OpenText(filename);
        string       entireText = stream.ReadToEnd();

        stream.Close();

        char[] splitIdentifier = { ' ' };

        //StringReader reader = new StringReader(entireText);

        //int.Parse(reader.ReadLine());	// max
        int.Parse(MegaCacheParticle.ReadLine(entireText));              // max

        //int frames = int.Parse(reader.ReadLine());
        int frames = int.Parse(MegaCacheParticle.ReadLine(entireText));

        MegaCacheParticleImage img;

        if (mod.image == null)
        {
            img = ScriptableObject.CreateInstance <MegaCacheParticleImage>();
        }
        else
        {
            if (EditorUtility.DisplayDialog("Add to or Replace", "Particles already loaded do you want to Replace?", "Yes", "No"))
            {
                img = ScriptableObject.CreateInstance <MegaCacheParticleImage>();
            }
            else
            {
                img = mod.image;
            }
        }

        int skip   = 1;
        int scount = 0;
        int maxp   = 0;

        for (int i = 0; i < frames; i++)
        {
            MegaCacheParticleHistory ph = new MegaCacheParticleHistory();
            img.particles.Add(ph);

            //int p = int.Parse(reader.ReadLine());
            int p = int.Parse(MegaCacheParticle.ReadLine(entireText));

            Vector3 pos = Vector3.zero;
            Vector3 rot = Vector3.zero;
            Vector3 vel = Vector3.zero;

            EditorUtility.DisplayProgressBar("Particle Import", "Importing frame " + i + " off " + frames, ((float)i / (float)frames));

            for (int j = 0; j < p; j++)
            {
                //string ps = reader.ReadLine();
                string ps = MegaCacheParticle.ReadLine(entireText);
                ps = ps.Replace(',', '.');

                string[] brokenString = ps.Split(splitIdentifier, 50);

                //int id = int.Parse(brokenString[0]) - 1;

                if (scount == 0)
                {
                    pos.x = float.Parse(brokenString[1]);
                    if (mod.maxfile)
                    {
                        pos.x = -pos.x;
                    }
                    pos.y = float.Parse(brokenString[2]);
                    pos.z = float.Parse(brokenString[3]);

                    float life = float.Parse(brokenString[12]);                         // / 30.0f;
                    //float age = life - (float.Parse(brokenString[13]));	// / 30.0f;

                    if (mod.vel)
                    {
                        vel.x = float.Parse(brokenString[4]);
                        if (mod.maxfile)
                        {
                            vel.x = -vel.x;
                        }
                        vel.y = float.Parse(brokenString[5]);
                        vel.z = float.Parse(brokenString[6]);

                        ph.vels.Add(vel * mod.importscale);
                    }

                    if (mod.rot)
                    {
                        if (mod.maxfile)
                        {
                            rot.x = float.Parse(brokenString[7]) * Mathf.Rad2Deg;
                            rot.z = float.Parse(brokenString[8]) * Mathf.Rad2Deg;
                            rot.y = float.Parse(brokenString[9]) * Mathf.Rad2Deg;
                        }
                        else
                        {
                            rot.x = float.Parse(brokenString[7]) * Mathf.Rad2Deg;
                            rot.y = float.Parse(brokenString[8]) * Mathf.Rad2Deg;
                            rot.z = float.Parse(brokenString[9]) * Mathf.Rad2Deg;
                        }

                        ph.rots.Add(rot);
                    }

                    if (mod.scale)
                    {
                        float scale = float.Parse(brokenString[11]);
                        ph.scale.Add(scale * mod.importscale);
                    }

                    if (mod.spin)
                    {
                        float spin = float.Parse(brokenString[10]) * Mathf.Rad2Deg;
                        ph.spin.Add(spin);
                    }

                    ph.life = life;
                    //ph.age.Add(age);

                    ph.positions.Add(pos * mod.importscale);
                }

                if (ph.positions.Count > maxp)
                {
                    maxp = ph.positions.Count;
                }
            }

            scount++;
            if (scount == skip)
            {
                scount = 0;
            }
        }

        EditorUtility.ClearProgressBar();

        for (int i = img.particles.Count - 1; i >= 0; i--)
        {
            MegaCacheParticleHistory ph = img.particles[i];

            if (ph.positions.Count < 1)
            {
                img.particles.RemoveAt(i);
                frames--;
            }
        }

        img.frames       = frames;
        img.maxparticles = maxp;
        mod.image        = img;
    }