コード例 #1
0
        /**
         * @private
         */
        protected void _updateDisplayData()
        {
            var prevDisplayData        = _displayData;
            var prevReplaceDisplayData = _replacedDisplayData;
            var prevTextureData        = _textureData;
            var prevMeshData           = _meshData;
            var currentDisplay         = _displayIndex >= 0 && _displayIndex < _displayList.Count ? _displayList[_displayIndex] : null;

            if (_displayIndex >= 0 && _displayIndex < _skinSlotData.displays.Count)
            {
                _displayData = _skinSlotData.displays[_displayIndex];
            }
            else
            {
                _displayData = null;
            }

            if (_displayIndex >= 0 && _displayIndex < _replacedDisplayDatas.Count)
            {
                _replacedDisplayData = _replacedDisplayDatas[_displayIndex];
            }
            else
            {
                _replacedDisplayData = null;
            }

            if (_displayData != prevDisplayData || _replacedDisplayData != prevReplaceDisplayData || this._display != currentDisplay)
            {
                var currentDisplayData = _replacedDisplayData != null ? _replacedDisplayData : _displayData;
                if (currentDisplayData != null && (currentDisplay == _rawDisplay || currentDisplay == _meshDisplay))
                {
                    _textureData = _replacedDisplayData != null ? _replacedDisplayData.texture : _displayData.texture;
                    if (currentDisplay == _meshDisplay)
                    {
                        if (_replacedDisplayData != null && _replacedDisplayData.mesh != null)
                        {
                            _meshData = _replacedDisplayData.mesh;
                        }
                        else
                        {
                            _meshData = _displayData.mesh;
                        }
                    }
                    else
                    {
                        _meshData = null;
                    }

                    // Update pivot offset.
                    if (_meshData != null)
                    {
                        _pivotX = 0.0f;
                        _pivotY = 0.0f;
                    }
                    else if (_textureData != null)
                    {
                        var scale = _armature.armatureData.scale;
                        _pivotX = currentDisplayData.pivot.x;
                        _pivotY = currentDisplayData.pivot.y;

                        if (currentDisplayData.isRelativePivot)
                        {
                            var rect   = _textureData.frame != null ? _textureData.frame : _textureData.region;
                            var width  = rect.width * scale;
                            var height = rect.height * scale;

                            if (_textureData.rotated)
                            {
                                width  = rect.height;
                                height = rect.width;
                            }

                            _pivotX *= width;
                            _pivotY *= height;
                        }

                        if (_textureData.frame != null)
                        {
                            _pivotX += _textureData.frame.x * scale;
                            _pivotY += _textureData.frame.y * scale;
                        }
                    }
                    else
                    {
                        _pivotX = 0.0f;
                        _pivotY = 0.0f;
                    }

                    if (
                        _displayData != null && currentDisplayData != _displayData &&
                        (_meshData == null || _meshData != _displayData.mesh)
                        )
                    {
                        _displayData.transform.ToMatrix(_helpMatrix);
                        _helpMatrix.Invert();
                        _helpMatrix.TransformPoint(0.0f, 0.0f, _helpPoint);
                        _pivotX -= _helpPoint.x;
                        _pivotY -= _helpPoint.y;

                        currentDisplayData.transform.ToMatrix(_helpMatrix);
                        _helpMatrix.Invert();
                        _helpMatrix.TransformPoint(0.0f, 0.0f, _helpPoint);
                        _pivotX += _helpPoint.x;
                        _pivotY += _helpPoint.y;
                    }

                    if (_meshData != prevMeshData) // Update mesh bones and ffd vertices.
                    {
                        if (_meshData != null && _displayData != null && _meshData == _displayData.mesh)
                        {
                            if (_meshData.skinned)
                            {
                                DragonBones.ResizeList(_meshBones, _meshData.bones.Count, null);

                                for (int i = 0, l = _meshBones.Count; i < l; ++i)
                                {
                                    _meshBones[i] = _armature.GetBone(_meshData.bones[i].name);
                                }

                                int ffdVerticesCount = 0;
                                for (int i = 0, l = _meshData.boneIndices.Count; i < l; ++i)
                                {
                                    ffdVerticesCount += _meshData.boneIndices[i].Length;
                                }

                                DragonBones.ResizeList(_ffdVertices, ffdVerticesCount * 2, 0.0f);
                            }
                            else
                            {
                                _meshBones.Clear();
                                DragonBones.ResizeList(_ffdVertices, _meshData.vertices.Count, 0.0f);
                            }

                            for (int i = 0, l = _ffdVertices.Count; i < l; ++i)
                            {
                                _ffdVertices[i] = 0.0f;
                            }

                            _meshDirty = true;
                        }
                        else
                        {
                            _meshBones.Clear();
                            _ffdVertices.Clear();
                        }
                    }
                    else if (_textureData != prevTextureData)
                    {
                        _meshDirty = true;
                    }
                }
                else
                {
                    _textureData = null;
                    _meshData    = null;
                    _pivotX      = 0.0f;
                    _pivotY      = 0.0f;
                    _meshBones.Clear();
                    _ffdVertices.Clear();
                }

                _displayDirty  = true;
                _originalDirty = true;

                if (_displayData != null)
                {
                    origin = _displayData.transform;
                }
                else if (_replacedDisplayData != null)
                {
                    origin = _replacedDisplayData.transform;
                }
            }

            // Update bounding box data.
            if (_replacedDisplayData != null)
            {
                _boundingBoxData = _replacedDisplayData.boundingBox;
            }
            else if (_displayData != null)
            {
                _boundingBoxData = _displayData.boundingBox;
            }
            else
            {
                _boundingBoxData = null;
            }
        }
コード例 #2
0
        protected void _globalToLocal(ArmatureData armature) // Support 2.x ~ 3.x data.
        {
            var keyFrames = new List <BoneFrameData>();
            var bones     = armature.sortedBones.ToArray();

            Array.Reverse(bones);

            foreach (var bone in bones)
            {
                if (bone.parent != null)
                {
                    bone.parent.transform.ToMatrix(_helpMatrix);
                    _helpMatrix.Invert();
                    _helpMatrix.TransformPoint(bone.transform.x,bone.transform.y,_helpPoint);
                    bone.transform.x         = _helpPoint.x;
                    bone.transform.y         = _helpPoint.y;
                    bone.transform.rotation -= bone.parent.transform.rotation;
                }

                foreach (var pair in armature.animations)
                {
                    var animation = pair.Value;
                    var timeline  = animation.GetBoneTimeline(bone.name);

                    if (timeline == null)
                    {
                        continue;
                    }

                    var parentTimeline = bone.parent != null?animation.GetBoneTimeline(bone.parent.name) : null;

                    _helpTransformB.CopyFrom(timeline.originTransform);
                    keyFrames.Clear();

                    var isFirstFrame = true;
                    foreach (var frame in timeline.frames)
                    {
                        if (keyFrames.Contains(frame))
                        {
                            continue;
                        }

                        keyFrames.Add(frame);

                        if (parentTimeline != null)
                        {
                            _getTimelineFrameMatrix(animation,parentTimeline,frame.position,_helpTransformA);
                            frame.transform.Add(_helpTransformB);
                            _helpTransformA.ToMatrix(_helpMatrix);
                            _helpMatrix.Invert();
                            _helpMatrix.TransformPoint(frame.transform.x,frame.transform.y,_helpPoint);
                            frame.transform.x         = _helpPoint.x;
                            frame.transform.y         = _helpPoint.y;
                            frame.transform.rotation -= _helpTransformA.rotation;
                        }
                        else
                        {
                            frame.transform.Add(_helpTransformB);
                        }

                        frame.transform.Minus(bone.transform);

                        if (isFirstFrame)
                        {
                            isFirstFrame = false;
                            timeline.originTransform.CopyFrom(frame.transform);
                            frame.transform.Identity();
                        }
                        else
                        {
                            frame.transform.Minus(timeline.originTransform);
                        }
                    }
                }
            }
        }