private void _ParseVertices(Dictionary <string, object> rawData, VerticesData vertices)
        {
            vertices.offset = int.Parse(rawData[DataParser.OFFSET].ToString());

            var weightOffset = this._intArrayBuffer[vertices.offset + (int)BinaryOffset.MeshWeightOffset];

            if (weightOffset >= 0)
            {
                var weight      = BaseObject.BorrowObject <WeightData>();
                var vertexCount = this._intArrayBuffer[vertices.offset + (int)BinaryOffset.MeshVertexCount];
                var boneCount   = this._intArrayBuffer[weightOffset + (int)BinaryOffset.WeigthBoneCount];
                weight.offset = weightOffset;

                for (int i = 0; i < boneCount; ++i)
                {
                    var boneIndex = this._intArrayBuffer[weightOffset + (int)BinaryOffset.WeigthBoneIndices + i];
                    weight.AddBone(this._rawBones[boneIndex]);
                }

                var boneIndicesOffset = weightOffset + (short)BinaryOffset.WeigthBoneIndices + boneCount;
                var weightCount       = 0;
                for (int i = 0, l = vertexCount; i < l; ++i)
                {
                    var vertexBoneCount = this._intArrayBuffer[boneIndicesOffset++];
                    weightCount       += vertexBoneCount;
                    boneIndicesOffset += vertexBoneCount;
                }

                weight.count    = weightCount;
                vertices.weight = weight;
            }
        }
 protected override void _OnClear()
 {
     this.verticesDirty = false;
     this.vertices.Clear();
     this.bones.Clear();
     this.verticesData = null;
 }
        public void init(VerticesData verticesDataValue, Armature armature)
        {
            this.verticesData = verticesDataValue;

            if (this.verticesData != null)
            {
                var vertexCount = 0;
                if (this.verticesData.weight != null)
                {
                    vertexCount = this.verticesData.weight.count * 2;
                }
                else
                {
                    vertexCount = (int)this.verticesData.data.intArray[this.verticesData.offset + (int)BinaryOffset.MeshVertexCount] * 2;
                }

                this.verticesDirty = true;
                this.vertices.ResizeList(vertexCount);
                this.bones.Clear();
                //
                for (int i = 0, l = this.vertices.Count; i < l; ++i)
                {
                    this.vertices[i] = 0.0f;
                }

                if (this.verticesData.weight != null)
                {
                    for (int i = 0, l = this.verticesData.weight.bones.Count; i < l; ++i)
                    {
                        var bone = armature.GetBone(this.verticesData.weight.bones[i].name);
                        this.bones.Add(bone);
                    }
                }
            }
            else
            {
                this.verticesDirty = false;
                this.vertices.Clear();
                this.bones.Clear();
                this.verticesData = null;
            }
        }
Exemple #4
0
        /// <private/>
        protected void _UpdateDisplayData()
        {
            var prevDisplayData  = this._displayData;
            var prevVerticesData = this._deformVertices != null ? this._deformVertices.verticesData : null;
            var prevTextureData  = this._textureData;

            DisplayData  rawDisplayData      = null;
            VerticesData currentVerticesData = null;

            this._displayData     = null;
            this._boundingBoxData = null;
            this._textureData     = null;

            if (this._displayIndex >= 0)
            {
                if (this._rawDisplayDatas != null)
                {
                    rawDisplayData = this._displayIndex < this._rawDisplayDatas.Count ? this._rawDisplayDatas[this._displayIndex] : null;
                }

                if (rawDisplayData == null)
                {
                    rawDisplayData = this._GetDefaultRawDisplayData(this._displayIndex);
                }

                if (this._displayIndex < this._displayDatas.Count)
                {
                    this._displayData = this._displayDatas[this._displayIndex];
                }
            }

            // Update texture and mesh data.
            if (this._displayData != null)
            {
                if (this._displayData.type == DisplayType.Mesh)
                {
                    currentVerticesData = (this._displayData as MeshDisplayData).vertices;
                }
                else if (this._displayData.type == DisplayType.Path)
                {
                    currentVerticesData = (this._displayData as PathDisplayData).vertices;
                }
                else if (rawDisplayData != null)
                {
                    if (rawDisplayData.type == DisplayType.Mesh)
                    {
                        currentVerticesData = (rawDisplayData as MeshDisplayData).vertices;
                    }
                    else if (rawDisplayData.type == DisplayType.Path)
                    {
                        currentVerticesData = (rawDisplayData as PathDisplayData).vertices;
                    }
                }

                if (this._displayData.type == DisplayType.BoundingBox)
                {
                    this._boundingBoxData = (this._displayData as BoundingBoxDisplayData).boundingBox;
                }
                else if (rawDisplayData != null)
                {
                    if (rawDisplayData.type == DisplayType.BoundingBox)
                    {
                        this._boundingBoxData = (rawDisplayData as BoundingBoxDisplayData).boundingBox;
                    }
                }

                if (this._displayData.type == DisplayType.Image)
                {
                    this._textureData = (this._displayData as ImageDisplayData).texture;
                }
                else if (this._displayData.type == DisplayType.Mesh)
                {
                    this._textureData = (this._displayData as MeshDisplayData).texture;
                }
            }

            if (this._displayData != prevDisplayData || currentVerticesData != prevVerticesData || this._textureData != prevTextureData)
            {
                // Update pivot offset.
                if (currentVerticesData == null && this._textureData != null)
                {
                    var imageDisplayData = this._displayData as ImageDisplayData;
                    var scale            = this._textureData.parent.scale * this._armature._armatureData.scale;
                    var frame            = this._textureData.frame;

                    this._pivotX = imageDisplayData.pivot.x;
                    this._pivotY = imageDisplayData.pivot.y;
                    //Debug.Log(_pivotX + "," + _pivotY);

                    var rect   = frame != null ? frame : this._textureData.region;
                    var width  = rect.width;
                    var height = rect.height;

                    if (this._textureData.rotated && frame == null)
                    {
                        width  = rect.height;
                        height = rect.width;
                    }

                    this._pivotX *= width * scale;
                    this._pivotY *= height * scale;
                    //Debug.Log(_pivotX + "," + _pivotY);
                    if (frame != null)
                    {
                        this._pivotX += frame.x * scale;
                        this._pivotY += frame.y * scale;
                    }

                    //Debug.Log("-----------");

                    // Update replace pivot. TODO
                    if (this._displayData != null && rawDisplayData != null && this._displayData != rawDisplayData)
                    {
                        rawDisplayData.transform.ToMatrix(Slot._helpMatrix);
                        Slot._helpMatrix.Invert();
                        Slot._helpMatrix.TransformPoint(0.0f, 0.0f, Slot._helpPoint);
                        this._pivotX -= Slot._helpPoint.x;
                        this._pivotY -= Slot._helpPoint.y;

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

                    if (!DragonBones.yDown)
                    {
                        this._pivotY = (this._textureData.rotated ? this._textureData.region.width : this._textureData.region.height) * scale - this._pivotY;
                    }
                }
                else
                {
                    this._pivotX = 0.0f;
                    this._pivotY = 0.0f;
                }

                // Update original transform.
                if (rawDisplayData != null)
                {
                    // Compatible.
                    this.origin = rawDisplayData.transform;
                }
                else if (this._displayData != null)
                {
                    // Compatible.
                    this.origin = this._displayData.transform;
                }
                else
                {
                    this.origin = null;
                }

                // Update vertices.
                if (currentVerticesData != prevVerticesData)
                {
                    if (this._deformVertices == null)
                    {
                        this._deformVertices = BaseObject.BorrowObject <DeformVertices>();
                    }

                    this._deformVertices.init(currentVerticesData, this._armature);
                }
                else if (this._deformVertices != null && this._textureData != prevTextureData)
                {
                    // Update mesh after update frame.
                    this._deformVertices.verticesDirty = true;
                }

                this._displayDirty   = true;
                this._transformDirty = true;
            }
        }
Exemple #5
0
 public void ShareFrom(VerticesData value)
 {
     this.isShared = true;
     this.offset   = value.offset;
     this.weight   = value.weight;
 }