Skip to content

3D engine that AI agents drive

Shrink the new messages and add the size note (#2393)

Nguyen Xuan An13215dfc83d2
diff --git a/changes/2393.size.md b/changes/2393.size.md
new file mode 100644
index 00000000..fcf783e3
--- /dev/null
+++ b/changes/2393.size.md
@@ -0,0 +1,3 @@
+- entry:sculpt: 95 bytes gzip for refusing an unknown stroke field and a direction on a stroke that ignores it, which sculptGeometry used to accept and answer with a wrong result.
+- scene:agent-scene: 156 bytes gzip across three guards that stop a silent wrong result: the same stroke check for the sculpt mesh edit, a flat fit box for armature presets, and the ground ray start that lets settle find colliders above 10 km.
+- goal:agent-scene: the bundle is over its goal already; each guard turns a silent wrong result into an error that says what to pass, and none can move out of the core bundle (settle, rig presets and the stroke code are reached from scene operations).
diff --git a/src/rig-presets.js b/src/rig-presets.js
index 51c30f90..a56cea7c 100644
--- a/src/rig-presets.js
+++ b/src/rig-presets.js
@@ -81,7 +81,7 @@ function requireExtents(preset, bounds) {
const flat = SCALING_AXES[preset].filter(axis => !(extents[axis] > flatBelow));
if (flat.length) {
const missing = flat.map(axis => AXIS_NAMES[axis]).join(' and ');
- throw new RangeError(`A ${preset} armature needs a fit box with ${missing} above zero, or every bone lands on one point. Fit a taller mesh or pass bones.`);
+ throw new RangeError(`A ${preset} fit box has no ${missing}; every bone would land on one point. Fit a taller mesh or pass bones.`);
}
}
diff --git a/src/sculpt-strokes.js b/src/sculpt-strokes.js
index 6227d2be..979e6801 100644
--- a/src/sculpt-strokes.js
+++ b/src/sculpt-strokes.js
@@ -22,14 +22,8 @@ export function prepareStrokes(strokes) {
if (!['inflate', 'displace', 'smooth'].includes(stroke?.type)) {
throw new TypeError('Sculpt stroke type must be inflate, displace or smooth.');
}
- for (const key of Object.keys(stroke)) {
- if (!STROKE_FIELDS.includes(key)) {
- throw new TypeError(`Sculpt stroke has an unsupported field "${key.slice(0, 48)}". Use type, center, radius, strength and, for displace, direction.`);
- }
- }
- if (stroke.type !== 'displace' && stroke.direction !== undefined) {
- throw new TypeError(`Only a displace stroke takes direction; remove it from this ${stroke.type} stroke.`);
- }
+ const unsupported = Object.keys(stroke).find(key => !STROKE_FIELDS.includes(key) || (key === 'direction' && stroke.type !== 'displace'));
+ if (unsupported) throw new TypeError(`Sculpt ${stroke.type} stroke does not take "${unsupported.slice(0, 32)}"; remove it.`);
const center = vector(stroke.center, 'center');
const radius = finite(stroke.radius, 'radius');
const strength = finite(stroke.strength, 'strength');
diff --git a/tests/rigging.test.js b/tests/rigging.test.js
index ee3d6b2c..8d7bbee0 100644
--- a/tests/rigging.test.js
+++ b/tests/rigging.test.js
@@ -150,7 +150,7 @@ test('a preset fitted to a flat mesh is refused instead of putting every bone on
armatures: [armature],
nodes: [{ id: 'mesh', geometry: 'sheet', material: 'paint', rotation: [-0.7071067811865476, 0, 0, 0.7071067811865476] }],
});
- assert.throws(() => createAgentScene(flatMesh({ id: 'rig', preset: 'humanoid', fit: { node: 'mesh' } })), /humanoid armature needs a fit box with height above zero/);
+ assert.throws(() => createAgentScene(flatMesh({ id: 'rig', preset: 'humanoid', fit: { node: 'mesh' } })), /humanoid fit box has no height/);
assert.throws(() => presetBones('quadruped', { min: [0, 0, 0], max: [1, 1, 0] }), /width and height|depth/);
assert.equal(presetBones('humanoid', { min: [0, 0, 0], max: [0, 2, 0] }).length > 0, true, 'a humanoid only scales with height');
});
diff --git a/tests/sculpt.test.js b/tests/sculpt.test.js
index 90f2f52a..ec2d7a02 100644
--- a/tests/sculpt.test.js
+++ b/tests/sculpt.test.js
@@ -117,7 +117,7 @@ test('UV seam duplication does not change area-weighted sculpt normals', () => {
test('a stroke field the sculpt does not know, or a direction on a stroke that ignores it, is refused', () => {
const stroke = { type: 'inflate', center: [0, 0, 0], radius: 2, strength: 0.1 };
- assert.throws(() => sculptGeometry(plane(), [{ ...stroke, radious: 3 }]), /unsupported field "radious"/);
- assert.throws(() => sculptGeometry(plane(), [{ ...stroke, direction: [0, 0, 1] }]), /Only a displace stroke takes direction.*inflate/);
- assert.throws(() => sculptGeometry(plane(), [{ ...stroke, type: 'smooth', direction: [0, 0, 1] }]), /smooth stroke/);
+ assert.throws(() => sculptGeometry(plane(), [{ ...stroke, radious: 3 }]), /does not take "radious"/);
+ assert.throws(() => sculptGeometry(plane(), [{ ...stroke, direction: [0, 0, 1] }]), /inflate stroke does not take "direction"/);
+ assert.throws(() => sculptGeometry(plane(), [{ ...stroke, type: 'smooth', direction: [0, 0, 1] }]), /smooth stroke does not take/);
});