How do i access a buffer stream properly

my method

local vbuf = go.get("/terrain#mesh", "vertices")
local verts = buffer.get_stream(vbuf, hash("vertices"))

the error
bad argument #1 to ‘get_stream’ (buffer expected, got userdata)

1 Like

go.get("#mesh", "vertices") does not return a Lua buffer object. It returns a resource reference (path hash) to the mesh’s .buffer resource. To access the streams you must first resolve that resource to an actual buffer with resource.get_buffer(), then call buffer.get_stream() on the returned buffer.

Check resource.get_buffer:

And buffer.get_stream:

Should be something like this:

local res_path = go.get("/terrain#mesh", "vertices")   -- gives you a resource path, not a buffer
local my_buf = resource.get_buffer(res_path)         --gives you an actual Lua buffer

local position = buffer.get_stream(my_buf, hash("position"))  -- use your real stream name here, e.g. if you have "position" in the buffer, as commonly is, use "position"

-- If you changed the buffer and want the mesh to use the updated data:
resource.set_buffer(res_path, my_buf)

To know the real stream names you can open the .buffer file assigned to the Mesh “Vertices” property (it’s JSON and should lists stream names).

Very useful presentation by Eugene:

4 Likes