protected virtual void ShowTwistAngles()
        {
            Handles.color = Color.green;

            int steps = GetStepsPerCurve() * m_splineBase.CurveCount;

            for (int i = 0; i <= steps; i++)
            {
                Vector3 dir   = m_splineBase.GetDirection(i / (float)steps);
                Vector3 point = m_splineBase.GetPoint(i / (float)steps);

                float   t          = i / (float)steps;
                float   twistAngle = m_splineBase.GetTwist(t);
                Vector3 v3;
                Vector3 up = GetUpVector();
                if (Math.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);
            }
        }
Ejemplo n.º 2
0
        public static void SetTwistAngle(SplineBase spline, int index, float twistAngle)
        {
            RecordHierarchy(spline.Root, "Battlehub.MeshDeformer2 Twist Angle");
            EditorUtility.SetDirty(spline);
            Twist twist = spline.GetTwist(index);

            twist.Data = twistAngle;
            spline.SetTwist(index, twist);
        }
Ejemplo n.º 3
0
        private void UpdatePosition(float t)
        {
            Vector3 position = m_spline.GetPoint(t);
            Vector3 dir      = m_spline.GetDirection(t);
            float   twist    = m_spline.GetTwist(t);

            transform.position = position;
            transform.LookAt(position + dir);
            transform.RotateAround(position, dir, twist);
        }
Ejemplo n.º 4
0
        public static void SetTwistOffset(SplineBase spline, int index, float t1, float t2)
        {
            Twist twist = spline.GetTwist(index);

            RecordHierarchy(spline.Root, "Battlehub.MeshDeformer2 Twist Offset");
            EditorUtility.SetDirty(spline);
            twist.T1 = t1;
            twist.T2 = t2;
            spline.SetTwist(index, twist);
        }
Ejemplo n.º 5
0
        private void UpdatePosition(float t)
        {
            Vector3 position = m_spline.GetPoint(t);
            Vector3 dir      = m_spline.GetDirection(t);
            float   twist    = m_spline.GetTwist(t);

            transform.position = position;
            Vector3    direction    = ((position + dir) - transform.position).normalized;
            Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, direction.y, direction.z));

            transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRotation, Time.deltaTime * rotationSpeed);
            //transform.LookAt(position + dir);
            transform.RotateAround(position, dir, twist);
        }
        private void Spawn()
        {
            int          index        = 0;
            int          nextIndex    = index + 1;
            Twist        twist        = m_spline.GetTwist(index);
            Vector3      ptPrev       = m_spline.GetControlPoint(index);
            Vector3      pt           = m_spline.GetControlPoint(nextIndex);
            GameObject   paperplaneGo = (GameObject)Instantiate(PaperplanePrefab, m_spline.GetPoint(0.0f), Quaternion.AngleAxis(twist.Data, pt - ptPrev) * Quaternion.LookRotation(pt - ptPrev));
            SplineFollow splineFollow = paperplaneGo.GetComponent <SplineFollow>();

            splineFollow.Spline = m_spline;

            if (!SmoothFollow.enabled)
            {
                SmoothFollow.SetTarget(paperplaneGo.transform);
                SmoothFollow.enabled = true;
            }
        }
Ejemplo n.º 7
0
        private void DrawSelectedPointInspector()
        {
            if (DrawSelectedPointInspectorOverride())
            {
                EditorGUI.BeginChangeCheck();
                ControlPointMode mode = (ControlPointMode)
                                        EditorGUILayout.EnumPopup("Mode", m_splineBase.GetControlPointMode(m_selectedIndex));
                if (EditorGUI.EndChangeCheck())
                {
                    SetMode(m_splineBase, mode, m_selectedIndex);
                }

                EditorGUI.BeginChangeCheck();

                int   index  = m_selectedIndex;
                bool  isLast = (m_selectedIndex + 1) / 3 == m_splineBase.CurveCount;
                Twist twist  = m_splineBase.GetTwist(index);
                EditorGUI.BeginChangeCheck();
                float twistAngle = EditorGUILayout.FloatField("Twist Angle", twist.Data);
                if (EditorGUI.EndChangeCheck())
                {
                    SetTwistAngle(m_splineBase, index, twistAngle);
                }


                if (m_splineBase.Loop || !isLast || m_splineBase.HasBranches(m_selectedIndex))
                {
                    float t1 = twist.T1;
                    float t2 = twist.T2;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.MinMaxSlider(new GUIContent("Twist Offset"), ref t1, ref t2, 0.0f, 1.0f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        SetTwistOffset(m_splineBase, index, t1, t2);
                    }
                }

                Thickness thickness = m_splineBase.GetThickness(index);
                EditorGUI.BeginChangeCheck();
                Vector3 thicknessValue = EditorGUILayout.Vector3Field("Thickness", thickness.Data);
                if (EditorGUI.EndChangeCheck())
                {
                    SetThickness(m_splineBase, index, thicknessValue);
                }

                if (m_splineBase.Loop || !isLast || m_splineBase.HasBranches(m_selectedIndex))
                {
                    float t1 = thickness.T1;
                    float t2 = thickness.T2;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.MinMaxSlider(new GUIContent("Thickness Offset"), ref t1, ref t2, 0.0f, 1.0f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        SetThicknessOffset(m_splineBase, index, t1, t2);
                    }
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();

                int   index = m_selectedIndex;
                Twist twist = m_splineBase.GetTwist(index);
                EditorGUI.BeginChangeCheck();
                float twistAngle = EditorGUILayout.FloatField("Twist Angle", twist.Data);
                if (EditorGUI.EndChangeCheck())
                {
                    SetTwistAngle(m_splineBase, index, twistAngle);
                }

                Thickness thickness = m_splineBase.GetThickness(index);
                EditorGUI.BeginChangeCheck();
                Vector3 thicknessValue = EditorGUILayout.Vector3Field("Thickness", thickness.Data);
                if (EditorGUI.EndChangeCheck())
                {
                    SetThickness(m_splineBase, index, thicknessValue);
                }
            }
        }
Ejemplo n.º 8
0
        private void Update()
        {
            if (m_spline == null)
            {
                return;
            }

            if (transform.localPosition != m_localPosition)
            {
                if (m_spline.SetControlPointLocal(m_index, transform.localPosition))
                {
                    m_localPosition = transform.localPosition;
                }
                else
                {
                    transform.localPosition = m_localPosition;
                }
            }


            if (transform.rotation != m_rotation)
            {
                if (m_index % 3 == 0)
                {
                    Vector3 v         = Vector3.back;
                    int     prevIndex = m_index - 1;
                    if (prevIndex < 0)
                    {
                        prevIndex = m_index + 1;
                        v         = Vector3.forward;
                    }

                    Vector3 prevPt = m_spline.GetControlPoint(prevIndex);
                    Vector3 pt     = m_spline.GetControlPoint(m_index);
                    Vector3 toPrev = (transform.rotation * v).normalized * (pt - prevPt).magnitude;

                    Twist twist = m_spline.GetTwist(m_index);

                    m_rotation = transform.rotation;
                    twist.Data = transform.eulerAngles.z;

                    m_updateAngle = false;
                    m_spline.SetTwist(m_index, twist);
                    m_spline.SetControlPoint(prevIndex, pt + toPrev);
                    m_updateAngle = true;
                }
                else
                {
                    transform.rotation = m_rotation;
                }
            }

            Thickness thickness     = m_spline.GetThickness(m_index);
            Vector3   thicknessData = thickness.Data;

            if (transform.localScale != thicknessData)
            {
                thickness.Data = transform.localScale;
                m_spline.SetThickness(m_index, thickness);
            }
        }