Open jowens opened 2 days ago
You can set the whole thing like this
const v = makeStructuredView(defs.uniforms.myUniforms);
v.set({
uni1: 123,
uni2: 456,
levelCount: [
{ f: 1, e: 2, v: 3, t: 4 },
{ f: 5, e: 6, v: 9, t: 2 },
...
],
levelBasePtr: [
{ f: 1, e: 2, v: 3, t: 4 },
{ f: 5, e: 6, v: 9, t: 2 },
...
],
});
You can set portions. Example
const v = makeStructuredView(defs.uniforms.myUniforms);
v.set({
uni2: 456,
});
v.set({
levelBasePtr: [
{ f: 1, e: 2, v: 3, t: 4 },
{ f: 5, e: 6, v: 9, t: 2 },
...
],
});
If you want to set arrays of structs sparcely it gets harder as you need to make the input sparce to match
v.set({
levelBasePtr: [
,
,
{ f: 1, e: 2, v: 3, t: 4 },
],
});
Set's only levelBasePtr[2]
Looking at your code above, it looks like you could do this
v.set({ levelCount: mesh.levelCount });
Checking, you can also set sparse arrays like this
// Sets f and t of levelBasePtr[9]
setStructuredView({ f: 112233, t: 445566 }, v.views.levelBasePtr[9]);
This is splendid. Thank you. My frantic "try everything" was not nearly as successful as your knowledge-based suggestions. Perhaps good additions to the docs?
Respectfully requesting enhancing the
makeStructuredView
with an example of setting a structure (or a partial structure) that's part of a member of structures. "Views" are complicated, and I don't have my mind wrapped around them yet, but I did this wrong many many ways before doing it by hand, and I bet there's a much cleaner way to do it.I'd then like to set
levelCount
, which I'm (sadly) doing as:Surely this can be done with less code.
An example of how to set a structure (or a piece of structure) when that structure is within an array would be helpful.