| 123456789101112131415161718192021 |
- import assert from 'node:assert/strict'
- import { verifyMaterialClosure } from './verify-material-closure.mjs'
- const valid = { meshes: [{ primitives: [{ material: 0 }] }], materials: [{ pbrMetallicRoughness: { baseColorTexture: { index: 0 } } }],
- textures: [{ source: 0, sampler: 0 }], images: [{}], samplers: [{}] }
- verifyMaterialClosure(valid)
- for (const mutate of [
- j => { j.meshes[0].primitives[0].material = 9 },
- j => { j.materials[0].pbrMetallicRoughness.baseColorTexture.index = 9 },
- j => { j.materials[0].pbrMetallicRoughness.baseColorTexture.index = -1 },
- j => { j.textures[0].source = 9 },
- j => { j.textures[0].sampler = 9 },
- j => { j.materials.push({}) }, j => { j.textures.push({ source: 0 }) },
- j => { j.images.push({}) }, j => { j.samplers.push({}) },
- ]) {
- const broken = structuredClone(valid); mutate(broken)
- assert.throws(() => verifyMaterialClosure(broken))
- }
- const defaultSampler = structuredClone(valid); delete defaultSampler.textures[0].sampler; delete defaultSampler.samplers
- verifyMaterialClosure(defaultSampler)
- verifyMaterialClosure({ meshes: [{ primitives: [{ material: 0 }] }], materials: [{}] })
- console.log(JSON.stringify({ passed: true, scope: 'material/texture/image/sampler range and dependency closure rejection' }))
|