How to bend sprite into curve path?

Hi All,

First or all, this is my first time using Monogame Framework. Can someone give me some direction, how to bend sprite or 2D texture into curve path?

In Unity we can render texture in curve using Mesh Filter, and because this is my first time using Monogame, I want to try to port my dynamic wire from Unity to Monogame. Anyone can help me? I also want to use Nez which developed by @prime31

This is my dynamic wire: https://twitter.com/i/status/1049494388928212993

Thanks in advance

You will need to use DrawUserIndexPrimitives to do it SpriteBatch isn’t designed for drawing triangles.

You could take a look at Extended i think they were working on a shape batcher a while back dunno if that will do it.

Yes this is what I need: DrawUserIndexPrimitives, I’ll try it.

Thank you very much.

I dunno how much you already understand about the draw user index primitives and this wont be much help but just so you can see how you basically set up a circle i have a old 3dclass that i sort of tossed together long ago and just left in the dust. It doesn’t show how to set them to the graphics device or instance them or anything but im guessing it wont take you long to figure that out.

Maybe you can use it as a basis to make a rope class. It would need a lot of work to go from what it is to that and maybe just good for seeing how you set up a primitive.

You will probably need to learn how to write your own shader and for something like that to do it efficiently you will probably want to write a vertex shader specifically to morph the primitives via matrixes or some formula.

public class Circle3d
{
    bool centered = true;

    // public so you can pull them out after you create it and set it onto the graphics device.
    public VertexPositionTexture[] vertices;
    public int[] indices;

    static int OrientationOptionRightUpForward
    {
        get;
        set;
    }

    public Circle3d(int segments)
    {
        CreateCircle(segments, .01f, true, 2);
    }
    /// <summary>
    /// Create a circle default orientation is 2 forward
    /// </summary>
    public Circle3d(int segments, float lineSize)
    {
        CreateCircle(segments, lineSize, true, 2);
    }
    /// <summary>
    /// Create a circle default orientation is 2 forward
    /// </summary>
    public Circle3d(int segments, float lineSize0to1, bool centerIt, int orientation012)
    {
        CreateCircle(segments, lineSize0to1, centerIt, orientation012);
    }
    /// <summary>
    /// Create a circle default orientation is 2 forward
    /// </summary>
    public void CreateCircle(int segments, float lineSize0to1, bool centerIt, int orientation012)
    {
        centered = centerIt;
        float centering = .5f;
        if (centered)
            centering = 0.0f;
        float offset = 1f - lineSize0to1;
        vertices = new VertexPositionTexture[segments * 2];
        indices = new int[segments * 6];
        float pi2 = (float)(Math.PI * 2d);
        float mult = 1f / (float)(segments);
        int index = 0;
        int v_index = 0;
        int i_index = 0;
        for (index = 0; index < segments; index++)
        {
            var u = (float)(index) * mult;
            double radians = u * pi2;
            float x = ((float)(Math.Sin(radians)) * .5f) + centering;
            float y = ((float)(Math.Cos(radians)) * .5f) + centering;
            vertices[v_index + 0] = new VertexPositionTexture(ReOrient(new Vector3(x, y, 0)), new Vector2(u, 0f));
            vertices[v_index + 1] = new VertexPositionTexture(ReOrient(new Vector3(x * offset, y * offset, 0)), new Vector2(u, 1f));
            if (index < segments - 1)
            {
                indices[i_index + 0] = v_index + 0; indices[i_index + 1] = v_index + 1; indices[i_index + 2] = v_index + 2;
                indices[i_index + 3] = v_index + 2; indices[i_index + 4] = v_index + 1; indices[i_index + 5] = v_index + 3;
            }
            else
            {
                // connect the last one directly to the front
                indices[i_index + 0] = v_index + 0; indices[i_index + 1] = v_index + 1; indices[i_index + 2] = 0;
                indices[i_index + 3] = 0; indices[i_index + 4] = v_index + 1; indices[i_index + 5] = 1;
            }
            v_index += 2;
            i_index += 6;
        }
    }
    Vector3 ReOrient(Vector3 v)
    {
        if (OrientationOptionRightUpForward == 1)
            v = new Vector3(v.Z, v.X, v.Y);
        if (OrientationOptionRightUpForward == 2)
            v = new Vector3(v.X, v.Z, v.Y);
        return v;
    }
    public void Draw(GraphicsDevice gd, Effect effect)
    {
        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
        {
            pass.Apply();
            gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, (indices.Length / 3), VertexPositionTexture.VertexDeclaration);
        }
    }
}

.

You can search on here for using primitives.
There are alot of code snippets in posts on the forum and other places.
If you run into trouble or are having a hard time getting it going just ask.

.

Re:Edit

.

Here is another small class (scroll down the post) i did for someone that shows how to do a prism in wireframe its not textured with anything but a dot it will generate. However it shows how to create and load up primitives on the device and run them using spritebatch. Its useable by just copy pasting the whole thing (2 parts) into a new projects game1 class and maybe changing the namespace,

Actually, I was having hard time implementing draw user index primitives. This is actually get me some direction. Thank you very much.

I will show the result when its done.