public MegaCachePCFrame LoadFrame(string filename, int frame) { MegaCachePCFrame fr = null; char[] splits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; string dir = Path.GetDirectoryName(filename); string file = Path.GetFileNameWithoutExtension(filename); string[] names; if (namesplit.Length > 0) { names = file.Split(namesplit[0]); names[0] += namesplit[0]; } else { names = file.Split(splits); } if (names.Length > 0) { string newfname = dir + "/" + names[0] + frame.ToString("D" + decformat) + ".csv"; fr = LoadFrame(newfname); } return(fr); }
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); }
public void LoadPC(MegaCachePointCloud mod, string filename, int first, int last, int step) { if (mod.image == null) { mod.image = ScriptableObject.CreateInstance <MegaCachePCImage>(); } 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)) { MegaCachePCFrame 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 MegaCachePCFrame LoadFrame(string filename, int frame) { MegaCachePCFrame 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) + ".csv"; fr = LoadFrame(newfname); } return(fr); }
//public Color color = Color.white; void UpdateParticles(float dt) { if (dt > 0.01f) { dt = 0.01f; } if (particle && image) { framenum = Mathf.Clamp(framenum, 0, image.frames.Count - 1); MegaCachePCFrame frame = image.frames[framenum]; // Do we need this particle.GetParticles(particles); //int ix = 0; //Matrix4x4 tm = transform.localToWorldMatrix; //Color col = color; 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].startSize = frame.intensity[i] * playsize * playscale; #else particles[i].size = frame.intensity[i] * playsize * playscale; #endif //col.a = frame.intensity[i]; //particles[i].color = col; } particle.SetParticles(particles, frame.points.Length); } }
public static void LoadFile(MegaCachePointCloud mod, string filename) { StreamReader stream = File.OpenText(filename); string entireText = stream.ReadToEnd(); stream.Close(); char[] splitIdentifier = { ',' }; StringReader reader = new StringReader(entireText); 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(); if ( 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]); it = float.Parse(brokenString[3]); pos.Add(p); inten.Add(it); } frame.points = pos.ToArray(); frame.intensity = inten.ToArray(); mod.image.frames.Add(frame); }