(value)
| 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 | // |
no outgoing calls
no test coverage detected