Does Mesh:setVertices require size to stay the same?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Does Mesh:setVertices require size to stay the same?

Post by ishkabible » Sun Jun 22, 2014 3:10 am

I want to use Meshs in my new project (btw I'm back, I had forgot how fun love2d can be!!). I am going to be creating a lot of meshes on the fly and sense newMesh is expensive I was hoping I could efficiently modify 1 mesh to draw all of my polygons. The number of polygons in the mesh may change so unless Mesh:setVertices lets me change the number of meshes I am going to need to have many different meshes for each poly count that I each separately modify (which is annoying). So does Mesh:setVertices require the size to stay the same or not?

Also does Mesh:setVertices require each polygon to be exactly of length 8 or can it be more? I have extra information that I want to store in my polygons so it would be nice if I could have the first 8 numbers be what is required for Mesh:setVertices and have the ones after be my extra information.

User avatar
slime
Solid Snayke
Posts: 2863
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Does Mesh:setVertices require size to stay the same?

Post by slime » Sun Jun 22, 2014 3:55 am

ishkabible wrote:So does Mesh:setVertices require the size to stay the same or not?
It doesn't, but if the size changes it might have to recreate stuff internally, which can be fairly expensive. So it's better to keep the size constant.
One option is to create the mesh with the maximum possible number of vertices initially, and then do Mesh:setVertex in a loop over the vertices you actually want to change and use [wiki]Mesh:setDrawRange[/wiki] to restrict what's drawn to just those vertices.

(That's actually pretty much how SpriteBatches are implemented, although they use OpenGL directly rather than using a love Mesh.)
ishkabible wrote:Also does Mesh:setVertices require each polygon to be exactly of length 8 or can it be more? I have extra information that I want to store in my polygons so it would be nice if I could have the first 8 numbers be what is required for Mesh:setVertices and have the ones after be my extra information.
I assume you mean the vertex components / attributes? Unfortunately those are fixed at 2 position numbers, 2 texture coordinate numbers, and 4 color numbers for now (although you can re-interpret what the numbers mean inside a custom vertex shader.)

In the future I'm planning to add the ability to attach arbitrary vertex attributes to Meshes so you can add as much stuff as you want, although you'll also need to create a custom vertex shader in order to use them when drawing, since LÖVE won't know by itself what those custom vertex attributes are meant to do.

User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: Does Mesh:setVertices require size to stay the same?

Post by ishkabible » Sun Jun 22, 2014 2:21 pm

Thanks! That helps me. I'll use your setRange. Didn't see that method!

Post Reply

Who is online

Users browsing this forum: No registered users and 202 guests