Also just for some more clarity. My geom extenstion (this one a little modified) does the following when assigning new buffers to a mesh.
------------------------------------------------------------------------------------------------------------
function geom:makeMesh( goname, indices, verts, uvs, normals )
if(#indices <= 0) then
print("[Error] Invalid indices count.")
return
end
local res = go.get(goname, "vertices")
local iverts = #indices
local meshdata = {}
-- positions are required (should assert or something)
tinsert(meshdata, { name = hash("position"), type=buffer.VALUE_TYPE_FLOAT32, count = 3 } )
if(normals) then tinsert(meshdata, { name = hash("normal"), type=buffer.VALUE_TYPE_FLOAT32, count = 3 } ) end
if(uvs) then tinsert(meshdata, { name = hash("texcoord0"), type=buffer.VALUE_TYPE_FLOAT32, count = 2 } ) end
local meshbuf = buffer.create(iverts, meshdata)
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
-- set the buffer with the vertices on the mesh
resource.set_buffer(res, meshbuf)
end
------------------------------------------------------------------------------------------------------------
So the problem isnt being able to generate mesh buffer data, but trying to replace the mesh component handle so that it has a new handle. This might be doable in C++ but I’m not certain of that.
If there are examples/methods that can do this, I would be very welcome to suggestions.
I think this specific comment shows the main problem:
local resource_name = "/my_cloned_buffer.bufferc" -- make this unique for each resource!
This means there needs to be a physical resource file for each res that needs to be attached/modified for each instance.
Note: The code includes some helper funcs that copy tables into buffer data for consumption by the buffer.