public InteropAnimation(PapFile pap) { _UnmanagedPtr = Interop.loadAnimation(pap.Animations.Length, pap.HavokData.Length, pap.HavokData, pap.Animations.Select(_ => _.Name).ToArray()); }
public AnimationContainer(Skeleton skeleton, PapFile file) { Skeleton = skeleton; File = file; _AnimationNameMap = file.Animations.ToDictionary(_ => _.Name, _ => _.Index); _UnmanagedPtr = HavokInterop.Execute(() => Interop.loadAnimationContainer(skeleton._UnmanagedPtr, file.HavokData, file.HavokData.Length)); var numAnim = HavokInterop.Execute(() => Interop.getNumAnimations(_UnmanagedPtr)); if (AnimationCount != numAnim) throw new System.IO.InvalidDataException(); }
public AnimationContainer(Skeleton skeleton, PapFile file) { Skeleton = skeleton; File = file; _AnimationNameMap = file.Animations.ToDictionary(_ => _.Name, _ => _.Index); _UnmanagedPtr = HavokInterop.Execute(() => Interop.loadAnimationContainer(skeleton._UnmanagedPtr, file.HavokData, file.HavokData.Length)); var numAnim = HavokInterop.Execute(() => Interop.getNumAnimations(_UnmanagedPtr)); if (AnimationCount != numAnim) { throw new System.IO.InvalidDataException(); } }
public static int ExportFbx(string fileName, Mesh[] ma, Skeleton skele, PapFile pap, int mode = 0) { ModelDefinition thisDefinition = ma[0].Model.Definition; // Create bonemap in the same manner that hkAnimationInterop does var nameMap = new Dictionary <string, int>(); for (var i = 0; i < skele.BoneNames.Length; ++i) { nameMap.Add(skele.BoneNames[i], i); } var boneMap = thisDefinition.BoneNames.Select(n => nameMap[n]).ToArray(); // Get mesh ptrs IntPtr[] meshes = new IntPtr[ma.Length]; for (int i = 0; i < meshes.Length; i++) { InteropMesh m = new InteropMesh(ma[i]); meshes[i] = m._UnmanagedPtr; } // Null pap handling byte[] anims = pap == null ? new byte[0] : pap.HavokData; string[] animNames = pap == null ? new string[0] : pap.Animations.Select(_ => _.Name).ToArray(); int result = 0; try { result = Interop.exportFbx(meshes, meshes.Length, skele.File.HavokData, skele.File.HavokData.Length, anims, anims.Length, animNames, boneMap, boneMap.Length, fileName, mode); } catch (Win32Exception e) { System.Diagnostics.Debug.WriteLine("Native error code " + e.NativeErrorCode + " encountered."); return(1); } catch (Exception e) { if (e is AccessViolationException || e is SEHException) { System.Diagnostics.Debug.WriteLine("Access violation with\n" + "Model:\t" + thisDefinition.File.Path + "\n" + "Pap:\t" + pap?.File.Path + "\n" + "Skele:\t" + skele.File.File.Path + "\n"); } return(1); } return(result); //todo: materials/textures }
private void OnExport() { Skeleton skele; ModelDefinition model; ImcVariant variant; int m, b; if (!TryGetModel(out skele, out model, out variant, out m, out b)) { return; } var papPath = string.Format(PapPathFormat, m, b); PapFile pap = null; // We have animation if (Parent.Realm.Packs.TryGetFile(papPath, out var papFileBase)) { pap = new PapFile(papFileBase); } VistaSaveFileDialog dialog = new VistaSaveFileDialog { OverwritePrompt = true, Title = "Export FBX to...", FileName = SelectedEntry.ToString().Replace(" / ", "_"), DefaultExt = ".fbx", Filter = "Autodesk FBX Files|*.fbx" }; bool?result = dialog.ShowDialog(); if (result.HasValue && result.Value && !string.IsNullOrEmpty(dialog.FileName)) { Task.Run(() => { // Set IsExporting for feedback IsExporting = true; int exportResult = FbxExport.ExportFbx(dialog.FileName, model.GetModel(0).Meshes, skele, pap); IsExporting = false; if (exportResult == 0) { System.Windows.MessageBox.Show("The export of " + Path.GetFileName(dialog.FileName) + " has completed.", "Export Complete", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, System.Windows.MessageBoxOptions.DefaultDesktopOnly); } else { System.Windows.MessageBox.Show("The export of " + Path.GetFileName(dialog.FileName) + " has failed.", "Export Failed", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, System.Windows.MessageBoxOptions.DefaultDesktopOnly); } }); } }