public void LoadPC(MegaCachePointCloudXYZ mod, string filename, int first, int last, int step) { if (mod.image == null) { mod.image = ScriptableObject.CreateInstance <MegaCachePCXYZImage>(); } if (mod.image && mod.image.frames.Count > 0) { if (!EditorUtility.DisplayDialog("Add to or Replace", "Add new Frames to existing list, or Replace All", "Add", "Replace")) { mod.image.frames.Clear(); mod.image.maxpoints = 0; } } if (step < 1) { step = 1; } for (int i = first; i <= last; i += step) { float a = (float)(i + 1 - first) / (last - first); if (!EditorUtility.DisplayCancelableProgressBar("Loading Clouds", "Frame " + i, a)) { MegaCachePCXYZFrame fr = mod.LoadFrame(filename, i); if (fr != null) { mod.image.frames.Add(fr); if (fr.points.Length > mod.image.maxpoints) { mod.image.maxpoints = fr.points.Length; } } else { EditorUtility.DisplayDialog("Can't Load File", "Could not load frame " + i + " of sequence! Import Stopped.", "OK"); break; } } else { break; } } EditorUtility.ClearProgressBar(); }
public MegaCachePCXYZFrame LoadFrame(string filename, int frame) { MegaCachePCXYZFrame fr = null; string dir = Path.GetDirectoryName(filename); string file = Path.GetFileNameWithoutExtension(filename); file = MegaCacheUtils.MakeFileName(file, ref decformat); //if ( file.Length > 0 ) { string newfname = dir + "/" + file + frame.ToString("D" + decformat) + ".xyz"; fr = LoadFrameStream(newfname); } return(fr); }
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); }
//int lastsetframe = -1; void UpdateParticles(float dt) { if (!update) { return; } if (dt > 0.01f) { dt = 0.01f; } //if ( framenum == lastsetframe ) //return; if (particle && image && image.frames != null && image.frames.Count > 0) { if (particles == null || particles.Length != image.maxpoints) { particles = new ParticleSystem.Particle[image.maxpoints]; } framenum = Mathf.Clamp(framenum, 0, image.frames.Count - 1); //lastsetframe = framenum; MegaCachePCXYZFrame frame = image.frames[framenum]; // Do we need this //particle.GetParticles(particles); if (havecol) { byte alpha = (byte)(transparency * 255.0f); for (int i = 0; i < frame.points.Length; i++) { particles[i].position = frame.points[i] * playscale; #if UNITY_2017 || UNITY_2018 particles[i].remainingLifetime = 1.0f; #else particles[i].lifetime = 1.0f; //ph.life - ps.time; #endif particles[i].startLifetime = 1.0f; //ph.life; Color32 c = frame.color[i]; c.a = alpha; #if UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_2017 || UNITY_2018 particles[i].startColor = c; particles[i].startSize = playsize * playscale; #else particles[i].color = c; particles[i].size = playsize * playscale; #endif } } else { //byte alpha = (byte)(transparency * 255.0f); for (int i = 0; i < frame.points.Length; i++) { particles[i].position = frame.points[i] * playscale; #if UNITY_2017 || UNITY_2018 particles[i].remainingLifetime = 1.0f; #else particles[i].lifetime = 1.0f; //ph.life - ps.time; #endif particles[i].startLifetime = 1.0f; //ph.life; #if UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_2017 || UNITY_2018 particles[i].startColor = color; particles[i].startSize = playsize * playscale; #else particles[i].size = playsize * playscale; particles[i].color = color; #endif } } particle.SetParticles(particles, frame.points.Length); } }
public void LoadPLYFileStream(MegaCachePointCloudXYZ mod, string filename) //, int first, int last, int step) { if (mod.image == null) { mod.image = ScriptableObject.CreateInstance <MegaCachePCXYZImage>(); } if (mod.image && mod.image.frames.Count > 0) { if (!EditorUtility.DisplayDialog("Add to or Replace", "Add new Frames to existing list, or Replace All", "Add", "Replace")) { mod.image.frames.Clear(); mod.image.maxpoints = 0; } } StreamReader stream = File.OpenText(filename); if (stream == null) { return; } //string entireText = stream.ReadToEnd(); char[] splitIdentifier = { ' ' }; //StringReader reader = new StringReader(entireText); bool readheader = true; int haveverts = -1; //int havenorms = -1; int havecols = -1; bool havealpha = false; int vcount = 0; int index = 0; while (readheader) { string ps = stream.ReadLine(); if (ps == null || ps.Length == 0) { break; } string[] brokenString = ps.Split(splitIdentifier, 50); switch (brokenString[0]) { case "ply": break; case "format": if (brokenString[1] != "ascii") { Debug.LogWarning("Only Ascci PLY format files are supported!"); stream.Close(); return; } break; case "end_header": readheader = false; break; case "comment": break; case "element": if (brokenString[1] == "vertex") { vcount = int.Parse(brokenString[2]); } break; case "property": if (brokenString[2] == "x") { haveverts = index; } //if ( brokenString[2] == "nx" ) //havenorms = index; if (brokenString[2] == "red") { havecols = index; } if (brokenString[2] == "alpha") { havealpha = true; } index++; break; } } if (havecols == -1) { mod.havecol = false; } else { mod.havecol = true; } 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 barcount = 0; int countlim = vcount / 100; int skip = 0; for (int i = 0; i < vcount; i++) { float a = (float)i / (float)vcount; barcount++; if (barcount > countlim) { barcount = 0; if (EditorUtility.DisplayCancelableProgressBar("Loading Points", "Point " + i, a)) { break; } } string ps = stream.ReadLine(); if (ps == null || ps.Length == 0) { break; } string[] brokenString = ps.Split(splitIdentifier, 50); //if ( brokenString.Length != 8 ) //{ //Debug.Log("l " + brokenString.Length + " i " + i + " ps " + ps); //break; //} p.x = float.Parse(brokenString[haveverts]); p.y = float.Parse(brokenString[haveverts + 1]); p.z = float.Parse(brokenString[haveverts + 2]); if (havecols >= 0) { c.r = byte.Parse(brokenString[havecols]); c.g = byte.Parse(brokenString[havecols + 1]); c.b = byte.Parse(brokenString[havecols + 2]); if (havealpha) { c.a = byte.Parse(brokenString[havecols + 3]); } } skip++; if (skip >= mod.particleskip) { skip = 0; pos.Add(p * mod.importscale); col.Add(c); } } stream.Close(); EditorUtility.ClearProgressBar(); frame.points = pos.ToArray(); frame.color = col.ToArray(); if (frame != null) { mod.image.frames.Add(frame); if (frame.points.Length > mod.image.maxpoints) { mod.image.maxpoints = frame.points.Length; } } }