Exemplo n.º 1
0
        private void DrawTangents(Vector3[] segment, float t)
        {
            float   tangentLength = HandleUtility.GetHandleSize(_SplineDataObject[_SplineBranchCreator.SelectedPointIndex]);
            Vector3 startPoint    = Bezier3DUtility.CubicCurveVector3(segment[0], segment[1], segment[2], segment[3], t + 0.1f);
            Vector3 tangent       = Bezier3DUtility.GetTangent(startPoint, Bezier3DUtility.CubicCurveVector3(segment[0], segment[1], segment[2], segment[3], t));

            Handles.color = Color.green;
            Handles.DrawLine(startPoint, startPoint + tangent * tangentLength);
        }
Exemplo n.º 2
0
        private void DrawBiNormals(Vector3[] segment, float t)
        {
            float   biNormalLength = HandleUtility.GetHandleSize(_SplineDataObject[_SplineBranchCreator.SelectedPointIndex]);
            Vector3 startPoint     = Bezier3DUtility.CubicCurveVector3(segment[0], segment[1], segment[2], segment[3], t + 0.1f);
            Vector3 tangent        = Bezier3DUtility.GetTangent(startPoint, Bezier3DUtility.CubicCurveVector3(segment[0], segment[1], segment[2], segment[3], t));
            Vector3 biNormal       = Vector3.Cross(Vector3.up, tangent).normalized;

            Handles.color = Color.red;
            Handles.DrawLine(startPoint, startPoint + biNormal * biNormalLength);
        }
Exemplo n.º 3
0
 private void OnInsertButtonPressed()
 {
     //Last point when open
     if (_SplineBranchCreator.SelectedPointIndex / 3 == _SplineDataObject.SegmentCount && !_SplineDataObject.IsClosed)
     {
         Undo.RecordObject(_SplineDataObject, "Add_segment");
         _SplineDataObject.AddSegment(
             _SplineDataObject[_SplineDataObject.PointCount - 1] +
             (_SplineDataObject[_SplineDataObject.PointCount - 1] - _SplineDataObject[_SplineDataObject.PointCount - 3]).normalized *
             (_SplineDataObject[_SplineDataObject.PointCount - 1] - _SplineDataObject[_SplineDataObject.PointCount - 3]).magnitude);
     }
     else
     {
         Undo.RecordObject(_SplineDataObject, "Insert_segment");
         if (_SplineDataObject.IsClosed && _SplineBranchCreator.SelectedPointIndex / 3 + 1 == _SplineDataObject.SegmentCount)
         {
             //Last point when closed
             _SplineDataObject.InsertSegment(_SplineBranchCreator.SelectedPointIndex,
                                             Bezier3DUtility.CubicCurveVector3(
                                                 a: _SplineDataObject[_SplineBranchCreator.SelectedPointIndex],
                                                 b: _SplineDataObject[_SplineBranchCreator.SelectedPointIndex + 1],
                                                 c: _SplineDataObject[_SplineBranchCreator.SelectedPointIndex + 2],
                                                 d: _SplineDataObject[0], 0.5f));
         }
         else
         {
             _SplineDataObject.InsertSegment(_SplineBranchCreator.SelectedPointIndex,
                                             Bezier3DUtility.CubicCurveVector3(
                                                 a: _SplineDataObject[_SplineBranchCreator.SelectedPointIndex],
                                                 b: _SplineDataObject[_SplineBranchCreator.SelectedPointIndex + 1],
                                                 c: _SplineDataObject[_SplineBranchCreator.SelectedPointIndex + 2],
                                                 d: _SplineDataObject[_SplineBranchCreator.SelectedPointIndex + 3], 0.5f));
         }
     }
     HandleUtility.Repaint();
     EditorUtility.SetDirty(_SplineDataObject);
 }