예제 #1
0
        private void Gizmos_DrawArrowGuide()
        {
            if (BaseTransform == null)
            {
                return;
            }
            if (LeadBone == null)
            {
                return;
            }

            if (_editor_arrowsAlpha > 0f)
            {
                float   d          = Vector3.Distance(LeadBone.position, BaseTransform.position);
                Vector3 arrowStart = Vector3.Lerp(BaseTransform.position, LeadBone.position, 0.7f);

                Handles.color = new Color(0.05f, 0.225f, 1f, 0.9f * _editor_arrowsAlpha);
                FGUI_Handles.DrawArrow(BaseTransform.TransformDirection(ModelForwardAxis) * d * .22f + arrowStart, Quaternion.LookRotation(BaseTransform.TransformDirection(ModelForwardAxis), BaseTransform.TransformDirection(ModelUpAxis)), d * 0.2f);

                Handles.color = new Color(0.05f, 0.8f, 0.05f, 0.75f * _editor_arrowsAlpha);
                arrowStart    = LeadBone.position + BaseTransform.TransformDirection(ModelUpAxis) * d * .285f;
                FGUI_Handles.DrawArrow(arrowStart, Quaternion.LookRotation(BaseTransform.TransformDirection(ModelUpAxis), BaseTransform.TransformDirection(ModelForwardAxis)), d * 0.15f, 4f, 0.5f);
            }

            if (_editor_arrowsAlpha > -0.1f)
            {
                _editor_arrowsAlpha -= 0.0125f;
            }
        }
        async Task ApplyTransform(BaseTransform t)
        {
            var newBitmap = _bitmap.Transform(t);

            _bitmap.Dispose();
            _bitmap = newBitmap;
            await UpdateImageSource();
        }
예제 #3
0
        void ApplyTransform(BaseTransform t)
        {
            var newBitmap = _bitmap.Transform(t);

            _bitmap.Dispose();
            _bitmap = newBitmap;
            UpdateImage();
        }
예제 #4
0
        void Gizmos_DrawMaxDistance()
        {
            if (MaximumDistance <= 0f)
            {
                return;
            }

            float   a        = 0.525f;
            Vector3 startPos = BaseTransform.position + BaseTransform.TransformVector(DistanceMeasurePoint);

            if (DistanceWithoutY)
            {
                if (maxDistanceExceed)
                {
                    Handles.color = new Color(1f, .1f, .1f, a);
                }
                else
                {
                    Handles.color = new Color(0.02f, .65f, 0.2f, a);
                }

                Handles.DrawWireDisc(startPos, Vector3.up, MaximumDistance);

                if (DistanceMeasurePoint != Vector3.zero)
                {
                    Gizmos.color = new Color(0.02f, .65f, 0.2f, a);
                    Gizmos.DrawLine(startPos - Vector3.right * (MaximumDistance + MaximumDistance * MaxOutDistanceFactor), startPos + Vector3.right * (MaximumDistance + MaximumDistance * MaxOutDistanceFactor));
                    Gizmos.DrawLine(startPos - Vector3.forward * (MaximumDistance + MaximumDistance * MaxOutDistanceFactor), startPos + Vector3.forward * (MaximumDistance + MaximumDistance * MaxOutDistanceFactor));
                }

                if (MaxOutDistanceFactor > 0f)
                {
                    Handles.color = new Color(.835f, .135f, .08f, a);
                    Handles.DrawWireDisc(startPos, Vector3.up, MaximumDistance + MaximumDistance * MaxOutDistanceFactor);
                }
            }
            else
            {
                if (maxDistanceExceed)
                {
                    Gizmos.color = new Color(1f, .1f, .1f, a);
                }
                else
                {
                    Gizmos.color = new Color(0.02f, .65f, 0.2f, a);
                }

                Gizmos.DrawWireSphere(startPos, MaximumDistance);

                if (MaxOutDistanceFactor > 0f)
                {
                    Gizmos.color = new Color(.835f, .135f, .08f, a);
                    Gizmos.DrawWireSphere(startPos, MaximumDistance + MaximumDistance * MaxOutDistanceFactor);
                }
            }
        }
예제 #5
0
    private void CreateSlots()
    {
        {
            //x bottom
            BaseTransform bt = new BaseTransform();
            bt.xAxisWorldX = 1; bt.yAxisWorldX = 0; bt.zAxisWorldX = 0; bt.origoWorldX = 0;
            bt.xAxisWorldY = 0; bt.yAxisWorldY = 1; bt.zAxisWorldY = 0; bt.origoWorldY = 1;
            bt.xAxisWorldZ = 0; bt.yAxisWorldZ = 0; bt.zAxisWorldZ = 1; bt.origoWorldZ = 2;
            slots[0]       = new Slot(0, bt);
        }

        {
            //x top
            BaseTransform bt = new BaseTransform();
            bt.xAxisWorldX = 1; bt.yAxisWorldX = 0; bt.zAxisWorldX = 0; bt.origoWorldX = 0;
            bt.xAxisWorldY = 0; bt.yAxisWorldY = 1; bt.zAxisWorldY = 0; bt.origoWorldY = 3;
            bt.xAxisWorldZ = 0; bt.yAxisWorldZ = 0; bt.zAxisWorldZ = 1; bt.origoWorldZ = 2;
            slots[1]       = new Slot(1, bt);
        }

        {
            //y near
            BaseTransform bt = new BaseTransform();
            bt.xAxisWorldX = 0; bt.yAxisWorldX = -1; bt.zAxisWorldX = 0; bt.origoWorldX = 3;
            bt.xAxisWorldY = 1; bt.yAxisWorldY = 0;  bt.zAxisWorldY = 0; bt.origoWorldY = 0;
            bt.xAxisWorldZ = 0; bt.yAxisWorldZ = 0;  bt.zAxisWorldZ = 1; bt.origoWorldZ = 1;
            slots[2]       = new Slot(2, bt);
        }

        {
            //y far
            BaseTransform bt = new BaseTransform();
            bt.xAxisWorldX = 0; bt.yAxisWorldX = -1; bt.zAxisWorldX = 0; bt.origoWorldX = 3;
            bt.xAxisWorldY = 1; bt.yAxisWorldY = 0;  bt.zAxisWorldY = 0; bt.origoWorldY = 0;
            bt.xAxisWorldZ = 0; bt.yAxisWorldZ = 0;  bt.zAxisWorldZ = 1; bt.origoWorldZ = 3;
            slots[3]       = new Slot(3, bt);
        }

        {
            //z left
            BaseTransform bt = new BaseTransform();
            bt.xAxisWorldX = 0;  bt.yAxisWorldX = 0; bt.zAxisWorldX = -1; bt.origoWorldX = 2;
            bt.xAxisWorldY = 0;  bt.yAxisWorldY = 1; bt.zAxisWorldY = 0;  bt.origoWorldY = 2;
            bt.xAxisWorldZ = 1;  bt.yAxisWorldZ = 0; bt.zAxisWorldZ = 0;  bt.origoWorldZ = 0;
            slots[4]       = new Slot(4, bt);
        }

        {
            //z right
            BaseTransform bt = new BaseTransform();
            bt.xAxisWorldX = 0; bt.yAxisWorldX = 0; bt.zAxisWorldX = -1; bt.origoWorldX = 4;
            bt.xAxisWorldY = 0; bt.yAxisWorldY = 1; bt.zAxisWorldY = 0;  bt.origoWorldY = 2;
            bt.xAxisWorldZ = 1; bt.yAxisWorldZ = 0; bt.zAxisWorldZ = 0;  bt.origoWorldZ = 0;
            slots[5]       = new Slot(5, bt);
        }
    }
예제 #6
0
        void ApplyTransform(BaseTransform t)
        {
            var newBitmap = _bitmap.Transform(t);

            _bitmap.Dispose();

            _bitmap    = newBitmap;
            _selection = new RectF(1f, 1f);

            UpdateImage();
        }
예제 #7
0
 /// <summary>
 /// Getting distance value from distance measure point to target position
 /// </summary>
 public float GetDistanceMeasure(Vector3 targetPosition)
 {
     if (DistanceWithoutY)
     {
         Vector3 p  = BaseTransform.position + BaseTransform.TransformVector(DistanceMeasurePoint);
         Vector2 p2 = new Vector2(p.x, p.z);
         return(Vector2.Distance(p2, new Vector2(targetPosition.x, targetPosition.z)));
     }
     else
     {
         return(Vector3.Distance(BaseTransform.position + BaseTransform.TransformVector(DistanceMeasurePoint), targetPosition));
     }
 }
        /// <summary>
        /// Anchoring reference position for look start point basing on current frame's pose of LeadBone
        /// </summary>
        public void RefreshLookStartPositionAnchor()
        {
            if (!usingAxisCorrection)
            {
                leadBoneInitLocalOffset = BaseTransform.InverseTransformPoint(LeadBone.position);
            }
            else
            {
                leadBoneInitLocalOffset = axisCorrectionMatrix.inverse.MultiplyPoint(LeadBone.position);
            }

            RefreshStartLookPoint = false;
        }
예제 #9
0
        internal ListItem GetPage(Web web, string listToLoad)
        {
            if (!string.IsNullOrEmpty(this.Library))
            {
                listToLoad = this.Library;
            }

            web.EnsureProperty(w => w.ServerRelativeUrl);
            var listServerRelativeUrl = UrlUtility.Combine(web.ServerRelativeUrl, listToLoad);

            List libraryContainingPage = null;

            if (BaseTransform.GetVersion(web.Context) == SPVersion.SP2010)
            {
                libraryContainingPage = web.GetListByName(listToLoad);
            }
            else
            {
                libraryContainingPage = web.GetList(listServerRelativeUrl);
            }

            if (libraryContainingPage != null)
            {
                CamlQuery query = null;
                if (!string.IsNullOrEmpty(this.name))
                {
                    query = new CamlQuery
                    {
                        ViewXml = string.Format(CAMLQueryByExtensionAndName, this.name)
                    };

                    if (!string.IsNullOrEmpty(this.Folder))
                    {
                        libraryContainingPage.EnsureProperty(p => p.RootFolder);
                        query.FolderServerRelativeUrl = $"{libraryContainingPage.RootFolder.ServerRelativeUrl}/{Folder}";
                    }

                    var page = libraryContainingPage.GetItems(query);
                    web.Context.Load(page);
                    web.Context.ExecuteQueryRetry();

                    if (page.Count >= 1)
                    {
                        // Return the first match
                        return(page[0]);
                    }
                }
            }

            return(null);
        }
예제 #10
0
        /// <summary>
        /// Returns a file as string
        /// </summary>
        /// <param name="web">The Web to process</param>
        /// <param name="serverRelativeUrl">The server relative URL to the file</param>
        /// <returns>The file contents as a string</returns>
        /// <remarks>#
        ///
        ///     Based on https://github.com/SharePoint/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/Extensions/FileFolderExtensions.cs
        ///     Modified to force onpremises support
        ///
        /// </remarks>
        public static string GetFileByServerRelativeUrlAsString(this Web web, string serverRelativeUrl)
        {
            var file    = web.GetFileByServerRelativeUrl(serverRelativeUrl);
            var context = web.Context;

            context.Load(file);
            context.ExecuteQueryRetry();

            var spVersion = BaseTransform.GetVersion(context);

            Stream sourceStream;

            if (spVersion == SPVersion.SP2010)
            {
                throw new System.Exception("SharePoint 2010 is not supported");
                //sourceStream = new MemoryStream();

                //if (context.HasPendingRequest)
                //{
                //    context.ExecuteQueryRetry();
                //}

                //var fileBinary = File.OpenBinaryDirect((ClientContext)context, serverRelativeUrl);
                //context.ExecuteQueryRetry();
                //Stream tempSourceStream = fileBinary.Stream;

                //CopyStream(tempSourceStream, sourceStream);
                //sourceStream.Seek(0, SeekOrigin.Begin);
            }
            else
            {
                ClientResult <Stream> stream = file.OpenBinaryStream();
                web.Context.ExecuteQueryRetry();
                sourceStream = stream.Value;
            }
            string returnString = string.Empty;

            using (Stream memStream = new MemoryStream())
            {
                CopyStream(sourceStream, memStream);
                memStream.Position = 0;

                using (var reader = new StreamReader(memStream))
                {
                    returnString = reader.ReadToEnd();
                }
            }

            return(returnString);
        }
예제 #11
0
        /// <summary>
        /// Computing look angles needed to look at target world position from this character
        /// </summary>
        public Vector2 ComputeAnglesTowards(Vector3 worldPosition)
        {
            // Direction towards target in different spaces
            Vector3 worldDirectionAndTargetAngles = (worldPosition - GetLookStartMeasurePosition()).normalized;

            // Supporting different axis orientation using matrix
            if (usingAxisCorrection)
            {
                worldDirectionAndTargetAngles = axisCorrectionMatrix.inverse.MultiplyVector(worldDirectionAndTargetAngles).normalized;
                worldDirectionAndTargetAngles = WrapVector(Quaternion.LookRotation(worldDirectionAndTargetAngles, axisCorrectionMatrix.MultiplyVector(ModelUpAxis).normalized).eulerAngles);
            }
            else // Easier calculations when using standard z - forward - y up
            {
                worldDirectionAndTargetAngles = BaseTransform.InverseTransformDirection(worldDirectionAndTargetAngles);
                worldDirectionAndTargetAngles = WrapVector(Quaternion.LookRotation(worldDirectionAndTargetAngles, BaseTransform.TransformDirection(ModelUpAxis)).eulerAngles);
            }

            return(worldDirectionAndTargetAngles);
        }
        /// <summary>
        /// Getting position to be followed by Look animator, if there is no target to follow position in front of lead bone will be returned
        /// </summary>
        public Vector3 GetLookAtPosition()
        {
            _LOG_NoRefs();

            if (FollowMode == EFFollowMode.FollowJustPosition)
            {
                return(FollowOffset);
            }
            else
            {
                Transform lookT = activeLookTarget;
                if (lookT == null)
                {
                    lookT = GetLookAtTransform();
                }

                // If there is no target to follow we move focus point to front of lead bone
                if (!lookT)
                {
                    return(LeadBone.position + BaseTransform.TransformVector(ModelForwardAxis) * Vector3.Distance(LeadBone.position, BaseTransform.position));
                }
                else
                {
                    if (FollowMode == EFFollowMode.ToFollowSpaceOffset)
                    {
                        return(lookT.position + lookT.TransformVector(FollowOffset));
                    }
                    else if (FollowMode == EFFollowMode.WorldOffset)
                    {
                        return(lookT.position + FollowOffset);
                    }
                    else if (FollowMode == EFFollowMode.LocalOffset)
                    {
                        return(lookT.position + BaseTransform.TransformVector(FollowOffset));
                    }
                    else
                    {
                        return(lookT.position);
                    }
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Method to bypass missing property in SharePoint 2010
        /// </summary>
        /// <param name="web">Web to operate on</param>
        /// <remarks>Only required on source contexts</remarks>
        /// <returns>web url</returns>
        public static string GetUrl(this Web web)
        {
            if (BaseTransform.GetVersion(web.Context) == SPVersion.SP2010)
            {
                var siteCtx = web.Context.GetSiteCollectionContext();
                siteCtx.Site.EnsureProperties(p => p.ServerRelativeUrl, p => p.Url);
                web.EnsureProperty(p => p.ServerRelativeUrl);

                var    siteUri = new Uri(siteCtx.Site.Url);
                string host    = $"{siteUri.Scheme}://{siteUri.DnsSafeHost}";

                var serverRelativeUrl = web.ServerRelativeUrl;

                return(UrlUtility.Combine(host, serverRelativeUrl));
            }
            else
            {
                return(web.EnsureProperty(p => p.Url));
            }
        }
예제 #14
0
        public void InitializeBaseVariables()
        {
            _LOG_NoRefs();

            LookState = EFHeadLookState.Null;

            SetAutoWeightsDefault();
            ComputeBonesRotationsFixVariables();

            InitBirdMode();
            ResetBones();

            smoothLookPosition    = GetForwardPosition();
            lookFreezeFocusPoint  = BaseTransform.InverseTransformPoint(smoothLookPosition);
            refreshReferencePose  = true;
            RefreshStartLookPoint = true;
            rootStaticRotation    = BaseTransform.rotation;
            _preBackBonesCount    = BackBonesCount;
            lastBaseRotation      = BaseTransform.rotation;

            // Reset corrections, sometimes quaternion is NaN there we fix it
            for (int i = 0; i < LookBones.Count; i++)
            {
                if (LookBones[i].correctionOffset == Vector3.zero)
                {
                    LookBones[i].correctionOffset = Vector3.zero;
                }
                LookBones[i].lastKeyframeRotation = LookBones[i].Transform.localRotation;
                LookBones[i].RefreshBoneDirections(BaseTransform);
            }


            if (UseEyes)
            {
                InitEyesModule();
            }

            initialized = true;
        }
        /// <summary>
        /// Look start reference position to measure direction from
        /// </summary>
        public Vector3 GetLookStartMeasurePosition()
        {
            _LOG_NoRefs();

            if (AnchorStartLookPoint)
            {
                // Supporting different axis orientation using matrix
                if (usingAxisCorrection)
                {
                    if (!Application.isPlaying)
                    {
                        UpdateCorrectionMatrix();
                    }

                    if (leadBoneInitLocalOffset == Vector3.zero)
                    {
                        return(LeadBone.position + axisCorrectionMatrix.MultiplyVector(StartLookPointOffset));
                    }
                    return(axisCorrectionMatrix.MultiplyPoint(leadBoneInitLocalOffset) + axisCorrectionMatrix.MultiplyVector(StartLookPointOffset));
                }
                else
                {
                    if (leadBoneInitLocalOffset == Vector3.zero)
                    {
                        return(LeadBone.position + BaseTransform.TransformVector(StartLookPointOffset));
                    }
                    return(BaseTransform.TransformPoint(leadBoneInitLocalOffset) + BaseTransform.TransformVector(StartLookPointOffset));
                }
            }
            else
            {
                if (!Application.isPlaying)
                {
                    LookBones[0].finalRotation = LeadBone.transform.rotation;
                }
                return(LeadBone.position + LookBones[0].finalRotation * StartLookPointOffset);
            }
        }
예제 #16
0
        /// <summary>
        /// Main head look rotation calculations logics execution
        /// </summary>
        private void CalculateLookAnimation()
        {
            // Begin check for stop lokoing
            _stopLooking = false;

            // Stopping looking when object to follow is null
            if (FollowMode != EFFollowMode.FollowJustPosition)
            {
                if (ObjectToFollow == null)
                {
                    if (MomentLookTransform == null)
                    {
                        _stopLooking = true;
                    }
                }
            }


            Vector3 lookRotation;

            LookPositionUpdate();
            LookWhenAboveGoBackCalculations();

            // When stopping look, we don't want head to goo too fast onto forward look pose
            if (_stopLooking)
            {
                finalLookPosition = transform.TransformPoint(lookFreezeFocusPoint);
            }
            else
            {
                if (!BirdMode)
                {
                    finalLookPosition = smoothLookPosition;
                }
                else
                {
                    finalLookPosition = BirdTargetPosition;
                }
            }


            if (FixingPreset != EFAxisFixOrder.Parental)
            {
                #region Calculating target rotation and angles

                // If our target is out of max distance let's look at default direction
                if (LookState == EFHeadLookState.OutOfMaxDistance)
                {
                    targetLookAngles = Vector3.MoveTowards(targetLookAngles, Vector3.zero, 1f + RotationSpeed);
                }
                else
                {
                    // Direction towards target in different spaces
                    Vector3 worldDirectionAndTargetAngles = (finalLookPosition - GetLookStartMeasurePosition()).normalized;

                    // Supporting different axis orientation using matrix
                    if (usingAxisCorrection)
                    {
                        worldDirectionAndTargetAngles = axisCorrectionMatrix.inverse.MultiplyVector(worldDirectionAndTargetAngles).normalized;
                        worldDirectionAndTargetAngles = WrapVector(Quaternion.LookRotation(worldDirectionAndTargetAngles, axisCorrectionMatrix.MultiplyVector(ModelUpAxis).normalized).eulerAngles);
                    }
                    else // Easier calculations when using standard z - forward - y up
                    {
                        worldDirectionAndTargetAngles = BaseTransform.InverseTransformDirection(worldDirectionAndTargetAngles);
                        worldDirectionAndTargetAngles = WrapVector(Quaternion.LookRotation(worldDirectionAndTargetAngles, BaseTransform.TransformDirection(ModelUpAxis)).eulerAngles);
                    }

                    targetLookAngles = worldDirectionAndTargetAngles;
                }

                Vector2 angles = targetLookAngles;
                angles = LimitAnglesCalculations(angles);
                AnimateAnglesTowards(angles);

                #endregion

                // Character rotation offset
                if (usingAxisCorrection)
                {
                    Quaternion fromto = Quaternion.FromToRotation(Vector3.right, Vector3.Cross(Vector3.up, ModelForwardAxis));
                    fromto       = Quaternion.Euler(finalLookAngles) * fromto * BaseTransform.rotation;
                    lookRotation = fromto.eulerAngles;
                }
                else
                {
                    lookRotation = finalLookAngles + BaseTransform.eulerAngles;
                }

                // Additional operations
                lookRotation += RotationOffset;
                lookRotation  = ConvertFlippedAxes(lookRotation);
            }
            else // Universal correction method
            {
                lookRotation  = LookRotationParental((finalLookPosition - GetLookStartMeasurePosition()).normalized).eulerAngles;
                lookRotation += RotationOffset;
            }

            if (!_stopLooking)
            {
                lookFreezeFocusPoint = BaseTransform.InverseTransformPoint(finalLookPosition);
            }
            targetLookRotation = Quaternion.Euler(lookRotation);

            SetTargetBonesRotations();
        }
예제 #17
0
 /// <summary>
 /// Correction matrix for axis correction calculations
 /// </summary>
 private void UpdateCorrectionMatrix()
 {
     // Supporting different axis orientation using matrix
     if (ModelUpAxis != Vector3.up || ModelForwardAxis != Vector3.forward)
     {
         usingAxisCorrection  = true;
         axisCorrectionMatrix = Matrix4x4.TRS(BaseTransform.position, Quaternion.LookRotation(BaseTransform.TransformDirection(ModelForwardAxis), BaseTransform.TransformDirection(ModelUpAxis)), BaseTransform.lossyScale);
     }
     else // Easier calculations when using standard z - forward - y up
     {
         usingAxisCorrection = false;
     }
 }
예제 #18
0
파일: Slot.cs 프로젝트: lassewedin/Puzzle
 public Slot(int index, BaseTransform baseTransform)
 {
     this.index         = index;
     this.baseTransform = baseTransform;
 }
        private void _Debug_Rays()
        {
            if (!DebugRays)
            {
                return;
            }

            Debug.DrawRay(GetLookStartMeasurePosition() + Vector3.up * 0.01f, Quaternion.Euler(finalLookAngles) * BaseTransform.TransformDirection(ModelForwardAxis), Color.cyan);
            //Vector3 startLook = GetLookStartMeasurePosition();

            //Debug.DrawRay(startLook + Vector3.up * 0.25f, axisCorrectionMatrix.MultiplyVector(Vector3.forward), Color.blue);
            //Debug.DrawRay(startLook + Vector3.up * 0.25f, axisCorrectionMatrix.MultiplyVector(Vector3.up), Color.green);

            //Debug.DrawRay(GetLookStartMeasurePosition() + Vector3.up * 0.9f, Quaternion.Euler(finalLookAngles) * Vector3.forward, Color.magenta);
            //Debug.DrawRay(GetLookStartMeasurePosition() + Vector3.up, Quaternion.Euler(finalLookAngles) * ModelForwardAxis, Color.cyan);

            //Quaternion fromto = Quaternion.FromToRotation(Vector3.forward, ModelForwardAxis) * Quaternion.FromToRotation(Vector3.up, ModelUpAxis);
            //Quaternion rot = Quaternion.Euler(finalLookAngles) * fromto * BaseTransform.rotation;

            //Debug.DrawRay(GetLookStartMeasurePosition() + Vector3.up * 1.1f, rot * Vector3.forward, Color.yellow);

            //fromto = Quaternion.FromToRotation(Vector3.right, Vector3.Cross(Vector3.up, ModelForwardAxis));
            //rot = fromto * Quaternion.Euler(finalLookAngles) * BaseTransform.rotation;

            //Debug.DrawRay(GetLookStartMeasurePosition() + Vector3.up * 1.2f, rot * Vector3.forward, Color.red);
        }
예제 #20
0
        /// <summary>
        /// Computing variables making Quaternion.Look universal for different skeletonal setups
        /// </summary>
        private void ComputeBonesRotationsFixVariables()
        {
            if (BaseTransform != null)
            {
                Quaternion preRot = BaseTransform.rotation;
                BaseTransform.rotation = Quaternion.identity;

                FromAuto = LeadBone.rotation * -Vector3.forward;

                float      angl       = Quaternion.Angle(Quaternion.identity, LeadBone.rotation);
                Quaternion rotateAxis = (LeadBone.rotation * Quaternion.Inverse(Quaternion.FromToRotation(FromAuto, ModelForwardAxis)));

                OffsetAuto = Quaternion.AngleAxis(angl, rotateAxis.eulerAngles.normalized).eulerAngles;

                BaseTransform.rotation = preRot;

                parentalReferenceLookForward = Quaternion.Inverse(LeadBone.parent.rotation) * BaseTransform.rotation * ModelForwardAxis.normalized;
                parentalReferenceUp          = Quaternion.Inverse(LeadBone.parent.rotation) * BaseTransform.rotation * ModelUpAxis.normalized;

                headForward = Quaternion.FromToRotation(LeadBone.InverseTransformDirection(BaseTransform.TransformDirection(ModelForwardAxis.normalized)), Vector3.forward) * Vector3.forward;
            }
            else
            {
                Debug.LogWarning("Base Transform isn't defined, so we can't use auto correction!");
            }
        }
 /// <summary>
 /// Getting position in front of head bone
 /// </summary>
 public Vector3 GetForwardPosition()
 {
     return(LeadBone.position + BaseTransform.TransformDirection(ModelForwardAxis));
 }
예제 #22
0
        internal ListItem GetPage(Web web, string listToLoad)
        {
            bool loadViaId = false;
            int  idToLoad  = -1;

            // Check what we got via the pagepipebind constructor and prep for getting the page
            if (!string.IsNullOrEmpty(this.name))
            {
                if (int.TryParse(this.Name, out int pageId))
                {
                    idToLoad  = pageId;
                    loadViaId = true;
                }
                else
                {
                    if (!this.BlogPage && !this.DelveBlogPage)
                    {
                        this.name = ClientSidePageUtilities.EnsureCorrectPageName(this.name);
                    }
                    this.pageListItem = null;
                }
            }
            else if (this.pageListItem != null)
            {
                if (this.pageListItem != null)
                {
                    if (this.BlogPage || this.DelveBlogPage)
                    {
                        this.name = this.pageListItem.FieldValues["Title"].ToString();
                    }
                    else
                    {
                        this.name = this.pageListItem.FieldValues["FileLeafRef"].ToString();
                    }
                }
            }

            if (!string.IsNullOrEmpty(this.Library))
            {
                listToLoad = this.Library;
            }

            // Blogs live in a list, not in a library
            if (this.BlogPage && !listToLoad.StartsWith("lists/", StringComparison.InvariantCultureIgnoreCase))
            {
                listToLoad = $"lists/{listToLoad}";
            }

            web.EnsureProperty(w => w.ServerRelativeUrl);
            var listServerRelativeUrl = UrlUtility.Combine(web.ServerRelativeUrl, listToLoad);

            List libraryContainingPage = null;

#if !NETSTANDARD2_1
            if (BaseTransform.GetVersion(web.Context) == SPVersion.SP2010)
            {
                libraryContainingPage = web.GetListByName(listToLoad);
            }
            else
            {
                libraryContainingPage = web.GetList(listServerRelativeUrl);
            }
#else
            libraryContainingPage = web.GetList(listServerRelativeUrl);
#endif

            if (libraryContainingPage != null)
            {
                if (loadViaId)
                {
                    var page = libraryContainingPage.GetItemById(idToLoad);
                    web.Context.Load(page);
                    web.Context.ExecuteQueryRetry();
                    return(page);
                }
                else
                {
                    CamlQuery query = null;
                    if (!string.IsNullOrEmpty(this.name))
                    {
                        if (this.BlogPage || this.DelveBlogPage)
                        {
                            query = new CamlQuery
                            {
                                ViewXml = string.Format(CAMLQueryForBlogByTitle, System.Text.Encodings.Web.HtmlEncoder.Default.Encode(this.name))
                            };
                        }
                        else
                        {
                            query = new CamlQuery
                            {
                                ViewXml = string.Format(CAMLQueryByExtensionAndName, System.Text.Encodings.Web.HtmlEncoder.Default.Encode(this.name))
                            };
                        }

                        if (!string.IsNullOrEmpty(this.Folder))
                        {
                            libraryContainingPage.EnsureProperty(p => p.RootFolder);
                            query.FolderServerRelativeUrl = $"{libraryContainingPage.RootFolder.ServerRelativeUrl}/{Folder}";
                        }

                        var page = libraryContainingPage.GetItems(query);
                        web.Context.Load(page);
                        web.Context.ExecuteQueryRetry();

                        if (page.Count >= 1)
                        {
                            // Return the first match
                            return(page[0]);
                        }
                    }
                }
            }

            return(null);
        }
예제 #23
0
        //Vector3 firstBoneOff = Vector3.zero;

        public void Init()
        {
            if (SpineBones.Count == 0)
            {
                if (SpineTransforms.Count > 2)
                {
                    CreateSpineChain(SpineTransforms[0], SpineTransforms[SpineTransforms.Count - 1]);
                    Debug.Log("[SPINE ANIMATOR] Auto Bone Conversion from old version of Spine Animator! Please select your objects with Spine Animator to pre-convert it instead of automatically doing it when game Starts! (" + name + ")");
                }
                else
                {
                    Debug.Log("[SPINE ANIMATOR] could not initialize Spine Animator inside '" + name + "' because there are no bones to animate!");
                    return;
                }
            }

            if (initialized)
            {
                Debug.Log("[Spine Animator] " + name + " is already initialized!"); return;
            }

            if (BaseTransform == null)
            {
                BaseTransform = FindBaseTransform();
            }

            // Checking bones for zero-distance ones
            for (int i = 0; i < SpineBones.Count; i++)
            {
                Vector3 childPos;
                if (i == SpineBones.Count - 1)
                {
                    childPos = SpineBones[i - 1].transform.position + (SpineBones[i - 1].transform.position - SpineBones[i].transform.position);
                }
                else
                {
                    childPos = SpineBones[i + 1].transform.position;
                }

                float dist = Vector3.Distance(SpineBones[i].transform.position, childPos);
                if (dist < 0.01f)
                {
                    float refDistance = (SpineBones[SpineBones.Count - 1].transform.position - SpineBones[SpineBones.Count - 2].transform.parent.position).magnitude;

                    Vector3 forw = SpineBones[i].transform.position - BaseTransform.position;
                    Vector3 loc  = BaseTransform.InverseTransformDirection(forw);
                    loc.y = 0f; loc.Normalize();

                    SpineBones[i + 1].DefaultForward = loc;

                    // firstBoneOff
                    SpineBones[i + 1].transform.position = SpineBones[i + 1].transform.position + BaseTransform.TransformDirection(loc) * refDistance * -0.125f;
                }
            }

            referenceDistance = 0f;
            // Preparing bones
            for (int i = 0; i < SpineBones.Count; i++)
            {
                SpineBones[i].PrepareBone(BaseTransform, SpineBones, i);
                referenceDistance += SpineBones[i].BoneLength;
            }

            referenceDistance /= (float)(SpineBones.Count);

            frontHead = new HeadBone(SpineBones[0].transform);
            frontHead.PrepareBone(BaseTransform, SpineBones, 0);
            backHead = new HeadBone(SpineBones[SpineBones.Count - 1].transform);
            backHead.PrepareBone(BaseTransform, SpineBones, SpineBones.Count - 1);

            // Collision calculations helper list
            CollidersDataToCheck = new List <FImp_ColliderData_Base>();

            // Straightening spine pose to desired positions and rotations on init
            chainReverseFlag = !LastBoneLeading;
            UpdateChainIndexHelperVariables();
            ReposeSpine();
            //SpineMotion();

            initialized = true;
        }
예제 #24
0
        public override void LateUpdate()
        {
            if (!initialized)
            {
                return;
            }

            base.LateUpdate();

            if (EyesNoKeyframes)
            {
                for (int i = 0; i < eyeForwards.Length; i++)
                {
                    eyes[i].localRotation = eyesInitLocalRotations[i];
                }
            }

            Transform eyeTarget = EyesTarget;

            if (eyeTarget == null)
            {
                if (MomentLookTransform != null)
                {
                    eyeTarget = MomentLookTransform;
                }
                else
                {
                    eyeTarget = ObjectToFollow;
                }
            }

            bool fade = false;

            if (eyeTarget == null)
            {
                fade = true;
            }
            else
            {
                if (EyesTarget == null)
                {
                    if (LookState != FLookAnimator.EFHeadLookState.ClampedAngle && LookState != EFHeadLookState.Following)
                    {
                        fade = true;
                    }
                }
            }

            if (fade)
            {
                EyesOutOfRangeBlend = Mathf.Max(0f, EyesOutOfRangeBlend - Time.deltaTime);
            }
            else
            {
                EyesOutOfRangeBlend = Mathf.Min(1f, EyesOutOfRangeBlend + Time.deltaTime);
            }


            blend = EyesBlend * EyesOutOfRangeBlend;
            if (blend <= 0f)
            {
                return;
            }


            if (eyeTarget != null)
            {
                Vector3 lookStartPosition;
                if (!AnchorReferencePoint)
                {
                    if (lookStartReferenceTransform == null)
                    {
                        if (BackBonesTransforms.Length > 0)
                        {
                            lookStartReferenceTransform = BackBonesTransforms[0];
                        }
                        else
                        {
                            lookStartReferenceTransform = LeadBone;
                        }
                    }
                    lookStartPosition = lookStartReferenceTransform.position + lookStartReferenceTransform.TransformVector(LookReferenceOffset);
                }
                else
                {
                    lookStartPosition = anchorHelper.position + BaseTransform.TransformVector(LookReferenceOffset);
                }


                Quaternion lookRotationQuat = Quaternion.LookRotation(eyeTarget.position - lookStartPosition);
                Vector3    lookRotation     = lookRotationQuat.eulerAngles;


                #region Limitating rotation

                Vector3 headRotation = (HeadReference.rotation * Quaternion.FromToRotation(headForward, Vector3.forward)).eulerAngles;// BaseTransform.rotation.eulerAngles;

                // Vector with degrees differences to all axes
                Vector2 deltaVector = new Vector3(Mathf.DeltaAngle(lookRotation.x, headRotation.x), Mathf.DeltaAngle(lookRotation.y, headRotation.y));

                // Limit when looking up or down
                if (deltaVector.x > EyesYRange.y)
                {
                    lookRotation.x = headRotation.x - EyesYRange.y;
                }
                else if (deltaVector.x < EyesYRange.x)
                {
                    lookRotation.x = headRotation.x - EyesYRange.x;
                }

                // Limit when looking left or right
                if (deltaVector.y > -EyesXRange.x)
                {
                    lookRotation.y = headRotation.y - EyesXRange.y;
                }
                else if (deltaVector.y < -EyesXRange.y)
                {
                    lookRotation.y = headRotation.y + EyesXRange.y;
                }

                #endregion


                for (int i = 0; i < eyes.Length; i++)
                {
                    Quaternion initRot   = eyes[i].rotation;
                    Quaternion newEyeRot = Quaternion.Euler(lookRotation);

                    float mul = 1f;
                    if (eyes[i] == LeftEye)
                    {
                        if (InvertLeftEye)
                        {
                            mul = -1f;
                        }
                    }
                    else if (eyes[i] == RightEye)
                    {
                        if (InvertRightEye)
                        {
                            mul = -1f;
                        }
                    }
                    newEyeRot *= Quaternion.FromToRotation(eyeForwards[i], Vector3.forward * mul);
                    newEyeRot *= eyesInitLocalRotations[i];

                    eyes[i].rotation  = newEyeRot;
                    eyes[i].rotation *= Quaternion.Inverse(eyesInitLocalRotations[i]);
                    if (EyesOffsetRotation != Vector3.zero)
                    {
                        eyes[i].rotation *= Quaternion.Euler(EyesOffsetRotation);
                    }
                    newEyeRot = eyes[i].rotation;

                    eyesLerpRotations[i] = Quaternion.Slerp(eyesLerpRotations[i], newEyeRot, Time.deltaTime * Mathf.Lerp(2f, 40f, EyesSpeed));

                    eyes[i].rotation = Quaternion.Slerp(initRot, eyesLerpRotations[i], blend);
                }
            }
        }
예제 #25
0
        private void Gizmos_DrawClamping(float radius, Vector3 lookPos)
        {
            if (!_gizmosDrawingLimiting && DebugRays == false)
            {
                return;
            }

            Handles.matrix = BaseTransform.localToWorldMatrix;

            Vector3 startLook      = GetLookStartMeasurePosition();
            Vector3 startLookLocal = BaseTransform.InverseTransformPoint(startLook);
            Vector3 dir            = (lookPos - startLook).normalized;

            if (LookState == EFHeadLookState.ClampedAngle)
            {
                Handles.color = new Color(1f, 1f, 0.1f, 0.7f);
            }
            else
            {
                Handles.color = new Color(0.3f, 1f, 0.1f, 0.7f);
            }

            //Gizmos.DrawLine(startLook, startLook + dir);

            Vector3 axisDir = BaseTransform.InverseTransformDirection(dir);

            axisDir.y = 0; axisDir.Normalize();
            Handles.DrawLine(startLookLocal, startLookLocal + axisDir * radius);

            if (YRotationLimits != _gizmosLastVertClamp)
            {
                _gizmosVertAlpha = 1.5f;
            }

            // Vertical
            Handles.color = new Color(0.3f, 1f, 0.7f, 0.08f * Mathf.Min(_gizmosVertAlpha, 1f));
            Handles.DrawSolidArc(startLookLocal, Vector3.right, ModelForwardAxis, YRotationLimits.y, radius / 1.2f);
            Handles.DrawSolidArc(startLookLocal, Vector3.right, ModelForwardAxis, YRotationLimits.x, radius / 1.2f);

            Handles.color = new Color(0.22f, .8f, 0.5f, 0.75f);
            Handles.DrawWireArc(startLookLocal, Vector3.right, ModelForwardAxis, YRotationLimits.y, radius / 1.2f);
            Handles.DrawWireArc(startLookLocal, Vector3.right, ModelForwardAxis, YRotationLimits.x, radius / 1.2f);

            if (StartLookElasticRangeY > 0f)
            {
                Handles.color = new Color(0.3f, 0.3f, 0.3f, 0.04f);
                Handles.DrawSolidArc(startLookLocal, Vector3.right, ModelForwardAxis, StartLookElasticRangeY, radius / 3.2f);
                Handles.DrawSolidArc(startLookLocal, Vector3.right, ModelForwardAxis, -StartLookElasticRangeY, radius / 3.2f);
            }

            if (XRotationLimits != _gizmosLastHorizClamp)
            {
                _gizmosHorizAlpha = 1.5f;
            }

            // Horizontal
            Handles.color = new Color(0.3f, 1f, 0.1f, 0.08f * Mathf.Min(_gizmosHorizAlpha, 1f));
            Handles.DrawSolidArc(startLookLocal, ModelUpAxis, ModelForwardAxis, XRotationLimits.x, radius);
            Handles.DrawSolidArc(startLookLocal, ModelUpAxis, ModelForwardAxis, XRotationLimits.y, radius);

            Handles.color = new Color(0.22f, .8f, 0.08f, 0.75f);
            Handles.DrawWireArc(startLookLocal, ModelUpAxis, ModelForwardAxis, XRotationLimits.x, radius);
            Handles.DrawWireArc(startLookLocal, ModelUpAxis, ModelForwardAxis, XRotationLimits.y, radius);

            if (StartLookElasticRangeX > 0f)
            {
                Handles.color = new Color(0.3f, 0.3f, 0.3f, 0.04f);
                Handles.DrawSolidArc(startLookLocal, ModelUpAxis, ModelForwardAxis, StartLookElasticRangeX, radius / 3.2f);
                Handles.DrawSolidArc(startLookLocal, ModelUpAxis, ModelForwardAxis, -StartLookElasticRangeX, radius / 3.2f);
            }


            if (LookState == EFHeadLookState.ClampedAngle)
            {
                Handles.color = new Color(1f, 1f, 0.1f, 0.7f);
            }
            else
            {
                Handles.color = new Color(0.3f, 1f, 0.7f, 0.7f);
            }

            axisDir   = BaseTransform.InverseTransformDirection(dir);
            axisDir.x = 0; axisDir.z = Mathf.Abs(axisDir.z); axisDir.Normalize();
            Handles.DrawLine(startLookLocal, startLookLocal + axisDir * radius / 1.2f);


            _gizmosLastHorizClamp = XRotationLimits;
            _gizmosLastVertClamp  = YRotationLimits;

            _gizmosVertAlpha  -= 0.03f;
            _gizmosHorizAlpha -= 0.03f;

            Handles.matrix = Matrix4x4.identity;
        }
예제 #26
0
        /// <summary>
        /// Get translation for the publishing pages library
        /// </summary>
        /// <param name="context">Context of the site</param>
        /// <returns>Translated name of the pages library</returns>
        public string GetPublishingPagesLibraryName(ClientContext context)
        {
            // Simplier implementation - Get the Pages library then get the relative URL of the rootfolder of the library

            //Keys:
            //  Web Property: __PagesListId
            //  Found in 2010, SPO

            string pagesLibraryName = "pages";

            if (context == null)
            {
                return(pagesLibraryName);
            }

            uint lcid = context.Web.EnsureProperty(p => p.Language);

            var propertyBagKey = Constants.WebPropertyKeyPagesListId;

            if (publishingPagesLibraryNames.ContainsKey(lcid))
            {
                if (publishingPagesLibraryNames.TryGetValue(lcid, out string name))
                {
                    return(name);
                }
                else
                {
                    // let's fallback to the default...we should never get here unless there's some threading issue
                    return(pagesLibraryName);
                }
            }
            else
            {
                if (BaseTransform.GetVersion(context) == SPVersion.SP2010)
                {
                    var keyVal = context.Web.GetPropertyBagValueString(propertyBagKey, string.Empty);
                    if (!string.IsNullOrEmpty(keyVal))
                    {
                        var list = context.Web.GetListById(Guid.Parse(keyVal), o => o.RootFolder.ServerRelativeUrl);
                        var webServerRelativeUrl = context.Web.EnsureProperty(w => w.ServerRelativeUrl);

                        pagesLibraryName = list.RootFolder.ServerRelativeUrl.Replace(webServerRelativeUrl, "").Trim('/').ToLower();

                        // add to cache
                        publishingPagesLibraryNames.TryAdd(lcid, pagesLibraryName);

                        return(pagesLibraryName);
                    }
                }
                else
                {
                    // Fall back to older logic
                    ClientResult <string> result = Microsoft.SharePoint.Client.Utilities.Utility.GetLocalizedString(context, "$Resources:List_Pages_UrlName", "osrvcore", int.Parse(lcid.ToString()));
                    context.ExecuteQueryRetry();

                    var altPagesLibraryName = new Regex(@"['´`]").Replace(result.Value, "");

                    if (string.IsNullOrEmpty(altPagesLibraryName))
                    {
                        return(pagesLibraryName);
                    }

                    // add to cache
                    publishingPagesLibraryNames.TryAdd(lcid, altPagesLibraryName.ToLower());

                    return(altPagesLibraryName.ToLower());
                }
            }

            return(pagesLibraryName);
        }
예제 #27
0
        private void Gizmos_DrawBones()
        {
            if (LeadBone == null)
            {
                return;
            }

            Color c         = Handles.color;
            Color boneColor = new Color(0.075f, .85f, 0.3f, gizmosAlpha * 0.7f);

            Handles.color = boneColor;

            Vector3 f = BaseTransform.TransformDirection(ModelForwardAxis);

            if (LeadBone.childCount > 0)
            {
                FGUI_Handles.DrawBoneHandle(LeadBone.position, LeadBone.position + BaseTransform.TransformDirection(ModelUpAxis) * Vector3.Distance(LeadBone.position, LeadBone.parent.position) / 2f, f);
            }

            if (LookBones.Count > 0)
            {
                // Drawing back-bones
                for (int i = 1; i < LookBones.Count; i++)
                {
                    if (LookBones[i].Transform != null)
                    {
                        if (LookBones[i] == null)
                        {
                            continue;
                        }
                        FGUI_Handles.DrawBoneHandle(LookBones[i].Transform.position, LookBones[i - 1].Transform.position, f);
                    }
                }

                if (LookBones.Count > 1)
                {
                    FGUI_Handles.DrawBoneHandle(LookBones[1].Transform.position, LeadBone.position, f);
                }
            }

            Handles.SphereHandleCap(0, LeadBone.position, Quaternion.identity, _gizmosDist * 0.025f, EventType.Repaint);

            for (int i = 0; i < LeadBone.childCount; i++)
            {
                Handles.color = new Color(0.8f, .8f, 0.8f, gizmosAlpha * 0.25f);
                Handles.DrawDottedLine(LeadBone.position, LeadBone.GetChild(i).position, 2.5f);
                Handles.color = new Color(0.8f, .8f, 0.8f, gizmosAlpha * 0.1f);
                Handles.SphereHandleCap(0, LeadBone.GetChild(i).position, Quaternion.identity, _gizmosDist * 0.01f, EventType.Repaint);
            }

            if (LookBones.Count > 1)
            {
                if (LookBones[LookBones.Count - 1].Transform.parent)
                {
                    Handles.color = new Color(0.8f, .8f, 0.8f, gizmosAlpha * 0.25f);
                    Handles.DrawDottedLine(LookBones[LookBones.Count - 1].Transform.position, LookBones[LookBones.Count - 1].Transform.parent.position, 3f);
                    Handles.color = new Color(0.8f, .8f, 0.8f, gizmosAlpha * 0.1f);
                    Handles.SphereHandleCap(0, LookBones[LookBones.Count - 1].Transform.parent.position, Quaternion.identity, _gizmosDist * 0.01f, EventType.Repaint);
                }
            }

            Handles.color = c;
        }
 /// <summary>
 /// Getting position for measuring distance from targeted positions
 /// </summary>
 public Vector3 GetDistanceMeasurePosition()
 {
     return(BaseTransform.position + BaseTransform.TransformVector(DistanceMeasurePoint));
 }