Skip to content

armgit / kiln

Public Imported from GitHub
0

Build and revise procedural 3D assets with your coding agent. Local MCP server, CLI and TypeScript engine with rendered review, editable source and GLB export.

feat(composer): scene_paint tool + edo paint kinds

Matt Kissingerdf0fab5802fb
diff --git a/src/__tests__/composer-agent-tools.test.ts b/src/__tests__/composer-agent-tools.test.ts
index f563c08c..ed33ae3c 100644
--- a/src/__tests__/composer-agent-tools.test.ts
+++ b/src/__tests__/composer-agent-tools.test.ts
@@ -63,7 +63,7 @@ function call(tools: Tool[], name: string, input: unknown = {}): Promise<AnyResu
}
describe('surface', () => {
- test('exposes the 16 scene_* tools by name', () => {
+ test('exposes the 17 scene_* tools by name', () => {
const { tools } = setup();
const names = tools.map((t) => t.name).sort();
expect(names).toEqual(
@@ -83,6 +83,7 @@ describe('surface', () => {
'scene_remove',
'scene_set_environment',
'scene_set_backdrop',
+ 'scene_paint',
'scene_finalize',
].sort(),
);
diff --git a/src/composer/agent/prompt.ts b/src/composer/agent/prompt.ts
index 9ebd9c5c..05a00b27 100644
--- a/src/composer/agent/prompt.ts
+++ b/src/composer/agent/prompt.ts
@@ -37,11 +37,12 @@ Every cluster / ring instance and every laid-out asset counts toward a hard 200-
## Scene theme + atmosphere (scene-level, not placements)
- scene_set_environment sets the ground + sky THEME (terrain colour, sun, fog). Allowed: meadow, desert, egypt, plaza, snow, arctic, edo, night, studio. Match it to the setting — use "edo" for a Japanese / Edo castle-town scene.
- scene_set_backdrop adds ONE horizon billboard. Allowed: mushroom-cloud, sun-disc, aurora, fuji. Use "fuji" (Mt. Fuji) for a Japanese / Edo scene; place it far behind the composition on the view axis (e.g. pos [0, 20, -160]) and scale it up to own the skyline. Optional — omit if none fits.
-- Set both EARLY (right after scene_list_assets), once each. They don't affect placement or overlaps.
+- scene_paint draws flat ground zones to MATCH your layout (a paved avenue, a market plaza) — kinds like stone-path, gravel, flagstone. Author it AFTER placing the buildings (so it lines up): a stone-path strip down the central axis from the entrance to the hero, plus a rect plaza or two. This is what makes the ground read as authored, not a blank field.
+- Set environment + backdrop EARLY (right after scene_list_assets); paint LATE (after the layout exists). None of them affect placement or overlaps.
## Tools
- Plan: scene_list_assets (always first), scene_view (the current program + counts).
-- Theme: scene_set_environment (ground/sky theme), scene_set_backdrop (one horizon billboard) — scene-level, set early, optional.
+- Theme: scene_set_environment (ground/sky theme), scene_set_backdrop (one horizon billboard) — set early; scene_paint (paved avenue / plaza zones) — set late, after placing. All scene-level, optional.
- Build: scene_layout (place the WHOLE catalog at once into an overlap-free baseline — your default first move), scene_place (one asset), scene_cluster (N scattered around a point), scene_ring (N on a circle).
- Refine: scene_move (reposition / use a separation vector / rescale), scene_face (re-orient), scene_group (bind + move together), scene_remove.
- See + check: scene_render (the whole scene from three angles — LOOK at it), scene_screenshot_camera (one vantage you choose), scene_validate (overlaps + the vector to separate each).
@@ -51,7 +52,7 @@ Every cluster / ring instance and every laid-out asset counts toward a hard 200-
1. scene_list_assets, and read the scene prompt: decide the layout idea (what anchors the scene, what frames it, where the groupings go). Then set the theme: scene_set_environment (and scene_set_backdrop if one fits the setting).
2. START with scene_layout to place the WHOLE catalog at once into an overlap-free baseline: omit \`assets\` to include everything; anchor "zonedCenters" spreads them across districts (a hub + four satellites), "single" packs them around the origin; pick a facing; pass a \`scale\` up if the assets read small on the ground. This is ONE call for the whole scene — do NOT hand-place dozens of assets one at a time, which exhausts the budget before you can finish.
3. scene_render and JUDGE it: spacing, facing, groupings, silhouette, overlaps. Use scene_screenshot_camera to check a key vantage (e.g. how it reads on approach).
-4. Refine with a HANDFUL of targeted edits, not a fresh placement per asset: scene_move / scene_face / scene_group the heroes, and build one or two deliberate clusters or rings for the spaces that matter (a courtyard, a motor-court, a row). scene_validate for overlaps (move by the mtv). Re-render once to confirm.
+4. Refine with a HANDFUL of targeted edits, not a fresh placement per asset: scene_move / scene_face / scene_group the heroes, and build one or two deliberate clusters or rings for the spaces that matter (a courtyard, a motor-court, a row). Then scene_paint the ground to match (an avenue strip + a plaza). scene_validate for overlaps (move by the mtv). Re-render once to confirm.
5. Call scene_finalize once, before the budget runs out. A laid-out, lightly-refined, overlap-free scene that is FINALIZED beats a half-hand-placed one that never finishes.`;
export interface BuildComposerPromptOptions {
diff --git a/src/composer/agent/tools.ts b/src/composer/agent/tools.ts
index 656f2913..45889649 100644
--- a/src/composer/agent/tools.ts
+++ b/src/composer/agent/tools.ts
@@ -13,10 +13,10 @@
* `tool()`. No THREE — rendering is the injected host port. Errors are in-band
* `{ ok:false, error, hint }` (tools never throw at the model).
*
- * Surface (16): read — scene_list_assets, scene_view, scene_validate,
+ * Surface (17): read — scene_list_assets, scene_view, scene_validate,
* scene_render, scene_screenshot_camera · mutate — scene_layout, scene_place,
* scene_cluster, scene_ring, scene_move, scene_face, scene_group, scene_remove ·
- * theme — scene_set_environment, scene_set_backdrop · commit — scene_finalize.
+ * theme — scene_set_environment, scene_set_backdrop, scene_paint · commit — scene_finalize.
* (Extends the design doc's 12 with scene_cluster / scene_ring so the agent can
* author the grouping primitives the program already serializes.)
*/
@@ -24,7 +24,13 @@ import { ImageBlock, JsonBlock, type JSONValue, type Tool, tool } from '@strands
import { z } from 'zod';
import { serialize } from '../dsl';
-import type { EvalResult, Placement, PlacementModel, PlacementProvenance } from '../model';
+import type {
+ EvalResult,
+ Placement,
+ PlacementModel,
+ PlacementProvenance,
+ ScenePaintZoneSpec,
+} from '../model';
import type { OverlapViolation } from '../overlap';
import type { SceneRenderPort, SceneRenderResult } from '../render-port';
@@ -75,6 +81,34 @@ const groundThemeEnum = z.enum([
'studio',
]);
const backdropKindEnum = z.enum(['mushroom-cloud', 'sun-disc', 'aurora', 'fuji']);
+const paintKindEnum = z.enum([
+ 'grass',
+ 'concrete',
+ 'asphalt',
+ 'sand',
+ 'flagstone',
+ 'snow',
+ 'ice',
+ 'gravel',
+ 'stone-path',
+]);
+const paintShape = z.union([
+ z.object({
+ type: z.literal('rect'),
+ x: z.number(),
+ z: z.number(),
+ hx: z.number(),
+ hz: z.number(),
+ }),
+ z.object({
+ type: z.literal('strip'),
+ axis: z.enum(['x', 'z']),
+ offset: z.number(),
+ half: z.number(),
+ from: z.number(),
+ to: z.number(),
+ }),
+]);
// ── render-result → content blocks ────────────────────────────────────────────
@@ -638,6 +672,41 @@ export function makeSceneComposerTools(opts: MakeComposerToolsOptions): Tool[] {
},
});
+ const paintTool: Tool = tool({
+ name: 'scene_paint',
+ description:
+ 'PAINT the ground to match your layout — flat zones drawn onto the terrain (NOT placed ' +
+ 'assets), so the town reads as built on purpose. Pass the full set of zones at once; this ' +
+ 'REPLACES any previous paint. Coordinates are the same [x,z] world units you place assets in. ' +
+ 'Kinds: stone-path (a paved avenue/courtyard), gravel (raked garden), flagstone, concrete, ' +
+ 'sand, grass, asphalt, snow, ice. Two shapes: a "strip" is a long band — ' +
+ '{ type:"strip", axis:"x"|"z", offset:<the fixed cross-axis coord>, half:<half-width>, ' +
+ 'from:<start along axis>, to:<end along axis> } — use it for the central avenue (e.g. a ' +
+ 'stone-path strip down the axis from the entrance gate to the hero); a "rect" is a patch — ' +
+ '{ type:"rect", x, z, hx:<half-x>, hz:<half-z> } — use it for a market plaza or a garden. ' +
+ 'Author a few deliberate zones (an avenue + a plaza or two), sized to span the assets they sit ' +
+ 'under. Call once, after you have placed the buildings so the paint lines up.',
+ inputSchema: z.object({
+ zones: z
+ .array(
+ z.object({ kind: paintKindEnum, shape: paintShape, laneLine: z.boolean().optional() }),
+ )
+ .max(24)
+ .describe('The full set of ground-paint zones (replaces any previous paint).'),
+ }),
+ callback: (input) => {
+ const i = input as { zones: ScenePaintZoneSpec[] };
+ model.setPaint(i.zones);
+ const ev = capture();
+ return {
+ ok: true,
+ paintZones: i.zones.length,
+ placements: ev.placements.length,
+ overlaps: ev.overlaps.length,
+ } as JSONValue;
+ },
+ });
+
const finalizeTool: Tool = tool({
name: 'scene_finalize',
description:
@@ -674,6 +743,7 @@ export function makeSceneComposerTools(opts: MakeComposerToolsOptions): Tool[] {
removeTool,
setEnvironmentTool,
setBackdropTool,
+ paintTool,
finalizeTool,
];
}
diff --git a/src/composer/model.ts b/src/composer/model.ts
index 3a4720c6..650a1da0 100644
--- a/src/composer/model.ts
+++ b/src/composer/model.ts
@@ -63,6 +63,26 @@ export interface SceneBackdropSpec {
scale?: number;
}
+/** A painted ground zone — mirrors Studio's ScenePaintShape/ScenePaintZone. A `rect`
+ * is a finite patch (a plaza); a `strip` is a long axis-aligned band (an avenue). */
+export type ScenePaintShapeSpec =
+ | { type: 'rect'; x: number; z: number; hx: number; hz: number }
+ | { type: 'strip'; axis: 'x' | 'z'; offset: number; half: number; from: number; to: number };
+export interface ScenePaintZoneSpec {
+ kind:
+ | 'grass'
+ | 'concrete'
+ | 'asphalt'
+ | 'sand'
+ | 'flagstone'
+ | 'snow'
+ | 'ice'
+ | 'gravel'
+ | 'stone-path';
+ shape: ScenePaintShapeSpec;
+ laneLine?: boolean;
+}
+
/** One evaluated instance: a generation placed in the world, linked to its statement. */
export interface Placement {
instanceId: string;
@@ -142,6 +162,8 @@ export interface SceneModelJSON {
environment?: SceneGroundTheme;
/** Scene-level atmosphere backdrop the agent chose (scene_set_backdrop). */
backdrop?: SceneBackdropSpec;
+ /** Painted ground zones the agent authored (scene_paint), aligned to the layout. */
+ paint?: ScenePaintZoneSpec[];
}
export interface PlaceArgs {
@@ -225,6 +247,7 @@ export class PlacementModel {
private groupSeq = 0;
private env?: SceneGroundTheme;
private bg?: SceneBackdropSpec;
+ private groundPaint?: ScenePaintZoneSpec[];
constructor(
name: string,
@@ -471,6 +494,12 @@ export class PlacementModel {
sceneBackdrop(): SceneBackdropSpec | undefined {
return this.bg;
}
+ setPaint(zones: ScenePaintZoneSpec[]): void {
+ this.groundPaint = zones;
+ }
+ paint(): ScenePaintZoneSpec[] | undefined {
+ return this.groundPaint;
+ }
// ── evaluate ────────────────────────────────────────────────────────────────
@@ -572,6 +601,7 @@ export class PlacementModel {
statements: this.stmts,
...(this.env ? { environment: this.env } : {}),
...(this.bg ? { backdrop: this.bg } : {}),
+ ...(this.groundPaint?.length ? { paint: this.groundPaint } : {}),
}),
);
}
@@ -591,6 +621,7 @@ export class PlacementModel {
m.seq = maxSeq;
if (j.environment) m.env = j.environment;
if (j.backdrop) m.bg = j.backdrop;
+ if (j.paint?.length) m.groundPaint = j.paint;
return m;
}
}