Hey @Pawel. I have been away from Defold for a good 8 months (working in games business resulting in very little spare time). From memory, yes, I did make a mesh extension to do this - which allowed me to load gltfs among other things. Iāll dig it up over the weekend and get back to you.
From memory, it kind of cheats I make a dummy mesh object, then it fills the buffer at run time, but it does mean you can load in different gltfs into the same mesh, thus, I would expect it to handle mesh modification (which is essentially modifying those buffers).
Iām thinking about primitive implementation of LOD, so I could have high res model and low res model and I could switch between them, instead of factoring new game objects and removing old
Sorry I havent gotten back to this sooner. I really need to clone myself atm.
Interesting use for a LOD, Im not sure the performance would be there if you were writing verts when switching. I guess you might be referring to populating some buffers, then switching them using some factor?
Ok. Back again. If you look at the project n defold-tools called GLTF Lua Loader the method that sets the mesh data is called: geom:makeMesh
In this a couple of key methods from the extension are used:
Lines 34->36 of geometry-utils.lua:
geomextension.setbufferbytesfromtable( meshbuf, "position", indices, verts )
if(normals) then geomextension.setbufferbytesfromtable( meshbuf, "normal", indices, normals ) end
if(uvs) then geomextension.setbufferbytesfromtable( meshbuf, "texcoord0", indices, uvs ) end
As can be seen this sets the meshbuffers position indexes, normals and texcoord. You can also set verts. In file gltfloader.lua line 169:
geomextension.setbufferfloatsfromtable(bv.byteOffset or 0, bv.byteLength or 0, buffer.data, gltf.verts)
In the geomextensions there are a number of helper functions for this. Iāll make geomextensions a proper extensions repo so people can just include the lib in Defold projects - will look at this on the weekend.
All the best everyone (and yes, Im getting back into Defold after a crazy time in games⦠our whole studio got erm ālet goā. ⦠cant say anymore).
The example modifies the mesh at runtime and creates a new cube everyframe with a different size. Obviously youād normally use scale, but this is a simple way to show how to update meshes at runtime. I was going to add a vid, but that really doesnt make sense, since it looks like its scaling
I havent tried including this as an extension in another project. Will give it a try, but it should be ok.