public static void LoadPDASequence(MegaCacheParticle mod, string filename, int start, int end) { char[] namesplit = { '.' }; string[] fname = filename.Split(namesplit); List <int> dellist = new List <int>(); MegaCacheParticleImage img = ScriptableObject.CreateInstance <MegaCacheParticleImage>(); bool remove = false; //img.frames = 0; for (int i = start; i < end; i++) { if (i == end - 1) { remove = true; } string name = fname[0] + "." + i + ".pda"; //Debug.Log("name " + name); if (File.Exists(name)) { LoadPDAFile(mod, img, name, remove); //img.frames++; } } //Debug.Log("particles " + img.particles.Count); for (int i = img.particles.Count - 1; i >= 0; i--) { MegaCacheParticleHistory ph = img.particles[i]; //Debug.Log("c " + ph.positions.Count); if (ph.positions.Count <= 1) { img.particles.RemoveAt(i); } } if (mod.removealive) { for (int i = dellist.Count - 1; i >= 0; i--) { if (dellist[i] < img.particles.Count) { img.particles.RemoveAt(dellist[i]); } } } //img.maxparticles = img.particles.Count; mod.image = img; //Debug.Log("particles " + img.particles.Count); }
void LoadFile(MegaCacheParticle mod, string filename) { //mod.frames.Clear(); StreamReader stream = File.OpenText(filename); string entireText = stream.ReadToEnd(); stream.Close(); char[] splitIdentifier = { ' ' }; char[] fsplit = { 'f' }; StringReader reader = new StringReader(entireText); int max = int.Parse(reader.ReadLine()); //Debug.Log("max " + max); int frames = int.Parse(reader.ReadLine()); //Debug.Log("frames " + frames); MegaCacheParticleImage img = CreateInstance <MegaCacheParticleImage>(); for (int i = 0; i < frames; i++) { MegaCacheParticleFrame fr = new MegaCacheParticleFrame(); int p = int.Parse(reader.ReadLine()); //Debug.Log("parts " + p); for (int j = 0; j < p; j++) { string ps = reader.ReadLine(); string[] brokenString = ps.Split(splitIdentifier, 50); Vector3 pos = Vector3.zero; pos.x = float.Parse(brokenString[0]); pos.y = float.Parse(brokenString[1]); pos.z = float.Parse(brokenString[2]); if (brokenString.Length > 3) { float life = float.Parse(brokenString[4].Split(fsplit)[0]) / 30.0f; fr.life.Add(life); float age = life - (float.Parse(brokenString[3].Split(fsplit)[0])) / 30.0f; fr.age.Add(age); } fr.positions.Add(pos * mod.importscale); } img.frames.Add(fr); } mod.image = img; }
void LoadFile(MegaCacheParticle mod, string filename) { //mod.frames.Clear(); StreamReader stream = File.OpenText(filename); string entireText = stream.ReadToEnd(); stream.Close(); char[] splitIdentifier = { ' ' }; char[] fsplit = { 'f' }; StringReader reader = new StringReader(entireText); int max = int.Parse(reader.ReadLine()); //Debug.Log("max " + max); int frames = int.Parse(reader.ReadLine()); //Debug.Log("frames " + frames); MegaCacheParticleImage img = CreateInstance<MegaCacheParticleImage>(); for ( int i = 0; i < frames; i++ ) { MegaCacheParticleFrame fr = new MegaCacheParticleFrame(); int p = int.Parse(reader.ReadLine()); //Debug.Log("parts " + p); for ( int j = 0; j < p; j++ ) { string ps = reader.ReadLine(); string[] brokenString = ps.Split(splitIdentifier, 50); Vector3 pos = Vector3.zero; pos.x = float.Parse(brokenString[0]); pos.y = float.Parse(brokenString[1]); pos.z = float.Parse(brokenString[2]); if ( brokenString.Length > 3 ) { float life = float.Parse(brokenString[4].Split(fsplit)[0]) / 30.0f; fr.life.Add(life); float age = life - (float.Parse(brokenString[3].Split(fsplit)[0])) / 30.0f; fr.age.Add(age); } fr.positions.Add(pos * mod.importscale); } img.frames.Add(fr); } mod.image = img; }
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 override void OnInspectorGUI() { MegaCacheParticle mod = (MegaCacheParticle)target; serializedObject.Update(); EditorGUIUtility.LookLikeControls(); EditorGUILayout.PropertyField(_prop_particle, new GUIContent("Particle System")); EditorGUILayout.PropertyField(_prop_maxparticles, new GUIContent("Max Particles")); EditorGUILayout.PropertyField(_prop_importscale, new GUIContent("Import Scale")); if (GUILayout.Button("Load Particle Cache")) { string file = EditorUtility.OpenFilePanel("Particle Cache", mod.lastpath, "txt"); if (file != null && file.Length > 1) { mod.lastpath = file; LoadFile(mod, file); } } EditorGUILayout.BeginVertical("box"); if (mod.image) { EditorGUILayout.IntSlider(_prop_frame, 0, mod.image.frames.Count - 1, new GUIContent("Frame")); } mod.animate = EditorGUILayout.BeginToggleGroup("Animate", mod.animate); EditorGUILayout.PropertyField(_prop_time, new GUIContent("Time")); EditorGUILayout.PropertyField(_prop_fps, new GUIContent("Fps")); EditorGUILayout.PropertyField(_prop_speed, new GUIContent("Speed")); EditorGUILayout.PropertyField(_prop_loopmode, new GUIContent("Loop Mode")); EditorGUILayout.EndVertical(); EditorGUILayout.EndToggleGroup(); if (GUI.changed) { serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(target); } }
void LoadPDAPlayback(MegaCacheParticle mod, string filename, int start, int end) { char[] namesplit = { '.' }; string[] fname = filename.Split(namesplit); //List<int> dellist = new List<int>(); MegaCacheParticleImage img = ScriptableObject.CreateInstance <MegaCacheParticleImage>(); bool remove = false; img.frames = 0; for (int i = start; i < end; i++) { if (i == end - 1) { remove = true; } string name = fname[0] + "." + i + ".pda"; if (File.Exists(name)) { LoadPDAFile(mod, img, name, remove); } } img.maxparticles = 0; for (int i = img.particles.Count - 1; i >= 0; i--) { MegaCacheParticleHistory ph = img.particles[i]; if (ph.positions.Count > img.maxparticles) { img.maxparticles = ph.positions.Count; } } img.frames = img.particles.Count; mod.image = img; //Debug.Log("maxp " + img.maxparticles); }
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); }
public override void OnInspectorGUI() { MegaCacheParticleLegacyPlayback mod = (MegaCacheParticleLegacyPlayback)target; serializedObject.Update(); #if !UNITY_5 && !UNITY_2017 && !UNITY_2018 EditorGUIUtility.LookLikeControls(); #endif EditorGUILayout.PropertyField(_prop_time, new GUIContent("Time")); if (mod.time < 0.0f) { mod.time = 0.0f; } EditorGUILayout.PropertyField(_prop_fps, new GUIContent("Fps")); EditorGUILayout.PropertyField(_prop_loopmode, new GUIContent("Loop Mode")); EditorGUILayout.PropertyField(_prop_particle, new GUIContent("Particle System")); EditorGUILayout.PropertyField(_prop_importscale, new GUIContent("Import Scale")); EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Data Import Options"); EditorGUILayout.PropertyField(_prop_vel, new GUIContent("Velocity")); EditorGUILayout.PropertyField(_prop_rot, new GUIContent("Rotation")); EditorGUILayout.PropertyField(_prop_scale, new GUIContent("Scale")); EditorGUILayout.PropertyField(_prop_spin, new GUIContent("Spin")); EditorGUILayout.PropertyField(_prop_removealive, new GUIContent("Remove Alive")); EditorGUILayout.PropertyField(_prop_maxfile, new GUIContent("Max File")); EditorGUILayout.EndVertical(); if (GUILayout.Button("Import Particle Cache")) { string file = EditorUtility.OpenFilePanel("Import Particle Cache", mod.lastpath, "prt"); if (file != null && file.Length > 1) { mod.lastpath = file; //MegaCacheParticle.LoadFilePlayBack(mod, file); MegaCacheParticlePlaybackEditor.LoadFilePlayBack(mod, file); } } EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Save Data Options"); EditorGUILayout.PropertyField(_prop_optimize, new GUIContent("Optimize")); EditorGUILayout.PropertyField(_prop_savevel, new GUIContent("Velocity")); EditorGUILayout.PropertyField(_prop_saverot, new GUIContent("Rotation")); EditorGUILayout.PropertyField(_prop_savescale, new GUIContent("Scale")); EditorGUILayout.PropertyField(_prop_savespin, new GUIContent("Spin")); EditorGUILayout.EndVertical(); if (GUILayout.Button("Save Particle Cache File")) { string file = EditorUtility.SaveFilePanel("Save MegaCache Particle Cache", mod.lastpath, "Particles", "mcp"); if (file != null && file.Length > 1) { mod.lastpath = file; MegaCacheParticle.SaveCacheFile(mod, file); } } if (GUILayout.Button("Load MegaCache File")) { string file = EditorUtility.OpenFilePanel("Load MegaCache Particle Cache", mod.lastpath, "mcp"); if (file != null && file.Length > 1) { mod.lastpath = file; //MegaCacheParticleImage img = MegaCacheParticleImage.LoadCache(file); MegaCacheParticleImage img = MegaCacheFile.LoadCache(file); if (img) { if (mod.image) { if (Application.isEditor) { DestroyImmediate(mod.image); } else { Destroy(mod.image); } } mod.image = img; } } } string infstring = ""; if (mod.image) { infstring = "Current Memory: " + (mod.image.CalcMemory() / 1024) + "KB"; if (mod.image.optimized) { infstring += "\nParticles Optmized: " + mod.image.optparticles.Count; } else { infstring += "\nParticles: " + mod.image.particles.Count; } } EditorGUILayout.HelpBox(infstring, MessageType.None); EditorGUILayout.PropertyField(_prop_cachesrc, new GUIContent("Cache Data Src")); EditorGUILayout.BeginVertical("box"); mod.showpaths = EditorGUILayout.BeginToggleGroup("Show Paths", mod.showpaths); mod.showstart = EditorGUILayout.IntSlider("Start", mod.showstart, 0, mod.showparticlestep); mod.showparticlestep = EditorGUILayout.IntSlider("Particle Step", mod.showparticlestep, 1, 50); mod.showposstep = EditorGUILayout.IntSlider("Position Step", mod.showposstep, 1, 10); mod.showcolor = EditorGUILayout.ColorField("Color", mod.showcolor); EditorGUILayout.EndToggleGroup(); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("box"); EditorGUILayout.Slider(_prop_speed, -2.0f, 2.0f, new GUIContent("Speed")); EditorGUILayout.Slider(_prop_scaleall, 0.0f, 4.0f, new GUIContent("Scale")); EditorGUILayout.Slider(_prop_sizescale, 0.0f, 8.0f, new GUIContent("Size")); EditorGUILayout.PropertyField(_prop_axis, new GUIContent("Rot Axis")); EditorGUILayout.EndVertical(); if (GUI.changed) { serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(target); } }
public override void OnInspectorGUI() { MegaCacheParticlePro mod = (MegaCacheParticlePro)target; serializedObject.Update(); #if !UNITY_5 && !UNITY_2017 && !UNITY_2018 EditorGUIUtility.LookLikeControls(); #endif //mod.framenum = EditorGUILayout.IntSlider("Frame", mod.framenum, 0, 99); EditorGUILayout.PropertyField(_prop_particle, new GUIContent("Particle System")); EditorGUILayout.PropertyField(_prop_maxparticles, new GUIContent("Max Particles")); EditorGUILayout.PropertyField(_prop_importscale, new GUIContent("Import Scale")); EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Data Import Options"); EditorGUILayout.PropertyField(_prop_vel, new GUIContent("Velocity")); EditorGUILayout.PropertyField(_prop_rot, new GUIContent("Rotation")); EditorGUILayout.PropertyField(_prop_scale, new GUIContent("Scale")); EditorGUILayout.PropertyField(_prop_spin, new GUIContent("Spin")); EditorGUILayout.PropertyField(_prop_removealive, new GUIContent("Remove Alive")); EditorGUILayout.PropertyField(_prop_yup, new GUIContent("Y Up Change")); EditorGUILayout.EndVertical(); if (GUILayout.Button("Import Particle Cache")) { string file = EditorUtility.OpenFilePanel("Import Particle Cache", mod.lastpath, "prt"); if (file != null && file.Length > 1) { mod.lastpath = file; MegaCacheParticle.LoadFile(mod, file); } } EditorGUILayout.PropertyField(_prop_seqstart, new GUIContent("Maya Seq Start")); EditorGUILayout.PropertyField(_prop_seqend, new GUIContent("Maya Seq End")); if (GUILayout.Button("Import Maya Particles")) { string file = EditorUtility.OpenFilePanel("Import Maya Particles", mod.lastpath, "pda"); if (file != null && file.Length > 1) { mod.lastpath = file; MegaCacheParticle.LoadPDASequence(mod, file, mod.seqstart, mod.seqend); } } EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Save Data Options"); EditorGUILayout.PropertyField(_prop_optimize, new GUIContent("Optimize")); EditorGUILayout.PropertyField(_prop_savevel, new GUIContent("Velocity")); EditorGUILayout.PropertyField(_prop_saverot, new GUIContent("Rotation")); EditorGUILayout.PropertyField(_prop_savescale, new GUIContent("Scale")); EditorGUILayout.PropertyField(_prop_savespin, new GUIContent("Spin")); EditorGUILayout.EndVertical(); if (GUILayout.Button("Save Particle Cache File")) { string file = EditorUtility.SaveFilePanel("Save MegaCache Particle Cache", mod.lastpath, "Particles", "mcp"); if (file != null && file.Length > 1) { mod.lastpath = file; MegaCacheParticle.SaveCacheFile(mod, file); } } if (GUILayout.Button("Load MegaCache File")) { string file = EditorUtility.OpenFilePanel("Load MegaCache Particle Cache", mod.lastpath, "mcp"); if (file != null && file.Length > 1) { mod.lastpath = file; //MegaCacheParticleImage img = MegaCacheParticleImage.LoadCache(file); MegaCacheParticleImage img = MegaCacheFile.LoadCache(file); if (img) { if (mod.image) { if (Application.isEditor) { DestroyImmediate(mod.image); } else { Destroy(mod.image); } } mod.image = img; } } } string infstring = ""; if (mod.image) { infstring = "Current Memory: " + (mod.image.CalcMemory() / 1024) + "KB"; if (mod.image.optimized) { infstring += "\nParticles: " + mod.image.optparticles.Count; } else { infstring += "\nParticles: " + mod.image.particles.Count; } } EditorGUILayout.HelpBox(infstring, MessageType.None); EditorGUILayout.PropertyField(_prop_cachesrc, new GUIContent("Cache Data Src")); EditorGUILayout.BeginVertical("box"); mod.showpaths = EditorGUILayout.BeginToggleGroup("Show Paths", mod.showpaths); mod.showstart = EditorGUILayout.IntSlider("Start", mod.showstart, 0, mod.showparticlestep); mod.showparticlestep = EditorGUILayout.IntSlider("Particle Step", mod.showparticlestep, 1, 50); mod.showposstep = EditorGUILayout.IntSlider("Position Step", mod.showposstep, 1, 10); mod.showcolor = EditorGUILayout.ColorField("Color", mod.showcolor); EditorGUILayout.EndToggleGroup(); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("box"); EditorGUILayout.Slider(_prop_speed, -2.0f, 2.0f, new GUIContent("Speed")); EditorGUILayout.Slider(_prop_scaleall, 0.0f, 4.0f, new GUIContent("Scale")); EditorGUILayout.Slider(_prop_emitscale, 0.0f, 4.0f, new GUIContent("Emit Scale")); EditorGUILayout.Slider(_prop_sizescale, 0.0f, 4.0f, new GUIContent("Size")); EditorGUILayout.Slider(_prop_emitspeed, 0.0f, 4.0f, new GUIContent("Emit Speed")); EditorGUILayout.PropertyField(_prop_useemit, new GUIContent("Use Emit Rate")); EditorGUILayout.PropertyField(_prop_emitrate, new GUIContent("Emit Rate")); EditorGUILayout.PropertyField(_prop_prewarm, new GUIContent("Pre Warm")); EditorGUILayout.PropertyField(_prop_axis, new GUIContent("Rot Axis")); EditorGUILayout.PropertyField(_prop_use3drot, new GUIContent("Use 3D Rot")); EditorGUILayout.EndVertical(); if (GUI.changed) { serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(target); } }
public static 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); offset = 0; //reader.ReadLine(); // ATTRIBUTES ReadLine(entireText); //string[] attribs = reader.ReadLine().Split(splitIdentifier, System.StringSplitOptions.RemoveEmptyEntries); string[] attribs = ReadLine(entireText).Split(splitIdentifier, System.StringSplitOptions.RemoveEmptyEntries); //reader.ReadLine(); // TYPES ReadLine(entireText); //string[] types = reader.ReadLine().Split(splitIdentifier, System.StringSplitOptions.RemoveEmptyEntries); // actual values string[] types = 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 = ReadLine(entireText).Split(splitIdentifier, 2); int numParticles = int.Parse(vals[1]); //reader.ReadLine(); // BEGIN DATA ReadLine(entireText); 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 = 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; } } MegaCacheParticleHistory ph; if (id >= img.particles.Count) { ph = new MegaCacheParticleHistory(); img.particles.Add(ph); Debug.Log("add particle " + img.particles.Count); } else { ph = img.particles[id]; } 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); } }
public static void SaveCacheFile(MegaCacheParticle mod, string filename) { // save cache file FileStream fs = new FileStream(filename, FileMode.Create); if (fs != null) { BinaryWriter bw = new BinaryWriter(fs); if (bw != null) { MegaCacheParticleImage img = mod.image; int version = 1; bw.Write(version); bw.Write((int)img.particles.Count); bw.Write(mod.optimize); bw.Write(mod.saverot); bw.Write(mod.savevel); bw.Write(mod.savescale); bw.Write(mod.savespin); bw.Write(img.frames); bw.Write(img.maxparticles); for (int i = 0; i < img.particles.Count; i++) { MegaCacheParticleHistory ph = img.particles[i]; bw.Write(ph.positions.Count); bw.Write(ph.life); bw.Write(ph.id); if (mod.optimize) { Bounds bounds = MegaCacheUtils.GetBounds(ph.positions); bw.Write(bounds.min.x); bw.Write(bounds.min.y); bw.Write(bounds.min.z); bw.Write(bounds.size.x); bw.Write(bounds.size.y); bw.Write(bounds.size.z); for (int v = 0; v < ph.positions.Count; v++) { Vector3 pos = ph.positions[v]; short sb = (short)(((pos.x - bounds.min.x) / bounds.size.x) * 65535.0f); bw.Write(sb); sb = (short)(((pos.y - bounds.min.y) / bounds.size.y) * 65535.0f); bw.Write(sb); sb = (short)(((pos.z - bounds.min.z) / bounds.size.z) * 65535.0f); bw.Write(sb); } } else { for (int v = 0; v < ph.positions.Count; v++) { Vector3 pos = ph.positions[v]; bw.Write(pos.x); bw.Write(pos.y); bw.Write(pos.z); } } if (mod.savevel) { Bounds bounds = MegaCacheUtils.GetBounds(ph.vels); bw.Write(bounds.min.x); bw.Write(bounds.min.y); bw.Write(bounds.min.z); bw.Write(bounds.size.x); bw.Write(bounds.size.y); bw.Write(bounds.size.z); if (mod.optimize) { for (int v = 0; v < ph.vels.Count; v++) { Vector3 pos = ph.vels[v]; byte sb = (byte)(((pos.x - bounds.min.x) / bounds.size.x) * 255.0f); bw.Write(sb); sb = (byte)(((pos.y - bounds.min.y) / bounds.size.y) * 255.0f); bw.Write(sb); sb = (byte)(((pos.z - bounds.min.z) / bounds.size.z) * 255.0f); bw.Write(sb); } } else { for (int v = 0; v < ph.vels.Count; v++) { Vector3 pos = ph.vels[v]; bw.Write(pos.x); bw.Write(pos.y); bw.Write(pos.z); } } } if (mod.savescale) { if (mod.optimize) { Bounds bounds = MegaCacheUtils.GetBounds(ph.scale); bw.Write(bounds.min.x); bw.Write(bounds.size.x); for (int v = 0; v < ph.scale.Count; v++) { float scl = ph.scale[v]; byte sb = (byte)(((scl - bounds.min.x) / bounds.size.x) * 255.0f); bw.Write(sb); } } else { for (int v = 0; v < ph.scale.Count; v++) { bw.Write(ph.scale[v]); } } } if (mod.saverot) { if (mod.optimize) { Bounds bounds = MegaCacheUtils.GetBounds(ph.rots); bw.Write(bounds.min.x); bw.Write(bounds.min.y); bw.Write(bounds.min.z); bw.Write(bounds.size.x); bw.Write(bounds.size.y); bw.Write(bounds.size.z); for (int v = 0; v < ph.rots.Count; v++) { Vector3 scl = ph.rots[v]; byte sb = (byte)(((scl.x - bounds.min.x) / bounds.size.x) * 255.0f); bw.Write(sb); sb = (byte)(((scl.y - bounds.min.y) / bounds.size.y) * 255.0f); bw.Write(sb); sb = (byte)(((scl.z - bounds.min.z) / bounds.size.z) * 255.0f); bw.Write(sb); } } else { for (int v = 0; v < ph.rots.Count; v++) { Vector3 rot = ph.rots[v]; bw.Write(rot.x); bw.Write(rot.y); bw.Write(rot.z); } } } if (mod.savespin) { if (mod.optimize) { Bounds bounds = MegaCacheUtils.GetBounds(ph.spin); bw.Write(bounds.min.x); bw.Write(bounds.size.x); for (int v = 0; v < ph.spin.Count; v++) { float scl = ph.spin[v]; byte sb = (byte)(((scl - bounds.min.x) / bounds.size.x) * 255.0f); bw.Write(sb); } } else { for (int v = 0; v < ph.scale.Count; v++) { bw.Write(ph.scale[v]); } } } } bw.Close(); } fs.Close(); } }
public static void LoadFilePlayBack(MegaCacheParticle mod, string filename) { StreamReader stream = File.OpenText(filename); string entireText = stream.ReadToEnd(); stream.Close(); char[] splitIdentifier = { ' ' }; StringReader reader = new StringReader(entireText); int.Parse(reader.ReadLine()); // max int frames = int.Parse(reader.ReadLine()); MegaCacheParticleImage img; if (mod.image == null) { img = ScriptableObject.CreateInstance <MegaCacheParticleImage>(); } else { } 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()); Vector3 pos = Vector3.zero; Vector3 rot = Vector3.zero; Vector3 vel = Vector3.zero; for (int j = 0; j < p; j++) { string ps = reader.ReadLine(); string[] brokenString = ps.Split(splitIdentifier, 50); //int id = int.Parse(brokenString[0]) - 1; if (scount == 0) { pos.x = float.Parse(brokenString[1]); 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]); vel.y = float.Parse(brokenString[5]); vel.z = float.Parse(brokenString[6]); ph.vels.Add(vel * mod.importscale); } if (mod.rot) { rot.x = float.Parse(brokenString[7]); rot.y = float.Parse(brokenString[8]); rot.z = float.Parse(brokenString[9]); 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]); 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; } } for (int i = img.particles.Count - 1; i >= 0; i--) { MegaCacheParticleHistory ph = img.particles[i]; if (ph.positions.Count <= 1) { img.particles.RemoveAt(i); } } img.frames = frames; img.maxparticles = maxp; mod.image = img; }
public static void LoadFile(MegaCacheParticle mod, string filename) { //if ( mod.mode == MegaCacheParticleMode.Playback ) //{ //LoadFilePlayBack(mod, filename); //return; //} 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(ReadLine(entireText)); // max //int frames = int.Parse(reader.ReadLine()); int frames = int.Parse(ReadLine(entireText)); MegaCacheParticleImage img = ScriptableObject.CreateInstance <MegaCacheParticleImage>(); bool remove = false; List <int> dellist = new List <int>(); int skip = 1; int scount = 0; bool zerocheck = true; int sub = 0; for (int i = 0; i < frames; i++) { if (i == frames - 1) { remove = true; } //int p = int.Parse(reader.ReadLine()); int p = int.Parse(ReadLine(entireText)); Vector3 pos = Vector3.zero; Vector3 rot = Vector3.zero; Vector3 vel = Vector3.zero; for (int j = 0; j < p; j++) { //string ps = reader.ReadLine(); string ps = ReadLine(entireText); ps = ps.Replace(',', '.'); string[] brokenString = ps.Split(splitIdentifier, 50); int id = int.Parse(brokenString[0]); // - 1; if (zerocheck) { zerocheck = false; if (id == 0) { sub = 0; } else { sub = 1; } } id = id - sub; if (remove) { // Anything still active in the last frame cant be used dellist.Add(id); } else { if (scount == 0) { MegaCacheParticleHistory ph; if (id >= img.particles.Count) { ph = new MegaCacheParticleHistory(); img.particles.Add(ph); } else { ph = img.particles[id]; } pos.x = float.Parse(brokenString[1]); pos.y = float.Parse(brokenString[2]); pos.z = float.Parse(brokenString[3]); if (mod.yupimport) { pos = AdjustYUp(pos); } 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]); vel.y = float.Parse(brokenString[5]); vel.z = float.Parse(brokenString[6]); if (mod.yupimport) { vel = AdjustYUp(vel); } ph.vels.Add(vel * mod.importscale); } if (mod.rot) { 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); } } } scount++; if (scount == skip) { scount = 0; } } for (int i = img.particles.Count - 1; i >= 0; i--) { MegaCacheParticleHistory ph = img.particles[i]; if (ph.positions.Count <= 1) { img.particles.RemoveAt(i); } } if (mod.removealive) { for (int i = dellist.Count - 1; i >= 0; i--) { if (dellist[i] < img.particles.Count) { img.particles.RemoveAt(dellist[i]); } } } mod.image = img; }
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; }
public static void LoadFile(MegaCacheParticle mod, string filename) { //if ( mod.mode == MegaCacheParticleMode.Playback ) //{ //LoadFilePlayBack(mod, filename); //return; //} StreamReader stream = File.OpenText(filename); string entireText = stream.ReadToEnd(); stream.Close(); char[] splitIdentifier = { ' ' }; StringReader reader = new StringReader(entireText); int.Parse(reader.ReadLine()); // max int frames = int.Parse(reader.ReadLine()); MegaCacheParticleImage img = ScriptableObject.CreateInstance<MegaCacheParticleImage>(); bool remove = false; List<int> dellist = new List<int>(); int skip = 1; int scount = 0; for ( int i = 0; i < frames; i++ ) { if ( i == frames - 1 ) remove = true; int p = int.Parse(reader.ReadLine()); Vector3 pos = Vector3.zero; Vector3 rot = Vector3.zero; Vector3 vel = Vector3.zero; for ( int j = 0; j < p; j++ ) { string ps = reader.ReadLine(); string[] brokenString = ps.Split(splitIdentifier, 50); int id = int.Parse(brokenString[0]) - 1; if ( remove ) { // Anything still active in the last frame cant be used dellist.Add(id); } else { if ( scount == 0 ) { MegaCacheParticleHistory ph; if ( id >= img.particles.Count ) { ph = new MegaCacheParticleHistory(); img.particles.Add(ph); } else ph = img.particles[id]; pos.x = float.Parse(brokenString[1]); 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]); vel.y = float.Parse(brokenString[5]); vel.z = float.Parse(brokenString[6]); ph.vels.Add(vel * mod.importscale); } if ( mod.rot ) { rot.x = float.Parse(brokenString[7]); rot.y = float.Parse(brokenString[8]); rot.z = float.Parse(brokenString[9]); 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]); ph.spin.Add(spin); } ph.life = life; //ph.age.Add(age); ph.positions.Add(pos * mod.importscale); } } } scount++; if ( scount == skip ) { scount = 0; } } for ( int i = img.particles.Count - 1; i >= 0; i-- ) { MegaCacheParticleHistory ph = img.particles[i]; if ( ph.positions.Count <= 1 ) { img.particles.RemoveAt(i); } } if ( mod.removealive ) { for ( int i = dellist.Count - 1; i >= 0; i-- ) { if ( dellist[i] < img.particles.Count ) img.particles.RemoveAt(dellist[i]); } } mod.image = img; }
public static void SaveCacheFile(MegaCacheParticle mod, string filename) { // save cache file FileStream fs = new FileStream(filename, FileMode.Create); if ( fs != null ) { BinaryWriter bw = new BinaryWriter(fs); if ( bw != null ) { MegaCacheParticleImage img = mod.image; int version = 1; bw.Write(version); bw.Write((int)img.particles.Count); bw.Write(mod.optimize); bw.Write(mod.saverot); bw.Write(mod.savevel); bw.Write(mod.savescale); bw.Write(mod.savespin); bw.Write(img.frames); bw.Write(img.maxparticles); for ( int i = 0; i < img.particles.Count; i++ ) { MegaCacheParticleHistory ph = img.particles[i]; bw.Write(ph.positions.Count); bw.Write(ph.life); bw.Write(ph.id); if ( mod.optimize ) { Bounds bounds = MegaCacheUtils.GetBounds(ph.positions); bw.Write(bounds.min.x); bw.Write(bounds.min.y); bw.Write(bounds.min.z); bw.Write(bounds.size.x); bw.Write(bounds.size.y); bw.Write(bounds.size.z); for ( int v = 0; v < ph.positions.Count; v++ ) { Vector3 pos = ph.positions[v]; short sb = (short)(((pos.x - bounds.min.x) / bounds.size.x) * 65535.0f); bw.Write(sb); sb = (short)(((pos.y - bounds.min.y) / bounds.size.y) * 65535.0f); bw.Write(sb); sb = (short)(((pos.z - bounds.min.z) / bounds.size.z) * 65535.0f); bw.Write(sb); } } else { for ( int v = 0; v < ph.positions.Count; v++ ) { Vector3 pos = ph.positions[v]; bw.Write(pos.x); bw.Write(pos.y); bw.Write(pos.z); } } if ( mod.savevel ) { Bounds bounds = MegaCacheUtils.GetBounds(ph.vels); bw.Write(bounds.min.x); bw.Write(bounds.min.y); bw.Write(bounds.min.z); bw.Write(bounds.size.x); bw.Write(bounds.size.y); bw.Write(bounds.size.z); if ( mod.optimize ) { for ( int v = 0; v < ph.vels.Count; v++ ) { Vector3 pos = ph.vels[v]; byte sb = (byte)(((pos.x - bounds.min.x) / bounds.size.x) * 255.0f); bw.Write(sb); sb = (byte)(((pos.y - bounds.min.y) / bounds.size.y) * 255.0f); bw.Write(sb); sb = (byte)(((pos.z - bounds.min.z) / bounds.size.z) * 255.0f); bw.Write(sb); } } else { for ( int v = 0; v < ph.vels.Count; v++ ) { Vector3 pos = ph.vels[v]; bw.Write(pos.x); bw.Write(pos.y); bw.Write(pos.z); } } } if ( mod.savescale ) { if ( mod.optimize ) { Bounds bounds = MegaCacheUtils.GetBounds(ph.scale); bw.Write(bounds.min.x); bw.Write(bounds.size.x); for ( int v = 0; v < ph.scale.Count; v++ ) { float scl = ph.scale[v]; byte sb = (byte)(((scl - bounds.min.x) / bounds.size.x) * 255.0f); bw.Write(sb); } } else { for ( int v = 0; v < ph.scale.Count; v++ ) bw.Write(ph.scale[v]); } } if ( mod.saverot ) { if ( mod.optimize ) { Bounds bounds = MegaCacheUtils.GetBounds(ph.rots); bw.Write(bounds.min.x); bw.Write(bounds.min.y); bw.Write(bounds.min.z); bw.Write(bounds.size.x); bw.Write(bounds.size.y); bw.Write(bounds.size.z); for ( int v = 0; v < ph.rots.Count; v++ ) { Vector3 scl = ph.rots[v]; byte sb = (byte)(((scl.x - bounds.min.x) / bounds.size.x) * 255.0f); bw.Write(sb); sb = (byte)(((scl.y - bounds.min.y) / bounds.size.y) * 255.0f); bw.Write(sb); sb = (byte)(((scl.z - bounds.min.z) / bounds.size.z) * 255.0f); bw.Write(sb); } } else { for ( int v = 0; v < ph.rots.Count; v++ ) { Vector3 rot = ph.rots[v]; bw.Write(rot.x); bw.Write(rot.y); bw.Write(rot.z); } } } if ( mod.savespin ) { if ( mod.optimize ) { Bounds bounds = MegaCacheUtils.GetBounds(ph.spin); bw.Write(bounds.min.x); bw.Write(bounds.size.x); for ( int v = 0; v < ph.spin.Count; v++ ) { float scl = ph.spin[v]; byte sb = (byte)(((scl - bounds.min.x) / bounds.size.x) * 255.0f); bw.Write(sb); } } else { for ( int v = 0; v < ph.scale.Count; v++ ) { bw.Write(ph.scale[v]); } } } } bw.Close(); } fs.Close(); } }
public static void LoadFilePlayBack(MegaCacheParticle mod, string filename) { StreamReader stream = File.OpenText(filename); string entireText = stream.ReadToEnd(); stream.Close(); char[] splitIdentifier = { ' ' }; StringReader reader = new StringReader(entireText); int.Parse(reader.ReadLine()); // max int frames = int.Parse(reader.ReadLine()); MegaCacheParticleImage img = ScriptableObject.CreateInstance<MegaCacheParticleImage>(); 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()); Vector3 pos = Vector3.zero; Vector3 rot = Vector3.zero; Vector3 vel = Vector3.zero; for ( int j = 0; j < p; j++ ) { string ps = reader.ReadLine(); string[] brokenString = ps.Split(splitIdentifier, 50); //int id = int.Parse(brokenString[0]) - 1; if ( scount == 0 ) { pos.x = float.Parse(brokenString[1]); 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]); vel.y = float.Parse(brokenString[5]); vel.z = float.Parse(brokenString[6]); ph.vels.Add(vel * mod.importscale); } if ( mod.rot ) { rot.x = float.Parse(brokenString[7]); rot.y = float.Parse(brokenString[8]); rot.z = float.Parse(brokenString[9]); 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]); 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; } for ( int i = img.particles.Count - 1; i >= 0; i-- ) { MegaCacheParticleHistory ph = img.particles[i]; if ( ph.positions.Count <= 1 ) { img.particles.RemoveAt(i); } } img.frames = frames; img.maxparticles = maxp; mod.image = img; }