Example #1
0
        /**
         * @language zh_CN
         * 添加指定的骨骼遮罩。
         * @param boneName 指定的骨骼名称。
         * @param recursive 是否为该骨骼的子骨骼添加遮罩。
         * @version DragonBones 3.0
         */
        public void AddBoneMask(string name, bool recursive = true)
        {
            var currentBone = _armature.GetBone(name);

            if (currentBone == null)
            {
                return;
            }

            if (
                !_boneMask.Contains(name) &&
                _animationData.GetBoneTimeline(name) != null
                ) // Add mixing
            {
                _boneMask.Add(name);
            }

            if (recursive)
            {
                foreach (var bone in _armature.GetBones())
                {
                    var boneName = bone.name;
                    if (
                        !_boneMask.Contains(boneName) &&
                        _animationData.GetBoneTimeline(boneName) != null &&
                        currentBone.Contains(bone)
                        ) // Add recursive mixing.
                    {
                        _boneMask.Add(boneName);
                    }
                }
            }

            _updateTimelineStates();
        }
Example #2
0
        /**
         * @language zh_CN
         * 添加骨骼遮罩。
         * @param boneName 指定的骨骼名称。
         * @param recursive 是否为该骨骼的子骨骼添加遮罩。
         * @version DragonBones 3.0
         */
        public void AddBoneMask(string name, bool recursive = true)
        {
            var currentBone = _armature.GetBone(name);

            if (currentBone == null)
            {
                return;
            }

            if (!_boneMask.Contains(name)) // Add mixing
            {
                _boneMask.Add(name);
            }

            if (recursive)
            {
                var bones = _armature.GetBones();
                for (int i = 0, l = bones.Count; i < l; ++i)
                {
                    var bone = bones[i];
                    if (!_boneMask.Contains(bone.name) && currentBone.Contains(bone)) // Add recursive mixing.
                    {
                        _boneMask.Add(bone.name);
                    }
                }
            }

            _updateTimelineStates();
        }
Example #3
0
        /**
         * @private
         */
        protected void _BuildBones(BuildArmaturePackage dataPackage, Armature armature)
        {
            var bones = dataPackage.armature.sortedBones;

            for (int i = 0, l = bones.Count; i < l; ++i)
            {
                var boneData = bones[i];
                var bone     = BaseObject.BorrowObject <Bone>();
                bone.Init(boneData);

                if (boneData.parent != null)
                {
                    armature.AddBone(bone, boneData.parent.name);
                }
                else
                {
                    armature.AddBone(bone, string.Empty);
                }

                var constraints = boneData.constraints;

                for (int j = 0, lJ = constraints.Count; j < lJ; ++j)
                {
                    var constraintData = constraints[j];
                    var target         = armature.GetBone(constraintData.target.name);
                    if (target == null)
                    {
                        continue;
                    }

                    // TODO more constraint type.
                    var ikConstraintData = constraintData as IKConstraintData;
                    var constraint       = BaseObject.BorrowObject <IKConstraint>();
                    var root             = ikConstraintData.root != null?armature.GetBone(ikConstraintData.root.name) : null;

                    constraint.target       = target;
                    constraint.bone         = bone;
                    constraint.root         = root;
                    constraint.bendPositive = ikConstraintData.bendPositive;
                    constraint.scaleEnabled = ikConstraintData.scaleEnabled;
                    constraint.weight       = ikConstraintData.weight;

                    if (root != null)
                    {
                        root.AddConstraint(constraint);
                    }
                    else
                    {
                        bone.AddConstraint(constraint);
                    }
                }
            }
        }
Example #4
0
        /**
         * @private
         */
        protected void _buildBones(BuildArmaturePackage dataPackage, Armature armature)
        {
            var bones = dataPackage.armature.sortedBones;

            for (int i = 0, l = bones.Count; i < l; ++i)
            {
                var boneData = bones[i];
                var bone     = BaseObject.BorrowObject <Bone>();
                bone._init(boneData);

                if (boneData.parent != null)
                {
                    armature.AddBone(bone, boneData.parent.name);
                }
                else
                {
                    armature.AddBone(bone);
                }

                if (boneData.ik != null)
                {
                    bone.ikBendPositive = boneData.bendPositive;
                    bone.ikWeight       = boneData.weight;
                    bone._setIK(armature.GetBone(boneData.ik.name), boneData.chain, boneData.chainIndex);
                }
            }
        }
        public void AddBoneMask(Armature armature, string name, bool recursive = false)
        {
            var currentBone = armature.GetBone(name);

            if (currentBone == null)
            {
                return;
            }

            if (!boneMask.Contains(name)) // Add mixing
            {
                boneMask.Add(name);
            }

            if (recursive) // Add recursive mixing.
            {
                var bones = armature.GetBones();
                for (int i = 0, l = bones.Count; i < l; ++i)
                {
                    var bone = bones[i];
                    if (!boneMask.Contains(bone.name) && currentBone.Contains(bone))
                    {
                        boneMask.Add(bone.name);
                    }
                }
            }
        }
Example #6
0
        /**
         * @private
         */
        protected void _buildBones(BuildArmaturePackage dataPackage, Armature armature)
        {
            foreach (var boneData in dataPackage.armature.sortedBones)
            {
                var bone = BaseObject.BorrowObject <Bone>();
                bone.name = boneData.name;
                bone.inheritTranslation = boneData.inheritTranslation;
                bone.inheritRotation    = boneData.inheritRotation;
                bone.inheritScale       = boneData.inheritScale;
                bone.length             = boneData.length;
                bone.origin.CopyFrom(boneData.transform);

                if (boneData.parent != null)
                {
                    armature.AddBone(bone, boneData.parent.name);
                }
                else
                {
                    armature.AddBone(bone);
                }

                if (boneData.ik != null)
                {
                    bone.ikBendPositive = boneData.bendPositive;
                    bone.ikWeight       = boneData.weight;
                    bone._setIK(armature.GetBone(boneData.ik.name), boneData.chain, boneData.chainIndex);
                }
            }
        }
 static int GetBone(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         DragonBones.Armature obj = (DragonBones.Armature)ToLua.CheckObject(L, 1, typeof(DragonBones.Armature));
         string           arg0    = ToLua.CheckString(L, 2);
         DragonBones.Bone o       = obj.GetBone(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
        /// <private/>
        public void RemoveBoneMask(Armature armature, string name, bool recursive = true)
        {
            if (boneMask.Contains(name)) // Remove mixing.
            {
                boneMask.Remove(name);
            }

            if (recursive)
            {
                var currentBone = armature.GetBone(name);
                if (currentBone != null)
                {
                    var bones = armature.GetBones();
                    if (boneMask.Count > 0) // Remove recursive mixing.
                    {
                        for (int i = 0, l = bones.Count; i < l; ++i)
                        {
                            var bone = bones[i];
                            if (boneMask.Contains(bone.name) && currentBone.Contains(bone))
                            {
                                boneMask.Remove(bone.name);
                            }
                        }
                    }
                    else // Add unrecursive mixing.
                    {
                        for (int i = 0, l = bones.Count; i < l; ++i)
                        {
                            var bone = bones[i];
                            if (bone == currentBone)
                            {
                                continue;
                            }

                            if (!currentBone.Contains(bone))
                            {
                                boneMask.Add(bone.name);
                            }
                        }
                    }
                }
            }
        }
        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;
            }
        }