Exemplo n.º 1
0
        // public method

        public override void DoAwake()
        {
            base.DoAwake();

            if (float.IsNaN(m_baseVolume))
            {
                Vector3 s /*= m_baseScale*/ = V3Ext.FixZeroComponent(m_tr.localScale);
                m_baseVolume = s.x * s.y * s.z;
            }
        }
Exemplo n.º 2
0
        public override void DoUpdate()
        {
            base.DoUpdate();

            Vector3 selfScale = m_tr.GetScale(m_ownerSpace);

            selfScale = V3Ext.FixZeroComponent(selfScale); //ensure no 0 component
            Vector3 endScale    = selfScale;
            float   totalVolume = m_baseVolume * m_volumeMulti;

            // apply effect
            switch (m_eFreeAxis)
            {
            case EAxis.X:
            {
                float vol  = Mathf.Abs(totalVolume / selfScale.x);
                float sqrt = Mathf.Sqrt(vol);

                endScale.y = endScale.z = sqrt;
            }
            break;

            case EAxis.Y:
            {
                float vol  = Mathf.Abs(totalVolume / selfScale.y);
                float sqrt = Mathf.Sqrt(vol);

                endScale.x = endScale.z = sqrt;
            }
            break;

            case EAxis.Z:
            {
                float vol  = Mathf.Abs(totalVolume / selfScale.z);
                float sqrt = Mathf.Sqrt(vol);

                endScale.x = endScale.y = sqrt;
            }
            break;
            }

            // influence
            if (!Mathf.Approximately(m_influence, 1f))
            {
                endScale = Misc.Lerp(selfScale, endScale, m_influence);
            }

            m_tr.SetScale(endScale, m_ownerSpace);
            //if (m_modifyInitInfo)
            //    m_cstack.SetInitLocScale(m_tr.localScale);
        }
Exemplo n.º 3
0
        private void _RecordInitInfo()
        {
            Vector3    selfWorldPos = m_tr.position;
            Quaternion selfWorldRot = m_tr.rotation;
            Vector3    selfWorldSca = m_tr.lossyScale;

            Vector3    newLocPos = m_target.InverseTransformPoint(selfWorldPos);
            Quaternion newLocRot = Quaternion.Inverse(m_target.rotation) * selfWorldRot;
            Vector3    newLocSca = V3Ext.DivideComp(selfWorldSca, m_target.lossyScale);

            m_pseudoLocTr.pos   = newLocPos;
            m_pseudoLocTr.rot   = newLocRot;
            m_pseudoLocTr.scale = newLocSca;
        }
Exemplo n.º 4
0
            public void ExecuteWorldSoft(SoftSelection softSel, Vector3 worldFrom, Vector3 worldTo, Vector3 worldPivotPos)
            {
                //Dbg.Log("ScaleVerts.ExecuteWorldSoft: from: {0}, to: {1}, revert: {2}", worldFrom.ToString("F3"), worldTo.ToString("F3"), bRevert);
                Vector3 worldScaleDelta = V3Ext.DivideComp(worldTo, worldFrom); //when I say "world", it's not bound to be global orientation

                Matrix4x4 mat, matI;

                _GetMatrices(out mat, out matI);

                //Vector3 localPivotPos = m_Pivot.ModelPos; //this will accumulate errors
                Vector3 localPivotPos = m_Tr.InverseTransformPoint(worldPivotPos);

                softSel.Prepare();

                // apply change to verts
                Mesh m = m_Mesh.mesh;

                Vector3[] cachedVertsArray = softSel.CachedVertPos;
                Vector3[] vertsArray       = (Vector3[])cachedVertsArray.Clone();
                VLst      softSelIdxLst    = softSel.GetEffectVerts();

                //Vector3[] curVertArray = MeshCache.Instance.vertices;
                //Dbg.Log("modelPivotPos = {0}, {1}", localPivotPos.ToString("F3"), Misc.ListToString(softSelIdxLst, idx => { return curVertArray[idx].ToString("F3"); } ));

                // apply scaling
                for (int i = 0; i < softSelIdxLst.Count; ++i)
                {
                    int     vidx = softSelIdxLst[i];
                    Vector3 off  = vertsArray[vidx] - localPivotPos;

                    // calc scale mat
                    Vector3 percScale;
                    float   percentage = softSel.GetPercentage(vidx);
                    percScale = Vector3.Lerp(Vector3.one, worldScaleDelta, percentage);

                    Matrix4x4 matScalePerc = Matrix4x4.Scale(percScale);
                    Matrix4x4 combinedMat  = (mat * matScalePerc * matI);
                    Vector3   newOff       = combinedMat.MultiplyPoint(off);

                    vertsArray[vidx] = localPivotPos + newOff;

                    //Dbg.Log("newOff={0}, off={1}, verts={2}, mat=\n{3}", newOff.ToString("F6"), off.ToString("F6"), vertsArray[vidx].ToString("F6"), combinedMat.ToString("F8"));
                }

                // apply to mesh
                UndoMesh.SetVertices(m, vertsArray);

                //Dbg.Log("=======================");
            }
Exemplo n.º 5
0
        private bool _AllBonesInLine()
        {
            if (m_jointArr.Length < 2)
            {
                return(false);
            }

            var dir = (m_jointArr[1].position - m_jointArr[0].position).normalized;

            for (int i = 1; i < m_jointArr.Length - 1; ++i)
            {
                var j0   = m_jointArr[i];
                var j1   = m_jointArr[i + 1];
                var tdir = (j1.position - j0.position).normalized;
                if (!Mathf.Approximately(V3Ext.AbsDot(dir, tdir), 1f))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
            /// <summary>
            /// scale specified verts based on pivot (parameter in world space)
            /// a affine transformation(?)
            /// </summary>
            /// <param name="vertIdxLst">the list containing index to all affected verts</param>
            /// <param name="worldScaleDelta">the scale info in world space</param>
            public void ExecuteWorld(VLst vertIdxLst, Vector3 worldFrom, Vector3 worldTo, Vector3 worldPivotPos)
            {
                Vector3   worldScaleDelta = V3Ext.DivideComp(worldTo, worldFrom); //when I say "world", it's not bound to be global orientation
                Matrix4x4 combinedMat     = _CalcCombinedMat(ref worldScaleDelta);

                //Vector3 localPivotPos = m_Pivot.ModelPos; //this will accumulate errors
                Vector3 localPivotPos = m_Tr.InverseTransformPoint(worldPivotPos);

                // apply change to verts
                Mesh m = m_Mesh.mesh;

                Vector3[] vertsArray = m.vertices;
                for (int i = 0; i < vertIdxLst.Count; ++i)
                {
                    int     vidx   = vertIdxLst[i];
                    Vector3 off    = vertsArray[vidx] - localPivotPos;
                    Vector3 newOff = combinedMat.MultiplyPoint(off);
                    vertsArray[vidx] = localPivotPos + newOff;
                    //Dbg.Log("newOff={0}, off={1}, verts={2}, mat=\n{3}", newOff.ToString("F6"), off.ToString("F6"), vertsArray[vidx].ToString("F6"), combinedMat.ToString("F8"));
                }

                // apply to mesh
                UndoMesh.SetVertices(m, vertsArray);
            }