Ejemplo n.º 1
0
    public static void RotateBone(Transform effector, Transform bone, Vector3 goalPos)
    {
        Vector3 effectorPos = effector.position;
        Vector3 bonePos     = bone.position;

        Vector3 boneToEffector = effectorPos - bonePos;
        Vector3 boneToGoal     = goalPos - bonePos;

        Quaternion fromToRotation = Quaternion.FromToRotation(boneToEffector, boneToGoal);

        // Apply the old rotation first, then the new rotation.
        // This is because the new rotation is created based on old rotation
        // applied to the object.
        Quaternion newRotation = fromToRotation * bone.rotation;

        // check whether any constraint attached to the bone
        RotationConstraint constraint = bone.GetComponent <RotationConstraint>();

        if (constraint)
        {
            constraint.autoUpdate = false;
            constraint.SetWorldRotation(newRotation);
        }
        else
        {
            bone.rotation = newRotation;
        }
    }
Ejemplo n.º 2
0
        public override string ToString()
        {
            StringBuilder __sb = new StringBuilder("MGeometryConstraint(");

            __sb.Append(", ParentObjectID: ");
            __sb.Append(ParentObjectID);
            if (ParentToConstraint != null && __isset.ParentToConstraint)
            {
                __sb.Append(", ParentToConstraint: ");
                __sb.Append(ParentToConstraint == null ? "<null>" : ParentToConstraint.ToString());
            }
            if (TranslationConstraint != null && __isset.TranslationConstraint)
            {
                __sb.Append(", TranslationConstraint: ");
                __sb.Append(TranslationConstraint == null ? "<null>" : TranslationConstraint.ToString());
            }
            if (RotationConstraint != null && __isset.RotationConstraint)
            {
                __sb.Append(", RotationConstraint: ");
                __sb.Append(RotationConstraint == null ? "<null>" : RotationConstraint.ToString());
            }
            if (__isset.WeightingFactor)
            {
                __sb.Append(", WeightingFactor: ");
                __sb.Append(WeightingFactor);
            }
            __sb.Append(")");
            return(__sb.ToString());
        }
    ConstraintStatus AddConstraint(string boneToConstrain, string sourceBone, float weight, Axis freeze)
    {
        var  transform = GameObject.Find(boneToConstrain);
        bool catsUsed  = false;

        if (transform == null)
        {
            transform = GameObject.Find(boneToConstrain.Replace(".", "_"));
            catsUsed  = true;
        }

        if (transform == null)
        {
            EditorUtility.DisplayDialog("Error Twist bone not found!", "The twist bone: " + boneToConstrain + " Could not be found!", "ok");
            return(ConstraintStatus.Error);
        }
        var bone = transform.gameObject;

        if (bone == null)
        {
            EditorUtility.DisplayDialog("Error Twist bone not found!", "The twist bone: " + boneToConstrain + " Could not be found!", "ok");
            return(ConstraintStatus.Error);
        }

        RotationConstraint rc = bone.AddComponent(typeof(RotationConstraint)) as RotationConstraint;

        if (rc != null)
        {
            rc.weight       = weight;
            rc.rotationAxis = freeze;
            var sourceTransform = GameObject.Find(sourceBone).transform;
            var source          = new ConstraintSource();
            source.sourceTransform = sourceTransform;
            source.weight          = 1;
            rc.AddSource(source);
            rc.locked           = false;
            rc.constraintActive = true;
            newConstraints.Add(rc);
            if (catsUsed)
            {
                return(ConstraintStatus.Success);
            }
            else
            {
                return(ConstraintStatus.CATSUsedSuccess);
            }
        }
        else
        {
            Debug.LogWarning("Rotation constraint probably already setup for: " + boneToConstrain);
            return(ConstraintStatus.Warning);
        }
    }
Ejemplo n.º 4
0
        private void CreateTarget()
        {
            Debug.Log("<color=cyan>[CAMERA ORBIT]</color> '<b>Target</b>' doesn't exist. Creating a target automatically...");
            GameObject target = new GameObject("target");

            target.transform.position = targetPosition;
            RotationConstraint rotConst = target.AddComponent <RotationConstraint>();

            SettingConstrintProperties(target.GetComponent <RotationConstraint>());

            mainTarget = target.transform;
        }
Ejemplo n.º 5
0
        private void CheckTarget()
        {
            if (alternativeTarget.GetComponent <RotationConstraint>() == null)
            {
                Debug.Log("<color=cyan>[CAMERA ORBIT]</color> There is no component '<b>RotationConstraint</b>' attached to the target.\nCreating the component automatically...");
                alternativeTarget.rotation = Quaternion.identity;
                RotationConstraint rotConst = alternativeTarget.gameObject.AddComponent <RotationConstraint>();
            }

            SettingConstrintProperties(alternativeTarget.GetComponent <RotationConstraint>());
            mainTarget = alternativeTarget.transform;
        }
Ejemplo n.º 6
0
        private void SettingConstrintProperties(RotationConstraint rotConst)
        {
            ConstraintSource constraintSource = new ConstraintSource()
            {
                sourceTransform = mainCamera.transform, weight = 1
            };

            rotConst.constraintActive = true;
            rotConst.AddSource(constraintSource);
            rotConst.rotationAxis   = Axis.None;
            rotConst.rotationAxis   = Axis.Y;
            rotConst.rotationOffset = Vector3.zero;
        }
Ejemplo n.º 7
0
        public static void Activate(this RotationConstraint constraint)
        {
            constraint.constraintActive = false;

            List <ConstraintSource> sources = new List <ConstraintSource>();

            constraint.GetSources(sources);

            constraint.rotationAtRest = Vector3.zero;
            constraint.rotationOffset = Vector3.zero;

            foreach (var source in sources)
            {
                constraint.rotationAtRest = constraint.transform.localRotation.eulerAngles;
                constraint.rotationOffset = (Quaternion.Inverse(source.sourceTransform.localRotation) * constraint.transform.rotation).eulerAngles;
            }

            constraint.constraintActive = true;
        }
Ejemplo n.º 8
0
        private Vector3 ProjectHandlebarGivenConstraint(RotationConstraint constraint, Vector3 handlebarRotation, Transform manipulationRoot)
        {
            Vector3 result = handlebarRotation;

            switch (constraint)
            {
            case RotationConstraint.XAxisOnly:
                result.x = 0;
                break;

            case RotationConstraint.YAxisOnly:
                result.y = 0;
                break;

            case RotationConstraint.ZAxisOnly:
                result.z = 0;
                break;
            }
            return(CameraCache.Main.transform.TransformDirection(result));
        }
 /// <summary>
 /// Initializes the custom components.
 /// </summary>
 private void InitializeCustomComponents()
 {
     _thirdPersonController = personController.GetComponent<ThirdPersonController>();
     _thirdPersonCameraController = personController.GetComponent<ThirdPersonCamera>();
     _flyScan = personController.GetComponent<FlyScan>();
     _characterMotor = personController.GetComponent<CharacterMotor>();
     _fpsInputController = personController.GetComponent<FPSInputController>();
     _rotationConstraint = eyesCamera.GetComponent<RotationConstraint>();
     _myMouseLook = personController.GetComponent<MyMouseLook>();
 }
Ejemplo n.º 10
0
 public void Write(TProtocol oprot)
 {
     oprot.IncrementRecursionDepth();
     try
     {
         TStruct struc = new TStruct("MGeometryConstraint");
         oprot.WriteStructBegin(struc);
         TField field = new TField();
         if (ParentObjectID == null)
         {
             throw new TProtocolException(TProtocolException.INVALID_DATA, "required field ParentObjectID not set");
         }
         field.Name = "ParentObjectID";
         field.Type = TType.String;
         field.ID   = 1;
         oprot.WriteFieldBegin(field);
         oprot.WriteString(ParentObjectID);
         oprot.WriteFieldEnd();
         if (ParentToConstraint != null && __isset.ParentToConstraint)
         {
             field.Name = "ParentToConstraint";
             field.Type = TType.Struct;
             field.ID   = 2;
             oprot.WriteFieldBegin(field);
             ParentToConstraint.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (TranslationConstraint != null && __isset.TranslationConstraint)
         {
             field.Name = "TranslationConstraint";
             field.Type = TType.Struct;
             field.ID   = 3;
             oprot.WriteFieldBegin(field);
             TranslationConstraint.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (RotationConstraint != null && __isset.RotationConstraint)
         {
             field.Name = "RotationConstraint";
             field.Type = TType.Struct;
             field.ID   = 4;
             oprot.WriteFieldBegin(field);
             RotationConstraint.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (__isset.WeightingFactor)
         {
             field.Name = "WeightingFactor";
             field.Type = TType.Double;
             field.ID   = 5;
             oprot.WriteFieldBegin(field);
             oprot.WriteDouble(WeightingFactor);
             oprot.WriteFieldEnd();
         }
         oprot.WriteFieldStop();
         oprot.WriteStructEnd();
     }
     finally
     {
         oprot.DecrementRecursionDepth();
     }
 }
Ejemplo n.º 11
0
 public HandlebarRotateLogic(RotationConstraint rotationConstraint)
 {
     m_rotationConstraint = rotationConstraint;
 }
Ejemplo n.º 12
0
 public static Tween TweenWeight(this RotationConstraint constraint, float to, float duration) =>
 Tweening.To(getter: () => constraint.weight,
             setter: weight => constraint.weight = weight,
             to, duration).SetTarget(constraint);
Ejemplo n.º 13
0
 public static Tween TweenRotationOffset(this RotationConstraint constraint, Vector3 to, float duration) =>
 Tweening.To(getter: () => constraint.rotationOffset,
             setter: rotationOffset => constraint.rotationOffset = rotationOffset,
             to, duration).SetTarget(constraint);
 // Start is called before the first frame update
 void Start()
 {
     xRotation = cameraPivot.GetComponent <RotationConstraint>();
 }
Ejemplo n.º 15
0
 private void Start()
 {
     this.rc        = GetComponent <RotationConstraint>();
     this.rc.weight = weight;
 }
Ejemplo n.º 16
0
 public void Setup(Dictionary <uint, Vector3> handsPressedMap, Transform manipulationRoot)
 {
     m_currentRotationConstraint = m_rotationConstraint;
     m_previousHandlebarRotation = GetHandlebarDirection(handsPressedMap, manipulationRoot);
 }
Ejemplo n.º 17
0
 public TwoHandRotateLogic(RotationConstraint rotationConstraint)
 {
     m_rotationConstraint = rotationConstraint;
 }