Esempio n. 1
0
        /**
         * @private
         */
        protected override void _onClear()
        {
            base._onClear();

            inheritTranslation = false;
            inheritRotation    = false;
            inheritScale       = false;
            ikBendPositive     = false;
            length             = 0.0f;
            ikWeight           = 0.0f;

            _transformDirty   = BoneTransformDirty.None;
            _visible          = true;
            _cachedFrameIndex = -1;
            _ikChain          = 0;
            _ikChainIndex     = 0;
            _updateState      = -1;
            _blendLayer       = 0;
            _blendLeftWeight  = 0.0f;
            _blendTotalWeight = 0.0f;
            _animationPose.Identity();
            _bones.Clear();
            _slots.Clear();
            _boneData           = null;
            _ik                 = null;
            _cachedFrameIndices = null;
        }
Esempio n. 2
0
        /**
         * @inheritDoc
         */
        protected override void _onClear()
        {
            base._onClear();

            inheritTranslation = false;
            inheritRotation    = false;
            inheritScale       = false;
            ikBendPositive     = false;
            ikWeight           = 0.0f;
            length             = 0.0f;

            _transformDirty  = BoneTransformDirty.All; // Update
            _blendIndex      = -1;
            _cacheFrameIndex = -1;
            _cacheFrames     = null;
            _animationPose.Identity();

            _visible      = true;
            _ikChain      = 0;
            _ikChainIndex = 0;
            _ik           = null;
            _bones.Clear();
            _slots.Clear();
        }
Esempio n. 3
0
 /**
  * @language zh_CN
  * 下一帧更新变换。 (当骨骼没有动画状态或动画状态播放完成时,骨骼将不在更新)
  * @version DragonBones 3.0
  */
 public void InvalidUpdate()
 {
     _transformDirty = BoneTransformDirty.All;
 }
Esempio n. 4
0
        /**
         * @private
         */
        internal void _update(int cacheFrameIndex)
        {
            _updateState = -1;

            if (cacheFrameIndex >= 0 && _cachedFrameIndices != null)
            {
                var cachedFrameIndex = _cachedFrameIndices[cacheFrameIndex];
                if (cachedFrameIndex >= 0 && _cachedFrameIndex == cachedFrameIndex) // Same cache.
                {
                    _transformDirty = BoneTransformDirty.None;
                }
                else if (cachedFrameIndex >= 0.0f) // Has been Cached.
                {
                    _transformDirty   = BoneTransformDirty.All;
                    _cachedFrameIndex = cachedFrameIndex;
                }
                else if (
                    _transformDirty == BoneTransformDirty.All ||
                    (_parent != null && _parent._transformDirty != BoneTransformDirty.None) ||
                    (_ik != null && ikWeight > 0.0f && _ik._transformDirty != BoneTransformDirty.None)
                    ) // Dirty.
                {
                    _transformDirty   = BoneTransformDirty.All;
                    _cachedFrameIndex = -1;
                }
                else if (_cachedFrameIndex >= 0) // Same cache but not cached yet.
                {
                    _transformDirty = BoneTransformDirty.None;
                    _cachedFrameIndices[cacheFrameIndex] = _cachedFrameIndex;
                }
                else // Dirty.
                {
                    _transformDirty   = BoneTransformDirty.All;
                    _cachedFrameIndex = -1;
                }
            }
            else if (
                _transformDirty == BoneTransformDirty.All ||
                (_parent != null && _parent._transformDirty != BoneTransformDirty.None) ||
                (_ik != null && ikWeight > 0.0f && _ik._transformDirty != BoneTransformDirty.None)
                )
            {
                cacheFrameIndex   = -1;
                _transformDirty   = BoneTransformDirty.All; // For update children and ik children.
                _cachedFrameIndex = -1;
            }

            if (_transformDirty != BoneTransformDirty.None)
            {
                if (_transformDirty == BoneTransformDirty.All)
                {
                    _transformDirty = BoneTransformDirty.Self;

                    if (_cachedFrameIndex < 0)
                    {
                        _updateGlobalTransformMatrix();

                        if (cacheFrameIndex >= 0)
                        {
                            _cachedFrameIndex = _cachedFrameIndices[cacheFrameIndex] = _armature._armatureData.SetCacheFrame(globalTransformMatrix, global);
                        }
                    }
                    else
                    {
                        _armature._armatureData.GetCacheFrame(globalTransformMatrix, global, _cachedFrameIndex);
                    }

                    _updateState = 0;
                }
                else
                {
                    _transformDirty = BoneTransformDirty.None;
                }
            }
        }
Esempio n. 5
0
        /**
         * @private
         */
        internal void _update(int cacheFrameIndex)
        {
            _blendIndex = 0;

            var frameIndex = cacheFrameIndex * BoneTimelineData.COUNT;

            if (cacheFrameIndex >= 0)
            {
                var frameFlag = _cacheFrames[frameIndex];
                if (_cacheFrameIndex >= 0 && _cacheFrameIndex == frameFlag) // Same cache.
                {
                    _transformDirty = BoneTransformDirty.None;
                }
                else if (frameFlag >= 0.0f)                    // Has been Cached.
                {
                    _transformDirty  = BoneTransformDirty.All; // For update children and ik children.
                    _cacheFrameIndex = -1;
                }
                else if (
                    _transformDirty == BoneTransformDirty.All ||
                    (_parent != null && _parent._transformDirty != BoneTransformDirty.None) ||
                    (_ik != null && ikWeight > 0.0f && _ik._transformDirty != BoneTransformDirty.None)
                    )                                          // Dirty.
                {
                    _transformDirty  = BoneTransformDirty.All; // For update children and ik children.
                    _cacheFrameIndex = cacheFrameIndex;
                }
                else if (_cacheFrameIndex >= 0) // Same cache but not cached yet.
                {
                    _transformDirty          = BoneTransformDirty.None;
                    _cacheFrames[frameIndex] = _cacheFrameIndex;
                }
                else // Dirty.
                {
                    _transformDirty  = BoneTransformDirty.All;
                    _cacheFrameIndex = cacheFrameIndex;
                }
            }
            else if (
                _transformDirty == BoneTransformDirty.All ||
                (_parent != null && _parent._transformDirty != BoneTransformDirty.None) ||
                (_ik != null && ikWeight > 0.0f && _ik._transformDirty != BoneTransformDirty.None)
                )
            {
                _transformDirty  = BoneTransformDirty.All; // For update children and ik children.
                _cacheFrameIndex = -1;
            }

            if (_transformDirty != BoneTransformDirty.None)
            {
                if (_transformDirty == BoneTransformDirty.All)
                {
                    _transformDirty = BoneTransformDirty.Self;

                    if (_cacheFrameIndex == cacheFrameIndex)
                    {
                        /*global.copyFrom(origin).add(offset).add(_animationPose);*/
                        global.x      = origin.x + offset.x + _animationPose.x;
                        global.y      = origin.y + offset.y + _animationPose.y;
                        global.skewX  = origin.skewX + offset.skewX + _animationPose.skewX;
                        global.skewY  = origin.skewY + offset.skewY + _animationPose.skewY;
                        global.scaleX = origin.scaleX * offset.scaleX * _animationPose.scaleX;
                        global.scaleY = origin.scaleY * offset.scaleY * _animationPose.scaleY;

                        _updateGlobalTransformMatrix();

                        if (_ik != null && _ikChainIndex == _ikChain && ikWeight > 0.0f)
                        {
                            if (inheritTranslation && _ikChain > 0 && _parent != null)
                            {
                                _computeIKB();
                            }
                            else
                            {
                                _computeIKA();
                            }
                        }

                        if (cacheFrameIndex >= 0)
                        {
                            _cacheFrameIndex              = cacheFrameIndex;
                            _cacheFrames[frameIndex]      = cacheFrameIndex;
                            _cacheFrames[frameIndex + 1]  = this.globalTransformMatrix.a;
                            _cacheFrames[frameIndex + 2]  = this.globalTransformMatrix.b;
                            _cacheFrames[frameIndex + 3]  = this.globalTransformMatrix.c;
                            _cacheFrames[frameIndex + 4]  = this.globalTransformMatrix.d;
                            _cacheFrames[frameIndex + 5]  = this.globalTransformMatrix.tx;
                            _cacheFrames[frameIndex + 6]  = this.globalTransformMatrix.ty;
                            _cacheFrames[frameIndex + 7]  = this.global.skewX;
                            _cacheFrames[frameIndex + 8]  = this.global.skewY;
                            _cacheFrames[frameIndex + 9]  = this.global.scaleX;
                            _cacheFrames[frameIndex + 10] = this.global.scaleY;
                        }
                    }
                    else
                    {
                        _cacheFrameIndex              = (int)_cacheFrames[frameIndex + 0];
                        this.globalTransformMatrix.a  = _cacheFrames[frameIndex + 1];
                        this.globalTransformMatrix.b  = _cacheFrames[frameIndex + 2];
                        this.globalTransformMatrix.c  = _cacheFrames[frameIndex + 3];
                        this.globalTransformMatrix.d  = _cacheFrames[frameIndex + 4];
                        this.globalTransformMatrix.tx = _cacheFrames[frameIndex + 5];
                        this.globalTransformMatrix.ty = _cacheFrames[frameIndex + 6];
                        this.global.skewX             = _cacheFrames[frameIndex + 7];
                        this.global.skewY             = _cacheFrames[frameIndex + 8];
                        this.global.scaleX            = _cacheFrames[frameIndex + 9];
                        this.global.scaleY            = _cacheFrames[frameIndex + 10];
                    }
                }
                else
                {
                    _transformDirty = BoneTransformDirty.None;
                }
            }
        }
Esempio n. 6
0
        /**
         * @private
         */
        private void _computeIKB()
        {
            var parentGlobal = this._parent.global;
            var ikGlobal     = _ik.global;

            var x = this.globalTransformMatrix.a * length;
            var y = this.globalTransformMatrix.b * length;

            var lLL = x * x + y * y;
            var lL  = (float)Math.Sqrt(lLL);

            var dX  = this.global.x - parentGlobal.x;
            var dY  = this.global.y - parentGlobal.y;
            var lPP = dX * dX + dY * dY;
            var lP  = (float)Math.Sqrt(lPP);

            dX = ikGlobal.x - parentGlobal.x;
            dY = ikGlobal.y - parentGlobal.y;
            var lTT = dX * dX + dY * dY;
            var lT  = (float)Math.Sqrt(lTT);

            var ikRadianA = 0.0f;

            if (lL + lP <= lT || lT + lL <= lP || lT + lP <= lL)
            {
                ikRadianA = (float)Math.Atan2(ikGlobal.y - parentGlobal.y, ikGlobal.x - parentGlobal.x) + this._parent.offset.skewY; // Support offset.
                if (lL + lP <= lT)
                {
                }
                else if (lP < lL)
                {
                    ikRadianA += DragonBones.PI;
                }
            }
            else
            {
                var h  = (lPP - lLL + lTT) / (2.0f * lTT);
                var r  = (float)Math.Sqrt(lPP - h * h * lTT) / lT;
                var hX = parentGlobal.x + (dX * h);
                var hY = parentGlobal.y + (dY * h);
                var rX = -dY * r;
                var rY = dX * r;

                if (ikBendPositive)
                {
                    this.global.x = hX - rX;
                    this.global.y = hY - rY;
                }
                else
                {
                    this.global.x = hX + rX;
                    this.global.y = hY + rY;
                }

                ikRadianA = (float)Math.Atan2(this.global.y - parentGlobal.y, this.global.x - parentGlobal.x) + this._parent.offset.skewY; // Support offset.
            }

            ikRadianA = (ikRadianA - parentGlobal.skewY) * ikWeight;

            parentGlobal.skewX += ikRadianA;
            parentGlobal.skewY += ikRadianA;

            parentGlobal.ToMatrix(this._parent.globalTransformMatrix);
            this._parent._transformDirty = BoneTransformDirty.Self;

            this.global.x = parentGlobal.x + (float)Math.Cos(parentGlobal.skewY) * lP;
            this.global.y = parentGlobal.y + (float)Math.Sin(parentGlobal.skewY) * lP;

            var ikRadianB =
                (float)(
                    Math.Atan2(ikGlobal.y - this.global.y, ikGlobal.x - this.global.x) + this.offset.skewY -
                    this.global.skewY * 2 + Math.Atan2(y, x)
                    ) * this.ikWeight; // Support offset.

            this.global.skewX += ikRadianB;
            this.global.skewY += ikRadianB;

            this.global.ToMatrix(this.globalTransformMatrix);
        }