//Display mesh extruded along a curve
    public static void DisplayExtrudedMesh(List <InterpolationTransform> transforms, MeshProfile profile)
    {
        Mesh mesh = ExtrudeMeshAlongCurve.GenerateMesh(transforms, profile, 0.25f);

        if (mesh == null)
        {
            return;
        }

        //Gizmos.DrawMesh(mesh);
        Gizmos.DrawWireMesh(mesh);
        //TestAlgorithmsHelpMethods.DisplayMesh(mesh, Color.green);
        //TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(mesh, 0);

        //Graphics.DrawMeshNow(mesh, Vector3.zero, Quaternion.identity);
    }
Exemple #2
0
    //Uses transforms as start and end position, the length of the handles is determines by the z scale of each transform
    private void BezierCubicTest_Transform(InterpolationTransform transA, InterpolationTransform transB, float scaleA, float scaleB)
    {
        MyVector3 posA = transA.position;
        MyVector3 posB = transB.position;

        //The forward vector should move along from a to b
        MyVector3 handleA = posA + transA.Forward * scaleA;
        MyVector3 handleB = posB + -transB.Forward * scaleB;

        BezierCubic curve = new BezierCubic(posA, posB, handleA, handleB);

        //The interpolated values
        List <Vector3> positions = new List <Vector3>();
        List <float>   tValues   = new List <float>();

        //Loop between 0 and 1 in steps, where 1 step is minimum
        //So if steps is 5 then the line will be cut in 5 sections
        int steps = 30;

        float t_stepSize = 1f / (float)steps;

        float t = 0f;

        //+1 becuase wa also have to include the first point
        for (int i = 0; i < steps + 1; i++)
        {
            //Debug.Log(t);

            MyVector3 interpolatedPos = BezierCubic.GetPosition(posA, posB, handleA, handleB, t);

            positions.Add(interpolatedPos.ToVector3());

            tValues.Add(t);

            t += t_stepSize;
        }

        //Different orientation algorithms
        List <InterpolationTransform> transforms = InterpolationTransform.GetTransforms_InterpolateBetweenUpVectors(curve, tValues, transA.Up, transB.Up);

        //List<InterpolationTransform> transforms = InterpolationTransform.GetTransforms_UpRef(curve, tValues, transA.Up);

        //List<InterpolationTransform> transforms = InterpolationTransform.GetTransforms_FrenetNormal(curve, tValues);

        //List<InterpolationTransform> transforms = InterpolationTransform.GetTransforms_RotationMinimisingFrame(curve, tValues, transA.Up);


        //The curve
        DisplayInterpolation.DisplayCurve(positions, useRandomColor: true);

        //The start and end values and the handle points
        DisplayInterpolation.DisplayHandle(handleA.ToVector3(), posA.ToVector3());
        DisplayInterpolation.DisplayHandle(handleB.ToVector3(), posB.ToVector3());

        //Display transform
        DisplayInterpolation.DisplayOrientations(transforms, 1f);

        //Mesh
        Mesh extrudedMesh = ExtrudeMeshAlongCurve.GenerateMesh(transforms, meshProfile, 0.25f);

        if (extrudedMesh != null && displayMeshFilter != null)
        {
            displayMeshFilter.sharedMesh = extrudedMesh;
        }
    }