Beispiel #1
0
 public Quaternion GetBoneTargetRotation(FullBodyBipedEffector type)
 {
     OCIChar.IKInfo info = this._target.ociChar.listIKTarget[_effectorToIndex[type]];
     if (!this._target.ikEnabled || info.active == false)
     {
         return(Quaternion.identity);
     }
     return(info.guideObject.transformTarget.localRotation);
 }
Beispiel #2
0
 public Vector3 GetBendGoalPosition(FullBodyBipedChain type, bool world = true)
 {
     OCIChar.IKInfo info = this._target.ociChar.listIKTarget[_chainToIndex[type]];
     if (!this._target.ikEnabled || info.active == false)
     {
         return(Vector3.zero);
     }
     return(world ? info.guideObject.transformTarget.position : info.guideObject.transformTarget.localPosition);
 }
 private static OCIChar.IKInfo AddIKTarget(
     OCIChar _ociChar,
     IKCtrl _ikCtrl,
     int _no,
     FBIKChain _chain,
     bool _usedRot,
     Transform _bone)
 {
     OCIChar.IKInfo ikInfo = AddObjectAssist.AddIKTarget(_ociChar, _ikCtrl, _no, (Transform)((IKConstraintBend)_chain.bendConstraint).bendGoal, _usedRot, _bone, false);
     ((IKConstraintBend)_chain.bendConstraint).weight   = (__Null)1.0;
     ((IKConstraintBend)_chain.bendConstraint).bendGoal = (__Null)ikInfo.targetObject;
     return(ikInfo);
 }
 private static OCIChar.IKInfo AddIKTarget(
     OCIChar _ociChar,
     IKCtrl _ikCtrl,
     int _no,
     IKEffector _effector,
     bool _usedRot,
     Transform _bone)
 {
     OCIChar.IKInfo ikInfo = AddObjectAssist.AddIKTarget(_ociChar, _ikCtrl, _no, (Transform)_effector.target, _usedRot, _bone, true);
     _effector.positionWeight = (__Null)1.0;
     _effector.rotationWeight = !_usedRot ? (__Null)0.0 : (__Null)1.0;
     _effector.target         = (__Null)ikInfo.targetObject;
     return(ikInfo);
 }
Beispiel #5
0
 public void SetBendGoalPosition(FullBodyBipedChain type, Vector3 targetPosition, bool world = true)
 {
     OCIChar.IKInfo info = this._target.ociChar.listIKTarget[_chainToIndex[type]];
     if (this._target.ikEnabled && info.active)
     {
         if (this._currentDragType != DragType.None)
         {
             if (this._oldPosValues.ContainsKey(info.guideObject.dicKey) == false)
             {
                 this._oldPosValues.Add(info.guideObject.dicKey, info.guideObject.changeAmount.pos);
             }
             info.guideObject.changeAmount.pos = world ? info.guideObject.transformTarget.parent.InverseTransformPoint(targetPosition) : targetPosition;
         }
     }
 }
Beispiel #6
0
 public void SetBoneTargetRotation(FullBodyBipedEffector type, Quaternion targetRotation)
 {
     OCIChar.IKInfo info = this._target.ociChar.listIKTarget[_effectorToIndex[type]];
     if (this._target.ikEnabled && info.active)
     {
         if (this._currentDragType != DragType.None)
         {
             if (this._oldRotValues.ContainsKey(info.guideObject.dicKey) == false)
             {
                 this._oldRotValues.Add(info.guideObject.dicKey, info.guideObject.changeAmount.rot);
             }
             info.guideObject.changeAmount.rot = targetRotation.eulerAngles;
         }
     }
 }
Beispiel #7
0
 /// <summary>
 /// Add a link between the selected guide object and the selected object.
 /// </summary>
 /// <param name="selectedGuideObject">Name of the bone associated with the guide object.</param>
 /// <param name="selectedObject">ObjectCtrlInfo of the object. Can be an item, a folder, or a route.</param>
 public void AddLink(string selectedGuideObject, ObjectCtrlInfo selectedObject)
 {
     if (selectedGuideObject == "eyes")
     {
         AddEyeLink(selectedObject);
     }
     else if (selectedGuideObject == "neck")
     {
         AddNeckLink(selectedObject);
     }
     else
     {
         OCIChar.IKInfo ikInfo = OCIChar.listIKTarget.First(x => x.boneObject.name == selectedGuideObject);
         GuideObjectLinks[ikInfo] = selectedObject;
     }
 }
Beispiel #8
0
 /// <summary>
 /// Remove a link between the selected guide object and any object it is currently linked to.
 /// </summary>
 /// <param name="selectedGuideObject">Name of the bone associated with the guide object.</param>
 public void RemoveLink(string selectedGuideObject)
 {
     if (selectedGuideObject == "eyes")
     {
         RemoveEyeLink();
     }
     else if (selectedGuideObject == "neck")
     {
         RemoveNeckLink();
     }
     else
     {
         OCIChar.IKInfo ikInfo = OCIChar.listIKTarget.First(x => x.boneObject.name == selectedGuideObject);
         GuideObjectLinksV1.Remove(ikInfo);
         GuideObjectLinks.Remove(ikInfo);
     }
 }
Beispiel #9
0
 /// <summary>
 /// Remove a link between the selected guide object and any object it is currently linked to.
 /// </summary>
 public void RemoveLink(OCIChar.IKInfo ikInfo)
 {
     GuideObjectLinksV1.Remove(ikInfo);
     GuideObjectLinks.Remove(ikInfo);
 }
Beispiel #10
0
 /// <summary>
 /// Add a v1 link. Only ever added by loading card data, new links will never by of this type.
 /// </summary>
 private void AddLinkV1(string selectedGuideObject, ObjectCtrlInfo selectedObject)
 {
     OCIChar.IKInfo ikInfo = OCIChar.listIKTarget.First(x => x.boneObject.name == selectedGuideObject);
     GuideObjectLinksV1[ikInfo] = selectedObject;
 }
Beispiel #11
0
        private void CopyLimbToTwinInternal()
        {
            this.StartDrag(DragType.Both);
            this._lockDrag = true;
            HashSet <OIBoneInfo.BoneGroup> fkTwinLimb = new HashSet <OIBoneInfo.BoneGroup>();

            switch (this._nextFKCopy)
            {
            case OIBoneInfo.BoneGroup.RightLeg:
                fkTwinLimb.Add(OIBoneInfo.BoneGroup.LeftLeg);
                fkTwinLimb.Add((OIBoneInfo.BoneGroup) 5);
                break;

            case OIBoneInfo.BoneGroup.LeftLeg:
                fkTwinLimb.Add(OIBoneInfo.BoneGroup.RightLeg);
                fkTwinLimb.Add((OIBoneInfo.BoneGroup) 3);
                break;

            case OIBoneInfo.BoneGroup.RightArm:
                fkTwinLimb.Add(OIBoneInfo.BoneGroup.LeftArm);
                fkTwinLimb.Add((OIBoneInfo.BoneGroup) 17);
                break;

            case OIBoneInfo.BoneGroup.LeftArm:
                fkTwinLimb.Add(OIBoneInfo.BoneGroup.RightArm);
                fkTwinLimb.Add((OIBoneInfo.BoneGroup) 9);
                break;
            }

            this._additionalRotationEqualsCommands = new List <GuideCommand.EqualsInfo>();
            foreach (OCIChar.BoneInfo bone in this._target.ociChar.listBones)
            {
                Transform twinBoneTransform = null;
                Transform boneTransform     = bone.guideObject.transformTarget;
                if (fkTwinLimb.Contains(bone.boneGroup) == false)
                {
                    continue;
                }
                twinBoneTransform = this._bonesEditor.GetTwinBone(boneTransform);
                if (twinBoneTransform == null)
                {
                    twinBoneTransform = boneTransform;
                }

                OCIChar.BoneInfo twinBone;
                if (twinBoneTransform != null && this._target.fkObjects.TryGetValue(twinBoneTransform.gameObject, out twinBone))
                {
                    if (twinBoneTransform == boneTransform)
                    {
                        Quaternion rot = Quaternion.Euler(bone.guideObject.changeAmount.rot);
                        rot = new Quaternion(rot.x, -rot.y, -rot.z, rot.w);

                        Vector3 oldRotValue = bone.guideObject.changeAmount.rot;

                        bone.guideObject.changeAmount.rot = rot.eulerAngles;

                        this._additionalRotationEqualsCommands.Add(new GuideCommand.EqualsInfo()
                        {
                            dicKey   = bone.guideObject.dicKey,
                            oldValue = oldRotValue,
                            newValue = bone.guideObject.changeAmount.rot
                        });
                    }
                    else
                    {
                        Quaternion twinRot = Quaternion.Euler(twinBone.guideObject.changeAmount.rot);
                        twinRot = new Quaternion(twinRot.x, -twinRot.y, -twinRot.z, twinRot.w);
                        Vector3 oldRotValue = bone.guideObject.changeAmount.rot;
                        bone.guideObject.changeAmount.rot = twinRot.eulerAngles;
                        this._additionalRotationEqualsCommands.Add(new GuideCommand.EqualsInfo()
                        {
                            dicKey   = bone.guideObject.dicKey,
                            oldValue = oldRotValue,
                            newValue = bone.guideObject.changeAmount.rot
                        });
                    }
                }
            }

            FullBodyBipedChain    limb = this._nextIKCopy;
            FullBodyBipedEffector effectorSrc;
            FullBodyBipedChain    bendGoalSrc;
            FullBodyBipedEffector effectorDest;
            FullBodyBipedChain    bendGoalDest;
            Transform             effectorSrcRealBone;
            Transform             effectorDestRealBone;
            Transform             root;

            switch (limb)
            {
            case FullBodyBipedChain.LeftArm:
                effectorSrc          = FullBodyBipedEffector.LeftHand;
                effectorSrcRealBone  = this._body.references.leftHand;
                effectorDestRealBone = this._body.references.rightHand;
                root = this._body.solver.spineMapping.spineBones[this._body.solver.spineMapping.spineBones.Length - 2];
                break;

            case FullBodyBipedChain.LeftLeg:
                effectorSrc          = FullBodyBipedEffector.LeftFoot;
                effectorSrcRealBone  = this._body.references.leftFoot;
                effectorDestRealBone = this._body.references.rightFoot;
                root = this._body.solver.spineMapping.spineBones[0];
                break;

            case FullBodyBipedChain.RightArm:
                effectorSrc          = FullBodyBipedEffector.RightHand;
                effectorSrcRealBone  = this._body.references.rightHand;
                effectorDestRealBone = this._body.references.leftHand;
                root = this._body.solver.spineMapping.spineBones[this._body.solver.spineMapping.spineBones.Length - 2];
                break;

            case FullBodyBipedChain.RightLeg:
                effectorSrc          = FullBodyBipedEffector.RightFoot;
                effectorSrcRealBone  = this._body.references.rightFoot;
                effectorDestRealBone = this._body.references.leftFoot;
                root = this._body.solver.spineMapping.spineBones[0];
                break;

            default:
                effectorSrc          = FullBodyBipedEffector.RightHand;
                effectorSrcRealBone  = null;
                effectorDestRealBone = null;
                root = null;
                break;
            }
            bendGoalSrc  = limb;
            bendGoalDest = this.GetTwinChain(limb);
            effectorDest = this.GetTwinEffector(effectorSrc);

            Vector3 localPos = root.InverseTransformPoint(this._target.ociChar.listIKTarget[_effectorToIndex[effectorSrc]].guideObject.transformTarget.position);

            localPos.x *= -1f;
            Vector3 effectorPosition = root.TransformPoint(localPos);

            localPos    = root.InverseTransformPoint(this._target.ociChar.listIKTarget[_chainToIndex[bendGoalSrc]].guideObject.transformTarget.position);
            localPos.x *= -1f;
            Vector3 bendGoalPosition = root.TransformPoint(localPos);


            this.SetBoneTargetPosition(effectorDest, effectorPosition);
            this.SetBendGoalPosition(bendGoalDest, bendGoalPosition);
            this.SetBoneTargetRotation(effectorDest, this.GetBoneTargetRotation(effectorDest));

            this._scheduleNextIKPostUpdate = () =>
            {
                Quaternion rot = effectorSrcRealBone.localRotation;
                rot = new Quaternion(rot.x, -rot.y, -rot.z, rot.w);
                effectorDestRealBone.localRotation = rot;                                                             //Setting real bone local rotation
                OCIChar.IKInfo effectorDestInfo = this._target.ociChar.listIKTarget[_effectorToIndex[effectorDest]];
                effectorDestInfo.guideObject.transformTarget.rotation = effectorDestRealBone.rotation;                //Using real bone rotation to set IK target rotation;
                this.SetBoneTargetRotation(effectorDest, effectorDestInfo.guideObject.transformTarget.localRotation); //Setting again the IK target with its own local rotation through normal means so it isn't ignored by neo while saving
                this._lockDrag = false;
                this.StopDrag();
            };
        }
        private static OCIChar.IKInfo AddIKTarget(
            OCIChar _ociChar,
            IKCtrl _ikCtrl,
            int _no,
            Transform _target,
            bool _usedRot,
            Transform _bone,
            bool _isRed)
        {
            OIIKTargetInfo _targetInfo = (OIIKTargetInfo)null;
            bool           flag        = !_ociChar.oiCharInfo.ikTarget.TryGetValue(_no, out _targetInfo);

            if (flag)
            {
                _targetInfo = new OIIKTargetInfo(Studio.Studio.GetNewIndex());
                _ociChar.oiCharInfo.ikTarget.Add(_no, _targetInfo);
            }
            switch (_no)
            {
            case 0:
                _targetInfo.group = OIBoneInfo.BoneGroup.Body;
                break;

            case 1:
            case 2:
            case 3:
                _targetInfo.group = OIBoneInfo.BoneGroup.LeftArm;
                break;

            case 4:
            case 5:
            case 6:
                _targetInfo.group = OIBoneInfo.BoneGroup.RightArm;
                break;

            case 7:
            case 8:
            case 9:
                _targetInfo.group = OIBoneInfo.BoneGroup.LeftLeg;
                break;

            case 10:
            case 11:
            case 12:
                _targetInfo.group = OIBoneInfo.BoneGroup.RightLeg;
                break;
            }
            GameObject gameObject = new GameObject(((Object)_target).get_name() + "(work)");

            gameObject.get_transform().SetParent(((Component)_ociChar.charInfo).get_transform());
            GuideObject _guideObject = Singleton <GuideObjectManager> .Instance.Add(gameObject.get_transform(), _targetInfo.dicKey);

            _guideObject.mode              = GuideObject.Mode.LocalIK;
            _guideObject.enableRot         = _usedRot;
            _guideObject.enableScale       = false;
            _guideObject.enableMaluti      = false;
            _guideObject.calcScale         = false;
            _guideObject.scaleRate         = 0.5f;
            _guideObject.scaleRot          = 0.05f;
            _guideObject.scaleSelect       = 0.1f;
            _guideObject.parentGuide       = _ociChar.guideObject;
            _guideObject.guideSelect.color = !_isRed?Color.get_blue() : Color.get_red();

            _guideObject.moveCalc = GuideMove.MoveCalc.TYPE3;
            OCIChar.IKInfo ikInfo = new OCIChar.IKInfo(_guideObject, _targetInfo, _target, gameObject.get_transform(), _bone);
            if (!flag)
            {
                _targetInfo.changeAmount.OnChange();
            }
            _ikCtrl.addIKInfo = ikInfo;
            _ociChar.listIKTarget.Add(ikInfo);
            _guideObject.SetActive(false, true);
            return(ikInfo);
        }