MCPcopy
hub / github.com/processing/p5.js / _packStructArray

Method _packStructArray

src/webgpu/p5.RendererWebGPU.js:3532–3547  ·  view source on GitHub ↗
(data, schema)

Source from the content-addressed store, hash-verified

3530 // Packs an array of plain objects into a Float32Array using the given struct schema.
3531 // Reuses _packField so layout rules match uniform packing exactly.
3532 _packStructArray(data, schema) {
3533 const { fields, stride } = schema;
3534 const totalBytes = Math.max(data.length * stride, 16);
3535 const alignedBytes = Math.ceil(totalBytes / 16) * 16;
3536 const buffer = new ArrayBuffer(alignedBytes);
3537 const floatView = new Float32Array(buffer);
3538 const dataView = new DataView(buffer);
3539 for (let i = 0; i < data.length; i++) {
3540 const item = data[i];
3541 const baseOffset = i * stride;
3542 for (const field of fields) {
3543 this._packField(field, item[field.name], floatView, dataView, baseOffset);
3544 }
3545 }
3546 return floatView;
3547 }
3548
3549 // Inverse of _packStructArray reads packed buffer back into plain JS objects
3550 // using the same schema layout - fields, stride and offsets

Callers 3

createStorageMethod · 0.95
updateMethod · 0.80
setMethod · 0.80

Calls 1

_packFieldMethod · 0.95

Tested by

no test coverage detected