void DrawBezierPathSceneEditor() { bool displayControlPoints = data.displayControlPoints && (bezierPath.ControlPointMode != BezierPath.ControlMode.Automatic || !globalDisplaySettings.hideAutoControls); Bounds bounds = bezierPath.PathBounds; // Draw normals if (data.showNormals) { if (!hasUpdatedNormalsVertexPath) { normalsVertexPath = new VertexPath(bezierPath, normalsSpacing); hasUpdatedNormalsVertexPath = true; } if (editingNormalsOld != data.showNormals) { editingNormalsOld = data.showNormals; Repaint(); } Handles.color = globalDisplaySettings.normals; for (int i = 0; i < normalsVertexPath.NumVertices; i++) { Vector3 prevVertex = normalsVertexPath.vertices[Mathf.Max(0, i - 1)]; Vector3 nextVertex = normalsVertexPath.vertices[Mathf.Min(normalsVertexPath.NumVertices - 1, i + 1)]; Vector3 forward = prevVertex - nextVertex; forward *= globalDisplaySettings.normalsWidth; Vector3[] points = new Vector3[4]; points[0] = normalsVertexPath.vertices[i] - forward * 0.5f; points[1] = points[0] + normalsVertexPath.normals[i] * globalDisplaySettings.normalsLength; points[2] = points[1] + forward; points[3] = points[0] + forward; Handles.DrawSolidRectangleWithOutline(points, globalDisplaySettings.normals, globalDisplaySettings.normals); } } for (int i = 0; i < bezierPath.NumSegments; i++) { Vector3[] points = bezierPath.GetPointsInSegment(i); if (data.showPerSegmentBounds) { Bounds segmentBounds = CubicBezierUtility.CalculateBounds(points); Handles.color = globalDisplaySettings.segmentBounds; Handles.DrawWireCube(segmentBounds.center, segmentBounds.size); } // Draw lines between control points if (displayControlPoints) { Handles.color = (bezierPath.ControlPointMode == BezierPath.ControlMode.Automatic) ? globalDisplaySettings.handleDisabled : globalDisplaySettings.controlLine; Handles.DrawLine(points[1], points[0]); Handles.DrawLine(points[2], points[3]); } // Draw path bool highlightSegment = (i == selectedSegmentIndex && Event.current.shift && draggingHandleIndex == -1 && mouseOverHandleIndex == -1); Color segmentCol = (highlightSegment) ? globalDisplaySettings.highlightedPath : globalDisplaySettings.bezierPath; Handles.DrawBezier(points[0], points[3], points[1], points[2], segmentCol, null, 2); } // Draw rotate/scale/move tool if (data.pathTransformationEnabled && !Event.current.alt && !Event.current.shift) { if (Tools.current == Tool.Rotate) { Undo.RecordObject(creator, "Rotate Path"); Quaternion newHandleRot = Handles.DoRotationHandle(currentHandleRot, bezierPath.Pivot); Quaternion deltaRot = newHandleRot * Quaternion.Inverse(currentHandleRot); currentHandleRot = newHandleRot; Quaternion newRot = deltaRot * bezierPath.Rotation; bezierPath.Rotation = newRot; if (shareTransformsWithPath) { creator.transform.rotation = newRot; rotationOld = newRot; } } else if (Tools.current == Tool.Scale) { Undo.RecordObject(creator, "Scale Path"); bezierPath.Scale = Handles.DoScaleHandle(bezierPath.Scale, bezierPath.Pivot, Quaternion.identity, HandleUtility.GetHandleSize(bezierPath.Pivot)); if (shareTransformsWithPath) { creator.transform.localScale = bezierPath.Scale; scaleOld = bezierPath.Scale; } } else { Undo.RecordObject(creator, "Move Path"); bezierPath.Pivot = bounds.center; Vector3 newCentre = Handles.DoPositionHandle(bezierPath.Pivot, Quaternion.identity); Vector3 deltaCentre = newCentre - bezierPath.Pivot; bezierPath.Position += deltaCentre; if (shareTransformsWithPath) { creator.transform.position = bezierPath.Position; positionOld = bezierPath.Position; } } } if (data.showPathBounds) { Handles.color = globalDisplaySettings.bounds; Handles.DrawWireCube(bounds.center, bounds.size); } if (data.displayAnchorPoints) { for (int i = 0; i < bezierPath.NumPoints; i += 3) { DrawHandle(i); } } if (displayControlPoints) { for (int i = 1; i < bezierPath.NumPoints - 1; i += 3) { DrawHandle(i); DrawHandle(i + 1); } } }
void DrawBezierPathSceneEditor() { var displayControlPoints = Data.displayControlPoints && (BezierPath.ControlPointMode != BezierPath.ControlMode.Automatic || !_globalDisplaySettings.hideAutoControls); var bounds = BezierPath.PathBounds; // Draw normals if (Data.showNormals) { if (!_hasUpdatedNormalsVertexPath) { _normalsVertexPath = new VertexPath(BezierPath, NormalsSpacing); _hasUpdatedNormalsVertexPath = true; } if (_editingNormalsOld != Data.showNormals) { _editingNormalsOld = Data.showNormals; Repaint(); } Handles.color = _globalDisplaySettings.normals; for (var i = 0; i < _normalsVertexPath.NumVertices; i++) { Handles.DrawLine( _normalsVertexPath.Vertices[i], _normalsVertexPath.Vertices[i] + _normalsVertexPath.Normals[i] * _globalDisplaySettings.normalsLength); } } for (var i = 0; i < BezierPath.NumSegments; i++) { var points = BezierPath.GetPointsInSegment(i); if (Data.showPerSegmentBounds) { var segmentBounds = CubicBezierUtility.CalculateBounds(points); Handles.color = _globalDisplaySettings.segmentBounds; Handles.DrawWireCube(segmentBounds.center, segmentBounds.size); } // Draw lines between control points if (displayControlPoints) { Handles.color = (BezierPath.ControlPointMode == BezierPath.ControlMode.Automatic) ? _globalDisplaySettings.handleDisabled : _globalDisplaySettings.controlLine; Handles.DrawLine(points[1], points[0]); Handles.DrawLine(points[2], points[3]); } // Draw path var highlightSegment = (i == _selectedSegmentIndex && Event.current.shift && _draggingHandleIndex == -1 && _mouseOverHandleIndex == -1); var segmentCol = (highlightSegment) ? _globalDisplaySettings.highlightedPath : _globalDisplaySettings.bezierPath; Handles.DrawBezier(points[0], points[3], points[1], points[2], segmentCol, null, 2); } // Draw rotate/scale/move tool if (Data.pathTransformationEnabled && !Event.current.alt && !Event.current.shift) { if (Tools.current == Tool.Rotate) { Undo.RecordObject(_creator, "Rotate Path"); var newHandleRot = Handles.DoRotationHandle(_currentHandleRot, BezierPath.Pivot); var deltaRot = newHandleRot * Quaternion.Inverse(_currentHandleRot); _currentHandleRot = newHandleRot; var newRot = deltaRot * BezierPath.Rotation; BezierPath.Rotation = newRot; if (_shareTransformsWithPath) { _creator.transform.rotation = newRot; _rotationOld = newRot; } } else if (Tools.current == Tool.Scale) { Undo.RecordObject(_creator, "Scale Path"); BezierPath.Scale = Handles.DoScaleHandle( BezierPath.Scale, BezierPath.Pivot, Quaternion.identity, HandleUtility.GetHandleSize(BezierPath.Pivot)); if (_shareTransformsWithPath) { _creator.transform.localScale = BezierPath.Scale; _scaleOld = BezierPath.Scale; } } else { Undo.RecordObject(_creator, "Move Path"); BezierPath.Pivot = bounds.center; var newCentre = Handles.DoPositionHandle(BezierPath.Pivot, Quaternion.identity); var deltaCentre = newCentre - BezierPath.Pivot; BezierPath.Position += deltaCentre; if (_shareTransformsWithPath) { _creator.transform.position = BezierPath.Position; _positionOld = BezierPath.Position; } } } if (Data.showPathBounds) { Handles.color = _globalDisplaySettings.bounds; Handles.DrawWireCube(bounds.center, bounds.size); } if (Data.displayAnchorPoints) { for (var i = 0; i < BezierPath.NumPoints; i += 3) { DrawHandle(i); } } if (displayControlPoints) { for (var i = 1; i < BezierPath.NumPoints - 1; i += 3) { DrawHandle(i); DrawHandle(i + 1); } } }