public bool LoadFromBytes(byte[] bytes) { string dat = ""; try { dat = Encoding.UTF8.GetString(bytes); } catch { return(false); } JSONNode data = JSON.Parse(dat); if (!data.IsArray) { return(false); } meshes = new List <Meshobject>(); foreach (var jn in data) { if (!jn.Value.IsObject) { return(false); } Meshobject mesh = new Meshobject((JSONObject)jn.Value); meshes.Add(mesh); } return(true); }
public MultimeshObject PhotonsToMesh(List <ScatterPhoton> photons) { MultimeshObject ret = new MultimeshObject(); List <Vector3> verts = new List <Vector3>(); List <Vector2> uvs = new List <Vector2>(); //List<Color> clrs = new List<Color>(); List <int> indc = new List <int>(); // Debug.LogFormat("Photons started: {0}",photons.Count); int cntph = 0; foreach (ScatterPhoton ph in photons) { int cnt = 0; while (!ph.decayed) { verts.Add(ph.position - initialPos); // float shft = (en.time - mintime) / td; uvs.Add(new Vector2(ph.timeOffset, 0)); //65530 // clrs.Add(Color.Lerp(Color.red, Color.green, shft)); if (cnt == 0 && ph.decayed) { verts.RemoveAt(verts.Count - 1); uvs.RemoveAt(uvs.Count - 1); } if (cnt > 0) { indc.Add(verts.Count - 2); indc.Add(verts.Count - 1); } if (verts.Count > 65530) { break; } // Debug.LogFormat("Phdir: {0}", ph.direction); ph.Propagate(IcecubeDust.AbsorbtionLength(ph.position, ph.direction), IcecubeDust.ScatterLength(ph.position)); cnt += 1; } cntph++; if (cntph % 100 == 0) { // Debug.LogFormat("Photons now: {0}", cntph); } if (verts.Count > 65530) { Meshobject newM = new Meshobject(verts.ToArray(), uvs.ToArray(), indc.ToArray()); ret.meshes.Add(newM); verts.Clear(); uvs.Clear(); indc.Clear(); } } if (indc.Count > 1) { Meshobject newM = new Meshobject(verts.ToArray(), uvs.ToArray(), indc.ToArray()); ret.meshes.Add(newM); } //Debug.Log("Returning from sim"); return(ret); }
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"); }