@pascal-app/geometry-script 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export declare const CHEF_LAMP_SCRIPT = "\nimport * as THREE from 'three';\nexport const params = {\n radius: { default: 1.15, min: .3, max: 1.5, step: .05 },\n drop: { default: 3.5, min: .25, max: 4, step: .05 },\n tiers: { default: 3, min: 1, max: 3, step: 1 },\n};\nexport const mount = 'ceiling';\nexport default function build({ params: p, THREE }) {\n const g = new THREE.Group();\n const bronze = new THREE.MeshStandardMaterial({ color: '#b79b65', metalness: .82, roughness: .24 });\n bronze.name = 'slot_champagne';\n const glow = new THREE.MeshStandardMaterial({ color: '#fff0d3', emissive: '#ffd59a', emissiveIntensity: .85, roughness: .3 });\n glow.name = 'slot_alabaster';\n const rings = new THREE.Group(); rings.name = 'part:alabaster_rings'; rings.userData.type = 'light'; g.add(rings);\n const cables = new THREE.Group(); cables.name = 'part:suspension'; cables.userData.type = 'light'; g.add(cables);\n for (let j = 0; j < p.tiers; j++) {\n const r = p.radius * (1 - j * .23), y = p.drop * (.12 + j * .24);\n for (const dy of [-.05, .05]) {\n const a = new THREE.Mesh(new THREE.TorusGeometry(r, .018, 12, 80), bronze);\n a.rotation.x = Math.PI / 2; a.position.y = y + dy; rings.add(a);\n }\n const a = new THREE.Mesh(new THREE.TorusGeometry(r, .044, 16, 80), glow);\n a.rotation.x = Math.PI / 2; a.position.y = y; rings.add(a);\n for (let i = 0; i < 3; i++) {\n const angle = i * Math.PI * 2 / 3;\n const c = new THREE.Mesh(new THREE.CylinderGeometry(.003, .003, p.drop - y, 6), bronze);\n c.position.set(r * Math.cos(angle), (p.drop + y) / 2, r * Math.sin(angle)); cables.add(c);\n }\n const light = new THREE.PointLight('#ffdcad', 38 / p.tiers, 12, 2);\n light.name = 'light:ring_' + j; light.position.set(0, y, 0); rings.add(light);\n }\n const cap = new THREE.Mesh(new THREE.CylinderGeometry(.17, .17, .025, 32), bronze);\n cap.position.y = p.drop; cables.add(cap);\n return g;\n}\n";
2
+ //# sourceMappingURL=ceiling-lamp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ceiling-lamp.d.ts","sourceRoot":"","sources":["../../src/__fixtures__/ceiling-lamp.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,84DAoC5B,CAAA"}
@@ -0,0 +1,37 @@
1
+ export const CHEF_LAMP_SCRIPT = `
2
+ import * as THREE from 'three';
3
+ export const params = {
4
+ radius: { default: 1.15, min: .3, max: 1.5, step: .05 },
5
+ drop: { default: 3.5, min: .25, max: 4, step: .05 },
6
+ tiers: { default: 3, min: 1, max: 3, step: 1 },
7
+ };
8
+ export const mount = 'ceiling';
9
+ export default function build({ params: p, THREE }) {
10
+ const g = new THREE.Group();
11
+ const bronze = new THREE.MeshStandardMaterial({ color: '#b79b65', metalness: .82, roughness: .24 });
12
+ bronze.name = 'slot_champagne';
13
+ const glow = new THREE.MeshStandardMaterial({ color: '#fff0d3', emissive: '#ffd59a', emissiveIntensity: .85, roughness: .3 });
14
+ glow.name = 'slot_alabaster';
15
+ const rings = new THREE.Group(); rings.name = 'part:alabaster_rings'; rings.userData.type = 'light'; g.add(rings);
16
+ const cables = new THREE.Group(); cables.name = 'part:suspension'; cables.userData.type = 'light'; g.add(cables);
17
+ for (let j = 0; j < p.tiers; j++) {
18
+ const r = p.radius * (1 - j * .23), y = p.drop * (.12 + j * .24);
19
+ for (const dy of [-.05, .05]) {
20
+ const a = new THREE.Mesh(new THREE.TorusGeometry(r, .018, 12, 80), bronze);
21
+ a.rotation.x = Math.PI / 2; a.position.y = y + dy; rings.add(a);
22
+ }
23
+ const a = new THREE.Mesh(new THREE.TorusGeometry(r, .044, 16, 80), glow);
24
+ a.rotation.x = Math.PI / 2; a.position.y = y; rings.add(a);
25
+ for (let i = 0; i < 3; i++) {
26
+ const angle = i * Math.PI * 2 / 3;
27
+ const c = new THREE.Mesh(new THREE.CylinderGeometry(.003, .003, p.drop - y, 6), bronze);
28
+ c.position.set(r * Math.cos(angle), (p.drop + y) / 2, r * Math.sin(angle)); cables.add(c);
29
+ }
30
+ const light = new THREE.PointLight('#ffdcad', 38 / p.tiers, 12, 2);
31
+ light.name = 'light:ring_' + j; light.position.set(0, y, 0); rings.add(light);
32
+ }
33
+ const cap = new THREE.Mesh(new THREE.CylinderGeometry(.17, .17, .025, 32), bronze);
34
+ cap.position.y = p.drop; cables.add(cap);
35
+ return g;
36
+ }
37
+ `;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A parametric cabinet as an agent wrote it. At its defaults, and with `display` off, it builds. With
3
+ * `display` on, one `box(...)` call is an argument short, so `z` receives the material and the
4
+ * mesh's position is not a number: the compile used to answer with NaN bounds.
5
+ */
6
+ export declare const FITTED_CABINET_SCRIPT = "import * as THREE from 'three';export const mount='floor';export const params={width:{default:4.3,min:1,max:8},height:{default:2.8,min:1,max:3.2},display:{default:false}};export default function build({params:p}){let g=new THREE.Group();const m=(n,c,r,metal=0)=>{let a=new THREE.MeshStandardMaterial({color:c,roughness:r,metalness:metal});a.name='slot_'+n;return a};let wood=m('espresso','#463326',.46),bronze=m('bronze','#ac8b54',.28,.8),linen=m('lining','#c0b29d',.8);function box(w,h,d,x,y,z,mat){let a=new THREE.Mesh(new THREE.BoxGeometry(w,h,d),mat);a.position.set(x,y,z);g.add(a)}let n=Math.round(p.width/.72),bay=p.width/n;box(p.width,.09,.58,0,.045,0,bronze);box(p.width,p.height-.09,.05,0,(p.height+.09)/2,-.27,wood);box(p.width,.07,.58,0,p.height-.035,0,bronze);for(let i=0;i<=n;i++)box(.035,p.height,.58,-p.width/2+i*bay,p.height/2,0,wood);for(let i=0;i<n;i++){let x=-p.width/2+(i+.5)*bay;if(!p.display){box(bay-.03,p.height-.2,.06,x,p.height/2,.25,wood);box(.015,.65,.025,x+bay*.32,p.height*.5,.295,bronze);for(let j=0;j<8;j++)box(.012,p.height-.25,.012,x-bay*.43+j*bay*.12,p.height/2,.287,bronze);}else{box(bay-.035,.7,.5,x,.46,wood);for(let row=0;row<4;row++){let y=.9+row*.57;box(bay-.03,.03,.54,x,y,0,bronze);for(let k=0;k<5;k++){box(.065,.27+(k%3)*.03,.22,x-bay*.32+k*.10,y+.17,.1,k%2?linen:wood);}}}}g.name='part:fitted_cabinet';g.userData.type='cabinet';return g;}";
7
+ //# sourceMappingURL=fitted-cabinet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fitted-cabinet.d.ts","sourceRoot":"","sources":["../../src/__fixtures__/fitted-cabinet.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,42CAA42C,CAAA"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A parametric cabinet as an agent wrote it. At its defaults, and with `display` off, it builds. With
3
+ * `display` on, one `box(...)` call is an argument short, so `z` receives the material and the
4
+ * mesh's position is not a number: the compile used to answer with NaN bounds.
5
+ */
6
+ export const FITTED_CABINET_SCRIPT = `import * as THREE from 'three';export const mount='floor';export const params={width:{default:4.3,min:1,max:8},height:{default:2.8,min:1,max:3.2},display:{default:false}};export default function build({params:p}){let g=new THREE.Group();const m=(n,c,r,metal=0)=>{let a=new THREE.MeshStandardMaterial({color:c,roughness:r,metalness:metal});a.name='slot_'+n;return a};let wood=m('espresso','#463326',.46),bronze=m('bronze','#ac8b54',.28,.8),linen=m('lining','#c0b29d',.8);function box(w,h,d,x,y,z,mat){let a=new THREE.Mesh(new THREE.BoxGeometry(w,h,d),mat);a.position.set(x,y,z);g.add(a)}let n=Math.round(p.width/.72),bay=p.width/n;box(p.width,.09,.58,0,.045,0,bronze);box(p.width,p.height-.09,.05,0,(p.height+.09)/2,-.27,wood);box(p.width,.07,.58,0,p.height-.035,0,bronze);for(let i=0;i<=n;i++)box(.035,p.height,.58,-p.width/2+i*bay,p.height/2,0,wood);for(let i=0;i<n;i++){let x=-p.width/2+(i+.5)*bay;if(!p.display){box(bay-.03,p.height-.2,.06,x,p.height/2,.25,wood);box(.015,.65,.025,x+bay*.32,p.height*.5,.295,bronze);for(let j=0;j<8;j++)box(.012,p.height-.25,.012,x-bay*.43+j*bay*.12,p.height/2,.287,bronze);}else{box(bay-.035,.7,.5,x,.46,wood);for(let row=0;row<4;row++){let y=.9+row*.57;box(bay-.03,.03,.54,x,y,0,bronze);for(let k=0;k<5;k++){box(.065,.27+(k%3)*.03,.22,x-bay*.32+k*.10,y+.17,.1,k%2?linen:wood);}}}}g.name='part:fitted_cabinet';g.userData.type='cabinet';return g;}`;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A sliding door as an agent wrote it: a frame part, two leaf groups (`leaf_0`, `leaf_1`) and one
3
+ * `open` clip that slides each leaf apart by writing `leaf_i.position` tracks.
4
+ */
5
+ export declare const SLIDING_DOOR_SCRIPT = "import * as THREE from 'three';\nexport const mount='wall';\nexport const params={width:{default:2.4,min:.75,max:4,unit:'m'},height:{default:2.5,min:2,max:3,unit:'m'},glazed:{default:false}};\nexport default function build({params:p}){const g=new THREE.Group();const w=p.width,h=p.height;const wood=new THREE.MeshStandardMaterial({color:'#35251a',roughness:.62});wood.name='slot_aged_cedar';const brass=new THREE.MeshStandardMaterial({color:'#9f7840',roughness:.4,metalness:.75});brass.name='slot_antique_brass';const paper=new THREE.MeshStandardMaterial({color:p.glazed?'#b9cdc5':'#eadfc4',roughness:p.glazed?.14:.95,transparent:true,opacity:p.glazed?.24:.91,side:THREE.DoubleSide});paper.name=p.glazed?'glass':'slot_washi';const box=(par,x,y,z,a,b,c,m)=>{const q=new THREE.Mesh(new THREE.BoxGeometry(a,b,c),m);q.position.set(x,y,z);par.add(q);return q;};const f=new THREE.Group();f.name='part:portal';f.userData.type='trim';g.add(f);box(f,-w/2+.045,h/2,0,.09,h,.22,wood);box(f,w/2-.045,h/2,0,.09,h,.22,wood);box(f,0,h-.05,0,w,.1,.22,wood);box(f,0,.02,0,w,.04,.22,brass);const tracks=[];const pw=(w-.18)/2,ph=h-.15;for(let i=0;i<2;i++){const s=new THREE.Group();s.name='leaf_'+i;s.userData.type='panel';const cx=(i===0?-1:1)*pw/2,zz=i===0?.025:-.025;s.position.set(cx,0,zz);g.add(s);box(s,0,ph/2+.05,0,pw-.055,ph,.025,paper);for(const x of [-pw/2+.025,pw/2-.025])box(s,x,ph/2+.05,.01,.05,ph,.065,wood);for(const y of [.075,.42,ph+.025])box(s,0,y,.01,pw,.05,.065,wood);box(s,0,.24,0,pw-.08,.29,.045,wood);for(let j=1;j<4;j++)box(s,-pw/2+j*pw/4,(ph+.45)/2,.02,.018,ph-.42,.04,wood);for(let j=1;j<8;j++)box(s,0,.42+j*(ph-.42)/8,.02,pw-.07,.017,.04,wood);const pull=new THREE.Mesh(new THREE.TorusGeometry(.036,.007,8,24),brass);pull.position.set((i===0?1:-1)*(pw/2-.11),1.02,.062);s.add(pull);for(let j=0;j<3;j++)box(s,-pw*.28+j*pw*.28,.25,.027,.04,.07,.008,brass);tracks.push(new THREE.VectorKeyframeTrack(s.name+'.position',[0,1.3],[cx,0,zz,cx+(i===0?-1:1)*pw*.93,0,zz]));}const cut=box(g,0,h/2,0,w,h,1,wood);cut.name='cutout';g.animations=[new THREE.AnimationClip('open',1.3,tracks)];return g;}";
6
+ //# sourceMappingURL=sliding-door.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sliding-door.d.ts","sourceRoot":"","sources":["../../src/__fixtures__/sliding-door.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,mBAAmB,mjEAG80D,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A sliding door as an agent wrote it: a frame part, two leaf groups (`leaf_0`, `leaf_1`) and one
3
+ * `open` clip that slides each leaf apart by writing `leaf_i.position` tracks.
4
+ */
5
+ export const SLIDING_DOOR_SCRIPT = `import * as THREE from 'three';
6
+ export const mount='wall';
7
+ export const params={width:{default:2.4,min:.75,max:4,unit:'m'},height:{default:2.5,min:2,max:3,unit:'m'},glazed:{default:false}};
8
+ export default function build({params:p}){const g=new THREE.Group();const w=p.width,h=p.height;const wood=new THREE.MeshStandardMaterial({color:'#35251a',roughness:.62});wood.name='slot_aged_cedar';const brass=new THREE.MeshStandardMaterial({color:'#9f7840',roughness:.4,metalness:.75});brass.name='slot_antique_brass';const paper=new THREE.MeshStandardMaterial({color:p.glazed?'#b9cdc5':'#eadfc4',roughness:p.glazed?.14:.95,transparent:true,opacity:p.glazed?.24:.91,side:THREE.DoubleSide});paper.name=p.glazed?'glass':'slot_washi';const box=(par,x,y,z,a,b,c,m)=>{const q=new THREE.Mesh(new THREE.BoxGeometry(a,b,c),m);q.position.set(x,y,z);par.add(q);return q;};const f=new THREE.Group();f.name='part:portal';f.userData.type='trim';g.add(f);box(f,-w/2+.045,h/2,0,.09,h,.22,wood);box(f,w/2-.045,h/2,0,.09,h,.22,wood);box(f,0,h-.05,0,w,.1,.22,wood);box(f,0,.02,0,w,.04,.22,brass);const tracks=[];const pw=(w-.18)/2,ph=h-.15;for(let i=0;i<2;i++){const s=new THREE.Group();s.name='leaf_'+i;s.userData.type='panel';const cx=(i===0?-1:1)*pw/2,zz=i===0?.025:-.025;s.position.set(cx,0,zz);g.add(s);box(s,0,ph/2+.05,0,pw-.055,ph,.025,paper);for(const x of [-pw/2+.025,pw/2-.025])box(s,x,ph/2+.05,.01,.05,ph,.065,wood);for(const y of [.075,.42,ph+.025])box(s,0,y,.01,pw,.05,.065,wood);box(s,0,.24,0,pw-.08,.29,.045,wood);for(let j=1;j<4;j++)box(s,-pw/2+j*pw/4,(ph+.45)/2,.02,.018,ph-.42,.04,wood);for(let j=1;j<8;j++)box(s,0,.42+j*(ph-.42)/8,.02,pw-.07,.017,.04,wood);const pull=new THREE.Mesh(new THREE.TorusGeometry(.036,.007,8,24),brass);pull.position.set((i===0?1:-1)*(pw/2-.11),1.02,.062);s.add(pull);for(let j=0;j<3;j++)box(s,-pw*.28+j*pw*.28,.25,.027,.04,.07,.008,brass);tracks.push(new THREE.VectorKeyframeTrack(s.name+'.position',[0,1.3],[cx,0,zz,cx+(i===0?-1:1)*pw*.93,0,zz]));}const cut=box(g,0,h/2,0,w,h,1,wood);cut.name='cutout';g.animations=[new THREE.AnimationClip('open',1.3,tracks)];return g;}`;
@@ -0,0 +1,2 @@
1
+ export declare const CINEMA_SCREEN_SCRIPT = "import * as THREE from 'three';export const mount='wall-side';export default function build(){let g=new THREE.Group();const mat=(n,c,r,m=0)=>{let a=new THREE.MeshStandardMaterial({color:c,roughness:r,metalness:m});a.name='slot_'+n;return a;};const dark=mat('acoustic','#252127',1),brass=mat('bronze','#927649',.3,.8),screen=mat('screen','#8e9ba5',.85),speaker=mat('speaker','#121215',.8);function b(w,h,d,x,y,z,m){let a=new THREE.Mesh(new THREE.BoxGeometry(w,h,d),m);a.position.set(x,y,z);g.add(a);}b(6.6,2.5,.08,0,1.25,.04,dark);b(4.85,2.32,.06,0,1.25,.11,brass);b(4.72,2.19,.035,0,1.25,.16,screen);for(let s of [-1,1]){for(let i=0;i<9;i++)b(.025,2.46,.12,s*(2.52+i*.085),1.25,.12,brass);b(.35,1.3,.17,s*2.94,.85,.21,speaker);for(let y of [.48,.86,1.2]){let cone=new THREE.Mesh(new THREE.CylinderGeometry(.105,.08,.035,24),dark);cone.rotation.x=Math.PI/2;cone.position.set(s*2.94,y,.315);g.add(cone);}}g.name='part:screen_surround';g.userData.type='panel';return g;}";
2
+ //# sourceMappingURL=wall-screen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wall-screen.d.ts","sourceRoot":"","sources":["../../src/__fixtures__/wall-screen.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,48BAA48B,CAAA"}
@@ -0,0 +1 @@
1
+ export const CINEMA_SCREEN_SCRIPT = `import * as THREE from 'three';export const mount='wall-side';export default function build(){let g=new THREE.Group();const mat=(n,c,r,m=0)=>{let a=new THREE.MeshStandardMaterial({color:c,roughness:r,metalness:m});a.name='slot_'+n;return a;};const dark=mat('acoustic','#252127',1),brass=mat('bronze','#927649',.3,.8),screen=mat('screen','#8e9ba5',.85),speaker=mat('speaker','#121215',.8);function b(w,h,d,x,y,z,m){let a=new THREE.Mesh(new THREE.BoxGeometry(w,h,d),m);a.position.set(x,y,z);g.add(a);}b(6.6,2.5,.08,0,1.25,.04,dark);b(4.85,2.32,.06,0,1.25,.11,brass);b(4.72,2.19,.035,0,1.25,.16,screen);for(let s of [-1,1]){for(let i=0;i<9;i++)b(.025,2.46,.12,s*(2.52+i*.085),1.25,.12,brass);b(.35,1.3,.17,s*2.94,.85,.21,speaker);for(let y of [.48,.86,1.2]){let cone=new THREE.Mesh(new THREE.CylinderGeometry(.105,.08,.035,24),dark);cone.rotation.x=Math.PI/2;cone.position.set(s*2.94,y,.315);g.add(cone);}}g.name='part:screen_surround';g.userData.type='panel';return g;}`;
@@ -0,0 +1,47 @@
1
+ import { type AgentContext, type SceneNodes } from '@pascal-app/core/agent-operations';
2
+ import type { AuthorScenePayload } from '@pascal-app/core/agent-tools';
3
+ import type { CompiledGeometryScript } from '@pascal-app/core/schema';
4
+ export type AuthorSceneCompile = (input: {
5
+ code: string;
6
+ kind: 'object' | 'window' | 'door' | 'floor' | 'wall-face';
7
+ inputs?: Record<string, unknown>;
8
+ nodeId?: string;
9
+ }) => Promise<CompiledGeometryScript>;
10
+ /** Build and validate a complete candidate before either host changes the live scene. */
11
+ export declare function compileAuthorScene(nodes: SceneNodes, input: {
12
+ payload: AuthorScenePayload;
13
+ replace?: boolean;
14
+ buildingId?: string;
15
+ }, context: AgentContext, compile: AuthorSceneCompile, signal?: AbortSignal): Promise<{
16
+ result: Record<string, unknown> & import("@pascal-app/core/agent-operations").AuthorSceneReport;
17
+ keep?: import("@pascal-app/core/agent-operations").SessionKeep;
18
+ afterReconcile?: (nodes: SceneNodes) => {
19
+ result: Record<string, unknown>;
20
+ changes?: import("@pascal-app/core/agent-operations").SceneChanges;
21
+ };
22
+ candidate: import("@pascal-app/core/agent-operations").AuthorSceneState;
23
+ buildingId: string;
24
+ changes: {
25
+ materials?: readonly import("@pascal-app/core").SceneMaterial[];
26
+ create?: {
27
+ node: import("@pascal-app/core").AnyNode;
28
+ parentId?: string;
29
+ }[];
30
+ delete?: string[];
31
+ collections?: Record<string, import("@pascal-app/core").Collection | null>;
32
+ update: ({
33
+ id: string;
34
+ data: Partial<import("@pascal-app/core").AnyNode>;
35
+ } | {
36
+ id: `building_${string}`;
37
+ data: {
38
+ metadata: {
39
+ authorSceneState: import("@pascal-app/core/agent-operations").AuthorSceneState;
40
+ };
41
+ };
42
+ })[];
43
+ };
44
+ itemTriangles: number;
45
+ itemsCompiled: number;
46
+ }>;
47
+ //# sourceMappingURL=author-scene.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"author-scene.d.ts","sourceRoot":"","sources":["../src/author-scene.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,YAAY,EAQjB,KAAK,UAAU,EAGhB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAErE,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,WAAW,CAAA;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAA;AAErC,yFAAyF;AACzF,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,EAC9E,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,kBAAkB,EAC3B,MAAM,CAAC,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiHrB"}
@@ -0,0 +1,96 @@
1
+ import { floorScriptInputs, wallFaceScriptInputs } from '@pascal-app/core';
2
+ import { applySceneChanges, authorScene, authorSceneCeilingPoints, authorSceneFaceScripts, authorSceneFinishGaps, authorSceneFloorScripts, finalizeAuthorScene, setRoomFloorScript, setWallFaceScript, } from '@pascal-app/core/agent-operations';
3
+ /** Build and validate a complete candidate before either host changes the live scene. */
4
+ export async function compileAuthorScene(nodes, input, context, compile, signal) {
5
+ signal?.throwIfAborted();
6
+ authorScene(nodes, { ...input, compiled: {}, prepareOnly: true }, context);
7
+ const compiled = {};
8
+ const compileErrors = {};
9
+ const modules = [];
10
+ for (const level of input.payload.levels) {
11
+ for (const item of level.items ?? [])
12
+ modules.push({ id: item.id, code: item.code, kind: 'object' });
13
+ for (const wall of level.walls ?? [])
14
+ wall.openings?.forEach((opening, index) => {
15
+ if (opening.code)
16
+ modules.push({ id: `${wall.id}/${index}`, code: opening.code, kind: opening.kind });
17
+ });
18
+ }
19
+ modules.push(...authorSceneCeilingPoints(input.payload).map((point) => ({
20
+ ...point,
21
+ kind: 'object',
22
+ })));
23
+ let cursor = 0;
24
+ await Promise.all(Array.from({ length: Math.min(4, modules.length) }, async () => {
25
+ while (cursor < modules.length) {
26
+ const { id, code, kind } = modules[cursor++];
27
+ signal?.throwIfAborted();
28
+ try {
29
+ compiled[id] = await compile({ code, kind });
30
+ }
31
+ catch (error) {
32
+ signal?.throwIfAborted();
33
+ compileErrors[id] = error instanceof Error ? error.message : String(error);
34
+ }
35
+ }
36
+ }));
37
+ const outcome = authorScene(nodes, { ...input, compiled, compileErrors, prepareOnly: true }, context);
38
+ let candidate = { ...nodes, ...outcome.candidate.nodes };
39
+ for (const { roomId, zoneId, code } of authorSceneFloorScripts(input.payload, outcome.result)) {
40
+ signal?.throwIfAborted();
41
+ try {
42
+ const inputs = floorScriptInputs(candidate, zoneId);
43
+ if (!inputs)
44
+ throw new Error('The room has no floor to build on.');
45
+ const built = await compile({ code, kind: 'floor', nodeId: zoneId, inputs });
46
+ candidate = applySceneChanges(candidate, setRoomFloorScript(candidate, { zoneId, compiled: built, inputs }, context).changes);
47
+ outcome.result.floorScripts++;
48
+ const gaps = authorSceneFinishGaps(roomId, built.manifest, {
49
+ room: candidate[zoneId]?.name ?? roomId,
50
+ polygon: inputs.polygon,
51
+ });
52
+ if (gaps)
53
+ outcome.result.warnings.push(gaps);
54
+ }
55
+ catch (error) {
56
+ signal?.throwIfAborted();
57
+ outcome.result.defects.push({
58
+ id: roomId,
59
+ code: 'floor_script_failed',
60
+ message: `${error instanceof Error ? error.message : String(error)} (the room keeps its floor finish)`,
61
+ });
62
+ }
63
+ }
64
+ for (const { wallId, face, nodeId, code, toHeight } of authorSceneFaceScripts(input.payload, outcome.result, candidate)) {
65
+ signal?.throwIfAborted();
66
+ try {
67
+ const inputs = wallFaceScriptInputs(candidate, nodeId, face, toHeight);
68
+ if (!inputs)
69
+ throw new Error('The face has nothing to build on.');
70
+ const built = await compile({ code, kind: 'wall-face', nodeId, inputs });
71
+ candidate = applySceneChanges(candidate, setWallFaceScript(candidate, { wallId: nodeId, face, compiled: built, inputs, toHeight }, context).changes);
72
+ outcome.result.faceScripts++;
73
+ const gaps = authorSceneFinishGaps(`${wallId}/${face}`, built.manifest, {
74
+ wall: wallId,
75
+ face,
76
+ });
77
+ if (gaps)
78
+ outcome.result.warnings.push(gaps);
79
+ }
80
+ catch (error) {
81
+ signal?.throwIfAborted();
82
+ outcome.result.defects.push({
83
+ id: `${wallId}/${face}`,
84
+ code: 'face_script_failed',
85
+ message: `${error instanceof Error ? error.message : String(error)} (the face keeps its paint)`,
86
+ });
87
+ }
88
+ }
89
+ signal?.throwIfAborted();
90
+ outcome.candidate.nodes = Object.fromEntries(Object.keys(outcome.candidate.nodes).map((id) => [id, candidate[id]]));
91
+ return {
92
+ ...finalizeAuthorScene(nodes, outcome),
93
+ itemTriangles: Object.values(compiled).reduce((count, item) => count + item.manifest.triangles, 0),
94
+ itemsCompiled: Object.keys(compiled).length,
95
+ };
96
+ }
package/dist/compile.d.ts CHANGED
@@ -4,6 +4,14 @@ export type { GeometryScriptMount };
4
4
  export type GeometryScriptCompileInput = {
5
5
  code: string;
6
6
  params?: Record<string, GeometryScriptParamValue>;
7
+ /**
8
+ * What the host builds the module for (a room floor's `polygon`, `holes` and `elevation`, a wall
9
+ * face's `outline` and `holes`): the build reads them in `params` beside its declared ones, and
10
+ * as `inputs`; they are not among the returned params, which the scene keeps. A build given them
11
+ * is in the host's frame, so it is not re-origined for its mount, and it is cut to the floor's
12
+ * polygon or the face's outline, less their holes: the module lays out, Pascal clips.
13
+ */
14
+ inputs?: Record<string, unknown>;
7
15
  };
8
16
  export type GeometryScriptCompileOutput = CompiledGeometryScript & {
9
17
  glb: ArrayBuffer;
@@ -13,21 +21,27 @@ export declare const GEOMETRY_SCRIPT_LIMITS: {
13
21
  readonly materials: 32;
14
22
  readonly extent: 60;
15
23
  };
16
- export declare const MOUNTS: Set<"wall" | "ceiling" | "floor" | "wall-side">;
24
+ export declare const MOUNTS: Set<"ceiling" | "floor" | "wall" | "wall-side">;
17
25
  export declare function readParamSpecs(raw: unknown): GeometryScriptParamSpec[];
18
26
  export declare function resolveParams(specs: GeometryScriptParamSpec[], overrides: Record<string, GeometryScriptParamValue>): Record<string, GeometryScriptParamValue>;
19
27
  /**
20
28
  * Everything after a module has built its object, whatever the language:
21
- * re-origins it for its mount, reads the conventions into the manifest, samples
22
- * its clips and exports the GLB. `built.animations` holds its clips.
29
+ * re-origins it for its mount (or, built for a host's inputs, cuts it to the
30
+ * floor or face they describe and measures how much of it the build covers), reads the conventions into the manifest,
31
+ * samples its clips and exports the GLB. `built.animations` holds its clips.
23
32
  */
24
- export declare function finishBuild({ built, mount, specs, params, code, language, }: {
33
+ export declare function finishBuild({ built, mount, specs, params, code, language, inputs, }: {
25
34
  built: THREE.Object3D;
26
35
  mount: GeometryScriptMount;
27
36
  specs: GeometryScriptParamSpec[];
28
37
  params: Record<string, GeometryScriptParamValue>;
29
38
  code: string;
30
39
  language: GeometryScriptLanguage;
40
+ /**
41
+ * What the host built it for (`compileGeometryScript`'s `inputs`): the build stays where it
42
+ * stands, in the host's frame, and is cut to the floor or face they describe.
43
+ */
44
+ inputs?: Record<string, unknown>;
31
45
  }): Promise<GeometryScriptCompileOutput>;
32
46
  export declare function assertScriptSize(code: string): void;
33
47
  export declare function compileGeometryScript(input: GeometryScriptCompileInput): Promise<GeometryScriptCompileOutput>;
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EAEtB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAW9B,YAAY,EAAE,mBAAmB,EAAE,CAAA;AAEnC,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAA;CAClD,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG,sBAAsB,GAAG;IAAE,GAAG,EAAE,WAAW,CAAA;CAAE,CAAA;AAEvF,eAAO,MAAM,sBAAsB;;;;CAIzB,CAAA;AAyBV,eAAO,MAAM,MAAM,iDAA0E,CAAA;AAe7F,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,uBAAuB,EAAE,CA6BtE;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,uBAAuB,EAAE,EAChC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,GAClD,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAc1C;AAqoBD;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,EAChC,KAAK,EACL,KAAK,EACL,KAAK,EACL,MAAM,EACN,IAAI,EACJ,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAA;IACrB,KAAK,EAAE,mBAAmB,CAAA;IAC1B,KAAK,EAAE,uBAAuB,EAAE,CAAA;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAA;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,sBAAsB,CAAA;CACjC,GAAG,OAAO,CAAC,2BAA2B,CAAC,CA4DvC;AAMD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,QAI5C;AAED,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,2BAA2B,CAAC,CAkCtC"}
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EAEtB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAa9B,YAAY,EAAE,mBAAmB,EAAE,CAAA;AAEnC,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAA;IACjD;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG,sBAAsB,GAAG;IAAE,GAAG,EAAE,WAAW,CAAA;CAAE,CAAA;AAEvF,eAAO,MAAM,sBAAsB;aACjC,SAAS,EAAE,MAAO;aAClB,SAAS,EAAE,EAAE;aACb,MAAM,EAAE,EAAE;CACF,CAAA;AAyBV,eAAO,MAAM,MAAM,iDAA0E,CAAA;AAe7F,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,uBAAuB,EAAE,CA6BtE;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,uBAAuB,EAAE,EAChC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,GAClD,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAc1C;AA2uBD;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,EAChC,KAAK,EACL,KAAK,EACL,KAAK,EACL,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,MAAM,GACP,EAAE;IACD,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAA;IACrB,KAAK,EAAE,mBAAmB,CAAA;IAC1B,KAAK,EAAE,uBAAuB,EAAE,CAAA;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAA;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,sBAAsB,CAAA;IAChC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,GAAG,OAAO,CAAC,2BAA2B,CAAC,CA4EvC;AAMD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,QAI5C;AAED,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,2BAA2B,CAAC,CA2CtC"}
package/dist/compile.js CHANGED
@@ -9,6 +9,8 @@ import { ParametricGeometry } from 'three/examples/jsm/geometries/ParametricGeom
9
9
  import { RoundedBoxGeometry } from 'three/examples/jsm/geometries/RoundedBoxGeometry.js';
10
10
  import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js';
11
11
  import { ADDITION, Brush, DIFFERENCE, Evaluator, INTERSECTION, SUBTRACTION } from 'three-bvh-csg';
12
+ import { measureCoverage } from './coverage.js';
13
+ import { cutToRegion, hostRegion } from './cut.js';
12
14
  import { transformModule } from './transform.js';
13
15
  export const GEOMETRY_SCRIPT_LIMITS = {
14
16
  triangles: 300_000,
@@ -110,29 +112,88 @@ function assertFinite(geometry, label) {
110
112
  throw new Error(`${label} has non-finite vertex positions`);
111
113
  }
112
114
  }
113
- /** Bounds of the visible geometry: helpers (cutout, collider) and lights do not count. */
114
- function visibleBounds(root) {
115
- const box = new THREE.Box3();
116
- const meshBox = new THREE.Box3();
117
- root.updateWorldMatrix(true, true);
115
+ const AXES = ['x', 'y', 'z'];
116
+ /** What a transform component holds when it is no finite number: "NaN", "a MeshStandardMaterial". */
117
+ function describeValue(value) {
118
+ if (typeof value === 'number')
119
+ return String(value);
120
+ if (value && typeof value === 'object')
121
+ return `a ${value.constructor?.name ?? 'object'}`;
122
+ return String(value);
123
+ }
124
+ /** The first position, rotation or scale component of this object that is not a finite number. */
125
+ function transformFault(object) {
126
+ const vectors = { position: object.position, rotation: object.rotation, scale: object.scale };
127
+ for (const [field, vector] of Object.entries(vectors)) {
128
+ for (const axis of AXES) {
129
+ const value = vector[axis];
130
+ if (typeof value !== 'number' || !Number.isFinite(value)) {
131
+ return `${field}.${axis} = ${describeValue(value)}`;
132
+ }
133
+ }
134
+ }
135
+ return null;
136
+ }
137
+ /**
138
+ * Why a box of visible geometry has no finite corner. `Box3.isEmpty()` is false for a NaN corner,
139
+ * so a mesh at a position that is not a number (a helper called one argument short passes it a
140
+ * material) would otherwise build NaN bounds, and from them an item that fails its own schema.
141
+ */
142
+ function unmeasurable(root) {
143
+ const meshes = [];
144
+ root.traverse((object) => {
145
+ const mesh = object;
146
+ if (mesh.isMesh && !isHelper(mesh))
147
+ meshes.push(mesh);
148
+ });
149
+ for (const mesh of meshes)
150
+ assertFinite(mesh.geometry, mesh.name || 'A mesh');
151
+ for (const [index, mesh] of meshes.entries()) {
152
+ for (let object = mesh; object; object = object.parent) {
153
+ const fault = transformFault(object);
154
+ if (!fault)
155
+ continue;
156
+ const place = `mesh ${index + 1} of ${meshes.length}`;
157
+ const who = object.name
158
+ ? `"${object.name}"`
159
+ : object === mesh
160
+ ? `an unnamed ${mesh.geometry.type} mesh (${place})`
161
+ : `an unnamed ${object.type.toLowerCase()} holding ${place}`;
162
+ return new Error(`The object cannot be measured: ${who} has ${fault}, which is not a finite number. Positions, rotations and scales take numbers (metres, radians); a helper called one argument short passes the next value, a material for instance, in its place.`);
163
+ }
164
+ }
165
+ return new Error('The object cannot be measured: its size is not a finite number.');
166
+ }
167
+ /** The meshes that draw: helpers (cutout, collider), and anything under one, do not. */
168
+ function visibleMeshes(root) {
169
+ const meshes = [];
118
170
  root.traverse((object) => {
119
171
  const mesh = object;
120
172
  if (!mesh.isMesh || isHelper(mesh))
121
173
  return;
122
- let hidden = false;
123
174
  for (let p = mesh; p; p = p.parent)
124
175
  if (isHelper(p))
125
- hidden = true;
126
- if (hidden)
127
- return;
176
+ return;
177
+ meshes.push(mesh);
178
+ });
179
+ return meshes;
180
+ }
181
+ /** Bounds of the visible geometry: helpers (cutout, collider) and lights do not count. */
182
+ function visibleBounds(root) {
183
+ const box = new THREE.Box3();
184
+ const meshBox = new THREE.Box3();
185
+ root.updateWorldMatrix(true, true);
186
+ for (const mesh of visibleMeshes(root)) {
128
187
  mesh.geometry.computeBoundingBox();
129
188
  meshBox.copy(mesh.geometry.boundingBox).applyMatrix4(mesh.matrixWorld);
130
189
  box.union(meshBox);
131
- });
190
+ }
132
191
  return box;
133
192
  }
134
193
  function originFor(box, mount) {
135
194
  const center = box.getCenter(new THREE.Vector3());
195
+ if (mount === 'ceiling')
196
+ return new THREE.Vector3(center.x, box.max.y, center.z);
136
197
  if (mount === 'wall-side')
137
198
  return new THREE.Vector3(center.x, box.min.y, box.min.z);
138
199
  return new THREE.Vector3(center.x, box.min.y, center.z);
@@ -426,6 +487,49 @@ function analyseGeometry(root, parts) {
426
487
  })),
427
488
  };
428
489
  }
490
+ function flipWinding(source) {
491
+ const geometry = source.index ? source.toNonIndexed() : source.clone();
492
+ for (const [name, attribute] of Object.entries(geometry.attributes)) {
493
+ const { itemSize, array } = attribute;
494
+ for (let vertex = 0; vertex + 2 < attribute.count; vertex += 3) {
495
+ for (let k = 0; k < itemSize; k++) {
496
+ const b = (vertex + 1) * itemSize + k;
497
+ const c = (vertex + 2) * itemSize + k;
498
+ const swapped = array[b];
499
+ array[b] = array[c];
500
+ array[c] = swapped;
501
+ }
502
+ }
503
+ if (name === 'normal')
504
+ for (let i = 0; i < array.length; i++)
505
+ array[i] = -array[i];
506
+ }
507
+ return geometry;
508
+ }
509
+ /**
510
+ * The viewer draws every material front side only (its WebGPU MRT workaround),
511
+ * so a double-sided plane shows nothing from behind. The back face is baked into
512
+ * the geometry instead: the triangles again, wound the other way with their
513
+ * normals negated; a back-side material keeps only that copy. Runs before the
514
+ * triangle count and the merge, so both see what is exported.
515
+ */
516
+ function bakeBackFaces(root) {
517
+ root.traverse((object) => {
518
+ const mesh = object;
519
+ if (!mesh.isMesh || isHelper(mesh) || Array.isArray(mesh.material))
520
+ return;
521
+ const { side } = mesh.material;
522
+ if (side === THREE.FrontSide)
523
+ return;
524
+ const back = flipWinding(mesh.geometry);
525
+ mesh.geometry =
526
+ side === THREE.BackSide
527
+ ? back
528
+ : (BufferGeometryUtils.mergeGeometries([mesh.geometry.toNonIndexed(), back]) ??
529
+ mesh.geometry);
530
+ mesh.material.side = THREE.FrontSide;
531
+ });
532
+ }
429
533
  /**
430
534
  * Merges each part's meshes by material, so a porch draws as a few dozen
431
535
  * meshes instead of hundreds (draw calls, not triangles, are the cost). Part
@@ -689,25 +793,40 @@ async function digest(bytes) {
689
793
  }
690
794
  /**
691
795
  * Everything after a module has built its object, whatever the language:
692
- * re-origins it for its mount, reads the conventions into the manifest, samples
693
- * its clips and exports the GLB. `built.animations` holds its clips.
796
+ * re-origins it for its mount (or, built for a host's inputs, cuts it to the
797
+ * floor or face they describe and measures how much of it the build covers), reads the conventions into the manifest,
798
+ * samples its clips and exports the GLB. `built.animations` holds its clips.
694
799
  */
695
- export async function finishBuild({ built, mount, specs, params, code, language, }) {
800
+ export async function finishBuild({ built, mount, specs, params, code, language, inputs, }) {
696
801
  const root = new THREE.Group();
697
802
  root.name = 'pascal_script_root';
698
803
  root.add(built);
699
804
  const box = visibleBounds(root);
700
805
  if (box.isEmpty())
701
806
  throw new Error('build() returned no visible meshes');
807
+ if (![box.min.x, box.min.y, box.min.z, box.max.x, box.max.y, box.max.z].every(Number.isFinite)) {
808
+ throw unmeasurable(root);
809
+ }
702
810
  const size = box.getSize(new THREE.Vector3());
703
811
  if (Math.max(size.x, size.y, size.z) > GEOMETRY_SCRIPT_LIMITS.extent) {
704
812
  throw new Error(`The object is ${vec(size).join(' × ')} m; the limit is ${GEOMETRY_SCRIPT_LIMITS.extent} m per side. Units are metres.`);
705
813
  }
706
- built.position.sub(originFor(box, mount));
814
+ if (!inputs)
815
+ built.position.sub(originFor(box, mount));
707
816
  root.updateWorldMatrix(true, true);
708
817
  const read = readAnimations(built, root);
709
818
  const clips = sampleTransformClips(root, read.clips);
710
819
  const animated = read.animated;
820
+ const region = inputs && hostRegion(inputs);
821
+ let coverage = null;
822
+ if (region) {
823
+ cutToRegion(visibleMeshes(root), region, box);
824
+ if (visibleBounds(root).isEmpty()) {
825
+ throw new Error(`Nothing the build made lies on its ${region.axis === 'y' ? 'floor' : 'face'}: everything is outside it or in its openings.`);
826
+ }
827
+ coverage = measureCoverage(visibleMeshes(root), region);
828
+ }
829
+ bakeBackFaces(root);
711
830
  const conventions = readConventions(root);
712
831
  if (conventions.triangles > GEOMETRY_SCRIPT_LIMITS.triangles) {
713
832
  throw new Error(`${conventions.triangles} triangles exceeds the ${GEOMETRY_SCRIPT_LIMITS.triangles} limit`);
@@ -743,6 +862,7 @@ export async function finishBuild({ built, mount, specs, params, code, language,
743
862
  cutout: conventions.cutout,
744
863
  collider: conventions.collider,
745
864
  triangles: conventions.triangles,
865
+ ...coverage,
746
866
  }),
747
867
  };
748
868
  }
@@ -770,14 +890,23 @@ export async function compileGeometryScript(input) {
770
890
  throw new Error(`\`mount\` must be one of ${[...MOUNTS].join(', ')}`);
771
891
  const specs = readParamSpecs(exported.params);
772
892
  const params = resolveParams(specs, input.params ?? {});
893
+ const inputs = input.inputs ?? {};
773
894
  const built = await exported.build({
774
- params,
775
- inputs: {},
895
+ params: { ...params, ...inputs },
896
+ inputs,
776
897
  THREE,
777
898
  lib: LIB,
778
899
  });
779
900
  if (!(built instanceof THREE.Object3D)) {
780
901
  throw new Error('build() must return a THREE.Object3D (usually a THREE.Group)');
781
902
  }
782
- return finishBuild({ built, mount, specs, params, code: input.code, language: 'three' });
903
+ return finishBuild({
904
+ built,
905
+ mount,
906
+ specs,
907
+ params,
908
+ code: input.code,
909
+ language: 'three',
910
+ inputs: input.inputs,
911
+ });
783
912
  }
@@ -0,0 +1,22 @@
1
+ import * as THREE from 'three';
2
+ import type { HostRegion } from './cut.js';
3
+ /** A rectangle in the region's plane: a floor's (x, z), a face's (x along the wall, y up). */
4
+ export type UncoveredPatch = {
5
+ min: [number, number];
6
+ max: [number, number];
7
+ };
8
+ export type Coverage = {
9
+ coverage: number;
10
+ uncovered: UncoveredPatch[];
11
+ };
12
+ /**
13
+ * How much of the region the build covers, seen square-on to its plane (a floor from above, a
14
+ * face from the room). `coverage` is the covered share of the region's area, two decimals,
15
+ * joints included: read along strips between the heights of every corner, exact for boards and
16
+ * tiles laid square. On a grid of 2 cm cells (coarser on a region too big for 250k of them), a
17
+ * cell more than half bare is bare; `uncovered` bounds the largest bare patches (two cells across
18
+ * at least, so no joint is one; patches nearer than NEAR are one place), largest first. Null
19
+ * when the region has no area.
20
+ */
21
+ export declare function measureCoverage(meshes: THREE.Mesh[], region: HostRegion): Coverage | null;
22
+ //# sourceMappingURL=coverage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../src/coverage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAgBvC,8FAA8F;AAC9F,MAAM,MAAM,cAAc,GAAG;IAAE,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAA;AAE7E,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,cAAc,EAAE,CAAA;CAAE,CAAA;AAsOxE;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CA4CzF"}