3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Refuse open with another edge key and non-boolean pack or rotate (#2373)
Nguyen Xuan An15412f240941
diff --git a/changes/2373.md b/changes/2373.mdnew file mode 100644index 00000000..631f44e0--- /dev/null+++ b/changes/2373.md@@ -0,0 +1 @@+- `selectEdges` now refuses `open` combined with `along` (or any other key) and names both, and `projectUv` and `packUvIslands` refuse a non-boolean `pack` or `rotate` instead of treating a string as true (#2373).diff --git a/src/mesh-bevel.js b/src/mesh-bevel.jsindex 2692ff14..d0af51e4 100644--- a/src/mesh-bevel.js+++ b/src/mesh-bevel.js@@ -32,6 +32,7 @@ export function selectEdges(mesh, rule, table) {const mask = new Uint8Array(mesh.edgeCount);const facesOf = edge => table.faces[edge];if (keys.length !== 1 && rule.along === undefined) throw new TypeError('Edge rule takes exactly one of between, angle, boundaryOf, along, open, all.');+ if (rule.open !== undefined && keys.length > 1) throw new TypeError(`Edge rule open does not take ${keys.filter(key => key !== 'open').join(', ')}.`);if (rule.open !== undefined) return selectOpenEdges(mesh, rule, table);if (rule.all === true) {for (let edge = 0; edge < mesh.edgeCount; edge++) mask[edge] = facesOf(edge).length === 2 ? 1 : 0;diff --git a/src/mesh-uv-project.js b/src/mesh-uv-project.jsindex 608e70f8..c1ddd2ee 100644--- a/src/mesh-uv-project.js+++ b/src/mesh-uv-project.js@@ -151,6 +151,10 @@ function uvIslands(mesh, uv) {return [...islands.values()];}+function requireBoolean(name, value) {+ if (typeof value !== 'boolean') throw new TypeError(`${name} must be true or false.`);+}+/*** Pack the uv islands of corner attribute `uv` into the unit square with one common scale, so texel density keeps its* ratio between islands. margin: gap between islands and around the square. rotate: lay tall islands on their side.@@ -158,6 +162,7 @@ function uvIslands(mesh, uv) {*/export function packUvIslands(mesh, { margin = 0.01, rotate = true } = {}) {requireUvMargin('packUvIslands', margin);+ requireBoolean('rotate', rotate);const uv = mesh.attributes.corner.uv?.data;if (!uv) throw new RangeError('the mesh has no uv to pack. Put uv_unwrap, or uv_project with pack false, before uv_pack.');const islands = uvIslands(mesh, uv);@@ -188,6 +193,8 @@ export function projectUv(mesh, { mode = 'cube', axis = 'y', pack = true, marginrequireOneOf('mode', mode, UV_PROJECTION_MODES);requireOneOf('axis', axis, Object.keys(AXIS_INDEX));requireUvMargin('projectUv', margin);+ requireBoolean('pack', pack);+ requireBoolean('rotate', rotate);const projected = withCornerUv(mesh, projectCorners(mesh, mode, AXIS_INDEX[axis]));if (!pack) return { mesh: projected, islands: uvIslands(projected, projected.attributes.corner.uv.data).length };return packUvIslands(projected, { margin, rotate });diff --git a/tests/mesh-bevel.test.js b/tests/mesh-bevel.test.jsindex bc9027e4..5bf79d89 100644--- a/tests/mesh-bevel.test.js+++ b/tests/mesh-bevel.test.js@@ -75,6 +75,8 @@ test('edge rules select rims, sharp edges, region borders and everything', () =>assert.equal(count({ boundaryOf: { tag: 'front' } }), 4);assert.equal(count({ all: true }), 12);assert.throws(() => selectEdges(mesh, { angle: 30, all: true }, table), /exactly one/);+ assert.throws(() => selectEdges(mesh, { open: true, along: [1, 0, 0] }, table), /open does not take along/);+ assert.throws(() => selectEdges(mesh, { open: true, maxAngle: 5 }, table), /open does not take maxAngle/);});test('chamfering one edge removes exactly the triangular prism', () => {diff --git a/tests/mesh-uv-project.test.js b/tests/mesh-uv-project.test.jsindex 57cda4a9..240f8024 100644--- a/tests/mesh-uv-project.test.js+++ b/tests/mesh-uv-project.test.js@@ -130,3 +130,11 @@ test('packing needs uv and the edits validate their fields', () => {assert.deepEqual(normalizeMeshEdits([{ op: 'uv_project', mode: 'sphere' }])[0], { op: 'uv_project', mode: 'sphere', axis: 'y', pack: true, margin: 0.01, rotate: true });assert.equal(normalizeMeshStack([{ op: 'uv_project', mode: 'cube' }, { op: 'uv_pack' }]).length, 2);});++test('projectUv and packUvIslands refuse a non-boolean pack or rotate, naming the field', () => {+ assert.throws(() => projectUv(crate(), { mode: 'cube', pack: 'false' }), /pack must be true or false/);+ assert.throws(() => projectUv(crate(), { mode: 'cube', rotate: 'no' }), /rotate must be true or false/);+ const projected = projectUv(crate(), { mode: 'cube', pack: false }).mesh;+ assert.throws(() => packUvIslands(projected, { rotate: 1 }), /rotate must be true or false/);+ assert.ok(projectUv(crate(), { mode: 'cube', pack: false, rotate: false }).islands > 0);+});