Example #1
0
 public Bone(Bone parent, string name = null)
     : this(name)
 {
     Parent = parent;
     if (parent != null)
      Parent.AddChildren(this);
 }
        public Bone Add(BoneActor actor)
        {
            Bone bone = null;
            if (actor.Parent != null)
            {
                var parent = actor.Parent.AssignedBone;
                bone = new Bone(parent);
            }
            else
            {
                bone = new Bone()
                {
                    Length = FirstBoneDefaultLenght
                };
                _skeleton.AddBone(bone);
            }

            actor.AssignedBone = bone;
            SetBoneData(actor);

            actor.OnParentChange += OnParentChangeHandler;

            _boneDictionary.Add(bone, actor);
            return bone;
        }
 public BoneActor Add(Vector2 startPosition, Bone parent = null)
 {
     Bone bone = new Bone(parent)
     {
         AbsolutePosition = startPosition,
         Length = FirstBoneDefaultLenght
     };
     if (parent == null)
     {
         _skeleton.AddBone(bone);
     }
     return CreateBoneActorWith(bone);
 }
 public BoneActor Add(Vector2 startPosition, Vector2 endPosition, Bone parent = null)
 {
     Bone bone = new Bone(parent)
     {
         AbsolutePosition = startPosition,
         AbsoluteEnd = endPosition
     };
     if (parent == null)
     {
         _skeleton.AddBone(bone);
     }
     return CreateBoneActorWith(bone);
 }
Example #5
0
        public void AddAnimationFrame(Bone bone, BoneAnimationFrame frame)
        {
            if (_framesMapping.ContainsKey(bone))
            {
                _framesMapping[bone].Add(frame);
            }
            else
            {
                var frames = new List<BoneAnimationFrame>() { frame };
                _framesMapping.Add(bone, frames);
            }

            if (_longestAnimationTime < frame.EndTime)
            {
                _longestAnimationTime = frame.EndTime;
            }
        }
Example #6
0
        private void UpdateBone(Bone bone)
        {
            var endTime = _elapsedTime;
            if (!_framesMapping.ContainsKey(bone))
                return;
            var frames = _framesMapping[bone];
            var frame = frames.GetAt(_elapsedTime);

            if (frame == null)
            {
                frame = frames.GetLastFrame();
                endTime = frame.EndTime;
            }

            if (frame == null)
                return;
            frame.SetBoneTransformationValues(bone, endTime);
        }
        public void RelativeEndIsConsistent()
        {
            var boneRoot = new Bone();
            var boneChild = new Bone(boneRoot);
            var leafChild = new Bone(boneChild);

            boneRoot.AbsolutePosition = new Vector2(100);
            boneRoot.Length = 128;

            AssetHelpers.AreEqual(new Vector2(100, 228), boneRoot.AbsoluteEnd, 0.00001f);

            boneChild.AbsolutePosition = boneRoot.AbsoluteEnd;
            boneChild.AbsoluteEnd = new Vector2(250, 378);

            AssetHelpers.AreEqual(new Vector2(250, 378), boneChild.AbsoluteEnd, 0.00001f);

            leafChild.AbsolutePosition = boneChild.AbsoluteEnd;
            leafChild.AbsoluteEnd = new Vector2(400, 528);

            AssetHelpers.AreEqual(new Vector2(400, 528), leafChild.AbsoluteEnd, 0.00001f);
        }
        public void RotatingRootKeepsAllChildrenConsistent()
        {
            var boneRoot = new Bone();
            var boneChild = new Bone(boneRoot);
            var leafChild = new Bone(boneChild);

            boneRoot.AbsolutePosition = new Vector2(0);
            boneRoot.Length = 100;

            boneChild.AbsolutePosition = boneRoot.AbsoluteEnd;
            boneChild.AbsoluteEnd = new Vector2(0, 200);

            leafChild.AbsolutePosition = boneChild.AbsoluteEnd;
            leafChild.AbsoluteEnd = new Vector2(0, 400);

            boneRoot.AbsoluteEnd = new Vector2(100, 0);

            AssetHelpers.AreEqual(new Vector2(100, 0), boneRoot.AbsoluteEnd, 0.0001f);
            AssetHelpers.AreEqual(new Vector2(200, 0), boneChild.AbsoluteEnd, 0.0001f);
            AssetHelpers.AreEqual(new Vector2(400, 0), leafChild.AbsoluteEnd, 0.0001f);
        }
        public void MovingRootKeepsAllChildrenConsistent()
        {
            var boneRoot = new Bone();
            var boneChild = new Bone(boneRoot);
            var leafChild = new Bone(boneChild);

            boneRoot.AbsolutePosition = new Vector2(100);
            boneRoot.Length = 128;

            boneChild.AbsolutePosition = boneRoot.AbsoluteEnd;
            boneChild.AbsoluteEnd = new Vector2(250, 378);

            leafChild.AbsolutePosition = boneChild.AbsoluteEnd;
            leafChild.AbsoluteEnd = new Vector2(400, 528);

            boneRoot.AbsolutePosition = new Vector2(150);

            AssetHelpers.AreEqual(new Vector2(150, 278), boneRoot.AbsoluteEnd, 0.00001f);
            AssetHelpers.AreEqual(new Vector2(300, 428), boneChild.AbsoluteEnd, 0.00001f);
            AssetHelpers.AreEqual(new Vector2(450, 578), leafChild.AbsoluteEnd, 0.00001f);
        }
 public BoneActorSceneObject(BoneActor boneActor, IPuppeteerSceneOjectActionContext context)
 {
     _boneActor = boneActor;
     _context = context;
     _bone = _boneActor.AssignedBone;
 }
Example #11
0
 public void AddChildren(Bone children)
 {
     if (_children.Contains(children)) return;
     children.Parent = this;
 }
Example #12
0
 public void RemoveChildren(Bone children)
 {
     if (!_children.Contains(children)) return;
     children.Parent = null;
 }
 private void PropagateBoneChanges(Bone bone)
 {
     var children = bone.Children;
     foreach (var child in children)
     {
         var actor = _boneDictionary[child];
         SetActorData(actor);
         PropagateBoneChanges(child);
     }
 }
        private BoneActor CreateBoneActorWith(Bone bone)
        {
            var actor = _scene.AddWorldEntity<BoneActor>();
            actor.AssignedBone = bone;

            actor.OnParentChange += OnParentChangeHandler;

            _boneDictionary.Add(bone, actor);
            return actor;
        }
 public void SynchronizeBoneChain(Bone bone)
 {
     var actor = _boneDictionary[bone];
     SetActorData(actor);
     PropagateBoneChanges(bone);
 }
        public void RotationsInBoneStructure()
        {
            var boneRoot = new Bone();
            var boneChild = new Bone(boneRoot);
            var leafChild = new Bone(boneChild);

            boneRoot.AbsolutePosition = new Vector2(0);
            boneRoot.Length = 100;

            boneChild.AbsolutePosition = boneRoot.AbsoluteEnd;
            boneChild.AbsoluteEnd = new Vector2(100, 0);

            leafChild.AbsolutePosition = boneChild.AbsoluteEnd;
            leafChild.AbsoluteEnd = new Vector2(200, 0);

            boneRoot.AbsoluteEnd = new Vector2(100, 0);

            AssetHelpers.AreEqual(new Vector2(100, 0), boneRoot.AbsoluteEnd, 0.0001f);
            AssetHelpers.AreEqual(new Vector2(0, -100), boneChild.AbsoluteEnd, 0.0001f);
            AssetHelpers.AreEqual(new Vector2(0, -200), leafChild.AbsoluteEnd, 0.0001f);
        }
Example #17
0
 public void SetBoneTransformationValues(Bone bone, TimeSpan totalElapsed)
 {
     bone.Translation = InterpolateTranslation(totalElapsed);
     bone.Rotation = InterpolateRotation(totalElapsed);
 }
Example #18
0
 private void UpdateChildBonesOf(Bone bone)
 {
     foreach(var child in bone.Children)
     {
         UpdateBone(child);
         UpdateChildBonesOf(child);
     }
 }