Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Accept the optional volumeFog fields in set-environment and the MCP schema (closes #661)

Nguyen Xuan An04ece152f9b0
diff --git a/changes/661-volume-fog-optional-fields.md b/changes/661-volume-fog-optional-fields.md
new file mode 100644
index 00000000..e7f7be5d
--- /dev/null
+++ b/changes/661-volume-fog-optional-fields.md
@@ -0,0 +1 @@
+- set-environment and the MCP schemas accept the optional volumeFog fields (scatterOctaves, multiScatter, multiExtinction, multiAnisotropy, keyTransmittance, surfaceTransmittance, heightFalloff) after creation (#661).
\ No newline at end of file
diff --git a/scripts/mcp-server.mjs b/scripts/mcp-server.mjs
index 4b89fb7e..b6d2b974 100644
--- a/scripts/mcp-server.mjs
+++ b/scripts/mcp-server.mjs
@@ -192,6 +192,13 @@ const volumeFog = z.strictObject({
contrast: bounded(0, 4).optional(),
profileSoftness: bounded(0, 0.95).optional(),
keyScattering: bounded(0, 10).optional(),
+ heightFalloff: bounded(0, 1e5).optional(),
+ scatterOctaves: z.number().int().min(1).max(4).optional(),
+ multiScatter: unit.optional(),
+ multiExtinction: unit.optional(),
+ multiAnisotropy: unit.optional(),
+ keyTransmittance: unit.optional(),
+ surfaceTransmittance: unit.optional(),
});
const affects = z.array(z.string()).optional();
const iesProfile = z.any().optional();
diff --git a/src/agent-scene.js b/src/agent-scene.js
index 7dda81a6..657e6b24 100644
--- a/src/agent-scene.js
+++ b/src/agent-scene.js
@@ -1591,10 +1591,10 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {
// Spot and area lights, cascades and sun links are absent from a recipe until it sets them.
const optionalFields = lookField === 'environment' ? ['ground', 'spotLights', 'areaLights', 'shadowCascades', 'keyAffects', 'objectReflections', 'floorSkyTrace', 'sunBounce', 'specularAntiAliasing', 'sunAngularRadius', 'lines', 'resolveCoplanar', 'viewTransform', 'look', 'hdri'] : [];
knownKeys(patch, [...Object.keys(candidate[lookField]), ...optionalFields], lookField);
- const nestedField = lookField === 'environment' ? 'volumeFog' : lookField === 'effects' ? 'bloom' : null;
+ const nestedField = lookField === 'environment' ? 'volumeFog' : 'bloom';
const merged = { ...candidate[lookField], ...(lookField === 'environment' ? environmentPatchWithSetup(patch) : patch) };
- if (nestedField && Object.hasOwn(patch, nestedField)) {
- knownKeys(patch[nestedField], Object.keys(candidate[lookField][nestedField]), nestedField);
+ if (Object.hasOwn(patch, nestedField)) {
+ if (lookField === 'effects') knownKeys(patch[nestedField], Object.keys(candidate[lookField][nestedField]), nestedField);
merged[nestedField] = { ...candidate[lookField][nestedField], ...patch[nestedField] };
}
candidate[lookField] = merged;
diff --git a/tests/mcp-environment-schema.test.js b/tests/mcp-environment-schema.test.js
index 2cea1aa5..ffeda0f0 100644
--- a/tests/mcp-environment-schema.test.js
+++ b/tests/mcp-environment-schema.test.js
@@ -131,3 +131,46 @@ test('a coplanar depth layer regroups parts, and the preview sees every texture
}
assert.equal(hasPatternTextures(scene.parts), false);
});
+
+const OPTIONAL_VOLUME_FOG_PATCH = { scatterOctaves: 2, multiScatter: 0.6, multiExtinction: 0.4, multiAnisotropy: 0.3, keyTransmittance: 0.2, surfaceTransmittance: 0.1, heightFalloff: 2 };
+
+test('set-environment sets every optional volumeFog field on a recipe that did not set them at creation', () => {
+ const scene = createAgentScene(coplanarRecipe());
+ scene.apply([{ type: 'set-environment', environment: { volumeFog: OPTIONAL_VOLUME_FOG_PATCH } }], { expectedRevision: scene.revision });
+ for (const [field, value] of Object.entries(OPTIONAL_VOLUME_FOG_PATCH)) assert.equal(scene.environment.volumeFog[field], value, field);
+ assert.throws(() => scene.apply([{ type: 'set-environment', environment: { volumeFog: { mystery: 1 } } }], { expectedRevision: scene.revision }), /mystery/);
+});
+
+test('the MCP scene_create and scene_apply schemas accept the optional volumeFog fields', async () => {
+ let scene;
+ const runtime = {
+ async capabilities() { return {}; },
+ async create({ recipe }) {
+ scene = createAgentScene(recipe);
+ return { revision: scene.revision };
+ },
+ async apply({ expectedRevision, operations }) {
+ scene.apply(operations, { expectedRevision });
+ return { revision: scene.revision };
+ },
+ async close() {},
+ activeSessionId() { return null; },
+ };
+ const server = createAgentMcpServer(runtime);
+ const client = new Client({ name: '67js-volume-fog-schema-test', version: '1' });
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
+ await server.connect(serverTransport);
+ await client.connect(clientTransport);
+ try {
+ const created = await client.callTool({ name: 'scene_create', arguments: { recipe: coplanarRecipe() } });
+ assert.notEqual(created.isError, true, created.content?.[0]?.text);
+ const applied = await client.callTool({ name: 'scene_apply', arguments: { expectedRevision: 0, operations: [{ type: 'set-environment', environment: { volumeFog: OPTIONAL_VOLUME_FOG_PATCH } }] } });
+ assert.notEqual(applied.isError, true, applied.content?.[0]?.text);
+ assert.equal(scene.environment.volumeFog.multiScatter, 0.6);
+ const atCreation = await client.callTool({ name: 'scene_create', arguments: { recipe: { ...coplanarRecipe(), environment: { volumeFog: OPTIONAL_VOLUME_FOG_PATCH } } } });
+ assert.notEqual(atCreation.isError, true, atCreation.content?.[0]?.text);
+ } finally {
+ await client.close();
+ await server.close();
+ }
+});
\ No newline at end of file