@deepblend/dsh-blender-contracts 0.6.3 → 0.7.0
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/lib/recipe-parameters.js +19 -9
- package/lib/recipe.js +15 -1
- package/lib/schema-types.d.ts +3 -3
- package/lib/schemas/recipe.schema.json +40 -2
- package/package.json +1 -1
package/lib/recipe-parameters.js
CHANGED
|
@@ -4,8 +4,8 @@ import { instantiateRecipeLock, RecipeError } from './recipe.js'
|
|
|
4
4
|
import { validateSceneSpec } from './scene-spec.js'
|
|
5
5
|
|
|
6
6
|
const axisOf = binding => ['x', 'y', 'z'].indexOf(binding.axis)
|
|
7
|
-
const structural = parameter => parameter.bindings.some(binding => binding.kind
|
|
8
|
-
&& parameter.bindings.every(binding => ['entity', 'camera'].includes(binding.kind))
|
|
7
|
+
const structural = parameter => parameter.bindings.some(binding => ['entity', 'generator'].includes(binding.kind))
|
|
8
|
+
&& parameter.bindings.every(binding => ['entity', 'camera', 'generator'].includes(binding.kind))
|
|
9
9
|
const entity = (spec, id) => spec.entities.find(item => item.id === id)
|
|
10
10
|
const vector = (target, property) => property === 'dimensions' ? target?.generator?.dimensions
|
|
11
11
|
: property === 'targetPoint' ? target?.targetPoint : target?.transform?.location
|
|
@@ -38,14 +38,21 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
|
|
|
38
38
|
}
|
|
39
39
|
const conflicts = []
|
|
40
40
|
for (const parameter of parameters) for (const binding of parameter.bindings) {
|
|
41
|
-
if (binding.kind
|
|
42
|
-
const
|
|
43
|
-
const
|
|
41
|
+
if (!['entity', 'generator'].includes(binding.kind)) continue
|
|
42
|
+
const oldEntity = entity(before.spec, binding.entityId), currentEntity = entity(currentSpec, binding.entityId)
|
|
43
|
+
const expected = binding.kind === 'generator' ? oldEntity?.generator?.[binding.property]
|
|
44
|
+
: vector(oldEntity, binding.property)?.[axisOf(binding)]
|
|
45
|
+
const actual = binding.kind === 'generator' ? currentEntity?.generator?.[binding.property]
|
|
46
|
+
: vector(currentEntity, binding.property)?.[axisOf(binding)]
|
|
44
47
|
if (!close(actual, expected)) conflicts.push({ parameterId: parameter.id, entityId: binding.entityId,
|
|
45
48
|
property: binding.property, axis: binding.axis, expected, actual })
|
|
46
|
-
if (binding.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
if (binding.kind === 'generator' && currentEntity?.generator?.shape !== oldEntity?.generator?.shape) {
|
|
50
|
+
conflicts.push({ parameterId: parameter.id, entityId: binding.entityId, property: 'shape',
|
|
51
|
+
expected: oldEntity?.generator?.shape, actual: currentEntity?.generator?.shape })
|
|
52
|
+
}
|
|
53
|
+
if (binding.property === 'dimensions' || binding.kind === 'generator') {
|
|
54
|
+
const oldScale = oldEntity?.transform?.scale ?? [1, 1, 1]
|
|
55
|
+
const scale = currentEntity?.transform?.scale ?? [1, 1, 1]
|
|
49
56
|
if (!scale?.every((value, axis) => close(value, oldScale[axis]))) {
|
|
50
57
|
conflicts.push({ parameterId: parameter.id, entityId: binding.entityId,
|
|
51
58
|
property: 'scale', expected: oldScale, actual: scale })
|
|
@@ -75,7 +82,10 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
|
|
|
75
82
|
continue
|
|
76
83
|
}
|
|
77
84
|
const actual = entity(currentSpec, binding.entityId), target = entity(after.spec, binding.entityId)
|
|
78
|
-
if (binding.
|
|
85
|
+
if (binding.kind === 'generator') {
|
|
86
|
+
if (!generators.has(actual.id)) generators.set(actual.id, structuredClone(actual.generator))
|
|
87
|
+
generators.get(actual.id)[binding.property] = target.generator[binding.property]
|
|
88
|
+
} else if (binding.property === 'dimensions') {
|
|
79
89
|
if (!generators.has(actual.id)) generators.set(actual.id, structuredClone(actual.generator))
|
|
80
90
|
generators.get(actual.id).dimensions[axis] = target.generator.dimensions[axis]
|
|
81
91
|
} else {
|
package/lib/recipe.js
CHANGED
|
@@ -12,6 +12,7 @@ export const RECIPE_CAPABILITIES = Object.freeze([
|
|
|
12
12
|
'material.principled', 'material.glass', 'material.emission', 'material.procedural', 'material.procedural.uv', 'material.anisotropy',
|
|
13
13
|
'animation.transform', 'animation.material',
|
|
14
14
|
'recipe.geometry-bindings',
|
|
15
|
+
'recipe.generator-bindings',
|
|
15
16
|
])
|
|
16
17
|
export const RECIPE_LIMITS = Object.freeze({ sceneBytes: 2 * 1024 * 1024, previewBytes: 4 * 1024 * 1024, previewPixels: 4 * 1024 * 1024 })
|
|
17
18
|
const structural = compileSchema(recipeSchema, { id: 'recipe.schema.json' })
|
|
@@ -100,6 +101,7 @@ export function validateRecipeManifest(manifest, options = {}) {
|
|
|
100
101
|
if (valueIssue) errors.push(valueIssue)
|
|
101
102
|
for (const binding of parameter.bindings) {
|
|
102
103
|
const target = binding.kind === 'material' ? `material:${binding.materialId}:${binding.property}`
|
|
104
|
+
: binding.kind === 'generator' ? `generator:${binding.entityId}:${binding.property}`
|
|
103
105
|
: ['entity', 'camera'].includes(binding.kind) ? `${binding.kind}:${binding.entityId ?? binding.cameraId}:${binding.property}.${binding.axis}` : `render-profile:${binding.profile}:exposure`
|
|
104
106
|
const prior = targets.get(target)
|
|
105
107
|
// Camera framing may add independent width/depth/height deltas. Repeating a
|
|
@@ -110,9 +112,10 @@ export function validateRecipeManifest(manifest, options = {}) {
|
|
|
110
112
|
const color = binding.kind === 'material' && binding.property === 'baseColor'
|
|
111
113
|
if ((parameter.type === 'color') !== color) errors.push(issue('RECIPE_BINDING_INVALID', path, 'Parameter type does not match the allowlisted property'))
|
|
112
114
|
if (parameter.type === 'number') {
|
|
113
|
-
if (['entity', 'camera'].includes(binding.kind)) {
|
|
115
|
+
if (['entity', 'camera', 'generator'].includes(binding.kind)) {
|
|
114
116
|
if (!Number.isFinite(binding.multiplier) || binding.multiplier === 0) errors.push(issue('RECIPE_BINDING_INVALID', path, 'Entity binding multiplier must be finite and nonzero'))
|
|
115
117
|
if (!declared.has('recipe.geometry-bindings')) errors.push(issue('RECIPE_CAPABILITY_UNDECLARED', path, 'Entity bindings require recipe.geometry-bindings'))
|
|
118
|
+
if (binding.kind === 'generator' && !declared.has('recipe.generator-bindings')) errors.push(issue('RECIPE_CAPABILITY_UNDECLARED', path, 'Generator bindings require recipe.generator-bindings'))
|
|
116
119
|
if (binding.property !== 'location' && binding.offsetAnimation !== undefined) errors.push(issue('RECIPE_BINDING_INVALID', path, 'Animation offsets are only valid on location bindings'))
|
|
117
120
|
continue
|
|
118
121
|
}
|
|
@@ -190,6 +193,15 @@ function bindingsAgainstScene(manifest, spec) {
|
|
|
190
193
|
(track.property === binding.property || track.property.startsWith(`${binding.property}.`)))) {
|
|
191
194
|
errors.push(issue('RECIPE_BINDING_INVALID', path, 'A parameter must not compete with animation on the same material property'))
|
|
192
195
|
}
|
|
196
|
+
} else if (binding.kind === 'generator') {
|
|
197
|
+
const entity = bindingTarget(spec, binding)
|
|
198
|
+
const current = entity?.generator?.[binding.property]
|
|
199
|
+
if (entity?.generator?.shape !== 'handled_cup' || !Number.isFinite(current) || current <= 0) {
|
|
200
|
+
errors.push(issue('RECIPE_BINDING_INVALID', path, 'Generator binding requires an explicit positive handled_cup scalar'))
|
|
201
|
+
continue
|
|
202
|
+
}
|
|
203
|
+
const ends = [parameter.minimum, parameter.maximum].map(value => current + (value - parameter.default) * binding.multiplier)
|
|
204
|
+
if (ends.some(value => !Number.isFinite(value) || value <= 0)) errors.push(issue('RECIPE_BINDING_INVALID', path, 'Generator binding range must remain positive and finite'))
|
|
193
205
|
} else if (['entity', 'camera'].includes(binding.kind)) {
|
|
194
206
|
const entity = bindingTarget(spec, binding)
|
|
195
207
|
const vector = bindingVector(entity, binding), axis = bindingAxis(binding)
|
|
@@ -330,6 +342,8 @@ function resolveRecipe(manifest, checked, values) {
|
|
|
330
342
|
const material = spec.materials.find(item => item.id === binding.materialId)
|
|
331
343
|
material.parameters[binding.property] = parameter.type === 'color'
|
|
332
344
|
? [...value, material.parameters.baseColor[3] ?? 1] : value
|
|
345
|
+
} else if (binding.kind === 'generator') {
|
|
346
|
+
bindingTarget(spec, binding).generator[binding.property] += (resolvedValues[parameter.id] - parameter.default) * binding.multiplier
|
|
333
347
|
} else if (['entity', 'camera'].includes(binding.kind)) {
|
|
334
348
|
const vector = bindingVector(bindingTarget(spec, binding), binding)
|
|
335
349
|
// Preserve the input's exact default bytes and avoid cumulative edits.
|
package/lib/schema-types.d.ts
CHANGED
|
@@ -73,12 +73,12 @@ export namespace ScenePatchSchema {
|
|
|
73
73
|
}
|
|
74
74
|
export type ScenePatch = ScenePatchSchema.Document;
|
|
75
75
|
|
|
76
|
-
/** Source SHA-256:
|
|
76
|
+
/** Source SHA-256: 1a67184f1ee765ae3b2679c5c9f8ccb19d7026213e28b6811f99b1744002326a */
|
|
77
77
|
export namespace RecipeSchema {
|
|
78
|
-
export type Binding = ({ "kind": "material"; "materialId": string; "property": "baseColor" | "roughness"; }) | ({ "kind": "render-profile"; "profile": "preview" | "final"; "property": "exposure"; }) | ({ "kind": "entity"; "entityId": string; "property": "dimensions" | "location"; "axis": "x" | "y" | "z"; "multiplier": number; "offsetAnimation"?: boolean; }) | ({ "kind": "camera"; "cameraId": string; "property": "location" | "targetPoint"; "axis": "x" | "y" | "z"; "multiplier": number; });
|
|
78
|
+
export type Binding = ({ "kind": "material"; "materialId": string; "property": "baseColor" | "roughness"; }) | ({ "kind": "render-profile"; "profile": "preview" | "final"; "property": "exposure"; }) | ({ "kind": "entity"; "entityId": string; "property": "dimensions" | "location"; "axis": "x" | "y" | "z"; "multiplier": number; "offsetAnimation"?: boolean; }) | ({ "kind": "camera"; "cameraId": string; "property": "location" | "targetPoint"; "axis": "x" | "y" | "z"; "multiplier": number; }) | ({ "kind": "generator"; "entityId": string; "property": "height" | "radius" | "wallThickness" | "handleLower" | "handleUpper" | "handleRadius" | "rootRadius" | "rootLength"; "multiplier": number; });
|
|
79
79
|
export type ColorParameter = { "id": string; "title": string; "description"?: string; "bindings": Array<RecipeSchema.Binding>; "type": "color"; "default": [number, number, number]; };
|
|
80
80
|
export type NumberParameter = { "id": string; "title": string; "description"?: string; "bindings": Array<RecipeSchema.Binding>; "type": "number"; "default": number; "minimum": number; "maximum": number; };
|
|
81
|
-
export type Document = { "schemaVersion": "deepblend.recipe/v1"; "id": string; "version": string; "title": string; "description": string; "author": { "name": string; "url"?: string; }; "license": string; "source": { "url": string; "note"?: string; }; "compatibility": { "sceneSchemaVersion": "deepblend.scene/v1"; "capabilities": Array<"geometry.primitive" | "geometry.primitive.dimensions" | "geometry.lathe" | "geometry.curve" | "geometry.handled_cup" | "geometry.handled_cup.tension" | "geometry.handled_cup.tension.extended" | "geometry.modifiers" | "material.principled" | "material.glass" | "material.emission" | "material.procedural" | "material.procedural.uv" | "material.anisotropy" | "animation.transform" | "animation.material" | "recipe.geometry-bindings">; }; "input": { "path": "scene-spec.json"; "sha256": string; }; "preview": { "path": "preview.png"; "sha256": string; "mediaType": "image/png"; "alt": string; }; "parameters": Array<(RecipeSchema.ColorParameter) | (RecipeSchema.NumberParameter)>; };
|
|
81
|
+
export type Document = { "schemaVersion": "deepblend.recipe/v1"; "id": string; "version": string; "title": string; "description": string; "author": { "name": string; "url"?: string; }; "license": string; "source": { "url": string; "note"?: string; }; "compatibility": { "sceneSchemaVersion": "deepblend.scene/v1"; "capabilities": Array<"geometry.primitive" | "geometry.primitive.dimensions" | "geometry.lathe" | "geometry.curve" | "geometry.handled_cup" | "geometry.handled_cup.tension" | "geometry.handled_cup.tension.extended" | "geometry.modifiers" | "material.principled" | "material.glass" | "material.emission" | "material.procedural" | "material.procedural.uv" | "material.anisotropy" | "animation.transform" | "animation.material" | "recipe.geometry-bindings" | "recipe.generator-bindings">; }; "input": { "path": "scene-spec.json"; "sha256": string; }; "preview": { "path": "preview.png"; "sha256": string; "mediaType": "image/png"; "alt": string; }; "parameters": Array<(RecipeSchema.ColorParameter) | (RecipeSchema.NumberParameter)>; };
|
|
82
82
|
}
|
|
83
83
|
export type RecipeManifest = RecipeSchema.Document;
|
|
84
84
|
export type Entity = SceneSpecSchema.Entity;
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"capabilities": {
|
|
98
98
|
"type": "array",
|
|
99
99
|
"minItems": 1,
|
|
100
|
-
"maxItems":
|
|
100
|
+
"maxItems": 18,
|
|
101
101
|
"items": {
|
|
102
102
|
"enum": [
|
|
103
103
|
"geometry.primitive",
|
|
@@ -116,7 +116,8 @@
|
|
|
116
116
|
"material.anisotropy",
|
|
117
117
|
"animation.transform",
|
|
118
118
|
"animation.material",
|
|
119
|
-
"recipe.geometry-bindings"
|
|
119
|
+
"recipe.geometry-bindings",
|
|
120
|
+
"recipe.generator-bindings"
|
|
120
121
|
]
|
|
121
122
|
}
|
|
122
123
|
}
|
|
@@ -312,6 +313,43 @@
|
|
|
312
313
|
}
|
|
313
314
|
},
|
|
314
315
|
"description": "Apply a bounded parameter delta to an explicit camera position or aim point; animated camera channels are refused."
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
"type": "object",
|
|
319
|
+
"additionalProperties": false,
|
|
320
|
+
"required": [
|
|
321
|
+
"kind",
|
|
322
|
+
"entityId",
|
|
323
|
+
"property",
|
|
324
|
+
"multiplier"
|
|
325
|
+
],
|
|
326
|
+
"properties": {
|
|
327
|
+
"kind": {
|
|
328
|
+
"const": "generator"
|
|
329
|
+
},
|
|
330
|
+
"entityId": {
|
|
331
|
+
"type": "string",
|
|
332
|
+
"pattern": "^[a-zA-Z][a-zA-Z0-9._-]{0,63}$"
|
|
333
|
+
},
|
|
334
|
+
"property": {
|
|
335
|
+
"enum": [
|
|
336
|
+
"height",
|
|
337
|
+
"radius",
|
|
338
|
+
"wallThickness",
|
|
339
|
+
"handleLower",
|
|
340
|
+
"handleUpper",
|
|
341
|
+
"handleRadius",
|
|
342
|
+
"rootRadius",
|
|
343
|
+
"rootLength"
|
|
344
|
+
]
|
|
345
|
+
},
|
|
346
|
+
"multiplier": {
|
|
347
|
+
"type": "number",
|
|
348
|
+
"minimum": -1000,
|
|
349
|
+
"maximum": 1000
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
"description": "Apply a bounded scalar delta to an explicit handled_cup generator dimension, preserving unbound generator properties."
|
|
315
353
|
}
|
|
316
354
|
]
|
|
317
355
|
},
|