Esempio n. 1
0
        private void RemoveBone(string name)
        {
            var ragdoll          = (Ragdoll)Values[0];
            var bodies           = ragdoll.Children.Where(x => x is RigidBody && x.IsActive);
            var joints           = bodies.SelectMany(y => y.Children).Where(z => z is Joint && z.IsActive).Cast <Joint>();
            var body             = bodies.First(x => x.Name == name);
            var replacementJoint = joints.FirstOrDefault(x => x.Parent == body && x.Target != null);

            // Fix joints using this bone
            foreach (var joint in joints)
            {
                if (joint.Target == body)
                {
                    if (replacementJoint != null)
                    {
                        // Swap the joint target to the parent of the removed body to keep ragdoll connected
                        using (new UndoBlock(Presenter.Undo, joint, "Fix joint"))
                        {
                            joint.Target           = replacementJoint.Target;
                            joint.EnableAutoAnchor = true;
                        }
                    }
                    else
                    {
                        // Remove joint that will no longer be valid
                        var action = new Actions.DeleteActorsAction(new List <SceneGraphNode> {
                            SceneGraphFactory.FindNode(joint.ID)
                        });
                        action.Do();
                        Presenter.Undo?.AddAction(action);
                    }
                }
            }

            // Remove body
            {
                var action = new Actions.DeleteActorsAction(new List <SceneGraphNode> {
                    SceneGraphFactory.FindNode(body.ID)
                });
                action.Do();
                Presenter.Undo?.AddAction(action);
            }
        }
Esempio n. 2
0
        private void RebuildBone(string name)
        {
            var ragdoll       = (Ragdoll)Values[0];
            var animatedModel = (AnimatedModel)ragdoll.Parent;

            // Remove existing body
            var bodies = ragdoll.Children.Where(x => x is RigidBody && x.IsActive);
            var body   = bodies.FirstOrDefault(x => x.Name == name);

            if (body != null)
            {
                var action = new Actions.DeleteActorsAction(new List <SceneGraphNode> {
                    SceneGraphFactory.FindNode(body.ID)
                });
                action.Do();
                Presenter.Undo?.AddAction(action);
            }

            // Build ragdoll
            SceneGraph.Actors.AnimatedModelNode.BuildRagdoll(animatedModel, new AnimatedModelNode.RebuildOptions(), ragdoll, name);
        }
Esempio n. 3
0
        private void Rebuild(AnimatedModelNode.RebuildOptions options)
        {
            var ragdoll       = (Ragdoll)Values[0];
            var animatedModel = (AnimatedModel)ragdoll.Parent;

            // Remove existing bodies
            var bodies  = ragdoll.Children.Where(x => x is RigidBody && x.IsActive);
            var actions = new List <IUndoAction>();

            foreach (var body in bodies)
            {
                var action = new Actions.DeleteActorsAction(new List <SceneGraphNode> {
                    SceneGraphFactory.FindNode(body.ID)
                });
                action.Do();
                actions.Add(action);
            }
            Presenter.Undo?.AddAction(new MultiUndoAction(actions));

            // Build ragdoll
            SceneGraph.Actors.AnimatedModelNode.BuildRagdoll(animatedModel, options, ragdoll);
        }