3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Count foamed water parts in placement checks and stop warning on water specular (#2288)
Nguyen Xuan Ana1906dc5c919
diff --git a/changes/2288-report.md b/changes/2288-report.mdnew file mode 100644index 00000000..f2f9ed61--- /dev/null+++ b/changes/2288-report.md@@ -0,0 +1 @@+- A part with foam or a wear mask, such as an ocean with a water material, now counts in the placement check, so a buoy on the sea is no longer reported floating above a far backing plane, and `specular` and `specularColor` are no longer reported as ignored on a water material (#2288)diff --git a/src/agent-diagnostics.js b/src/agent-diagnostics.jsindex e57e48cb..41374f0f 100644--- a/src/agent-diagnostics.js+++ b/src/agent-diagnostics.js@@ -10,6 +10,8 @@ const PLAIN_SURFACE_TAGS = new Set(['surface', 'gltf']);const LAYER_FIELDS = ['clearcoat', 'sheenColor', 'specular', 'specularColor', 'anisotropy', 'iridescence'];// The pass that draws transmission is a separate shader without these layers.const FIELDS_IGNORED_BY_TRANSMISSION = ['anisotropy', 'iridescence'];+// The water tag draws in the standard shader (shaders.js baseReflectance), so its specular layer sets the surface reflectance.+const SPECULAR_FIELDS_READ_ON_WATER = ['specular', 'specularColor'];const TRANSMISSION_DETAIL_FIELDS = ['thickness', 'attenuationColor', 'attenuationDistance'];export function diagnostic(kind, severity, target, message, fix) {@@ -27,7 +29,7 @@ function materialProblems(material) {const tag = material.tag ?? 'surface';const transmitting = hasValue(material, 'transmission');if (tag !== 'surface' && tag !== 'liquid') {- for (const field of LAYER_FIELDS.filter(layer => hasValue(material, layer))) {+ for (const field of LAYER_FIELDS.filter(layer => hasValue(material, layer) && !(tag === 'water' && SPECULAR_FIELDS_READ_ON_WATER.includes(layer)))) {problems.push(diagnostic('ignored-material-field', 'warning', material.id,`${field} is ignored on a material with tag ${tag}.`,`Remove ${field}, or set the material tag to surface with scene_apply set-material.`));diff --git a/src/agent-scene.js b/src/agent-scene.jsindex c274d27a..f72a1ca0 100644--- a/src/agent-scene.js+++ b/src/agent-scene.js@@ -2156,13 +2156,9 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {const drawnParts = new Map(state.restParts.map(part => [part.name, part]));for (const sourcePart of state.sourceRestParts) {const part = drawnParts.get(sourcePart.name);- const local = state.localBounds.get(sourcePart.geometry);- if (!part || !local || part.visibility?.visible === false) continue;- const positions = [];- for (let corner = 0; corner < 8; corner++) {- positions.push(corner & 1 ? local.max[0] : local.min[0], corner & 2 ? local.max[1] : local.min[1], corner & 4 ? local.max[2] : local.min[2]);- }- bounds.push({ name: part.name, ...boundsFor({ positions }, part.matrix) });+ if (!part || part.visibility?.visible === false) continue;+ // Measured from the geometry itself: a water part with foam or a wear mask draws a copy the cached local bounds do not list.+ bounds.push({ name: part.name, ...boundsFor(sourcePart.geometry, part.matrix) });}return bounds;},diff --git a/tests/ocean-report-checks.test.js b/tests/ocean-report-checks.test.jsnew file mode 100644index 00000000..9ca59dbd--- /dev/null+++ b/tests/ocean-report-checks.test.js@@ -0,0 +1,40 @@+import './support/load-agent-scene-modules.mjs';+import test from 'node:test';+import assert from 'node:assert/strict';+import { createAgentScene } from '../src/agent-scene.js';+import { placementProblems } from '../src/frame-checks.js';+import { recipeDiagnostics } from '../src/agent-diagnostics.js';++function oceanScene() {+ return createAgentScene({+ format: 'crucible.scene', schemaVersion: 1,+ geometries: [+ { id: 'sea', type: 'mesh', base: { type: 'grid', segments: 8 }, stack: [{ op: 'ocean', windSpeed: 0.5, size: 50, seed: 4 }] },+ { id: 'box', type: 'box' },+ ],+ materials: [{ id: 'water', tag: 'water', color: [0.02, 0.1, 0.2] }, { id: 'red', color: [0.8, 0.2, 0.2] }],+ nodes: [+ { id: 'sea', geometry: 'sea', material: 'water', scale: [50, 1, 50] },+ { id: 'sea_far', geometry: 'box', material: 'water', translation: [0, -1.5, -400], scale: [800, 0.1, 400] },+ { id: 'buoy', geometry: 'box', material: 'red', translation: [0, 0.3, 0], scale: [0.5, 0.6, 0.5] },+ ],+ camera: { eye: [0, 3, 8], target: [0, 0.5, 0], fov: 45 },+ });+}++test('an ocean part with water foam has world bounds, so a buoy on it is not floating', () => {+ const boxes = oceanScene().worldBounds();+ assert.ok(boxes.some(box => box.name === 'sea'), 'the sea part is in the bounds');+ assert.deepEqual(placementProblems({ boxes }), []);+});++test('specular on a water material is not reported as ignored, and still is on a foliage material', () => {+ const recipeWith = tag => ({+ materials: [{ id: 'm', tag, specular: 0.5, specularColor: [1, 1, 1], clearcoat: 0.5 }],+ nodes: [{ id: 'n', geometry: 'g', material: 'm' }],+ geometries: [{ id: 'g', type: 'box' }],+ });+ const fieldsIgnoredOn = tag => recipeDiagnostics(recipeWith(tag)).filter(entry => entry.kind === 'ignored-material-field').map(entry => entry.message.split(' ')[0]);+ assert.deepEqual(fieldsIgnoredOn('water'), ['clearcoat']);+ assert.deepEqual(fieldsIgnoredOn('foliage'), ['clearcoat', 'specular', 'specularColor']);+});