Exemplo n.º 1
0
 public WadMeshBoneNode(WadMeshBoneNode parent, WadMesh wadMesh, WadBone bone)
 {
     Name            = bone.Name;
     WadMesh         = wadMesh;
     Bone            = bone;
     GlobalTransform = Matrix4x4.Identity;
     Parent          = parent;
 }
Exemplo n.º 2
0
        private void ReplaceExistingBone(WadMesh mesh, WadMeshBoneNode node)
        {
            node.Bone.Mesh = mesh;
            node.WadMesh   = mesh;

            // Reload skeleton
            _lastBone = node;
            treeSkeleton.Nodes.AddRange(LoadSkeleton());
            ExpandSkeleton();

            panelRendering.Skeleton = _bones;
            panelRendering.Invalidate();
        }
Exemplo n.º 3
0
        public FormSkeletonEditor(WadToolClass tool, DeviceManager manager, Wad2 wad, WadMoveableId moveableId)
        {
            InitializeComponent();

            _wad      = wad;
            _moveable = _wad.Moveables[moveableId].Clone();
            _tool     = tool;

            panelRendering.Configuration = _tool.Configuration;
            panelRendering.InitializeRendering(tool, manager);

            _tool.EditorEventRaised += Tool_EditorEventRaised;

            WadMoveable skin;
            var         skinId = new WadMoveableId(TrCatalog.GetMoveableSkin(_tool.DestinationWad.GameVersion, _moveable.Id.TypeId));

            if (_tool.DestinationWad.Moveables.ContainsKey(skinId))
            {
                skin = _tool.DestinationWad.Moveables[skinId];
            }
            else
            {
                skin = _tool.DestinationWad.Moveables[_moveable.Id];
            }

            // Clone the skeleton and load it
            _bones = new List <WadMeshBoneNode>();
            for (int i = 0; i < _moveable.Bones.Count; i++)
            {
                var boneNode = new WadMeshBoneNode(null, skin.Bones[i].Mesh, _moveable.Bones[i]);
                boneNode.Bone.Translation = _moveable.Bones[i].Translation;
                boneNode.GlobalTransform  = Matrix4x4.Identity;
                _bones.Add(boneNode);
            }

            treeSkeleton.Nodes.AddRange(LoadSkeleton());
            ExpandSkeleton();

            panelRendering.Skeleton = _bones;

            if (treeSkeleton.SelectedNodes.Count <= 0)
            {
                treeSkeleton.SelectNode(treeSkeleton.Nodes[0]);
                panelRendering.SelectedNode = (WadMeshBoneNode)treeSkeleton.SelectedNodes[0].Tag;
            }

            panelRendering.Invalidate();
        }
Exemplo n.º 4
0
        private void ToggleBonePush()
        {
            if (treeSkeleton.SelectedNodes.Count == 0)
            {
                return;
            }
            var theNode = (WadMeshBoneNode)treeSkeleton.SelectedNodes[0].Tag;

            // Change opcode
            theNode.Bone.OpCode = theNode.Bone.OpCode ^ WadLinkOpcode.Push;

            // Reload skeleton
            _lastBone = theNode;
            treeSkeleton.Nodes.AddRange(LoadSkeleton());
            ExpandSkeleton();

            panelRendering.Skeleton = _bones;
            panelRendering.Invalidate();
        }
Exemplo n.º 5
0
        private void MoveBoneDown()
        {
            if (treeSkeleton.SelectedNodes.Count == 0)
            {
                return;
            }
            var theNode = (WadMeshBoneNode)treeSkeleton.SelectedNodes[0].Tag;

            // Swap bones
            int oldIndex = _bones.IndexOf(theNode);

            if (oldIndex == _bones.Count - 1)
            {
                return;
            }
            WadMeshBoneNode temp = _bones[oldIndex];

            _bones[oldIndex]     = _bones[oldIndex + 1];
            _bones[oldIndex + 1] = temp;

            // Fix keyframes
            foreach (var animation in _moveable.Animations)
            {
                foreach (var kf in animation.KeyFrames)
                {
                    for (int i = 0; i < kf.Angles.Count; i++)
                    {
                        var tempAngles = kf.Angles[oldIndex];
                        kf.Angles[oldIndex]     = kf.Angles[oldIndex + 1];
                        kf.Angles[oldIndex + 1] = tempAngles;
                    }
                }
            }

            // Reload skeleton
            _lastBone = temp;
            treeSkeleton.Nodes.AddRange(LoadSkeleton());
            ExpandSkeleton();

            panelRendering.Skeleton = _bones;
            panelRendering.Invalidate();
        }
Exemplo n.º 6
0
        private void InsertNewBone(WadMesh mesh, WadMeshBoneNode parentNode)
        {
            // Create the new bone
            var bone = new WadBone();

            bone.Mesh   = mesh;
            bone.Name   = "Bone_" + mesh.Name;
            bone.OpCode = WadLinkOpcode.NotUseStack;

            // Create the new node
            var node = new WadMeshBoneNode(parentNode, mesh, bone);

            // Insert the bone
            int index = _bones.IndexOf(parentNode);

            _bones.Insert(index + 1, node);

            // Special case: we're inserting root node
            if (_bones.Count == 1 && index == -1)
            {
                index = 0;
            }

            // Add angles to animations
            foreach (var animation in _moveable.Animations)
            {
                foreach (var kf in animation.KeyFrames)
                {
                    kf.Angles.Insert(index, new WadKeyFrameRotation());
                }
            }

            // Reload skeleton
            _lastBone = node;
            treeSkeleton.Nodes.AddRange(LoadSkeleton());
            ExpandSkeleton();

            panelRendering.Skeleton = _bones;
            panelRendering.Invalidate();
        }
Exemplo n.º 7
0
        private void DeleteBone()
        {
            if (treeSkeleton.SelectedNodes.Count == 0)
            {
                return;
            }
            var theNode = (WadMeshBoneNode)treeSkeleton.SelectedNodes[0].Tag;

            if (DarkMessageBox.Show(this, "Are you really sure to delete bone '" + theNode.Bone.Name + "'?" +
                                    "Angles associated to this bone will be deleted from all keyframes of all animations.",
                                    "Delete bone",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }

            // Delete the bone
            int index = _bones.IndexOf(theNode);

            _bones.RemoveAt(index);

            // Remove angles from animations
            foreach (var animation in _moveable.Animations)
            {
                foreach (var kf in animation.KeyFrames)
                {
                    kf.Angles.RemoveAt(index);
                }
            }

            // Reload skeleton
            _lastBone = null;
            treeSkeleton.Nodes.AddRange(LoadSkeleton());
            ExpandSkeleton();

            panelRendering.Skeleton = _bones;
            panelRendering.Invalidate();
        }