public void removeAnimations(ConvertAnimation ca) { if (anims.Contains(ca)) { anims.Remove(ca); } }
public void addAnimations(ConvertAnimation ca) { if (!anims.Contains(ca)) { anims.Add(ca); } }
private float playTurnAnim(PL[][] willTurn, PL first, int teamTo, int decidedAnim) { if (anims.Count == 0 || decidedAnim < 0) { defaultAnim(willTurn, first, teamTo); return(0); } ConvertAnimation c = anims[decidedAnim]; return(c.play(first, willTurn, teamTo)); }
private void createW2animsToolStripMenuItem_Click(object sender, EventArgs e) { if (modFileList.SelectedNode != null) { var filename = modFileList.SelectedNode.FullPath; var fullpath = Path.Combine(ActiveMod.FileDirectory, filename); if (!File.Exists(fullpath) && !Directory.Exists(fullpath)) { return; } string dir; if (File.Exists(fullpath)) { dir = Path.GetDirectoryName(fullpath); } else { dir = fullpath; } var files = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories).ToList(); var folderName = Path.GetFileName(fullpath); ConvertAnimation anim = new ConvertAnimation(); if (File.Exists(fullpath + ".w2anims")) { if (MessageBox.Show( folderName + ".w2anims already exists. This file will be overwritten. Are you sure you want to permanently overwrite " + folderName + " w2anims?" , "Confirmation", MessageBoxButtons.YesNo ) != DialogResult.Yes) { return; } } try { anim.Load(files, fullpath + ".w2anims"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error cooking files."); } } }
public void readBuffer(CAnimationBufferBitwiseCompressed buffer, int selectedAnimIdx, CR2WFile animFile) { uint numFrames = buffer.NumFrames.val; float animDuration = buffer.Duration?.val ?? 1.0f; animationSpeed = numFrames / animDuration; uint keyFrame = 0; byte[] data; //data = (chunk.GetVariableByName("fallbackData") as CByteArray).Bytes; currentAnimName = AnimationNames[selectedAnimIdx].Key; exportData.name = AnimationNames[selectedAnimIdx].Key; exportData.duration = animDuration; exportData.numFrames = numFrames; exportData.dt = buffer.Dt?.val ?? 0.03333333f; DeferredDataBuffer deferredData = buffer.DeferredData; var streamingOption = buffer.StreamingOption; if (deferredData != null && deferredData.Bufferdata.val != 0) if (streamingOption.WrappedEnum == Enums.SAnimationBufferStreamingOption.ABSO_PartiallyStreamable) data = ConvertAnimation.Combine(buffer.Data.Bytes, File.ReadAllBytes(animFile.FileName + "." + deferredData.Bufferdata.val + ".buffer")); else data = File.ReadAllBytes(animFile.FileName + "." + deferredData.Bufferdata.val + ".buffer"); else data = buffer.Data.Bytes; using (MemoryStream ms = new MemoryStream(data)) using (BinaryReader br = new BinaryReader(ms)) { foreach (SAnimationBufferBitwiseCompressedBoneTrack bone in buffer.Bones) { List<uint> currkeyframe = new List<uint>(); List<Quaternion> currorient = new List<Quaternion>(); List<Vector3Df> currorientEuler = new List<Vector3Df>(); currentBones.Add(bone); br.BaseStream.Position = bone.Orientation.DataAddr.val; int orientNumFrames = bone.Orientation.NumFrames.val; for (uint idx = 0; idx < orientNumFrames; idx++) { keyFrame = idx; //keyFrame += numFrames; currkeyframe.Add(keyFrame); //bone.GetVariableByName("position"); byte[] odata = br.ReadBytes(6); ulong bits = (ulong)odata[0] << 40 | (ulong)odata[1] << 32 | (ulong)odata[2] << 24 | (ulong)odata[3] << 16 | (ulong)odata[4] << 8 | odata[5]; ushort[] orients = new ushort[4]; float[] quart = new float[4]; orients[0] = (ushort)((bits & 0x0000FFF000000000) >> 36); orients[1] = (ushort)((bits & 0x0000000FFF000000) >> 24); orients[2] = (ushort)((bits & 0x0000000000FFF000) >> 12); orients[3] = (ushort)((bits & 0x0000000000000FFF)); for (int i = 0; i < orients.Length; i++) { float fVal = (2047.0f - orients[i]) * (1 / 2048.0f); quart[i] = fVal; } quart[3] = -quart[3]; Quaternion orientation = new Quaternion(quart[0], quart[1], quart[2], quart[3]); currorient.Add(orientation); Vector3Df euler = orientation.ToEuler(); currorientEuler.Add(euler); //Console.WriteLine("Euler : x=%f, y=%f, z=%f", euler.X, euler.Y, euler.Z); } orientKeyframes.Add(currkeyframe); orientations.Add(currorient); orientationsEuler.Add(currorientEuler); // TODO: Refactor List<Vector3Df> currposition = new List<Vector3Df>(); currkeyframe = new List<uint>(); int compression = 0; var compr = bone.Position.Compression; if (compr != null) compression = compr.val; var addr = bone.Position.DataAddr; if (addr != null) br.BaseStream.Position = addr.val; else br.BaseStream.Position = 0; var posNumFrames = bone.Position.NumFrames.val; for (uint idx = 0; idx < posNumFrames; idx++) { keyFrame = idx; //keyFrame += numFrames; currkeyframe.Add(keyFrame); var vec = new SVector3D(null, null, ""); vec.Read(br, compression); Vector3Df pos = new Vector3Df(vec.X.val, vec.Y.val, vec.Z.val); currposition.Add(pos); } positionsKeyframes.Add(currkeyframe); positions.Add(currposition); List<Vector3Df> currscale = new List<Vector3Df>(); currkeyframe = new List<uint>(); compression = 0; compr = bone.Scale.Compression; if (compr != null) compression = compr.val; addr = bone.Scale.DataAddr; if (addr != null) br.BaseStream.Position = addr.val; else br.BaseStream.Position = 0; var scaleNumFrames = bone.Scale.NumFrames.val; for (uint idx = 0; idx < scaleNumFrames; idx++) { keyFrame = idx; //keyFrame += numFrames; currkeyframe.Add(keyFrame); var vec = new SVector3D(null, null, ""); vec.Read(br, compression); Vector3Df scale = new Vector3Df(vec.X.val, vec.Y.val, vec.Z.val); currscale.Add(scale); } scalesKeyframes.Add(currkeyframe); scales.Add(currscale); } } }
/// <summary> /// Read animations and animbuffers data. /// </summary> public void SelectAnimation(CR2WFile animFile, int selectedAnimIdx) { // *************** READ ANIMATION DATA *************** if (animFile != null && selectedAnimIdx != -1) { positions.Clear(); positionsKeyframes.Clear(); orientations.Clear(); orientKeyframes.Clear(); scales.Clear(); scalesKeyframes.Clear(); foreach (var chunk in animFile.chunks) { if (chunk.Type == "CAnimationBufferBitwiseCompressed" && chunk.ChunkIndex == AnimationNames[selectedAnimIdx].Value) { uint numFrames = (chunk.GetVariableByName("numFrames") as CUInt32).val; float animDuration = (chunk.GetVariableByName("duration") as CFloat)?.val ?? 1.0f; animationSpeed = numFrames / animDuration; uint keyFrame = 0; byte[] data; var deferredData = chunk.GetVariableByName("deferredData") as CInt16; var streamingOption = (chunk.GetVariableByName("streamingOption") as CVariable); if (deferredData != null && deferredData.val != 0) { if (streamingOption != null && streamingOption.ToString() == "ABSO_PartiallyStreamable") { data = ConvertAnimation.Combine((chunk.GetVariableByName("data") as CByteArray).Bytes, File.ReadAllBytes(animFile.FileName + "." + deferredData.val + ".buffer")); } else { data = File.ReadAllBytes(animFile.FileName + "." + deferredData.val + ".buffer"); } } else { data = (chunk.GetVariableByName("data") as CByteArray).Bytes; } using (MemoryStream ms = new MemoryStream(data)) using (BinaryReader br = new BinaryReader(ms)) { foreach (CVector bone in (chunk.GetVariableByName("bones") as CArray).array) { List <uint> currkeyframe = new List <uint>(); List <Quaternion> currorient = new List <Quaternion>(); br.BaseStream.Position = ((bone.GetVariableByName("orientation") as CVector).GetVariableByName("dataAddr") as CUInt32).val; int orientNumFrames = ((bone.GetVariableByName("orientation") as CVector).GetVariableByName("numFrames") as CUInt16).val; for (uint idx = 0; idx < orientNumFrames; idx++) { keyFrame = idx; //keyFrame += numFrames; currkeyframe.Add(keyFrame); //bone.GetVariableByName("position"); string cm = chunk.GetVariableByName("orientationCompressionMethod")?.ToString() ?? ""; if (cm.Contains("ABOCM_PackIn48bitsW")) { byte[] odata = br.ReadBytes(6); ulong bits = (ulong)odata[0] << 40 | (ulong)odata[1] << 32 | (ulong)odata[2] << 24 | (ulong)odata[3] << 16 | (ulong)odata[4] << 8 | odata[5]; ushort[] orients = new ushort[4]; float[] quart = new float[4]; orients[0] = (ushort)((bits & 0x0000FFF000000000) >> 36); orients[1] = (ushort)((bits & 0x0000000FFF000000) >> 24); orients[2] = (ushort)((bits & 0x0000000000FFF000) >> 12); orients[3] = (ushort)((bits & 0x0000000000000FFF)); for (int i = 0; i < orients.Length; i++) { float fVal = (2047.0f - orients[i]) * (1 / 2048.0f); quart[i] = fVal; } quart[3] = -quart[3]; currorient.Add(new Quaternion(quart[0], quart[1], quart[2], quart[3])); } else { byte[] odata = br.ReadBytes(8); ushort[] plain = new ushort[4]; float[] quart = new float[4]; plain[0] = (ushort)BitConverter.ToInt16(odata, 0); plain[1] = (ushort)BitConverter.ToInt16(odata, 2); plain[2] = (ushort)BitConverter.ToInt16(odata, 4); plain[3] = (ushort)BitConverter.ToInt16(odata, 6); for (int i = 0; i < plain.Length; i++) { float fVal = (32767.0f - plain[i]) * (1 / 32768.0f); quart[i] = fVal; } quart[3] = -quart[3]; currorient.Add(new Quaternion(quart[0], quart[1], quart[2], quart[3])); } } orientKeyframes.Add(currkeyframe); orientations.Add(currorient); // TODO: Refactor List <Vector3Df> currposition = new List <Vector3Df>(); currkeyframe = new List <uint>(); int compression = 0; var compr = (bone.GetVariableByName("position") as CVector).GetVariableByName("compression") as CInt8; if (compr != null) { compression = compr.val; } var addr = (bone.GetVariableByName("position") as CVector).GetVariableByName("dataAddr") as CUInt32; if (addr != null) { br.BaseStream.Position = addr.val; } else { br.BaseStream.Position = 0; } var posNumFrames = ((bone.GetVariableByName("position") as CVector).GetVariableByName("numFrames") as CUInt16).val; for (uint idx = 0; idx < posNumFrames; idx++) { keyFrame = idx; //keyFrame += numFrames; currkeyframe.Add(keyFrame); var vec = new CVector3D(); vec.Read(br, compression); Vector3Df pos = new Vector3Df(vec.x.val, vec.y.val, vec.z.val); currposition.Add(pos); } positionsKeyframes.Add(currkeyframe); positions.Add(currposition); List <Vector3Df> currscale = new List <Vector3Df>(); currkeyframe = new List <uint>(); compression = 0; compr = (bone.GetVariableByName("scale") as CVector).GetVariableByName("compression") as CInt8; if (compr != null) { compression = compr.val; } addr = (bone.GetVariableByName("scale") as CVector).GetVariableByName("dataAddr") as CUInt32; if (addr != null) { br.BaseStream.Position = addr.val; } else { br.BaseStream.Position = 0; } var scaleNumFrames = ((bone.GetVariableByName("scale") as CVector).GetVariableByName("numFrames") as CUInt16).val; for (uint idx = 0; idx < scaleNumFrames; idx++) { keyFrame = idx; //keyFrame += numFrames; currkeyframe.Add(keyFrame); var vec = new CVector3D(); vec.Read(br, compression); Vector3Df scale = new Vector3Df(vec.x.val, vec.y.val, vec.z.val); currscale.Add(scale); } scalesKeyframes.Add(currkeyframe); scales.Add(currscale); } } break; } } } }
public void readBuffer(CR2WExportWrapper chunk, int selectedAnimIdx, CR2WFile animFile) { string dataAddrVar = "dataAddr"; uint numFrames = (chunk.GetVariableByName("numFrames") as CUInt32).val; float animDuration = (chunk.GetVariableByName("duration") as CFloat)?.val ?? 1.0f; animationSpeed = numFrames / animDuration; uint keyFrame = 0; byte[] data; //data = (chunk.GetVariableByName("fallbackData") as CByteArray).Bytes; currentAnimName = AnimationNames[selectedAnimIdx].Key; exportData.name = AnimationNames[selectedAnimIdx].Key; exportData.duration = animDuration; exportData.numFrames = numFrames; exportData.dt = (chunk.GetVariableByName("dt") as CFloat)?.val ?? 0.03333333f; var deferredData = chunk.GetVariableByName("deferredData") as CInt16; var streamingOption = (chunk.GetVariableByName("streamingOption") as CVariable); if (deferredData != null && deferredData.val != 0) { if (streamingOption != null && streamingOption.ToString() == "ABSO_PartiallyStreamable") { data = ConvertAnimation.Combine((chunk.GetVariableByName("data") as CByteArray).Bytes, File.ReadAllBytes(animFile.FileName + "." + deferredData.val + ".buffer")); } else { data = File.ReadAllBytes(animFile.FileName + "." + deferredData.val + ".buffer"); } } else { data = (chunk.GetVariableByName("data") as CByteArray).Bytes; } using (MemoryStream ms = new MemoryStream(data)) using (BinaryReader br = new BinaryReader(ms)) { foreach (CVector bone in (chunk.GetVariableByName("bones") as CArray).array) { List <uint> currkeyframe = new List <uint>(); List <Quaternion> currorient = new List <Quaternion>(); List <Vector3Df> currorientEuler = new List <Vector3Df>(); currentBones.Add(bone); br.BaseStream.Position = ((bone.GetVariableByName("orientation") as CVector).GetVariableByName(dataAddrVar) as CUInt32).val; int orientNumFrames = ((bone.GetVariableByName("orientation") as CVector).GetVariableByName("numFrames") as CUInt16).val; for (uint idx = 0; idx < orientNumFrames; idx++) { keyFrame = idx; //keyFrame += numFrames; currkeyframe.Add(keyFrame); //bone.GetVariableByName("position"); byte[] odata = br.ReadBytes(6); ulong bits = (ulong)odata[0] << 40 | (ulong)odata[1] << 32 | (ulong)odata[2] << 24 | (ulong)odata[3] << 16 | (ulong)odata[4] << 8 | odata[5]; ushort[] orients = new ushort[4]; float[] quart = new float[4]; orients[0] = (ushort)((bits & 0x0000FFF000000000) >> 36); orients[1] = (ushort)((bits & 0x0000000FFF000000) >> 24); orients[2] = (ushort)((bits & 0x0000000000FFF000) >> 12); orients[3] = (ushort)((bits & 0x0000000000000FFF)); for (int i = 0; i < orients.Length; i++) { float fVal = (2047.0f - orients[i]) * (1 / 2048.0f); quart[i] = fVal; } quart[3] = -quart[3]; Quaternion orientation = new Quaternion(quart[0], quart[1], quart[2], quart[3]); currorient.Add(orientation); Vector3Df euler = orientation.ToEuler(); currorientEuler.Add(euler); //Console.WriteLine("Euler : x=%f, y=%f, z=%f", euler.X, euler.Y, euler.Z); } orientKeyframes.Add(currkeyframe); orientations.Add(currorient); orientationsEuler.Add(currorientEuler); // TODO: Refactor List <Vector3Df> currposition = new List <Vector3Df>(); currkeyframe = new List <uint>(); int compression = 0; var compr = (bone.GetVariableByName("position") as CVector).GetVariableByName("compression") as CInt8; if (compr != null) { compression = compr.val; } var addr = (bone.GetVariableByName("position") as CVector).GetVariableByName(dataAddrVar) as CUInt32; if (addr != null) { br.BaseStream.Position = addr.val; } else { br.BaseStream.Position = 0; } var posNumFrames = ((bone.GetVariableByName("position") as CVector).GetVariableByName("numFrames") as CUInt16).val; for (uint idx = 0; idx < posNumFrames; idx++) { keyFrame = idx; //keyFrame += numFrames; currkeyframe.Add(keyFrame); var vec = new CVector3D(); vec.Read(br, compression); Vector3Df pos = new Vector3Df(vec.x.val, vec.y.val, vec.z.val); currposition.Add(pos); } positionsKeyframes.Add(currkeyframe); positions.Add(currposition); List <Vector3Df> currscale = new List <Vector3Df>(); currkeyframe = new List <uint>(); compression = 0; compr = (bone.GetVariableByName("scale") as CVector).GetVariableByName("compression") as CInt8; if (compr != null) { compression = compr.val; } addr = (bone.GetVariableByName("scale") as CVector).GetVariableByName(dataAddrVar) as CUInt32; if (addr != null) { br.BaseStream.Position = addr.val; } else { br.BaseStream.Position = 0; } var scaleNumFrames = ((bone.GetVariableByName("scale") as CVector).GetVariableByName("numFrames") as CUInt16).val; for (uint idx = 0; idx < scaleNumFrames; idx++) { keyFrame = idx; //keyFrame += numFrames; currkeyframe.Add(keyFrame); var vec = new CVector3D(); vec.Read(br, compression); Vector3Df scale = new Vector3Df(vec.x.val, vec.y.val, vec.z.val); currscale.Add(scale); } scalesKeyframes.Add(currkeyframe); scales.Add(currscale); } } }