I’m having a very strange issue.
I’m working on an explosion shader. It’s inspired by @Andrew_Stacey 's 2D explosion shader here,
http://codea.io/talk/discussion/2257/exploding-mesh-with-shaders
but it’s for 3D models. It disintegrates each of the faces along a trajectory derived from the face normal (unlike Andrew’s, I assume that the model is already multi-faceted, I don’t further subdivide the faces).
Now, the weird thing is, the shader was actually coming along nicely within a large project I’m working on, when I decided to export it to a minimal working example (MWE) to work on it further (and to share it). And, ironically enough, I can’t get the custom attribute buffer to work at all in the MWE. In the parent code, it works about 70% of the time, but does sometimes produce this error.
It’s probably something really simple, and I’ve just been staring at it too long, but I can’t work out what I’m doing wrong at all.
The bit that triggers the error is when I try to index the custom buffers. When this code runs:
local origin = m:buffer("origin")
local trajectory = m:buffer("trajectory")
origin:resize(#verts) --shouldn't be necessary. Triggers error.
trajectory:resize(#verts)
for i=1, #verts do
origin[i] = ori[i] --triggers error
I get:
error: [string “explode = {}…”]:9: attempt to index a nil value (local ‘origin’)
The mesh has been set up, it has vertices, colours, normals (so the custom buffers shouldn’t need resizing), it has a shader that compiled without error, which uses the custom attribute.
What have I forgotten??
The full MWE is here (it borrows code from @Ignatz , @Andrew_Stacey , and whoever made the Icosphere function):
I’d be very grateful if someone could put me out of my misery.