Ejemplo n.º 1
0
    public void MaybeRecreateProperMesh(int run, int ev, Vector3 initialPos, Vector3 heading, float duration, float emrate, float itime)
    {
        if (run == runId && ev == evId)
        {
            //same event..
            return;
        }
        foreach (extraData csc in cascades)
        {
            if (run == csc.runId && ev == csc.evId)
            {
                readCsv(csc);
                CascadeData[] cdat      = new CascadeData[bursts.Length];
                float         maxEnergy = 0;
                float         minnz     = 0;
                for (int i = 0; i < bursts.Length; i++)
                {
                    if (bursts[i].energy > maxEnergy)
                    {
                        maxEnergy = (float)bursts[i].energy;
                    }
                    if (minnz == 0 || (bursts[i].energy > 0 && minnz < bursts[i].energy))
                    {
                        minnz = (float)bursts[i].energy;
                    }
                }
                if (minnz * 5000 / maxEnergy < 1000)
                {
                    maxEnergy = minnz * 1000;
                }
                for (int i = 0; i < bursts.Length; i++)
                {
                    int en = (int)(bursts[i].energy * 5000 / maxEnergy);
                    if (en > 5000)
                    {
                        en = 5000;
                    }
                    cdat[i]          = new CascadeData(heading, 1.0f, (int)en, (float)bursts[i].time - itime);
                    cdat[i].location = bursts[i].coords;
                    Debug.Log("ENERGY");
                    Debug.Log(maxEnergy);
                    Debug.Log(en);
                    Debug.Log((int)bursts[i].energy);
                    //cdat[i].in = bursts[i].coords;
                }
                //new CascadeData(heading, 1.0f, 9500);


                MuonTrack tr = new MuonTrack(initialPos, heading, duration, 0.299792458f, 6000 / maxEnergy, cdat);//emrate
                data = tr.Simulate();
                data.SaveToFile(Application.persistentDataPath + "/" + "trail.gz");
                data.LoadFromFile(Application.persistentDataPath + "/" + "trail.gz");
                SpawnChildren();
                runId = run;
                evId  = ev;
                break;
            }
        }
    }
Ejemplo n.º 2
0
    void Start()
    {
        MultimeshObject output = new MultimeshObject();

        output.meshes = new List <Meshobject>();
        //string meshPath="Assets/csmesh800/cmesh800_";
        string fs = csvFile.text;

        string[]       fLines  = Regex.Split(fs, "\n|\r|\r\n");
        int            cnt     = 0;
        int            curMesh = -1;
        int            curId   = -1;
        List <Vector3> verts   = new List <Vector3>();
        List <Vector2> uvs     = new List <Vector2>();
        List <Color>   clrs    = new List <Color>();
        List <int>     indc    = new List <int>();
        Mesh           curM    = null;
        Vector3        avg     = Vector3.zero;
        float          mintime = -1;
        float          maxtime = -1;

        foreach (string line in fLines)
        {
            if (line.Length < 2)
            {
                continue;
            }
            PosEntry en = entryFromLine(line);
            lst.Add(en);
            cnt++;
            avg += en.pos;
            if (maxtime < 0 || en.time > maxtime)
            {
                maxtime = en.time;
            }
            if (mintime < 0 || en.time < mintime)
            {
                mintime = en.time;
            }

            /* if(curMesh!=en.meshnum)
             * {
             * if(curM!=null)
             * {
             *  AssetDatabase.CreateAsset(curM, "Assets/csmesh/cmesh_" + curMesh.ToString() + ".asset");
             * }
             * }
             * if(curMesh==-1) curMesh=en.meshnum;
             * if(curId==-1) curId=en.id;
             *
             *
             * cnt++;
             * if(cnt>100)
             * break;*/
        }
        Debug.Log(mintime);
        Debug.Log(maxtime);
        Debug.Log(avg / cnt);
        avg /= (float)cnt;
        cnt  = 0;
        float td = maxtime - mintime;

        foreach (PosEntry en in lst)
        {
            if (curMesh != en.meshnum)
            {
                Meshobject msh = new Meshobject(verts.ToArray(), uvs.ToArray(), indc.ToArray());
                output.meshes.Add(msh);
                //msh.indices = indc.ToArray();
                // msh.verts = verts.ToArray();
                // msh.uvs = uvs.ToArray();
                //if(curM!=null)
                // {
                // curM.vertices=verts.ToArray();
                // curM.uv=uvs.ToArray();
                // curM.colors=clrs.ToArray();
                // curM.SetIndices(indc.ToArray(),MeshTopology.Lines,0);
                //AssetDatabase.CreateAsset(curM, meshPath + curMesh.ToString() + ".asset");
                //}
                verts.Clear();
                uvs.Clear();
                clrs.Clear();
                indc.Clear();
                curMesh = en.meshnum;
                curM    = new Mesh();
                cnt     = 0;
            }
            if (curId == en.id)
            {
                indc.Add(cnt - 1);
                indc.Add(cnt);
            }
            else
            {
                curId = en.id;
            }
            verts.Add(en.pos + offset);// -avg);
            float shft = (en.time - mintime);
            if (System.Array.IndexOf(jet, en.id) > -1)
            {
                //ccolor.b = 0.8f;
                uvs.Add(new Vector2(shft, 1));
            }
            else
            {
                uvs.Add(new Vector2(shft, 0));
            }
            clrs.Add(Color.Lerp(Color.red, Color.green, shft));

            cnt++;
        }
        if (verts.Count >= 2 && indc.Count > 0)
        {
            Meshobject msh = new Meshobject(verts.ToArray(), uvs.ToArray(), indc.ToArray());
            output.meshes.Add(msh);
        }
        //if(curM!=null)
        //        {
        //       curM.vertices=verts.ToArray();
        //       curM.uv=uvs.ToArray();
        //       curM.colors=clrs.ToArray();
        //      curM.SetIndices(indc.ToArray(),MeshTopology.Lines,0);
        //			AssetDatabase.CreateAsset(curM, meshPath + curMesh.ToString() + ".asset");
        //            }
        //
        output.SaveToFile(Application.persistentDataPath + "/" + "csvparsed.gz");
    }