public Animation(byte[] file, int address, uint imageBase, int nummodels, Dictionary <int, string> labels) { if (labels.ContainsKey(address)) { Name = labels[address]; } else { Name = "animation_" + address.ToString("X8"); } Int32 ptr = address; Frames = ByteConverter.ToInt32(file, ptr + 4); AnimFlags animtype = (AnimFlags)ByteConverter.ToUInt16(file, ptr + 8); int framesize = (ByteConverter.ToUInt16(file, ptr + 10) & 0xF) * 8; ptr = (int)(ByteConverter.ToUInt32(file, ptr) - imageBase); for (int i = 0; i < nummodels; i++) { Models.Add(i, new AnimModelData(file, ptr + (i * framesize), imageBase, animtype)); if (Models[i].Position.Count == 0 & Models[i].Rotation.Count == 0 & Models[i].Scale.Count == 0) { Models.Remove(i); } } ModelParts = nummodels; }
public StartCameraPropAnimEvent(LuaTable table) : base(table) { if (GetProps(table, out var props)) { if (!GetValue(props, "cameraprops", out LuaTable cameraprops)) { return; } if (GetValue(cameraprops, "fovh", out FovH)) { SetFlags |= AnimFlags.FovH; } if (GetValue(cameraprops, "hvaspect", out HVAspect)) { SetFlags |= AnimFlags.HVAspect; } if (GetValue(cameraprops, "nearplane", out NearPlane)) { SetFlags |= AnimFlags.NearPlane; } if (GetValue(cameraprops, "farplane", out FarPlane)) { SetFlags |= AnimFlags.FarPlane; } } }
public static TRAMState FormState(AnimFlags state, Action activationHandler = null, string name = "") { return(new TRAMState() { m_correspondingValue = state, m_dbgName = name, OnActivate = activationHandler }); }
void OnLand() { m_state = m_state.OnLand(); m_lastFlags = m_state.m_correspondingValue; m_upperVector = 0; m_jumpStart = -1; m_waitingForLanding = false; m_rememberedSpeed = Vector3.zero; }
private Func <AnimFlags> DirectionalMove(ChannelKind mainChannel) { AnimFlags l_direction = AnimFlags.idle1; switch (mainChannel) { case ChannelKind.Forward: l_direction = AnimFlags.run; break; case ChannelKind.Backward: l_direction = AnimFlags.run_bk; break; case ChannelKind.Left: l_direction = AnimFlags.ss_lt; break; case ChannelKind.Right: l_direction = AnimFlags.ss_rt; break; } bool l_switchCase = false; return(() => { m_currentRoutine = () => { Func <AnimFlags> l_exitScenario = () => { m_currentRoutine = IdleCycle; return AnimFlags.stepb; }; Func <AnimFlags> l_stopScenario = () => { m_currentRoutine = IdleCycle; return AnimFlags.stop; }; Func <AnimFlags> l_loop = () => { return l_direction | (m_plch[mainChannel] ? ((l_switchCase = !l_switchCase) ? AnimFlags.rt : AnimFlags.lt) : l_stopScenario()); }; Func <AnimFlags> l_loopEnter = () => { m_currentRoutine = l_loop; return AnimFlags.start; }; return l_direction | (m_plch[mainChannel] ? l_loopEnter : l_exitScenario)(); }; return l_direction | AnimFlags.stepa; }); }
static byte[] GetSections(NJS_MOTION motion, int verbose = 0) { List <byte> result = new List <byte>(); int[] mkey_f_addr = new int[motion.ModelParts]; int[] mkey_a_addr = new int[motion.ModelParts]; int mkey_f_section = 0; int mkey_f_count = 0; // Get MKEY_F foreach (var anim in motion.Models) { AnimModelData model = anim.Value; if (model.Position != null && model.Position.Count > 0) { mkey_f_addr[anim.Key] = result.Count; if (verbose > 1) { Console.WriteLine("MKEY_F: {0} at {1}", anim.Key, result.Count.ToString("X")); } foreach (var item in model.Position) { result.AddRange(BitConverter.GetBytes(item.Key)); result.AddRange(BitConverter.GetBytes(item.Value.X)); result.AddRange(BitConverter.GetBytes(item.Value.Y)); result.AddRange(BitConverter.GetBytes(item.Value.Z)); mkey_f_count++; } } } if (mkey_f_count > 0) { result.InsertRange(mkey_f_section, BitConverter.GetBytes((uint)0)); result.InsertRange(mkey_f_section + 4, BitConverter.GetBytes((uint)mkey_f_count * 16)); } // Get MKEY_A int mkey_a_section = result.Count; int mkey_a_count = 0; foreach (var anim in motion.Models) { AnimModelData model = anim.Value; if (model.Rotation != null && model.Rotation.Count > 0) { mkey_a_addr[anim.Key] = result.Count; if (verbose > 1) { Console.WriteLine("MKEY_A: {0} at {1}", anim.Key, result.Count.ToString("X")); } foreach (var item in model.Rotation) { result.AddRange(BitConverter.GetBytes(item.Key)); result.AddRange(BitConverter.GetBytes(item.Value.X)); result.AddRange(BitConverter.GetBytes(item.Value.Y)); result.AddRange(BitConverter.GetBytes(item.Value.Z)); mkey_a_count++; } } } if (mkey_a_count > 0) { result.InsertRange(mkey_a_section, BitConverter.GetBytes((uint)1)); result.InsertRange(mkey_a_section + 4, BitConverter.GetBytes((uint)mkey_a_count * 16)); } // Get MDATA2 header int mdata_section = result.Count; for (int m = 0; m < motion.ModelParts; m++) { if (motion.Models.ContainsKey(m)) { AnimModelData model = motion.Models[m]; if (model.Position != null && model.Position.Count > 0) { result.AddRange(BitConverter.GetBytes((uint)(mkey_f_addr[m] + 8))); } else { result.AddRange(BitConverter.GetBytes((uint)0)); } if (model.Rotation != null && model.Rotation.Count > 0) { result.AddRange(BitConverter.GetBytes((uint)(mkey_a_addr[m] + 8))); } else { result.AddRange(BitConverter.GetBytes((uint)0)); } if (model.Position != null) { result.AddRange(BitConverter.GetBytes((uint)(model.Position.Count))); } else { result.AddRange(BitConverter.GetBytes((uint)0)); } if (model.Rotation != null) { result.AddRange(BitConverter.GetBytes((uint)(model.Rotation.Count))); } else { result.AddRange(BitConverter.GetBytes((uint)0)); } } else { result.AddRange(BitConverter.GetBytes((uint)0)); result.AddRange(BitConverter.GetBytes((uint)0)); result.AddRange(BitConverter.GetBytes((uint)0)); result.AddRange(BitConverter.GetBytes((uint)0)); } } result.InsertRange(mdata_section, BitConverter.GetBytes((uint)3)); result.InsertRange(mdata_section + 4, BitConverter.GetBytes((uint)(16 * motion.ModelParts + 8))); result.InsertRange(mdata_section + 8, BitConverter.GetBytes((uint)motion.ModelParts << 2)); result.InsertRange(mdata_section + 12, BitConverter.GetBytes((uint)2)); // Write motion header result.AddRange(BitConverter.GetBytes((uint)4)); result.AddRange(BitConverter.GetBytes((uint)12)); result.AddRange(BitConverter.GetBytes(mdata_section + 8)); result.AddRange(BitConverter.GetBytes(motion.Frames)); // It's MDATA2 so flags are hardcoded AnimFlags flags = 0; flags |= AnimFlags.Position; flags |= AnimFlags.Rotation; result.AddRange(BitConverter.GetBytes((short)flags)); result.AddRange(BitConverter.GetBytes((short)motion.InterpolationMode)); return(result.ToArray()); }
// Scan for Motions static void ScanMotions() { CurrentStep++; CurrentScanData = "Motions" + (ModelParts > 0 ? " with " + ModelParts.ToString() + " or more nodes" : ""); Console.WriteLine("Step {0}: Scanning for motions with at least {1} model parts... ", CurrentStep, ModelParts); if (ShortRot) { Console.WriteLine("Using short rotations"); } ByteConverter.BigEndian = BigEndian; if (!SingleOutputFolder) { Directory.CreateDirectory(Path.Combine(OutputFolder, "actions")); } for (uint address = StartAddress; address < EndAddress; address += 1) { if (CancelScan) { break; } if (ConsoleMode && address % 1000 == 0) { Console.Write("\r{0} ", address.ToString("X8")); } CurrentAddress = address; // Check for a valid MDATA pointer uint mdatap = ByteConverter.ToUInt32(datafile, (int)address); if (mdatap < ImageBase || mdatap >= datafile.Length - 12 + ImageBase || mdatap == 0) { //Console.WriteLine("Mdatap {0} fail", mdatap.ToString("X8")); continue; } uint frames = ByteConverter.ToUInt32(datafile, (int)address + 4); if (frames > 2000 || frames < 1) { //Console.WriteLine("Frames {0} fail", frames.ToString()); continue; } AnimFlags animtype = (AnimFlags)ByteConverter.ToUInt16(datafile, (int)address + 8); if (animtype == 0) { continue; } int mdata = 0; //Console.WriteLine("Flags: {0}", animtype.ToString()); if (animtype.HasFlag(AnimFlags.Position)) { mdata++; } if (animtype.HasFlag(AnimFlags.Rotation)) { mdata++; } if (animtype.HasFlag(AnimFlags.Scale)) { mdata++; } if (animtype.HasFlag(AnimFlags.Vector)) { mdata++; } if (animtype.HasFlag(AnimFlags.Vertex)) { mdata++; } if (animtype.HasFlag(AnimFlags.Normal)) { mdata++; } if (animtype.HasFlag(AnimFlags.Color)) { continue; } if (animtype.HasFlag(AnimFlags.Intensity)) { continue; } if (animtype.HasFlag(AnimFlags.Target)) { continue; } if (animtype.HasFlag(AnimFlags.Spot)) { continue; } if (animtype.HasFlag(AnimFlags.Point)) { continue; } if (animtype.HasFlag(AnimFlags.Roll)) { continue; } int mdatasize = 0; bool lost = false; switch (mdata) { case 1: case 2: mdatasize = 16; break; case 3: mdatasize = 24; break; case 4: mdatasize = 32; break; case 5: mdatasize = 40; break; default: lost = true; break; } if (lost) { continue; } // Check MKEY pointers int mdatas = 0; for (int u = 0; u < 255; u++) { for (int m = 0; m < mdata; m++) { if (lost) { continue; } uint pointer = ByteConverter.ToUInt32(datafile, (int)(mdatap - ImageBase) + mdatasize * u + 4 * m); if (pointer < ImageBase || pointer >= datafile.Length - 8 + ImageBase) { if (pointer != 0) { lost = true; //Console.WriteLine("Mkey pointer {0} lost", pointer.ToString("X8")); } } if (!lost) { // Read frame count int framecount = ByteConverter.ToInt32(datafile, (int)(mdatap - ImageBase) + mdatasize * u + 4 * mdata + 4 * m); if (framecount < 0 || framecount > 2000) { //Console.WriteLine("Framecount lost: {0}", framecount.ToString("X8")); lost = true; } if (pointer == 0 && framecount != 0) { //Console.WriteLine("Framecount non zero"); lost = true; } //if (!lost) Console.WriteLine("Mdata size: {0}, MkeyP: {1}, Frames: {2}", mdatasize, pointer.ToString("X8"), framecount.ToString()); } } if (!lost) { mdatas++; //Console.WriteLine("Mdata {0}, total {1}", u, mdatas); } } if (mdatas > 0 && mdatas >= ModelParts) { try { Console.WriteLine("\rAdding motion at {0}: {1} nodes", address.ToString("X8"), mdatas); //Console.WriteLine("trying Address: {0}, MdataP: {1}, mdatas: {2}", address.ToString("X8"), mdatap.ToString("X8"), mdata); NJS_MOTION mot = NJS_MOTION.ReadDirect(datafile, mdatas, (int)address, ImageBase, new Dictionary <int, Attach>(), ShortRot); if (mot.ModelParts <= 0) { continue; } if (mot.Frames <= 0) { continue; } if (mot.Models.Count == 0) { continue; } string fileOutputPath = Path.Combine(OutputFolder, "actions", address.ToString("X8") + ".saanim"); if (SingleOutputFolder) { fileOutputPath = Path.Combine(OutputFolder, address.ToString("X8") + ".saanim"); } mot.Save(fileOutputPath, NoMeta); FoundMotions++; addresslist.Add(address, "NJS_MOTION"); uint[] arr = new uint[2]; arr[0] = address; arr[1] = (uint)mot.ModelParts; actionlist.Add(address, arr); } catch (Exception ex) { Console.WriteLine("\rError adding motion at {0}: {1}", address.ToString("X8"), ex.Message); } } } Console.WriteLine("\rFound {0} motions", FoundMotions); }
void Update() { //GetComponentInChildren<Camera>().transform.localPosition = new Vector3(0, 25, -21); //GetComponentInChildren<Camera>().transform.LookAt(transform.position + Vector3.up * 15f); if (m_lockCursor) { if (Input.GetKey(KeyCode.Escape)) { m_lockCursor = false; Screen.lockCursor = false; } } else { if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) { m_lockCursor = true; Screen.lockCursor = true; } } Vector3 l_jw = new Vector3(0, m_jumpStart != 0 ? (-Mathf.Clamp((Time.time - m_jumpStart) / m_travelSpd - Mathf.PI, 0, 1)) + (Mathf.Cos(Mathf.Clamp((Time.time - m_jumpStart) / m_travelSpd, -Mathf.PI, Mathf.PI))) * (Input.GetKey(KeyCode.Space) ? m_longerTravelDist : m_travelDist) : 0, 0); CollisionFlags flags = GetComponentInChildren <CharacterController>().Move((transform.rotation * (m_motionVector + m_rememberedSpeed + l_jw * 100) + Physics.gravity) * Time.deltaTime); //rigidbody.MovePosition(Vector3.up); //rigidbody.MovePosition(Vector3.down); { if (m_lockCursor) { m_x += Input.GetAxis("Mouse X") * xSpeed * 0.02f; m_y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; } m_interpAngle = Quaternion.Lerp(m_interpAngle, m_targetAngle, Time.deltaTime * 15f); m_y = ClampAngle(m_y, yMinLimit, yMaxLimit); Quaternion rotation = Quaternion.Euler(m_y, m_x, 0); Vector3 position = rotation * new Vector3(0, 0, -25f) + transform.position; m_camera.rotation = Quaternion.Euler(rotation.eulerAngles.x, 0, 0); transform.rotation = Quaternion.Euler(0, rotation.eulerAngles.y + m_interpAngle.eulerAngles.y, 0); m_camera.position = position; m_camera.LookAt(transform.position + new Vector3(0, 15, 0)); } if ((flags & CollisionFlags.CollidedBelow) != 0) { if (m_waitingForLanding) { OnLand(); } } else { //if just lifted off if ((flags & CollisionFlags.CollidedBelow) == 0) { if ((m_lastCollisionFlags & CollisionFlags.CollidedBelow) != 0) { if (m_jumpStart == -1) { RaycastHit l_botLH = new RaycastHit(); Debug.DrawRay(transform.position + 1 * Vector3.up, Vector3.down, Color.red, 15f); if (!Physics.Raycast(new Ray() { origin = transform.position + 1 * Vector3.up, direction = Vector3.down }, out l_botLH, 1.25f)) { m_jumpStart = Time.time - Mathf.PI * m_travelSpd; m_rememberedSpeed = m_motionVector; Debug.Log("FALL LIFTOFF"); m_waitingForLanding = true; m_lastFlags = AnimFlags.jump | AnimFlags.idle; } } //m_jumpStart = Time.time; } } } m_lastCollisionFlags = flags; PlayClip(GetAnim()); if (animation[GetAnim()] != null) { adds = animation[GetAnim()].normalizedTime.ToString() + "\n" + (m_jumpStart != 0 ? m_upperVector * (Time.time - m_jumpStart) - 0.5f * (Time.time - m_jumpStart) * (Time.time - m_jumpStart) * 9.8f : 0).ToString(); } }
void PlayClip(string animname) { string l_bufferedName = animname; AnimFlags l_bufferedFlags = m_lastFlags; animname = (!ComFlag ? m_characterName : this.m_characterCombName) + l_bufferedName; if (!m_loadedClips.Contains(animname)) { AnimationClip l_clip = AnimationClipHolder.Get(animname, this); if (l_clip == null) { ComFlag = !ComFlag; animname = (!ComFlag ? m_characterName : this.m_characterCombName) + l_bufferedName; Debug.LogWarning("forcibly switching com flag"); m_lastFlags = l_bufferedFlags; l_clip = AnimationClipHolder.Get(animname, this); } if (l_clip == null)//if clip is still null { Debug.LogError("Cant load clip " + animname); return; } else { l_clip.name = animname; animation.AddClip(l_clip, animname); m_loadedClips.Add(animname); } } if (animname != m_clipname && !animation.IsPlaying(animname) && m_loadedClips.Contains(animname)) { Oni.Totoro.AnimationState old = 0; Oni.Totoro.AnimationState @new = 0; if (!string.IsNullOrEmpty(m_clipname)) { from = animation[m_clipname]; to = animation[animname]; old = (Round2.Generated.Binary.ONCC.GetByName("konoko_generic").GetAnimInfo(m_clipname)).ToState; } /* * NewBehaviourScript.m_events[name].stringParameter = NewBehaviourScript.m_events[name].stringParameter.Replace("|DONOTUSE", ""); * * if (!string.IsNullOrEmpty(m_clipname)) * { * NewBehaviourScript.m_events[m_clipname].stringParameter += "|DONOTUSE"; * from = animation[m_clipname]; * to = animation[name]; * old = NewBehaviourScript.m_anims[m_clipname].ToState; * * }*/ m_clipname = animname; @new = Round2.Generated.Binary.ONCC.GetByName("konoko_generic").GetAnimInfo(animname).FromState; adds2 = "mixstate: " + (old != @new); adds2 += "\nforced mix : " + m_forcedMix; adds2 += "\nfade len = " + (10f / animation[animname].clip.frameRate); adds2 += "\n" + old + "==" + @new; { if (old != @new || m_forcedMix) { animation.CrossFade(animname, 10f / animation[animname].clip.frameRate); } else { animation.CrossFade(animname, 3f / animation[animname].clip.frameRate); } } } else { if (!m_loadedClips.Contains(animname)) { Debug.LogError("nave no clip " + animname); Debug.LogError("clipdump:"); string dump = ""; /* * foreach(string __name in NewBehaviourScript.m_events.Keys) * { * dump += __name + "\n"; * }*/ Debug.LogError(dump); } } }
string GetAnim() { m_prevFlags = m_lastFlags; m_targetAngle = Quaternion.Euler(0, 0, 0); m_state = m_state.OnAnyFrame(); m_lastFlags = m_state.m_correspondingValue; string animname = ""; foreach (string s in m_lastFlags.ToString().Split(",".ToCharArray())) { switch (s.Replace(" ", "")) { case "ss_rt": animname += "ss_rt"; break; case "ss_lt": animname += "ss_lt"; break; case "run_bk": animname += "run_bk"; break; case "stepa": animname += "1stepa"; break; case "stepb": animname += "1stepb"; break; default: animname += s.Replace(" ", ""); break; case "rt": animname += "rt"; break; case "lt": animname += "lt"; break; } animname += "_"; } animname = animname.Remove(animname.Length - 1); if ((m_lastFlags & AnimFlags.run) != 0) { switch (animname) { case "run_1stepa": animname = "run1stepa"; break; case "run_1stepb": animname = "run1stepb"; break; case "run_start": animname = "runstart"; break; case "run_stop": animname = "runstop"; break; } } return(animname); }
public AnimModelData(byte[] file, int address, uint imageBase, AnimFlags animtype) { uint posoff = 0, rotoff = 0, scaoff = 0; if ((animtype & AnimFlags.Translate) == AnimFlags.Translate) { posoff = ByteConverter.ToUInt32(file, address); if (posoff > 0) posoff = posoff - imageBase; address += 4; } if ((animtype & AnimFlags.Rotate) == AnimFlags.Rotate) { rotoff = ByteConverter.ToUInt32(file, address); if (rotoff > 0) rotoff = rotoff - imageBase; address += 4; } if ((animtype & AnimFlags.Scale) == AnimFlags.Scale) { scaoff = ByteConverter.ToUInt32(file, address); if (scaoff > 0) scaoff = scaoff - imageBase; address += 4; } try { int tmpaddr; if ((animtype & AnimFlags.Translate) == AnimFlags.Translate) { int posframes = ByteConverter.ToInt32(file, address); if (posframes > 0) { tmpaddr = (int)posoff; for (int i = 0; i < posframes; i++) { Position.Add(ByteConverter.ToInt32(file, tmpaddr), new Vertex(file, tmpaddr + 4)); tmpaddr += 16; } } address += 4; } if ((animtype & AnimFlags.Rotate) == AnimFlags.Rotate) { int rotframes = ByteConverter.ToInt32(file, address); if (rotframes > 0) { tmpaddr = (int)rotoff; for (int i = 0; i < rotframes; i++) { Rotation.Add(ByteConverter.ToInt32(file, tmpaddr), new Rotation(file, tmpaddr + 4)); tmpaddr += 16; } } address += 4; } if ((animtype & AnimFlags.Scale) == AnimFlags.Scale) { int scaframes = ByteConverter.ToInt32(file, address); if (scaframes > 0) { tmpaddr = (int)scaoff; for (int i = 0; i < scaframes; i++) { Scale.Add(ByteConverter.ToInt32(file, tmpaddr), new Vertex(file, tmpaddr + 4)); tmpaddr += 16; } } address += 4; } } catch (ArgumentOutOfRangeException) { } }
public AnimModelData(byte[] file, int address, uint imageBase, AnimFlags animtype) { uint posoff = 0, rotoff = 0, scaoff = 0; if ((animtype & AnimFlags.Translate) == AnimFlags.Translate) { posoff = ByteConverter.ToUInt32(file, address); if (posoff > 0) { posoff = posoff - imageBase; } address += 4; } if ((animtype & AnimFlags.Rotate) == AnimFlags.Rotate) { rotoff = ByteConverter.ToUInt32(file, address); if (rotoff > 0) { rotoff = rotoff - imageBase; } address += 4; } if ((animtype & AnimFlags.Scale) == AnimFlags.Scale) { scaoff = ByteConverter.ToUInt32(file, address); if (scaoff > 0) { scaoff = scaoff - imageBase; } address += 4; } try { int tmpaddr; if ((animtype & AnimFlags.Translate) == AnimFlags.Translate) { int posframes = ByteConverter.ToInt32(file, address); if (posframes > 0) { tmpaddr = (int)posoff; for (int i = 0; i < posframes; i++) { Position.Add(ByteConverter.ToInt32(file, tmpaddr), new Vertex(file, tmpaddr + 4)); tmpaddr += 16; } } address += 4; } if ((animtype & AnimFlags.Rotate) == AnimFlags.Rotate) { int rotframes = ByteConverter.ToInt32(file, address); if (rotframes > 0) { tmpaddr = (int)rotoff; for (int i = 0; i < rotframes; i++) { Rotation.Add(ByteConverter.ToInt32(file, tmpaddr), new Rotation(file, tmpaddr + 4)); tmpaddr += 16; } } address += 4; } if ((animtype & AnimFlags.Scale) == AnimFlags.Scale) { int scaframes = ByteConverter.ToInt32(file, address); if (scaframes > 0) { tmpaddr = (int)scaoff; for (int i = 0; i < scaframes; i++) { Scale.Add(ByteConverter.ToInt32(file, tmpaddr), new Vertex(file, tmpaddr + 4)); tmpaddr += 16; } } address += 4; } } catch (ArgumentOutOfRangeException) { } }
public void ToStructVariables(TextWriter writer) { bool hasPos = false, hasRot = false, hasScl = false; string id = Name.MakeIdentifier(); foreach (KeyValuePair <int, AnimModelData> model in Models) { if (model.Value.Position.Count > 0) { hasPos = true; writer.Write("NJS_MKEY_F "); writer.Write(id); writer.Write("_"); writer.Write(model.Key); writer.WriteLine("_pos[] = {"); List <string> lines = new List <string>(model.Value.Position.Count); foreach (KeyValuePair <int, Vertex> item in model.Value.Position) { lines.Add("\t{ " + item.Key + ", " + item.Value.X.ToC() + ", " + item.Value.Y.ToC() + ", " + item.Value.Z.ToC() + " }"); } writer.WriteLine(string.Join("," + Environment.NewLine, lines.ToArray())); writer.WriteLine("};"); writer.WriteLine(); } if (model.Value.Rotation.Count > 0) { hasRot = true; writer.Write("NJS_MKEY_A "); writer.Write(id); writer.Write("_"); writer.Write(model.Key); writer.WriteLine("_rot[] = {"); List <string> lines = new List <string>(model.Value.Rotation.Count); foreach (KeyValuePair <int, Rotation> item in model.Value.Rotation) { lines.Add("\t{ " + item.Key + ", " + item.Value.X.ToCHex() + ", " + item.Value.Y.ToCHex() + ", " + item.Value.Z.ToCHex() + " }"); } writer.WriteLine(string.Join("," + Environment.NewLine, lines.ToArray())); writer.WriteLine("};"); writer.WriteLine(); } if (model.Value.Scale.Count > 0) { hasScl = true; writer.Write("NJS_MKEY_F "); writer.Write(id); writer.Write("_"); writer.Write(model.Key); writer.WriteLine("_scl[] = {"); List <string> lines = new List <string>(model.Value.Scale.Count); foreach (KeyValuePair <int, Vertex> item in model.Value.Scale) { lines.Add("\t{ " + item.Key + ", " + item.Value.X.ToC() + ", " + item.Value.Y.ToC() + ", " + item.Value.Z.ToC() + " }"); } writer.WriteLine(string.Join("," + Environment.NewLine, lines.ToArray())); writer.WriteLine("};"); writer.WriteLine(); } } if (hasPos & !hasRot & !hasScl) { hasRot = true; } if (hasRot & !hasPos & !hasScl) { hasPos = true; } if (hasScl & !hasPos & !hasRot) { hasRot = true; } AnimFlags flags = 0; ushort numpairs = 0; if (hasPos) { flags |= AnimFlags.Translate; numpairs++; } if (hasRot) { flags |= AnimFlags.Rotate; numpairs++; } if (hasScl) { flags |= AnimFlags.Scale; numpairs++; } writer.Write("NJS_MDATA"); writer.Write(numpairs); writer.Write(" "); writer.Write(id); writer.WriteLine("_mdat[] = {"); List <string> mdats = new List <string>(ModelParts); for (int i = 0; i < ModelParts; i++) { List <string> elems = new List <string>(numpairs * 2); if (hasPos) { if (Models.ContainsKey(i) && Models[i].Position.Count > 0) { elems.Add(string.Format("{0}_{1}_pos", id, i)); } else { elems.Add("NULL"); } } if (hasRot) { if (Models.ContainsKey(i) && Models[i].Rotation.Count > 0) { elems.Add(string.Format("{0}_{1}_rot", id, i)); } else { elems.Add("NULL"); } } if (hasScl) { if (Models.ContainsKey(i) && Models[i].Scale.Count > 0) { elems.Add(string.Format("{0}_{1}_scl", id, i)); } else { elems.Add("NULL"); } } if (hasPos) { if (Models.ContainsKey(i) && Models[i].Position.Count > 0) { elems.Add(string.Format("LengthOfArray<Uint32>({0}_{1}_pos)", id, i)); } else { elems.Add("0"); } } if (hasRot) { if (Models.ContainsKey(i) && Models[i].Rotation.Count > 0) { elems.Add(string.Format("LengthOfArray<Uint32>({0}_{1}_rot)", id, i)); } else { elems.Add("0"); } } if (hasScl) { if (Models.ContainsKey(i) && Models[i].Scale.Count > 0) { elems.Add(string.Format("LengthOfArray<Uint32>({0}_{1}_scl)", id, i)); } else { elems.Add("0"); } } mdats.Add("\t{ " + string.Join(", ", elems.ToArray()) + " }"); } writer.WriteLine(string.Join("," + Environment.NewLine, mdats.ToArray())); writer.WriteLine("};"); writer.WriteLine(); writer.Write("NJS_MOTION "); writer.Write(id); writer.Write(" = { "); writer.Write("{0}_mdat, ", id); writer.Write(Frames); writer.Write(", "); writer.Write(((StructEnums.NJD_MTYPE)flags).ToString().Replace(", ", " | ")); writer.Write(", "); writer.Write(numpairs); writer.WriteLine(" };"); }
public byte[] GetBytes(uint imageBase, Dictionary <string, uint> labels, out uint address) { List <byte> result = new List <byte>(); uint[] posoffs = new uint[ModelParts]; int[] posframes = new int[ModelParts]; uint[] rotoffs = new uint[ModelParts]; int[] rotframes = new int[ModelParts]; uint[] scloffs = new uint[ModelParts]; int[] sclframes = new int[ModelParts]; bool hasPos = false, hasRot = false, hasScl = false; foreach (KeyValuePair <int, AnimModelData> model in Models) { if (model.Value.Position.Count > 0) { hasPos = true; result.Align(4); posoffs[model.Key] = imageBase + (uint)result.Count; posframes[model.Key] = model.Value.Position.Count; foreach (KeyValuePair <int, Vertex> item in model.Value.Position) { result.AddRange(ByteConverter.GetBytes(item.Key)); result.AddRange(item.Value.GetBytes()); } } if (model.Value.Rotation.Count > 0) { hasRot = true; result.Align(4); rotoffs[model.Key] = imageBase + (uint)result.Count; rotframes[model.Key] = model.Value.Rotation.Count; foreach (KeyValuePair <int, Rotation> item in model.Value.Rotation) { result.AddRange(ByteConverter.GetBytes(item.Key)); result.AddRange(item.Value.GetBytes()); } } if (model.Value.Scale.Count > 0) { hasScl = true; result.Align(4); scloffs[model.Key] = imageBase + (uint)result.Count; sclframes[model.Key] = model.Value.Scale.Count; foreach (KeyValuePair <int, Vertex> item in model.Value.Scale) { result.AddRange(ByteConverter.GetBytes(item.Key)); result.AddRange(item.Value.GetBytes()); } } } result.Align(4); uint modeldata = imageBase + (uint)result.Count; if (hasPos & !hasRot & !hasScl) { hasRot = true; } if (hasRot & !hasPos & !hasScl) { hasPos = true; } if (hasScl & !hasPos & !hasRot) { hasRot = true; } for (int i = 0; i < ModelParts; i++) { if (hasPos) { result.AddRange(ByteConverter.GetBytes(posoffs[i])); } if (hasRot) { result.AddRange(ByteConverter.GetBytes(rotoffs[i])); } if (hasScl) { result.AddRange(ByteConverter.GetBytes(scloffs[i])); } if (hasPos) { result.AddRange(ByteConverter.GetBytes(posframes[i])); } if (hasRot) { result.AddRange(ByteConverter.GetBytes(rotframes[i])); } if (hasScl) { result.AddRange(ByteConverter.GetBytes(sclframes[i])); } } result.Align(4); address = (uint)result.Count; result.AddRange(ByteConverter.GetBytes(modeldata)); result.AddRange(ByteConverter.GetBytes(Frames)); AnimFlags flags = 0; ushort numpairs = 0; if (hasPos) { flags |= AnimFlags.Translate; numpairs++; } if (hasRot) { flags |= AnimFlags.Rotate; numpairs++; } if (hasScl) { flags |= AnimFlags.Scale; numpairs++; } result.AddRange(ByteConverter.GetBytes((ushort)flags)); result.AddRange(ByteConverter.GetBytes(numpairs)); return(result.ToArray()); }