void OpenBoneRemappingTool() { var targetSkeletonName = _meshNode.MeshModel.ParentSkeletonName; var existingSkeletonMeshNode = _meshNode.GetParentModel(); var existingSkeltonName = existingSkeletonMeshNode.Model.Header.SkeletonName; RemappedAnimatedBoneConfiguration config = new RemappedAnimatedBoneConfiguration(); var existingSkeletonFile = _animLookUp.GetSkeletonFileFromName(_pfs, targetSkeletonName); config.MeshSkeletonName = targetSkeletonName; config.MeshBones = AnimatedBone.CreateFromSkeleton(existingSkeletonFile, AnimatedBones.Select(x => x.BoneIndex).ToList()); var newSkeletonFile = _animLookUp.GetSkeletonFileFromName(_pfs, existingSkeltonName); config.ParnetModelSkeletonName = existingSkeltonName; config.ParentModelBones = AnimatedBone.CreateFromSkeleton(newSkeletonFile); AnimatedBlendIndexRemappingWindow window = new AnimatedBlendIndexRemappingWindow() { DataContext = new AnimatedBlendIndexRemappingViewModel(config) }; if (window.ShowDialog() == true) { var remapping = config.MeshBones.First().BuildRemappingList(); _componentManager.GetComponent <CommandExecutor>().ExecuteCommand(new RemapBoneIndexesCommand(_meshNode, remapping, config.ParnetModelSkeletonName, config.MoveMeshToFit, new GameSkeleton(existingSkeletonFile, null), new GameSkeleton(newSkeletonFile, null))); } }
public static void ShowView(List <ISelectable> meshesToFit, IComponentManager componentManager, SkeletonAnimationLookUpHelper skeletonHelper, PackFileService pfs) { var sceneManager = componentManager.GetComponent <SceneManager>(); var resourceLib = componentManager.GetComponent <ResourceLibary>(); var animCollection = componentManager.GetComponent <AnimationsContainerComponent>(); var meshNodes = meshesToFit .Where(x => x is Rmv2MeshNode) .Select(x => x as Rmv2MeshNode) .ToList(); var allSkeltonNames = meshNodes .Select(x => x.MeshModel.ParentSkeletonName) .Distinct(); if (allSkeltonNames.Count() != 1) { throw new Exception("Unexpected number of skeletons. This tool only works for one skeleton"); } var currentSkeletonName = allSkeltonNames.First(); var currentSkeletonFile = skeletonHelper.GetSkeletonFileFromName(pfs, currentSkeletonName); var usedBoneIndexes = meshNodes .SelectMany(x => x.Geometry.GetUniqeBlendIndices()) .Distinct() .Select(x => (int)x) .ToList(); var targetSkeleton = componentManager.GetComponent <IEditableMeshResolver>().GeEditableMeshRootNode().Skeleton; var targetSkeletonFile = skeletonHelper.GetSkeletonFileFromName(pfs, targetSkeleton.Name); RemappedAnimatedBoneConfiguration config = new RemappedAnimatedBoneConfiguration(); config.ParnetModelSkeletonName = targetSkeleton.Name; config.ParentModelBones = AnimatedBone.CreateFromSkeleton(targetSkeletonFile); config.MeshSkeletonName = currentSkeletonName; config.MeshBones = AnimatedBone.CreateFromSkeleton(currentSkeletonFile, usedBoneIndexes); var containingWindow = new Window(); containingWindow.Title = "Texture Preview Window"; containingWindow.DataContext = new MeshFitterViewModel(config, meshNodes, targetSkeleton.AnimationProvider.Skeleton, currentSkeletonFile, componentManager); containingWindow.Content = new MeshFitterView(); containingWindow.Closed += ContainingWindow_Closed; containingWindow.Show(); }
public MeshFitterViewModel(RemappedAnimatedBoneConfiguration configuration, List <Rmv2MeshNode> meshNodes, GameSkeleton targetSkeleton, AnimationFile currentSkeletonFile, IComponentManager componentManager) : base(configuration) { _meshNodes = meshNodes; _dwarfSkeleton = targetSkeleton; _componentManager = componentManager; _animationPlayer = _componentManager.GetComponent <AnimationsContainerComponent>().RegisterAnimationPlayer(new AnimationPlayer(), "Temp animation rerig"); _humanoid01Skeleton = new GameSkeleton(currentSkeletonFile, _animationPlayer); // Build empty animation _animationClip = new AnimationClip(); _animationClip.DynamicFrames.Add(new AnimationClip.KeyFrame()); for (int i = 0; i < _humanoid01Skeleton.BoneCount; i++) { _animationClip.DynamicFrames[0].Rotation.Add(_humanoid01Skeleton.Rotation[i]); _animationClip.DynamicFrames[0].Position.Add(_humanoid01Skeleton.Translation[i]); _animationClip.DynamicFrames[0].Scale.Add(Vector3.One); _animationClip.RotationMappings.Add(new AnimationFile.AnimationBoneMapping(i)); _animationClip.TranslationMappings.Add(new AnimationFile.AnimationBoneMapping(i)); } _animationPlayer.SetAnimation(_animationClip, _humanoid01Skeleton); _animationPlayer.Play(); var resourceLib = _componentManager.GetComponent <ResourceLibary>(); _currentSkeletonNode = new SkeletonNode(resourceLib.Content, new SimpleSkeletonProvider(_humanoid01Skeleton)); _componentManager.GetComponent <SceneManager>().RootNode.AddObject(_currentSkeletonNode); _oldAnimationPlayer = _meshNodes.First().AnimationPlayer; foreach (var mesh in _meshNodes) { mesh.AnimationPlayer = _animationPlayer; } }