예제 #1
0
        private void DrawVertexPathSceneEditor()
        {
            var bezierColor = globalDisplaySettings.bezierPath;

            bezierColor.a *= .5f;

            if (Getdata.showBezierPathInVertexMode)
            {
                for (int i = 0; i < GetBezierPath.NumSegments; i++)
                {
                    var points = GetBezierPath.GetPointsInSegment(i);

                    for (int j = 0; j < points.Length; j++)
                    {
                        points[j] = MathUtility.TransformPoint(points[j], creator.transform, GetBezierPath.Space);
                    }

                    Handles.DrawBezier(points[0], points[3], points[1], points[2], bezierColor, null, 2);
                }
            }

            Handles.color = globalDisplaySettings.vertexPath;

            for (int i = 0; i < creator.Path.NumPoints; i++)
            {
                var nextIndex = (i + 1) % creator.Path.NumPoints;

                if (nextIndex != 0 || GetBezierPath.IsClosed)
                {
                    Handles.DrawLine(creator.Path.GetPoint(i), creator.Path.GetPoint(nextIndex));
                }
            }

            if (Getdata.showNormalsInVertexMode)
            {
                Handles.color = globalDisplaySettings.normals;

                var normalLines = new Vector3[creator.Path.NumPoints * 2];

                for (int i = 0; i < creator.Path.NumPoints; i++)
                {
                    normalLines[i * 2]     = creator.Path.GetPoint(i);
                    normalLines[i * 2 + 1] = creator.Path.GetPoint(i) + creator.Path.localNormals[i] * globalDisplaySettings.normalsLength;
                }
                Handles.DrawLines(normalLines);
            }
        }
예제 #2
0
        private void DrawBezierPathSceneEditor()
        {
            var displayControlPoints = Getdata.displayControlPoints && (GetBezierPath.ControlPointMode != BezierPath.ControlMode.Automatic || !globalDisplaySettings.hideAutoControls);
            var bounds = GetBezierPath.CalculateBoundsWithTransform(creator.transform);

            if (Event.current.type == EventType.Repaint)
            {
                for (int i = 0; i < GetBezierPath.NumSegments; i++)
                {
                    var points = GetBezierPath.GetPointsInSegment(i);

                    for (int j = 0; j < points.Length; j++)
                    {
                        points[j] = MathUtility.TransformPoint(points[j], creator.transform, GetBezierPath.Space);
                    }

                    if (Getdata.showPerSegmentBounds)
                    {
                        var segmentBounds = CubicBezierUtility.CalculateSegmentBounds(points[0], points[1], points[2], points[3]);

                        Handles.color = globalDisplaySettings.segmentBounds;
                        Handles.DrawWireCube(segmentBounds.center, segmentBounds.size);
                    }

                    // Draw lines between control points
                    if (displayControlPoints)
                    {
                        Handles.color = (GetBezierPath.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 segmentColor     = (highlightSegment) ? globalDisplaySettings.highlightedPath : globalDisplaySettings.bezierPath;

                    Handles.DrawBezier(points[0], points[3], points[1], points[2], segmentColor, null, 2);
                }

                if (Getdata.showPathBounds)
                {
                    Handles.color = globalDisplaySettings.bounds;
                    Handles.DrawWireCube(bounds.center, bounds.size);
                }

                // Draw normals
                if (Getdata.showNormals)
                {
                    if (!hasUpdatedNormalsVertexPath)
                    {
                        normalsVertexPath           = new VertexPath(GetBezierPath, creator.transform, normalsSpacing);
                        hasUpdatedNormalsVertexPath = true;
                    }

                    if (editingNormalsOld != Getdata.showNormals)
                    {
                        editingNormalsOld = Getdata.showNormals;
                        Repaint();
                    }

                    var normalLines = new Vector3[normalsVertexPath.NumPoints * 2];

                    Handles.color = globalDisplaySettings.normals;

                    for (int i = 0; i < normalsVertexPath.NumPoints; i++)
                    {
                        normalLines[i * 2]     = normalsVertexPath.GetPoint(i);
                        normalLines[i * 2 + 1] = normalsVertexPath.GetPoint(i) + normalsVertexPath.GetNormal(i) * globalDisplaySettings.normalsLength;
                    }

                    Handles.DrawLines(normalLines);
                }
            }

            if (Getdata.displayAnchorPoints)
            {
                for (int i = 0; i < GetBezierPath.NumPoints; i += 3)
                {
                    DrawHandle(i);
                }
            }
            if (displayControlPoints)
            {
                for (int i = 1; i < GetBezierPath.NumPoints - 1; i += 3)
                {
                    DrawHandle(i);
                    DrawHandle(i + 1);
                }
            }
        }