@pascal-app/geometry-script 1.0.3 → 1.0.4

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.
package/dist/compile.d.ts CHANGED
@@ -13,7 +13,7 @@ export declare const GEOMETRY_SCRIPT_LIMITS: {
13
13
  readonly materials: 32;
14
14
  readonly extent: 60;
15
15
  };
16
- export declare const MOUNTS: Set<"wall" | "ceiling" | "floor" | "wall-side">;
16
+ export declare const MOUNTS: Set<"wall" | "ceiling" | "wall-side" | "floor">;
17
17
  export declare function readParamSpecs(raw: unknown): GeometryScriptParamSpec[];
18
18
  export declare function resolveParams(specs: GeometryScriptParamSpec[], overrides: Record<string, GeometryScriptParamValue>): Record<string, GeometryScriptParamValue>;
19
19
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pascal-app/geometry-script",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Compiles AI-authored three.js and Blender (bpy) geometry scripts into GLB artifacts with a Pascal manifest. Runs in a browser worker, Bun or Node — no DOM, no React.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -45,7 +45,7 @@
45
45
  "test": "bun test"
46
46
  },
47
47
  "dependencies": {
48
- "@pascal-app/core": "^1.0.3",
48
+ "@pascal-app/core": "^1.0.4",
49
49
  "three-bvh-csg": "^0.0.18"
50
50
  },
51
51
  "peerDependencies": {
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=compile.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compile.test.d.ts","sourceRoot":"","sources":["../src/compile.test.ts"],"names":[],"mappings":""}
@@ -1,199 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { matchScriptSlotsToLibrary, scriptSource } from '@pascal-app/core';
3
- import { addObject, applySceneChanges, editedScriptParams } from '@pascal-app/core/agent-operations';
4
- import { GeometryArtifactManifest, ItemNode, LevelNode } from '@pascal-app/core/schema';
5
- import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
6
- import { compileGeometryScript } from './index.js';
7
- const SASH = `
8
- import * as THREE from 'three'
9
- export const mount = 'wall'
10
- export default function build() {
11
- const g = new THREE.Group()
12
- const sash = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 0.05), new THREE.MeshStandardMaterial())
13
- sash.name = 'sash'
14
- g.add(sash)
15
- const times = [0, 1]
16
- g.animations = [new THREE.AnimationClip('open', 1, [new THREE.VectorKeyframeTrack('sash.position', times, [0, 0, 0, 0, 0.7, 0])])]
17
- return g
18
- }
19
- `;
20
- describe('clips', () => {
21
- test('a clip is stored ending on its last pose, not wrapped to its first', async () => {
22
- const { glb } = await compileGeometryScript({ code: SASH });
23
- const gltf = await new GLTFLoader().parseAsync(glb, '');
24
- const track = gltf.animations[0].tracks.find((t) => t.name.endsWith('.position'));
25
- const start = track.values[1];
26
- const end = track.values[track.values.length - 2];
27
- expect(end - start).toBeCloseTo(0.7, 3);
28
- });
29
- });
30
- test('an edit keeps the current param values the new code still accepts', async () => {
31
- const module = (params) => `export const params = ${params}
32
- export default function build({ THREE }) {
33
- const g = new THREE.Group(); g.add(new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1))); return g
34
- }`;
35
- const before = await compileGeometryScript({
36
- code: module(`{ width: { default: 5.2, min: 3, max: 8 }, depth: 2.4, height: 2.75, finish: 'pine', rail: 1, gone: 9 }`),
37
- params: { width: 6.3, depth: 1.7, height: 2.52, finish: 'walnut', rail: 0, gone: 4 },
38
- });
39
- const node = { type: 'item', source: scriptSource(before) };
40
- const after = await compileGeometryScript({
41
- code: module(`{
42
- width: { default: 5.2, min: 3, max: 8 },
43
- depth: { default: 2.4, min: 2, max: 4 },
44
- height: 2.75,
45
- finish: { default: 'oak', options: ['oak', 'ash'] },
46
- rail: true,
47
- lit: false,
48
- }`),
49
- params: editedScriptParams(node, { height: 3 }),
50
- });
51
- expect(after.params).toEqual({
52
- width: 6.3,
53
- depth: 2,
54
- height: 3,
55
- finish: 'oak',
56
- rail: true,
57
- lit: false,
58
- });
59
- });
60
- test('building and adding a scripted item assigns Pascal finishes and rebuilding keeps paint', async () => {
61
- const compiled = await compileGeometryScript({
62
- code: `export default function build({ THREE }) {
63
- const group = new THREE.Group();
64
- const samples = [
65
- ['slot_oak', '#a77440', 0, 1, false],
66
- ['slot_hardware', '#b08d57', 0.9, 1, false],
67
- ['glass', '#87ceeb', 0, 0.3, true],
68
- ['slot_paint', '#eae6de', 0, 1, false],
69
- ['slot_unknown', '#ff00ff', 0, 1, false],
70
- ['slot_oakTop', '#f3dcb5', 0, 1, false],
71
- ];
72
- samples.forEach(([name, color, metalness, opacity, transparent], i) => {
73
- const material = new THREE.MeshStandardMaterial({ color, metalness, opacity, transparent, roughness: 0.7 });
74
- material.name = name;
75
- const mesh = new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.2, 0.1), material);
76
- mesh.position.x = i * 0.2; group.add(mesh);
77
- });
78
- const bulb = new THREE.MeshStandardMaterial({color: '#ffffff', emissive: '#ffffff'});
79
- bulb.name = 'slot_bulb'; group.add(new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.1, 0.1), bulb));
80
- return group;
81
- }`,
82
- });
83
- const level = LevelNode.parse({ id: 'level_material_test' });
84
- const initial = { [level.id]: level };
85
- const context = { activeLevelId: level.id };
86
- const added = addObject(initial, { compiled, reason: 'no catalog cabinet' }, context);
87
- const nodes = applySceneChanges(initial, added.changes);
88
- const node = ItemNode.parse(nodes[added.result.nodeId]);
89
- expect(node.slots).toEqual({
90
- oak: 'library:wood-finewood27',
91
- hardware: 'library:metal-brass',
92
- glass: 'library:preset-glass',
93
- paint: 'library:preset-softwhite',
94
- oaktop: 'library:wood-finewood27',
95
- });
96
- expect(node.source.manifest.slots.find((slot) => slot.id === 'hardware')).toMatchObject({
97
- color: '#b08d57',
98
- metalness: 0.9,
99
- roughness: 0.7,
100
- });
101
- expect(node.source.manifest.slots.find((slot) => slot.id === 'unknown')?.color).toBe('#ff00ff');
102
- expect(node.source.manifest.slots.find((slot) => slot.id === 'bulb')?.emissive).toBe(true);
103
- const artifact = await new GLTFLoader().parseAsync(compiled.glb, '');
104
- expect(artifact.parser.json.materials.some((material) => material.name === 'slot_glass')).toBe(true);
105
- for (const paint of ['scene:mtl_user', 'library:preset-white', '#123456']) {
106
- const painted = ItemNode.parse({ ...node, slots: { ...node.slots, oak: paint } });
107
- const rebuilt = addObject({ ...nodes, [node.id]: painted }, { compiled, nodeId: node.id }, context);
108
- const after = applySceneChanges({ ...nodes, [node.id]: painted }, rebuilt.changes);
109
- expect(ItemNode.parse(JSON.parse(JSON.stringify(after[node.id]))).slots).toEqual({
110
- ...node.slots,
111
- oak: paint,
112
- });
113
- }
114
- });
115
- test('conflicting materials in one slot do not invent a matching tone', async () => {
116
- const { manifest } = await compileGeometryScript({
117
- code: `export default function build({ THREE }) {
118
- const group = new THREE.Group();
119
- for (const color of ['#a77440', '#3e220d']) {
120
- const material = new THREE.MeshStandardMaterial({ color }); material.name = 'slot_body';
121
- group.add(new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), material));
122
- }
123
- return group;
124
- }`,
125
- });
126
- expect(manifest.slots).toHaveLength(1);
127
- expect(manifest.slots[0].color).toBeUndefined();
128
- });
129
- test('only see-through materials hint glass', async () => {
130
- const { manifest } = await compileGeometryScript({
131
- code: `export default function build({ THREE }) {
132
- const group = new THREE.Group();
133
- const materials = [
134
- new THREE.MeshStandardMaterial({ color: '#fff8e7', transparent: true, opacity: 0.85 }),
135
- new THREE.MeshStandardMaterial({ color: '#2e7d32', transparent: true }),
136
- new THREE.MeshStandardMaterial({ color: '#ffffff', transparent: true, opacity: 0.3 }),
137
- new THREE.MeshPhysicalMaterial({ color: '#ffffff', transmission: 1 }),
138
- ];
139
- ['slot_shade', 'slot_leaves', 'slot_pane', 'slot_lens'].forEach((name, i) => {
140
- materials[i].name = name;
141
- group.add(new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), materials[i]));
142
- });
143
- return group;
144
- }`,
145
- });
146
- expect(matchScriptSlotsToLibrary(manifest)).toMatchObject({
147
- pane: 'library:preset-glass',
148
- lens: 'library:preset-glass',
149
- });
150
- expect(matchScriptSlotsToLibrary(manifest).shade).not.toBe('library:preset-glass');
151
- expect(matchScriptSlotsToLibrary(manifest).leaves).not.toBe('library:preset-glass');
152
- });
153
- test('cutter footprints retain concavity and host kind while old manifests still load', async () => {
154
- const { manifest } = await compileGeometryScript({
155
- code: `export default function build({ THREE }) {
156
- const g = new THREE.Group();
157
- g.add(new THREE.Mesh(new THREE.BoxGeometry(4, 1, 4), new THREE.MeshStandardMaterial()));
158
- const shape = new THREE.Shape(); shape.moveTo(0,0); shape.lineTo(2,0); shape.lineTo(2,1); shape.lineTo(1,1); shape.lineTo(1,2); shape.lineTo(0,2); shape.closePath();
159
- const geometry = new THREE.ExtrudeGeometry(shape, {depth:2, bevelEnabled:false}); geometry.rotateX(-Math.PI/2);
160
- const cutter = new THREE.Mesh(geometry); cutter.name='cut:slab'; cutter.position.y=-1; g.add(cutter); return g;
161
- }`,
162
- });
163
- const parsed = GeometryArtifactManifest.parse(manifest);
164
- expect(parsed.cutters).toHaveLength(1);
165
- expect(parsed.cutters[0].host).toBe('slab');
166
- const ring = parsed.cutters[0].polygon;
167
- const area = Math.abs(ring.reduce((sum, p, i) => {
168
- const q = ring[(i + 1) % ring.length];
169
- return sum + p[0] * q[1] - q[0] * p[1];
170
- }, 0)) / 2;
171
- expect(area).toBeCloseTo(3);
172
- expect(ring).toHaveLength(6);
173
- const { cutters, ...legacy } = manifest;
174
- expect(GeometryArtifactManifest.parse(legacy).cutters).toBeUndefined();
175
- });
176
- test('only slab and ceiling cutter outlines are stored while wall cutters stay in the artifact', async () => {
177
- for (const [mount, name, host] of [
178
- ['floor', 'cut:wall', undefined],
179
- ['wall', 'cutout', undefined],
180
- ['wall-side', 'cutout', undefined],
181
- ['floor', 'cutout', 'mounted'],
182
- ['ceiling', 'cutout', 'mounted'],
183
- ['ceiling', 'cut:ceiling', 'ceiling'],
184
- ]) {
185
- const { manifest, glb } = await compileGeometryScript({
186
- code: `export const mount = '${mount}';
187
- export default function build({ THREE }) {
188
- const group = new THREE.Group();
189
- group.add(new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1)));
190
- const cutter = new THREE.Mesh(new THREE.BoxGeometry(0.5, 2, 0.5));
191
- cutter.name = '${name}'; group.add(cutter); return group;
192
- }`,
193
- });
194
- expect(manifest.cutout).toBe(true);
195
- expect(manifest.cutters?.map((cutter) => cutter.host)).toEqual(host ? [host] : []);
196
- const artifact = await new GLTFLoader().parseAsync(glb, '');
197
- expect(artifact.parser.json.nodes.some((node) => node.name === name)).toBe(true);
198
- }
199
- });