Example #1
0
        public void DrawTip(IBone bone)
        {
            if (Event.current == null || Event.current.type != EventType.Repaint)
            {
                return;
            }

            BoneDrawingUtility.DrawBoneNodeOutline(bone.tip, Styles.tipColor, GetScale() * 0.5f);
        }
Example #2
0
        public BoneVertex()
        {
            bones = new IBone[4];
            for (int i = 0; i < 4; i++)
            {
                bones[i] = new IBone();
            }

            numbones = 0;
        }
        public void SetBoneName(IBone bone, string newName)
        {
            ((Bone)bone).name = newName;
            SetDirty();

            if (IsBoneNameMatchAutoFormat(newName))
            {
                FindBiggestAutoNameCounter();
            }
        }
 static void GetSpineAndHips(IBone hips, out IBone spine, out IBone leg_L, out IBone leg_R)
 {
     if (hips.Children.Count != 3)
     {
         throw new System.Exception("Hips require 3 children");
     }
     spine = SelectBone((l, r) => l.CenterOfDescendant().y > r.CenterOfDescendant().y ? l : r, hips.Children);
     leg_L = SelectBone((l, r) => l.CenterOfDescendant().x < r.CenterOfDescendant().x ? l : r, hips.Children);
     leg_R = SelectBone((l, r) => l.CenterOfDescendant().x > r.CenterOfDescendant().x ? l : r, hips.Children);
 }
 static void GetNeckAndArms(IBone chest, out IBone neck, out IBone arm_L, out IBone arm_R)
 {
     if (chest.Children.Count != 3)
     {
         throw new System.Exception("Chest require 3 children");
     }
     neck  = SelectBone((l, r) => l.CenterOfDescendant().y > r.CenterOfDescendant().y ? l : r, chest.Children);
     arm_L = SelectBone((l, r) => l.CenterOfDescendant().x < r.CenterOfDescendant().x ? l : r, chest.Children);
     arm_R = SelectBone((l, r) => l.CenterOfDescendant().x > r.CenterOfDescendant().x ? l : r, chest.Children);
 }
Example #6
0
 private void UpdateSpritesheetSettings(string boneID, IBone bone, SkeletalKeyframe keyFrame)
 {
     if (keyFrame.BoneAnimationData.ContainsKey(boneID))
     {
         bone.ApplySkin(
             keyFrame.BoneAnimationData[boneID].TextureName,
             keyFrame.BoneAnimationData[boneID].Origin,
             keyFrame.BoneAnimationData[boneID].SourceArea);
     }
 }
 private void MarkChildRetain(IBone parent)
 {
     foreach (var bone in m_BoneList.bones)
     {
         if (BoneUtility.IsOffspringOf(bone, parent) || bone == parent)
         {
             bone.markedRetainWorldPosition = true;
         }
     }
 }
 public void MoveTip(IBone bone, Vector3 tipPosition, bool keepChildPosition)
 {
     ((Bone)bone).tip = tipPosition;
     SetDirty();
     if (keepChildPosition)
     {
         MarkChildRetain(bone);
     }
     UpdateHierarchyFromBone(bone, keepChildPosition);
 }
        private void MoveBone(IBone bone, Vector3 b, bool disableSnap)
        {
            RecordUndo(bone, "bone body move");

            // In normal movement mode, moving a bone body will move it, and all its offspring.
            // If the parent tip is snapped to this bone, the parent tip will move together with this bone.
            // If any sibling(s) bone is snapped to this bone, those bone will move together, but just the bone, tip and offspring remain intact.
            if (!state.freeMoving)
            {
                var snapped = false;
                if (!bone.isRoot && ShouldSnap(b, bone.parent.tip) && !disableSnap)
                {
                    m_Model.MoveBone(bone, bone.parent.tip, false);
                    snapped = true;
                }
                else if (!bone.isRoot && ShouldSnap(b, bone.parent.position) && !disableSnap)
                {
                    m_Model.MoveBone(bone, bone.parent.position, false);
                    snapped = true;
                }
                if (!snapped)
                {
                    m_Model.MoveBone(bone, b, false);
                }

                // There are more works to do if we need to update the parent's tip
                if (m_UpdateParentTip[bone])
                {
                    var siblingToMoveTogether = m_SiblingToMoveTogether[bone];
                    var offspringOfSelected   = m_OffspringOfSelected[bone];
                    var offspringOfParent     = m_OffspringOfParent[bone];

                    // Move the sibling alongside with this bone.
                    foreach (var siblingBone in siblingToMoveTogether)
                    {
                        var oldChildTip = siblingBone.tip;
                        m_Model.MoveBone(siblingBone, bone.position);

                        // Maintain the previous tip position.
                        m_Model.MoveTip(siblingBone, oldChildTip);
                    }

                    // Move the parent's tip, all offspring of it are in updated position and marked to retain it.
                    m_Model.MoveTip(bone.parent, b);
                }
            }
            // In free movement mode, just move the bone, all offspring are not affected.
            // No sibling movement, no parent tip movement too.
            else
            {
                m_Model.MoveBone(bone, b);
            }

            m_View.Refresh();
        }
Example #10
0
 public override void AddBone(IBone boneToAdd, string parentBoneID)
 {
     if (!(boneToAdd is ISerializable))
     {
         throw new Exception("Bones for StorableSkeleton must implement ISerializable");
     }
     else
     {
         base.AddBone(boneToAdd, parentBoneID);
     }
 }
 private bool IsConflictWithOtherBoneNames(IBone bone)
 {
     foreach (var otherBone in m_Model.bones)
     {
         if (bone != otherBone && bone.name == otherBone.name)
         {
             return(true);
         }
     }
     return(false);
 }
Example #12
0
                public BoneImpl(IBone root, IBone?parent, float x, float y, float z)
                {
                    this.Root   = root;
                    this.Parent = parent;
                    this.SetLocalPosition(x, y, z);

                    this.Children = new ReadOnlyCollection <IBone>(this.children_);

                    this.counter_ = (parent as BoneImpl ?? root as BoneImpl) !.counter_;
                    this.Index    = this.counter_.GetAndIncrement();
                }
Example #13
0
        public void DrawPreviewLinkFromBone(IBone bone)
        {
            if (Event.current == null || Event.current.type != EventType.Repaint)
            {
                return;
            }

            var mousePosition = GetMouseWorldPosition();

            BoneDrawingUtility.DrawParentLink(mousePosition, bone.position, Styles.previewColor, GetScale());
        }
Example #14
0
        private void SetCurrentValuesAsAnimationStartPoints(string boneID, IBone bone)
        {
            if (!_boneFrameStartValues.ContainsKey(boneID))
            {
                _boneFrameStartValues.Add(boneID, new SkeletalKeyframe.DataContainer());
            }

            _boneFrameStartValues[boneID].Offset   = bone.RelativePosition;
            _boneFrameStartValues[boneID].Rotation = Utility.RectifyAngle(bone.RelativeRotation);
            _boneFrameStartValues[boneID].Scale    = bone.RelativeScale;
        }
Example #15
0
        public void DrawLinkToParent(IBone bone, bool selected)
        {
            if (Event.current == null || Event.current.type != EventType.Repaint)
            {
                return;
            }

            var pointingTo = bone.parent.position;

            BoneDrawingUtility.DrawParentLink(bone.position, pointingTo, selected ? Styles.selectedParentLinkColor : color, GetScale());
        }
        public static IEnumerable <IBone> Traverse(this IBone self)
        {
            yield return(self);

            foreach (var child in self.Children)
            {
                foreach (var x in child.Traverse())
                {
                    yield return(x);
                }
            }
        }
        public static Vector3 CenterOfDescendant(this IBone self)
        {
            var sum = Vector3.zero;
            int i   = 0;

            foreach (var x in self.Traverse())
            {
                sum += x.SkeletonLoacalPosition;
                ++i;
            }
            return(sum / i);
        }
Example #18
0
 private void AttemptToAddPrimaryBone(IBone boneToAdd)
 {
     if (!string.IsNullOrEmpty(PrimaryBoneID))
     {
         throw new Exception(string.Concat("Primary bone already exists - ID: ", PrimaryBoneID));
     }
     else
     {
         SetBoneStandardValues(boneToAdd);
         Bones.Add(boneToAdd.ID, boneToAdd);
         PrimaryBoneID = boneToAdd.ID;
     }
 }
Example #19
0
        public void DrawBone(IBone bone, bool selected)
        {
            if (Event.current == null || Event.current.type != EventType.Repaint)
            {
                return;
            }

            var scale = GetScale(bone.position, bone.tip);

            BoneDrawingUtility.DrawBoneNodeOutline(bone.position, selected ? Styles.selectedBoneColor : color, scale);
            BoneDrawingUtility.DrawBoneBody(bone.position, bone.tip, selected ? Styles.selectedBoneColor : color, scale);
            BoneDrawingUtility.DrawBoneNode(bone.position, selected ? Styles.selectedNodeColor : Styles.nodeColor, scale);
        }
        private void CalculateRenderDepthFromLimbTreeLevel()
        {
            IBone currentBone = this;
            float limbTreeLevelRenderDepthModifier = Depth_Modifier_From_Primary_To_Secondary_Limb_Levels;

            while (currentBone.Parent != null)
            {
                limbTreeLevelRenderDepthModifier *= Depth_Modifier_From_Secondary_To_Following_Limb_Levels;
                currentBone = currentBone.Parent;
            }

            RenderDepth = Parent.RenderDepth + (_relativeDepth / limbTreeLevelRenderDepthModifier);
        }
Example #21
0
 public IBoneWeights GetOrCreateBoneWeights(
     PreprojectMode preprojectMode,
     IBone bone)
 {
     if (!this.boneWeightsByBone_.TryGetValue(bone, out var boneWeights))
     {
         boneWeights = this.CreateBoneWeights(
             preprojectMode,
             new BoneWeight(bone, new FinMatrix4x4().SetIdentity(), 1));
         this.boneWeightsByBone_[bone] = boneWeights;
     }
     return(boneWeights);
 }
Example #22
0
        public void DrawPreviewTipFromTip(IBone bone)
        {
            if (Event.current == null || Event.current.type != EventType.Repaint)
            {
                return;
            }

            var mousePosition = GetMouseWorldPosition();
            var scale         = GetScale(bone.tip, mousePosition);

            BoneDrawingUtility.DrawBoneBody(bone.tip, mousePosition, Styles.previewColor, scale);
            BoneDrawingUtility.DrawBoneNodeOutline(bone.tip, Styles.previewColor, scale);
        }
        private string AutoBoneName(IBone parent)
        {
            string inheritedName;
            int    counter;

            DissectBoneName(parent.name, out inheritedName, out counter);

            if (inheritedName == k_DefaultRootName)
            {
                inheritedName = k_DefaultBoneName;
            }

            return(inheritedName + "_" + ++m_AutoNameCounter);
        }
        private void ApplyBoneOrientationToNode_(Node assNode, IBone finBone)
        {
            var finTransform =
                MatrixTransformUtil.FromTrs(finBone.LocalPosition,
                                            finBone.LocalRotation,
                                            finBone.LocalScale);

            var assNodeTransform = assNode.Transform;

            MatrixConversionUtil.CopyFinIntoAssimp(
                finTransform,
                ref assNodeTransform);
            assNode.Transform = assNodeTransform;
        }
Example #25
0
        public virtual void AddBone(IBone boneToAdd, string parentBoneID)
        {
            if (string.IsNullOrEmpty(parentBoneID))
            {
                AttemptToAddPrimaryBone(boneToAdd);
            }
            else
            {
                AttemptToAddChildBone(boneToAdd, parentBoneID);
            }

            RecalculateBonePositions();
            RecalculateBoneRenderDepths();
            RecalculateSkinTints();
        }
        public static bool IsOffspringOf(IBone bone, IBone potentialAncestor)
        {
            var isOffspring = false;

            do
            {
                bone = bone.parent;
                if (bone == potentialAncestor)
                {
                    isOffspring = true;
                    break;
                }
            }while (bone != null && !isOffspring);

            return(isOffspring);
        }
Example #27
0
        private int GetControlID(IBone bone, int hint, Dictionary <IBone, int> container)
        {
            int id = -1;

            if (!container.TryGetValue(bone, out id))
            {
                if (Event.current != null && Event.current.type != EventType.Used)
                {
                    id = GUIUtility.GetControlID(hint, FocusType.Keyboard);
                    container.Add(bone, id);
                    Debug.Assert(id != -1, "Failed to get new control ID");
                }
            }

            return(id);
        }
        public void DeleteBone(IBone bone)
        {
            foreach (var otherBone in m_BoneList.bones)
            {
                if (BoneUtility.IsOffspringOf(otherBone, bone))
                {
                    throw new InvalidOperationException("Cannot delete a parent bone with children. Children should all be removed/transfered first.");
                }
            }

            m_BoneList.bones.Remove((Bone)bone);

            m_OrderDirty = true;
            SetDirty();
            MarkChildRetain(bone);
            UpdateHierarchyFromBone(bone, true);
        }
Example #29
0
 private void AttemptToAddChildBone(IBone boneToAdd, string parentBoneID)
 {
     if (Bones.ContainsKey(boneToAdd.ID))
     {
         throw new Exception(string.Concat("Bone IDs must be unique! ID: ", boneToAdd.ID));
     }
     else if (!Bones.ContainsKey(parentBoneID))
     {
         throw new Exception(string.Concat("Parent does not exist! Child ID: ", boneToAdd.ID, " expected parent ID: ", parentBoneID));
     }
     else
     {
         SetBoneStandardValues(boneToAdd);
         boneToAdd.Parent = Bones[parentBoneID];
         Bones.Add(boneToAdd.ID, boneToAdd);
         Bones[parentBoneID].Children.Add(boneToAdd);
     }
 }
Example #30
0
        public Vector3 HandleBoneDrag(IBone bone)
        {
            var id = GetBoneControlID(bone);

            Vector3 forward;
            Vector3 up;
            Vector3 right;

            GetSliderDirection(out forward, out up, out right);

            EditorGUI.BeginChangeCheck();
            var newPosition = Handles.Slider2D(id, bone.position, Vector3.zero, forward, up, right, HandleUtility.GetHandleSize(bone.position), FakeCap, Vector2.zero);

            if (EditorGUI.EndChangeCheck())
            {
                return(newPosition);
            }
            return(Vector3.zero);
        }
 private void UpdateSpritesheetSettings(string boneID, IBone bone, SkeletalKeyframe keyFrame)
 {
     if (keyFrame.BoneAnimationData.ContainsKey(boneID))
     {
         bone.ApplySkin(
             keyFrame.BoneAnimationData[boneID].TextureName,
             keyFrame.BoneAnimationData[boneID].Origin,
             keyFrame.BoneAnimationData[boneID].SourceArea);
     }
 }
        public virtual void AddBone(IBone boneToAdd, string parentBoneID)
        {
            if (string.IsNullOrEmpty(parentBoneID)) { AttemptToAddPrimaryBone(boneToAdd); }
            else { AttemptToAddChildBone(boneToAdd, parentBoneID); }

            RecalculateBonePositions();
            RecalculateBoneRenderDepths();
            RecalculateSkinTints();
        }
 private void AttemptToAddChildBone(IBone boneToAdd, string parentBoneID)
 {
     if (Bones.ContainsKey(boneToAdd.ID))
     {
         throw new Exception(string.Concat("Bone IDs must be unique! ID: ", boneToAdd.ID));
     }
     else if (!Bones.ContainsKey(parentBoneID))
     {
         throw new Exception(string.Concat("Parent does not exist! Child ID: ", boneToAdd.ID, " expected parent ID: ", parentBoneID));
     }
     else
     {
         SetBoneStandardValues(boneToAdd);
         boneToAdd.Parent = Bones[parentBoneID];
         Bones.Add(boneToAdd.ID, boneToAdd);
         Bones[parentBoneID].Children.Add(boneToAdd);
     }
 }
 public override void AddBone(IBone boneToAdd, string parentBoneID)
 {
     if (!(boneToAdd is ISerializable)) { throw new Exception("Bones for StorableSkeleton must implement ISerializable"); }
     else { base.AddBone(boneToAdd, parentBoneID); }
 }
 private void AttemptToAddPrimaryBone(IBone boneToAdd)
 {
     if (!string.IsNullOrEmpty(PrimaryBoneID))
     {
         throw new Exception(string.Concat("Primary bone already exists - ID: ", PrimaryBoneID));
     }
     else
     {
         SetBoneStandardValues(boneToAdd);
         Bones.Add(boneToAdd.ID, boneToAdd);
         PrimaryBoneID = boneToAdd.ID;
     }
 }
 private void SetBoneStandardValues(IBone bone)
 {
     bone.RenderLayer = RenderLayer;
 }
        private void SetCurrentValuesAsAnimationStartPoints(string boneID, IBone bone)
        {
            if (!_boneFrameStartValues.ContainsKey(boneID)) { _boneFrameStartValues.Add(boneID, new SkeletalKeyframe.DataContainer()); }

            _boneFrameStartValues[boneID].Offset = bone.RelativePosition;
            _boneFrameStartValues[boneID].Rotation = Utility.RectifyAngle(bone.RelativeRotation);
            _boneFrameStartValues[boneID].Scale = bone.RelativeScale;
        }