Example #1
0
        protected override void ShowTwistAngles()
        {
            if (m_deformer == null)
            {
                base.ShowTwistAngles();
                return;
            }

            Handles.color = Color.green;
            int steps = GetStepsPerCurve();

            if (steps <= 0)
            {
                steps = 1;
            }
            else if (steps > 5)
            {
                steps = 5;
            }

            ScaffoldWrapper[] scaffolds = m_deformer.Scaffolds;
            for (int i = 0; i < scaffolds.Length; ++i)
            {
                ScaffoldWrapper scaffold = m_deformer.Scaffolds[i];
                for (int ci = 0; ci < scaffold.CurveIndices.Length; ++ci)
                {
                    int curveIndex = scaffold.CurveIndices[ci];
                    for (int j = 0; j <= steps; j++)
                    {
                        float   t     = (float)j / steps;
                        Vector3 dir   = m_deformer.GetDirection(t, curveIndex);
                        Vector3 point = m_deformer.GetPoint(t, curveIndex);

                        if (scaffold.IsRigid)
                        {
                            t = 1.0f;
                        }
                        float twistAngle = m_deformer.GetTwist(t, curveIndex);

                        Vector3 v3;
                        Vector3 up = GetUpVector();
                        if (Mathf.Abs(Vector3.Dot(dir, up)) < 1.0f)
                        {
                            v3 = Vector3.Cross(dir, up).normalized;
                        }
                        else
                        {
                            v3 = Vector3.Cross(dir, GetSideVector()).normalized;
                        }

                        if (dir == Vector3.zero)
                        {
                            continue;
                        }

                        Handles.DrawLine(point, point + Quaternion.AngleAxis(twistAngle, dir) * Quaternion.LookRotation(v3, up) * Vector3.forward * TwistAngleScale);
                    }
                }
            }
        }
Example #2
0
        private Vector3[] Deform(Slice[] slices, Mesh mesh, MeshDeformer deformer, bool isRigid)
        {
            Vector3[] vertices = mesh.vertices;
            for (int s = 0; s < slices.Length; ++s)
            {
                Slice slice = slices[s];

                Vector3 center = deformer.GetPoint(slice.T, slice.CurveIndex);
                center = deformer.transform.InverseTransformPoint(center);

                Vector3 dir = deformer.transform.InverseTransformVector(deformer.GetDirection(slice.T, slice.CurveIndex));
                float   t   = slice.T;
                if (isRigid)
                {
                    t = 1.0f;
                }

                if (dir == Vector3.zero)
                {
                    continue;
                }


                float   twistAngle    = deformer.GetTwist(t, slice.CurveIndex);
                Vector3 thickness     = deformer.GetThickness(t, slice.CurveIndex);
                float   wrapCurvature = deformer.GetWrap(t, slice.CurveIndex);

                Quaternion rotation = Quaternion.AngleAxis(twistAngle, dir) * Quaternion.LookRotation(dir, m_up) * m_axisRotation;
                Matrix4x4  matrix   = Matrix4x4.TRS(center, rotation, Vector3.one);
                int[]      indices  = slice.Indices;
                for (int i = 0; i < indices.Length; ++i)
                {
                    int     index  = indices[i];
                    Vector3 vertex = vertices[index];
                    vertex          = AxisTransform(deformer, vertex, slice.Center, thickness);
                    vertex          = WrapAroundAxisTransform(deformer, vertex, slice.Center, wrapCurvature);
                    vertex          = matrix.MultiplyPoint(vertex);
                    vertices[index] = vertex;
                }
            }
            return(vertices);
        }