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

Method _jsValueToWgslType

src/webgpu/p5.RendererWebGPU.js:3444–3464  ·  view source on GitHub ↗
(value)

Source from the content-addressed store, hash-verified

3442
3443 // Maps a plain JS value to the WGSL type string that represents it in a struct.
3444 _jsValueToWgslType(value) {
3445 if (typeof value === 'number') return 'f32';
3446 // Duck typing instead of instanceof to avoid importing a separate
3447 // copy of the Color/Vector classes
3448 if (value?.isVector) {
3449 if (value.dimensions === 2) return 'vec2f';
3450 if (value.dimensions === 3) return 'vec3f';
3451 if (value.dimensions === 4) return 'vec4f';
3452 throw new Error(`Unsupported vector dimension ${value.dimensions} for struct storage field`);
3453 }
3454 if (value?.isColor) {
3455 return 'vec4f';
3456 }
3457 if (Array.isArray(value)) {
3458 if (value.length === 2) return 'vec2f';
3459 if (value.length === 3) return 'vec3f';
3460 if (value.length === 4) return 'vec4f';
3461 throw new Error(`Unsupported array length ${value.length} for struct storage field`);
3462 }
3463 throw new Error(`Unsupported value type ${typeof value} for struct storage field`);
3464 }
3465
3466 // Infers a struct schema from the first element of a struct array.
3467 //

Callers 2

_inferStructSchemaMethod · 0.95
createStorageMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected