public void Dispose() { DbgPrimDrawer?.Dispose(); ChrAsm?.Dispose(); Skeleton = null; AnimContainer = null; MainMesh?.Dispose(); // Do not need to dispose DummyPolyMan because it goes // stores its primitives in the model's DbgPrimDrawer }
protected NewHavokAnimation(HavokAnimationData data, NewAnimSkeleton skeleton, NewAnimationContainer container) { this.data = data; ParentContainer = container; Skeleton = skeleton; lock (_lock_boneMatrixStuff) { blendableTransforms = new NewBlendableTransform[skeleton.HkxSkeleton.Count]; } RotMatrixAtStartOfAnim = ParentContainer.MODEL.CurrentRootMotionRotation; }
public NewHavokAnimation(HavokAnimationData data, NewAnimSkeleton_HKX skeleton, NewAnimationContainer container) { this.data = data; ParentContainer = container; Skeleton = skeleton; lock (_lock_boneMatrixStuff) { blendableTransforms = new NewBlendableTransform[skeleton.HkxSkeleton.Count]; } RootMotion = new RootMotionDataPlayer(data.RootMotion); }
protected NewHavokAnimation(HavokAnimationData data, NewAnimSkeleton skeleton, NewAnimationContainer container) { this.data = data; ParentContainer = container; Skeleton = skeleton; lock (_lock_boneMatrixStuff) { blendableTransforms = new List <NewBlendableTransform>(); for (int i = 0; i < skeleton.HkxSkeleton.Count; i++) { blendableTransforms.Add(NewBlendableTransform.Identity); } } RotMatrixAtStartOfAnim = ParentContainer.MODEL.CurrentRootMotionRotation; }
public static void NukeEntireRemoSystemAndGoBackToNormalDSAnimStudio() { RemoEventSim.Clear(); ViewportInteractor = null; AnimContainer = null; CurrentCutSibcam = null; CurrentCut = null; RemoName = "scnXXXXXX"; remoCutsLoaded.Clear(); remoCutHkxDict.Clear(); remoCutSibcamDict.Clear(); CurrentCutCameraMotion = null; CurrentCutFoV = null; GFX.World.ClearCustomCameraView_Override(); GFX.World.ClearCustomCameraView_Additive(); CurrentCutHits.Clear(); CurrentCutOtherBlocks.Clear(); DisposeAllModels(); }
public NewHavokAnimation_InterleavedUncompressed(string name, NewAnimSkeleton skeleton, HKX.HKADefaultAnimatedReferenceFrame refFrame, HKX.HKAAnimationBinding binding, HKX.HKAInterleavedUncompressedAnimation anim, NewAnimationContainer container) : base(new HavokAnimationData_InterleavedUncompressed(name, skeleton.OriginalHavokSkeleton, refFrame, binding, anim), skeleton, container) { }
public Model(IProgress <double> loadingProgress, string name, IBinder chrbnd, int modelIndex, IBinder anibnd, IBinder texbnd = null, List <string> additionalTpfNames = null, string possibleLooseTpfFolder = null, int baseDmyPolyID = 0, bool ignoreStaticTransforms = false, IBinder additionalTexbnd = null) : this() { Name = name; List <BinderFile> flverFileEntries = new List <BinderFile>(); List <TPF> tpfsUsed = new List <TPF>(); if (additionalTpfNames != null) { foreach (var t in additionalTpfNames) { if (File.Exists(t)) { tpfsUsed.Add(TPF.Read(t)); } } } FLVER2 flver = null; foreach (var f in chrbnd.Files) { var nameCheck = f.Name.ToLower(); if (flver == null && (nameCheck.EndsWith(".flver") || FLVER2.Is(f.Bytes))) { if (nameCheck.EndsWith($"_{modelIndex}.flver") || modelIndex == 0) { flver = FLVER2.Read(f.Bytes); } } else if (nameCheck.EndsWith(".tpf") || TPF.Is(f.Bytes)) { tpfsUsed.Add(TPF.Read(f.Bytes)); } else if (anibnd == null && nameCheck.EndsWith(".anibnd")) { if (nameCheck.EndsWith($"_{modelIndex}.anibnd") || modelIndex == 0) { if (BND3.Is(f.Bytes)) { anibnd = BND3.Read(f.Bytes); } else { anibnd = BND4.Read(f.Bytes); } } } } if (flver == null) { throw new ArgumentException("No FLVERs found within CHRBND."); } LoadFLVER2(flver, useSecondUV: false, baseDmyPolyID, ignoreStaticTransforms); loadingProgress.Report(1.0 / 4.0); AnimContainer = new NewAnimationContainer(this); if (anibnd != null) { LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_ANIBND", $"Loading ANIBND for {Name}...", innerProg => { AnimContainer.LoadBaseANIBND(anibnd, innerProg); }); } else { // This just messes up the model cuz they're already in // reference pose, whoops //Skeleton.ApplyBakedFlverReferencePose(); } loadingProgress.Report(2.0 / 3.0); if (tpfsUsed.Count > 0) { LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_TPFs", $"Loading TPFs for {Name}...", innerProg => { for (int i = 0; i < tpfsUsed.Count; i++) { TexturePool.AddTpf(tpfsUsed[i]); MainMesh.TextureReloadQueued = true; innerProg.Report(1.0 * i / tpfsUsed.Count); } MainMesh.TextureReloadQueued = true; }); } loadingProgress.Report(3.0 / 4.0); if (texbnd != null) { LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_TEXBND", $"Loading TEXBND for {Name}...", innerProg => { TexturePool.AddTextureBnd(texbnd, innerProg); MainMesh.TextureReloadQueued = true; }); } loadingProgress.Report(3.5 / 4.0); if (additionalTexbnd != null) { LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_AdditionalTEXBND", $"Loading extra TEXBND for {Name}...", innerProg => { TexturePool.AddTextureBnd(additionalTexbnd, innerProg); MainMesh.TextureReloadQueued = true; }); } loadingProgress.Report(3.9 / 4.0); if (possibleLooseTpfFolder != null && Directory.Exists(possibleLooseTpfFolder)) { TexturePool.AddTPFFolder(possibleLooseTpfFolder); MainMesh.TextureReloadQueued = true; } MainMesh.TextureReloadQueued = true; loadingProgress.Report(1.0); }
private static void LoadRemoHKX(byte[] hkxBytes, string animName) { Scene.DisableModelDrawing(); Scene.DisableModelDrawing2(); HKX.HKAAnimationBinding hk_binding = null; HKX.HKASplineCompressedAnimation hk_anim = null; HKX.HKASkeleton hk_skeleton = null; if (remoCutsLoaded.ContainsKey(animName)) { hk_binding = remoCutsLoaded[animName].hk_binding; hk_anim = remoCutsLoaded[animName].hk_anim; hk_skeleton = remoCutsLoaded[animName].hk_skeleton; } else { var hkx = HKX.Read(hkxBytes, HKX.HKXVariation.HKXDS1, false); foreach (var o in hkx.DataSection.Objects) { if (o is HKX.HKASkeleton asSkeleton) { hk_skeleton = asSkeleton; } else if (o is HKX.HKAAnimationBinding asBinding) { hk_binding = asBinding; } else if (o is HKX.HKASplineCompressedAnimation asAnim) { hk_anim = asAnim; } } remoCutsLoaded.Add(animName, new RemoCutCache() { hk_binding = hk_binding, hk_anim = hk_anim, hk_skeleton = hk_skeleton, }); } var animContainer = new NewAnimationContainer(); AnimContainer = animContainer; animContainer.ClearAnimations(); animContainer.Skeleton.LoadHKXSkeleton(hk_skeleton); var testIdleAnimThing = new NewHavokAnimation_SplineCompressed(animName, animContainer.Skeleton, null, hk_binding, hk_anim, animContainer); animContainer.AddNewAnimation(animName, testIdleAnimThing); animContainer.CurrentAnimationName = animName; var modelNames = animContainer.Skeleton.TopLevelHkxBoneIndices.Select(b => animContainer.Skeleton.HkxSkeleton[b].Name).ToList(); CurrentCutHits.Clear(); CurrentCutOtherBlocks.Clear(); lock (Scene._lock_ModelLoad_Draw) { Scene.Models.Clear(); } foreach (var name in modelNames) { Model mdl = null; if (!remoModelDict.ContainsKey(name)) { PauseStreamBGM(); if (name.StartsWith("c")) { string shortName = name.Substring(0, 5); mdl = GameDataManager.LoadCharacter(shortName); FmodManager.LoadInterrootFEV(shortName); if (mdl.IS_PLAYER) { ViewportInteractor.InitializeCharacterModel(mdl, isRemo: true); } } else if (name.StartsWith("o")) { string shortName = name.Substring(0, 5); mdl = GameDataManager.LoadObject(shortName); FmodManager.LoadInterrootFEV(shortName); } else if (name.StartsWith("m")) { mdl = GameDataManager.LoadMapPiece(AreaInt, BlockInt, 0, 0, int.Parse(name.Substring(1, 4))); } else if (name.StartsWith("A")) { int a = int.Parse(name.Substring(1, 2)); int b = int.Parse(name.Substring(4, 2)); if (b != BlockInt && !CurrentCutOtherBlocks.Contains(b)) { CurrentCutOtherBlocks.Add(b); } mdl = GameDataManager.LoadMapPiece(a, b, 0, 0, int.Parse(name.Substring(8, 4))); } else if (name.StartsWith("d")) { // TODO // Dummy entity e.g. 'd0000_0000'. Apparently just acts as a single DummyPoly? mdl = GameDataManager.LoadCharacter("c1000"); mdl.RemoDummyTransformPrim = new DebugPrimitives.DbgPrimWireArrow(name, new Transform(Microsoft.Xna.Framework.Matrix.CreateScale(0.25f) * mdl.CurrentTransform.WorldMatrix), Microsoft.Xna.Framework.Color.Lime) { Category = DebugPrimitives.DbgPrimCategory.AlwaysDraw }; mdl.RemoDummyTransformTextPrint = new StatusPrinter(null, Microsoft.Xna.Framework.Color.Lime); mdl.RemoDummyTransformTextPrint.AppendLine(name); mdl.IS_REMO_DUMMY = true; } else if (name.StartsWith("h")) { // Collision. CurrentCutHits.Add(name); } else { throw new NotImplementedException($"Cannot tell what object type '{name}' is in remo HKX"); } if (mdl != null) { mdl.Name = name; remoModelDict.Add(name, mdl); } } else { mdl = remoModelDict[name]; } if (mdl != null) { mdl.AnimContainer = animContainer; mdl.IsRemoModel = true; mdl.Name = name; mdl.SkeletonFlver.RevertToReferencePose(); mdl.SkeletonFlver.MapToSkeleton(animContainer.Skeleton, isRemo: true); mdl.UpdateSkeleton(); lock (Scene._lock_ModelLoad_Draw) { Scene.Models.Add(mdl); } } } var msbName = GameDataManager.GetInterrootPath($@"map\MapStudio\m{AreaInt:D2}_{BlockInt:D2}_00_00.msb"); var msb = MSB1.Read(msbName); Vector3 mapOffset = msb.Events.MapOffsets.FirstOrDefault()?.Position.ToXna() ?? Vector3.Zero; uint dg1 = 0, dg2 = 0, dg3 = 0, dg4 = 0; foreach (var hitName in CurrentCutHits) { var hit = msb.Parts.Collisions.FirstOrDefault(h => h.Name == hitName); dg1 |= hit.DrawGroups[0]; dg2 |= hit.DrawGroups[1]; dg3 |= hit.DrawGroups[2]; dg4 |= hit.DrawGroups[3]; } bool IsThingVisible(uint[] drawGroups) { return(((drawGroups[0] & dg1) == dg1) && ((drawGroups[1] & dg2) == dg2) && ((drawGroups[2] & dg3) == dg3) && ((drawGroups[3] & dg4) == dg4)); } foreach (var mapPiece in msb.Parts.MapPieces) { var thisEntityName = CurrentCutOtherBlocks.Count > 0 ? $"A{AreaInt:D2}B{BlockInt:D2}_{mapPiece.Name}" : mapPiece.Name; if (IsThingVisible(mapPiece.DrawGroups)) { Model mdl = null; if (remoModelDict.ContainsKey(thisEntityName)) { mdl = remoModelDict[thisEntityName]; mdl.AnimContainer = animContainer; mdl.IsRemoModel = true; mdl.SkeletonFlver.RevertToReferencePose(); mdl.SkeletonFlver.MapToSkeleton(animContainer.Skeleton, isRemo: true); mdl.UpdateSkeleton(); lock (Scene._lock_ModelLoad_Draw) { Scene.Models.Add(mdl); } continue; } mdl = GameDataManager.LoadMapPiece(AreaInt, BlockInt, 0, 0, int.Parse(mapPiece.ModelName.Substring(1, 4))); mdl.AnimContainer = animContainer; mdl.IsRemoModel = true; mdl.Name = thisEntityName; mdl.SkeletonFlver.RevertToReferencePose(); mdl.StartTransform.Position = mapPiece.Position.ToXna() - mapOffset; mdl.StartTransform.Rotation = Utils.EulerToQuaternion((mapPiece.Rotation * (SapMath.Pi / 180f)).ToXna()); mdl.StartTransform.Scale = mapPiece.Scale.ToXna(); mdl.CurrentTransform = mdl.StartTransform; mdl.IS_REMO_NOTSKINNED = true; mdl.SkeletonFlver.MapToSkeleton(animContainer.Skeleton, isRemo: true); mdl.UpdateSkeleton(); lock (Scene._lock_ModelLoad_Draw) { Scene.Models.Add(mdl); } remoModelDict.Add(thisEntityName, mdl); } } foreach (var mapPiece in msb.Parts.Objects) { var thisEntityName = CurrentCutOtherBlocks.Count > 0 ? $"A{AreaInt:D2}B{BlockInt:D2}_{mapPiece.Name}" : mapPiece.Name; if (IsThingVisible(mapPiece.DrawGroups)) { Model mdl = null; if (remoModelDict.ContainsKey(thisEntityName)) { mdl = remoModelDict[thisEntityName]; mdl.AnimContainer = animContainer; mdl.IsRemoModel = true; mdl.SkeletonFlver.RevertToReferencePose(); mdl.SkeletonFlver.MapToSkeleton(animContainer.Skeleton, isRemo: true); mdl.UpdateSkeleton(); lock (Scene._lock_ModelLoad_Draw) { Scene.Models.Add(mdl); } continue; } mdl = GameDataManager.LoadObject(mapPiece.ModelName); mdl.AnimContainer = animContainer; mdl.IsRemoModel = true; mdl.Name = thisEntityName; mdl.StartTransform.Position = mapPiece.Position.ToXna() - mapOffset; mdl.StartTransform.Rotation = Utils.EulerToQuaternion((mapPiece.Rotation * (SapMath.Pi / 180f)).ToXna()); mdl.StartTransform.Scale = mapPiece.Scale.ToXna(); mdl.CurrentTransform = mdl.StartTransform; mdl.IS_REMO_NOTSKINNED = true; mdl.SkeletonFlver.RevertToReferencePose(); mdl.SkeletonFlver.MapToSkeleton(animContainer.Skeleton, isRemo: true); mdl.UpdateSkeleton(); lock (Scene._lock_ModelLoad_Draw) { Scene.Models.Add(mdl); } remoModelDict.Add(thisEntityName, mdl); } } lock (Scene._lock_ModelLoad_Draw) { Scene.Models = Scene.Models.OrderBy(m => m.IS_PLAYER ? 0 : 1).ToList(); } CurrentCut = animName; animContainer.ScrubRelative(0); List <Model> mdls = null; lock (Scene._lock_ModelLoad_Draw) { mdls = Scene.Models.ToList(); } foreach (var m in mdls) { m.UpdateSkeleton(); } GFX.World.Update(0); Scene.EnableModelDrawing(); Scene.EnableModelDrawing2(); ResumeStreamedBGM(); ViewportInteractor.Graph.MainScreen.REMO_HOTFIX_REQUEST_PLAY_RESUME_NEXT_FRAME = true; ViewportInteractor.Graph.MainScreen.HardReset(); }