Ejemplo n.º 1
0
        public static void DrawSplineComputer(SplineComputer comp, double fromPercent = 0.0, double toPercent = 1.0, float alpha = 1f)
        {
            if (comp == null)
            {
                return;
            }
            Color prevColor   = Handles.color;
            Color orange      = new Color(1f, 0.564f, 0f);
            Color handleColor = comp.hasMorph && !MorphWindow.editShapeMode ? orange : comp.editorPathColor;

            handleColor.a = alpha;
            Handles.color = handleColor;
            if (comp.pointCount < 2)
            {
                return;
            }
            double add = comp.moveStep;

            if (add < 0.0025)
            {
                add = 0.0025;
            }

            if (comp.type == Spline.Type.BSpline && comp.pointCount > 1)
            {
                SplinePoint[] compPoints = comp.GetPoints();
                Handles.color = new Color(handleColor.r, handleColor.g, handleColor.b, 0.5f * alpha);
                for (int i = 0; i < compPoints.Length - 1; i++)
                {
                    Handles.DrawLine(compPoints[i].position, compPoints[i + 1].position);
                }
                Handles.color = handleColor;
            }

            if (!comp.drawThinckness)
            {
                double percent = fromPercent;
                fromPos = comp.EvaluatePosition(percent);
                toPos   = Vector3.zero;
                while (true)
                {
                    percent = DMath.Move(percent, toPercent, add);
                    toPos   = comp.EvaluatePosition(percent);
                    Handles.DrawLine(fromPos, toPos);
                    if (percent == toPercent)
                    {
                        break;
                    }
                    fromPos = toPos;
                }
                return;
            }
            else
            {
                Camera editorCamera = SceneView.currentDrawingSceneView.camera;
                double percent      = fromPercent;
                comp.Evaluate(fromResult, percent);
                Vector3 fromNormal = fromResult.normal;
                if (comp.billboardThickness)
                {
                    fromNormal = (editorCamera.transform.position - fromResult.position).normalized;
                }
                Vector3 fromRight = Vector3.Cross(fromResult.direction, fromNormal).normalized *fromResult.size * 0.5f;
                while (true)
                {
                    percent  = DMath.Move(percent, toPercent, add);
                    toResult = comp.Evaluate(percent);
                    Vector3 toNormal = toResult.normal;
                    if (comp.billboardThickness)
                    {
                        toNormal = (editorCamera.transform.position - toResult.position).normalized;
                    }
                    Vector3 toRight = Vector3.Cross(toResult.direction, toNormal).normalized *toResult.size * 0.5f;

                    Handles.DrawLine(fromResult.position + fromRight, toResult.position + toRight);
                    Handles.DrawLine(fromResult.position - fromRight, toResult.position - toRight);
                    Handles.DrawLine(fromResult.position + fromRight, fromResult.position - fromRight);
                    if (percent == toPercent)
                    {
                        break;
                    }
                    fromResult = toResult;
                    fromNormal = toNormal;
                    fromRight  = toRight;
                }
            }
            Handles.color = prevColor;
        }
Ejemplo n.º 2
0
        public static void DrawSplineComputer(SplineComputer comp, double fromPercent = 0.0, double toPercent = 1.0, float alpha = 1f)
        {
            if (comp == null)
            {
                return;
            }
            Color prevColor   = Handles.color;
            Color orange      = new Color(1f, 0.564f, 0f);
            Color handleColor = comp.hasMorph && !MorphWindow.editShapeMode ? orange : comp.editorPathColor;

            handleColor.a = alpha;
            Handles.color = handleColor;
            int iterations = Mathf.CeilToInt(comp.iterations * Mathf.Abs((float)(toPercent - fromPercent)));

            if (comp.pointCount < 2)
            {
                return;
            }

            if (comp.type == Spline.Type.BSpline && comp.pointCount > 1)
            {
                SplinePoint[] compPoints = comp.GetPoints();
                Handles.color = new Color(handleColor.r, handleColor.g, handleColor.b, 0.5f * alpha);
                for (int i = 0; i < compPoints.Length - 1; i++)
                {
                    Handles.DrawLine(compPoints[i].position, compPoints[i + 1].position);
                }
                Handles.color = handleColor;
            }

            if (!comp.drawThinckness)
            {
                if (positions.Length != iterations * 2)
                {
                    positions = new Vector3[iterations * 2];
                }
                Vector3 prevPoint  = comp.EvaluatePosition(fromPercent);
                int     pointIndex = 0;
                for (int i = 1; i < iterations; i++)
                {
                    double p = DMath.Lerp(fromPercent, toPercent, (double)i / (iterations - 1));
                    positions[pointIndex] = prevPoint;
                    pointIndex++;
                    positions[pointIndex] = comp.EvaluatePosition(p);
                    pointIndex++;
                    prevPoint = positions[pointIndex - 1];
                }
                Handles.DrawLines(positions);
            }
            else
            {
                Transform editorCamera = SceneView.currentDrawingSceneView.camera.transform;
                if (positions.Length != iterations * 6)
                {
                    positions = new Vector3[iterations * 6];
                }
                SplineResult prevResult = comp.Evaluate(fromPercent);
                Vector3      prevNormal = prevResult.normal;
                if (comp.billboardThickness)
                {
                    prevNormal = (editorCamera.position - prevResult.position).normalized;
                }
                Vector3 prevRight  = Vector3.Cross(prevResult.direction, prevNormal).normalized *prevResult.size * 0.5f;
                int     pointIndex = 0;
                for (int i = 1; i < iterations; i++)
                {
                    double       p         = DMath.Lerp(fromPercent, toPercent, (double)i / (iterations - 1));
                    SplineResult newResult = comp.Evaluate(p);
                    Vector3      newNormal = newResult.normal;
                    if (comp.billboardThickness)
                    {
                        newNormal = (editorCamera.position - newResult.position).normalized;
                    }
                    Vector3 newRight = Vector3.Cross(newResult.direction, newNormal).normalized *newResult.size * 0.5f;

                    positions[pointIndex] = prevResult.position + prevRight;
                    positions[pointIndex + iterations * 2] = prevResult.position - prevRight;
                    positions[pointIndex + iterations * 4] = newResult.position - newRight;
                    pointIndex++;
                    positions[pointIndex] = newResult.position + newRight;
                    positions[pointIndex + iterations * 2] = newResult.position - newRight;
                    positions[pointIndex + iterations * 4] = newResult.position + newRight;
                    pointIndex++;
                    prevResult = newResult;
                    prevRight  = newRight;
                    prevNormal = newNormal;
                }
                Handles.DrawLines(positions);
            }
            Handles.color = prevColor;
        }