@deepblend/dsh-blender-contracts 0.8.0 → 0.9.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/geometry-inspection.js +50 -0
- package/lib/index.js +2 -0
- package/lib/lamp-assembly-repair.js +18 -0
- package/lib/recipe-parameters.js +28 -13
- package/lib/recipe.js +19 -12
- package/lib/runtime-types.d.ts +15 -0
- package/lib/schema-types.d.ts +3 -3
- package/lib/schemas/recipe.schema.json +51 -2
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BlenderError, BlenderErrorCode } from './index.js'
|
|
2
|
+
|
|
3
|
+
export const GEOMETRY_INSPECTION_VERSION = 'deepblend.geometry-inspection/v1'
|
|
4
|
+
export const GEOMETRY_INSPECTION_LIMITS = Object.freeze({ entities: 8, checkpointBytes: 1024 ** 3, reportBytes: 64 * 1024 })
|
|
5
|
+
|
|
6
|
+
function refuse(message) {
|
|
7
|
+
throw new BlenderError(BlenderErrorCode.SCRIPT_ERROR, `Geometry inspection: ${message}`)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function validateGeometrySelection(request) {
|
|
11
|
+
if (!Array.isArray(request?.entityIds) || request.entityIds.length < 1 || request.entityIds.length > GEOMETRY_INSPECTION_LIMITS.entities ||
|
|
12
|
+
request.entityIds.some(id => typeof id !== 'string' || !id || id.trim() !== id || id.length > 128 || id.includes('\0')) ||
|
|
13
|
+
new Set(request.entityIds).size !== request.entityIds.length) refuse('select 1–8 distinct non-empty entity IDs.')
|
|
14
|
+
if (!Number.isSafeInteger(request.frame) || request.frame < 0 || request.frame > 1_000_000) refuse('an explicit integer frame from 0 to 1000000 is required.')
|
|
15
|
+
if (typeof request.checkpointSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(request.checkpointSha256)) refuse('the expected checkpoint SHA256 is required.')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Verify measured values rather than trusting a successful process exit. */
|
|
19
|
+
export function verifyGeometryReport(report, request) {
|
|
20
|
+
validateGeometrySelection(request)
|
|
21
|
+
const allowed = (value, keys) => value && typeof value === 'object' && Object.keys(value).every(key => keys.includes(key))
|
|
22
|
+
if (!report || Buffer.byteLength(JSON.stringify(report)) > GEOMETRY_INSPECTION_LIMITS.reportBytes ||
|
|
23
|
+
report.schemaVersion !== GEOMETRY_INSPECTION_VERSION || report.checkpointSha256 !== request.checkpointSha256 ||
|
|
24
|
+
report.frame !== request.frame || report.checkpointUnchanged !== true ||
|
|
25
|
+
typeof report.blenderVersion !== 'string' || !report.blenderVersion ||
|
|
26
|
+
!Array.isArray(report.objects) || report.objects.length !== request.entityIds.length ||
|
|
27
|
+
!allowed(report, ['schemaVersion', 'checkpointSha256', 'checkpointUnchanged', 'frame', 'blenderVersion', 'objects'])) refuse('the report does not match the requested source, frame or selection.')
|
|
28
|
+
const vector = (v, length) => Array.isArray(v) && v.length === length && v.every(Number.isFinite)
|
|
29
|
+
for (const [index, object] of report.objects.entries()) {
|
|
30
|
+
if (object?.entityId !== request.entityIds[index] || typeof object.type !== 'string' || !object.type) refuse('object identity differs from the selection.')
|
|
31
|
+
const keys = object.available === false ? ['entityId', 'type', 'available', 'unavailableReason'] :
|
|
32
|
+
['entityId', 'type', 'available', 'worldBoundsMeters', 'worldAxisExtentMm', 'worldMatrix', 'scale', 'vertexCount', 'polygonCount']
|
|
33
|
+
if (!allowed(object, keys)) refuse('unsupported measurement fields are not accepted; this protocol does not establish wall thickness or clearance.')
|
|
34
|
+
if (object.available === false) {
|
|
35
|
+
if (!['viewport-disabled', 'not-mesh', 'empty-or-invalid-geometry'].includes(object.unavailableReason) ||
|
|
36
|
+
['worldBoundsMeters', 'worldAxisExtentMm', 'worldMatrix', 'vertexCount', 'polygonCount', 'scale'].some(k => Object.hasOwn(object, k))) refuse('an unavailable object must not contain measurements.')
|
|
37
|
+
continue
|
|
38
|
+
}
|
|
39
|
+
if (object.available !== true || object.type !== 'MESH' || !allowed(object.worldBoundsMeters, ['min', 'max']) || !vector(object.worldBoundsMeters?.min, 3) ||
|
|
40
|
+
!vector(object.worldBoundsMeters?.max, 3) || !vector(object.worldAxisExtentMm, 3) || !vector(object.scale, 3) ||
|
|
41
|
+
!Array.isArray(object.worldMatrix) || object.worldMatrix.length !== 4 || !object.worldMatrix.every(row => vector(row, 4)) ||
|
|
42
|
+
!Number.isSafeInteger(object.vertexCount) || object.vertexCount <= 0 ||
|
|
43
|
+
!Number.isSafeInteger(object.polygonCount) || object.polygonCount < 0) refuse('a measured object contains invalid or non-finite geometry facts.')
|
|
44
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
45
|
+
const extent = (object.worldBoundsMeters.max[axis] - object.worldBoundsMeters.min[axis]) * 1000
|
|
46
|
+
if (extent < 0 || Math.abs(extent - object.worldAxisExtentMm[axis]) > Math.max(1e-6, Math.abs(extent) * 1e-9)) refuse('axis extents disagree with the measured world bounds.')
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return report
|
|
50
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -879,3 +879,5 @@ export {
|
|
|
879
879
|
|
|
880
880
|
export { RECIPE_SCHEMA_VERSION, RECIPE_CAPABILITIES, RECIPE_LIMITS, RecipeError, recipeCapabilitiesForScene, validateRecipeManifest, validateRecipePackage, instantiateRecipe, instantiateRecipeLock } from './recipe.js'
|
|
881
881
|
export { planRecipeGeometryEdit, recipeGeometryParameters } from './recipe-parameters.js'
|
|
882
|
+
|
|
883
|
+
export { GEOMETRY_INSPECTION_VERSION, GEOMETRY_INSPECTION_LIMITS, validateGeometrySelection, verifyGeometryReport } from './geometry-inspection.js'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Pinned compatibility repair for the shipped 2.1 lamp; never substitute catalog state. */
|
|
2
|
+
import { sha256Canonical } from './canonical.js'
|
|
3
|
+
import { RecipeError } from './recipe.js'
|
|
4
|
+
const legacyHash = "522b40602bb77b7934876467ea1eae1c4076092d69b30ca156209d14a0e6db3d"
|
|
5
|
+
export const lampAssemblyBindings = [{"kind": "entity", "entityId": "mast-socket", "property": "location", "axis": "x", "multiplier": -0.00055, "inputFloor": 230}, {"kind": "entity", "entityId": "mast-socket-collar", "property": "location", "axis": "x", "multiplier": -0.00055, "inputFloor": 230}, {"kind": "entity", "entityId": "upright-mast", "property": "location", "axis": "x", "multiplier": -0.00055, "inputFloor": 230}, {"kind": "entity", "entityId": "hinge-body", "property": "location", "axis": "x", "multiplier": -0.00055, "inputFloor": 230}, {"kind": "entity", "entityId": "hinge-front-cap", "property": "location", "axis": "x", "multiplier": -0.00055, "inputFloor": 230}, {"kind": "entity", "entityId": "hinge-rear-cap", "property": "location", "axis": "x", "multiplier": -0.00055, "inputFloor": 230}, {"kind": "entity", "entityId": "hinge-fine-ring", "property": "location", "axis": "x", "multiplier": -0.00055, "inputFloor": 230}, {"kind": "entity", "entityId": "hinge-centre-pin", "property": "location", "axis": "x", "multiplier": -0.00055, "inputFloor": 230}, {"kind": "curve-point", "entityId": "swept-upper-arm", "pointIndex": 0, "axis": "x", "multiplier": -0.00055, "inputFloor": 230}, {"kind": "curve-point", "entityId": "swept-upper-arm", "pointIndex": 1, "axis": "x", "multiplier": -0.00055, "inputFloor": 230}, {"kind": "curve-point", "entityId": "swept-upper-arm", "pointIndex": 2, "axis": "x", "multiplier": -0.000275, "inputFloor": 230}]
|
|
6
|
+
export function legacyLampAssembly(lock, state) {
|
|
7
|
+
const matches = lock.manifestSha256 === legacyHash
|
|
8
|
+
if (state?.assemblyRepair !== undefined && (!matches || state.assemblyRepair !== 'metal-lamp-clearance/v1')) {
|
|
9
|
+
throw new RecipeError('RECIPE_LOCK_INVALID', 'Unknown or mismatched saved assembly repair')
|
|
10
|
+
}
|
|
11
|
+
if (!matches) return null
|
|
12
|
+
const manifest = structuredClone(lock.manifest)
|
|
13
|
+
manifest.compatibility.capabilities.push('recipe.curve-point-bindings', 'recipe.threshold-bindings')
|
|
14
|
+
manifest.parameters.find(p => p.id === 'shade-diameter-mm').bindings.push(...structuredClone(lampAssemblyBindings))
|
|
15
|
+
const manifestHash = sha256Canonical(manifest)
|
|
16
|
+
return { manifest, currentLock: current => ({ ...current, manifest,
|
|
17
|
+
manifestSha256: manifestHash, packageDigest: manifestHash }) }
|
|
18
|
+
}
|
package/lib/recipe-parameters.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/** Plan existing-assembly edits as ordinary, bounded ScenePatch operations. */
|
|
2
|
+
import { legacyLampAssembly } from './lamp-assembly-repair.js'
|
|
2
3
|
import { latheShellTargets } from './lathe-shell.js'
|
|
3
4
|
import { canonicalStringify, sha256Canonical } from './canonical.js'
|
|
4
5
|
import { instantiateRecipeLock, RecipeError } from './recipe.js'
|
|
5
6
|
import { validateSceneSpec } from './scene-spec.js'
|
|
6
7
|
|
|
7
8
|
const axisOf = binding => ['x', 'y', 'z'].indexOf(binding.axis)
|
|
8
|
-
const structural = parameter => parameter.bindings.some(binding => ['entity', 'generator', 'lathe-shell'].includes(binding.kind))
|
|
9
|
-
&& parameter.bindings.every(binding => ['entity', 'camera', 'generator', 'lathe-shell'].includes(binding.kind))
|
|
9
|
+
const structural = parameter => parameter.bindings.some(binding => ['entity', 'generator', 'lathe-shell', 'curve-point'].includes(binding.kind))
|
|
10
|
+
&& parameter.bindings.every(binding => ['entity', 'camera', 'generator', 'lathe-shell', 'curve-point'].includes(binding.kind))
|
|
10
11
|
const entity = (spec, id) => spec.entities.find(item => item.id === id)
|
|
11
12
|
const vector = (target, property) => property === 'dimensions' ? target?.generator?.dimensions
|
|
12
13
|
: property === 'targetPoint' ? target?.targetPoint : target?.transform?.location
|
|
@@ -33,9 +34,11 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
|
|
|
33
34
|
}
|
|
34
35
|
currentLock = { ...lock, values: parameterState.values, valuesSha256: parameterState.valuesSha256 }
|
|
35
36
|
}
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
37
|
+
const savedBefore = parameterState === undefined ? origin : instantiateRecipeLock(currentLock)
|
|
38
|
+
const assembly = legacyLampAssembly(lock, parameterState)
|
|
39
|
+
const before = assembly && parameterState?.assemblyRepair ? instantiateRecipeLock(assembly.currentLock(currentLock)) : savedBefore
|
|
40
|
+
const after = instantiateRecipeLock(assembly ? assembly.currentLock(currentLock) : currentLock, changes)
|
|
41
|
+
const parameters = recipeGeometryParameters(assembly?.manifest ?? lock.manifest)
|
|
39
42
|
for (const id of Object.keys(changes)) {
|
|
40
43
|
if (!parameters.some(parameter => parameter.id === id)) {
|
|
41
44
|
throw new RecipeError('RECIPE_PARAMETER_INVALID', `Parameter ${id} is not an assembly geometry control`)
|
|
@@ -43,24 +46,29 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
|
|
|
43
46
|
}
|
|
44
47
|
const conflicts = []
|
|
45
48
|
for (const parameter of parameters) for (const binding of targets(parameter)) {
|
|
46
|
-
if (!['entity', 'generator'].includes(binding.kind)) continue
|
|
49
|
+
if (!['entity', 'generator', 'curve-point'].includes(binding.kind)) continue
|
|
47
50
|
const oldEntity = entity(before.spec, binding.entityId), currentEntity = entity(currentSpec, binding.entityId)
|
|
48
|
-
const expected = binding.kind === 'generator' ? oldEntity?.generator?.[binding.property]
|
|
51
|
+
const expected = binding.kind === 'curve-point' ? oldEntity?.generator?.path?.[binding.pointIndex]?.[axisOf(binding)] : binding.kind === 'generator' ? oldEntity?.generator?.[binding.property]
|
|
49
52
|
: vector(oldEntity, binding.property)?.[axisOf(binding)]
|
|
50
|
-
const actual = binding.kind === 'generator' ? currentEntity?.generator?.[binding.property]
|
|
53
|
+
const actual = binding.kind === 'curve-point' ? currentEntity?.generator?.path?.[binding.pointIndex]?.[axisOf(binding)] : binding.kind === 'generator' ? currentEntity?.generator?.[binding.property]
|
|
51
54
|
: vector(currentEntity, binding.property)?.[axisOf(binding)]
|
|
52
55
|
if (!close(actual, expected)) conflicts.push({ parameterId: parameter.id, entityId: binding.entityId,
|
|
53
|
-
property: binding.property, axis: binding.axis, expected, actual })
|
|
54
|
-
if (binding.kind
|
|
56
|
+
property: binding.kind === 'curve-point' ? `path.${binding.pointIndex}` : binding.property, axis: binding.axis, expected, actual })
|
|
57
|
+
if (['generator', 'curve-point'].includes(binding.kind) && currentEntity?.generator?.shape !== oldEntity?.generator?.shape) {
|
|
55
58
|
conflicts.push({ parameterId: parameter.id, entityId: binding.entityId, property: 'shape',
|
|
56
59
|
expected: oldEntity?.generator?.shape, actual: currentEntity?.generator?.shape })
|
|
57
60
|
}
|
|
61
|
+
if (binding.kind === 'curve-point' && (canonicalStringify(currentEntity?.transform) !== canonicalStringify(oldEntity?.transform)
|
|
62
|
+
|| !close(currentEntity?.generator?.path, oldEntity?.generator?.path))) {
|
|
63
|
+
conflicts.push({ parameterId: parameter.id, entityId: binding.entityId, property: 'curve-alignment',
|
|
64
|
+
expected: oldEntity?.generator?.path, actual: currentEntity?.generator?.path })
|
|
65
|
+
}
|
|
58
66
|
if (binding.latheShell && (canonicalStringify(currentEntity?.transform) !== canonicalStringify(oldEntity?.transform)
|
|
59
67
|
|| currentEntity?.generator?.closedProfile !== oldEntity?.generator?.closedProfile)) {
|
|
60
68
|
conflicts.push({ parameterId: parameter.id, entityId: binding.entityId,
|
|
61
69
|
property: 'shell-alignment', expected: oldEntity?.transform, actual: currentEntity?.transform })
|
|
62
70
|
}
|
|
63
|
-
if (binding.property === 'dimensions' || binding.kind
|
|
71
|
+
if (binding.property === 'dimensions' || ['generator', 'curve-point'].includes(binding.kind)) {
|
|
64
72
|
const oldScale = oldEntity?.transform?.scale ?? [1, 1, 1]
|
|
65
73
|
const scale = currentEntity?.transform?.scale ?? [1, 1, 1]
|
|
66
74
|
if (!scale?.every((value, axis) => close(value, oldScale[axis]))) {
|
|
@@ -72,7 +80,8 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
|
|
|
72
80
|
if (conflicts.length) throw new RecipeError('RECIPE_PARAMETER_CONFLICT',
|
|
73
81
|
'Recipe-controlled geometry was independently edited; resolve these fields before resizing', { conflicts })
|
|
74
82
|
|
|
75
|
-
const changed = parameters.filter(parameter => before.values[parameter.id] !== after.values[parameter.id]
|
|
83
|
+
const changed = parameters.filter(parameter => before.values[parameter.id] !== after.values[parameter.id]
|
|
84
|
+
|| assembly && !parameterState?.assemblyRepair && Object.keys(changes).includes(parameter.id))
|
|
76
85
|
const generators = new Map(), locations = new Map(), cameras = new Map(), tracks = new Map(), animationOffsets = new Map()
|
|
77
86
|
const protectedCameras = new Set()
|
|
78
87
|
for (const parameter of changed) for (const binding of targets(parameter)) {
|
|
@@ -92,13 +101,18 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
|
|
|
92
101
|
continue
|
|
93
102
|
}
|
|
94
103
|
const actual = entity(currentSpec, binding.entityId), target = entity(after.spec, binding.entityId)
|
|
95
|
-
if (binding.kind === '
|
|
104
|
+
if (binding.kind === 'curve-point') {
|
|
105
|
+
if (close(actual.generator.path[binding.pointIndex][axis], target.generator.path[binding.pointIndex][axis])) continue
|
|
106
|
+
if (!generators.has(actual.id)) generators.set(actual.id, structuredClone(actual.generator))
|
|
107
|
+
generators.get(actual.id).path[binding.pointIndex][axis] = target.generator.path[binding.pointIndex][axis]
|
|
108
|
+
} else if (binding.kind === 'generator') {
|
|
96
109
|
if (!generators.has(actual.id)) generators.set(actual.id, structuredClone(actual.generator))
|
|
97
110
|
generators.get(actual.id)[binding.property] = target.generator[binding.property]
|
|
98
111
|
} else if (binding.property === 'dimensions') {
|
|
99
112
|
if (!generators.has(actual.id)) generators.set(actual.id, structuredClone(actual.generator))
|
|
100
113
|
generators.get(actual.id).dimensions[axis] = target.generator.dimensions[axis]
|
|
101
114
|
} else {
|
|
115
|
+
if (close(actual.transform.location[axis], target.transform.location[axis])) continue
|
|
102
116
|
if (!locations.has(actual.id)) locations.set(actual.id, structuredClone(actual.transform.location))
|
|
103
117
|
const delta = target.transform.location[axis] - entity(before.spec, actual.id).transform.location[axis]
|
|
104
118
|
locations.get(actual.id)[axis] = target.transform.location[axis]
|
|
@@ -122,6 +136,7 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
|
|
|
122
136
|
return { operations, changedParameters: changed.map(parameter => parameter.id),
|
|
123
137
|
preservedCameraIds: [...protectedCameras], parameterState: {
|
|
124
138
|
schemaVersion: 'deepblend.recipe-parameters/v1', manifestSha256: lock.manifestSha256,
|
|
139
|
+
...(assembly ? { assemblyRepair: 'metal-lamp-clearance/v1' } : {}),
|
|
125
140
|
values: after.values, valuesSha256: sha256Canonical(after.values),
|
|
126
141
|
} }
|
|
127
142
|
}
|
package/lib/recipe.js
CHANGED
|
@@ -15,6 +15,8 @@ export const RECIPE_CAPABILITIES = Object.freeze([
|
|
|
15
15
|
'recipe.geometry-bindings',
|
|
16
16
|
'recipe.generator-bindings',
|
|
17
17
|
'recipe.lathe-shell-bindings',
|
|
18
|
+
'recipe.curve-point-bindings',
|
|
19
|
+
'recipe.threshold-bindings',
|
|
18
20
|
])
|
|
19
21
|
export const RECIPE_LIMITS = Object.freeze({ sceneBytes: 2 * 1024 * 1024, previewBytes: 4 * 1024 * 1024, previewPixels: 4 * 1024 * 1024 })
|
|
20
22
|
const structural = compileSchema(recipeSchema, { id: 'recipe.schema.json' })
|
|
@@ -26,7 +28,9 @@ const result = (errors, extra = {}) => ({ ok: errors.length === 0, errors, notic
|
|
|
26
28
|
summary: errors.length ? errors.map(error => `${error.path}: ${error.message}`).join('; ') : 'Recipe valid', ...extra })
|
|
27
29
|
const bindingAxis = binding => ['x', 'y', 'z'].indexOf(binding.axis)
|
|
28
30
|
const bindingTarget = (spec, binding) => binding.kind === 'camera' ? spec.cameras?.find(item => item.id === binding.cameraId) : spec.entities.find(item => item.id === binding.entityId)
|
|
29
|
-
const
|
|
31
|
+
const bindingDelta = (value, parameter, binding) => ((binding.inputFloor === undefined ? value : Math.max(value, binding.inputFloor))
|
|
32
|
+
- (binding.inputFloor === undefined ? parameter.default : Math.max(parameter.default, binding.inputFloor))) * binding.multiplier
|
|
33
|
+
const bindingVector = (target, binding) => binding.kind === 'curve-point' ? target?.generator?.path?.[binding.pointIndex] : binding.property === 'dimensions' ? target?.generator?.dimensions
|
|
30
34
|
: binding.property === 'targetPoint' ? target?.targetPoint : target?.transform?.location
|
|
31
35
|
const bindingTracks = (spec, binding) => (spec.animationTracks ?? []).filter(track => (track.targetKind ?? 'entity') === binding.kind
|
|
32
36
|
&& track.targetEntityId === (binding.entityId ?? binding.cameraId) && track.property === `location.${binding.axis}`)
|
|
@@ -105,6 +109,7 @@ export function validateRecipeManifest(manifest, options = {}) {
|
|
|
105
109
|
const slots = binding.kind === 'lathe-shell' ? latheShellTargets(binding) : [binding]
|
|
106
110
|
for (const slot of slots) {
|
|
107
111
|
const target = slot.kind === 'material' ? `material:${slot.materialId}:${slot.property}`
|
|
112
|
+
: slot.kind === 'curve-point' ? `curve-point:${slot.entityId}:${slot.pointIndex}.${slot.axis}`
|
|
108
113
|
: slot.kind === 'generator' ? `generator:${slot.entityId}:${slot.property}`
|
|
109
114
|
: ['entity', 'camera'].includes(slot.kind) ? `${slot.kind}:${slot.entityId ?? slot.cameraId}:${slot.property}.${slot.axis}` : `render-profile:${slot.profile}:exposure`
|
|
110
115
|
const prior = targets.get(target)
|
|
@@ -117,11 +122,13 @@ export function validateRecipeManifest(manifest, options = {}) {
|
|
|
117
122
|
const color = binding.kind === 'material' && binding.property === 'baseColor'
|
|
118
123
|
if ((parameter.type === 'color') !== color) errors.push(issue('RECIPE_BINDING_INVALID', path, 'Parameter type does not match the allowlisted property'))
|
|
119
124
|
if (parameter.type === 'number') {
|
|
120
|
-
if (['entity', 'camera', 'generator', 'lathe-shell'].includes(binding.kind)) {
|
|
125
|
+
if (['entity', 'camera', 'generator', 'lathe-shell', 'curve-point'].includes(binding.kind)) {
|
|
121
126
|
if (!Number.isFinite(binding.multiplier) || binding.multiplier === 0) errors.push(issue('RECIPE_BINDING_INVALID', path, 'Entity binding multiplier must be finite and nonzero'))
|
|
122
127
|
if (!declared.has('recipe.geometry-bindings')) errors.push(issue('RECIPE_CAPABILITY_UNDECLARED', path, 'Entity bindings require recipe.geometry-bindings'))
|
|
123
128
|
if (binding.kind === 'generator' && !declared.has('recipe.generator-bindings')) errors.push(issue('RECIPE_CAPABILITY_UNDECLARED', path, 'Generator bindings require recipe.generator-bindings'))
|
|
124
129
|
if (binding.kind === 'lathe-shell' && !declared.has('recipe.lathe-shell-bindings')) errors.push(issue('RECIPE_CAPABILITY_UNDECLARED', path, 'Lathe shell bindings require recipe.lathe-shell-bindings'))
|
|
130
|
+
if (binding.kind === 'curve-point' && !declared.has('recipe.curve-point-bindings')) errors.push(issue('RECIPE_CAPABILITY_UNDECLARED', path, 'Curve points require recipe.curve-point-bindings'))
|
|
131
|
+
if (binding.inputFloor !== undefined && (!declared.has('recipe.threshold-bindings') || binding.inputFloor < parameter.minimum || binding.inputFloor > parameter.maximum)) errors.push(issue('RECIPE_BINDING_INVALID', path, 'A threshold must be declared and inside the parameter range'))
|
|
125
132
|
if (binding.property !== 'location' && binding.offsetAnimation !== undefined) errors.push(issue('RECIPE_BINDING_INVALID', path, 'Animation offsets are only valid on location bindings'))
|
|
126
133
|
continue
|
|
127
134
|
}
|
|
@@ -204,7 +211,7 @@ function bindingsAgainstScene(manifest, spec) {
|
|
|
204
211
|
const original = deformLatheShell(spec, binding, 0)
|
|
205
212
|
const radius = Math.max(...original.shell.map(point => point[0]))
|
|
206
213
|
if (Math.abs(parameter.default * binding.multiplier - radius) > 1e-9) throw new TypeError('Shell parameter default must match the authored outer radius')
|
|
207
|
-
for (const value of [parameter.minimum, parameter.maximum]) deformLatheShell(spec, binding, (value
|
|
214
|
+
for (const value of [parameter.minimum, parameter.maximum]) deformLatheShell(spec, binding, bindingDelta(value, parameter, binding))
|
|
208
215
|
} catch (error) { errors.push(issue('RECIPE_BINDING_INVALID', path, error.message)) }
|
|
209
216
|
} else if (binding.kind === 'generator') {
|
|
210
217
|
const entity = bindingTarget(spec, binding)
|
|
@@ -213,24 +220,24 @@ function bindingsAgainstScene(manifest, spec) {
|
|
|
213
220
|
errors.push(issue('RECIPE_BINDING_INVALID', path, 'Generator binding requires an explicit positive handled_cup scalar'))
|
|
214
221
|
continue
|
|
215
222
|
}
|
|
216
|
-
const ends = [parameter.minimum, parameter.maximum].map(value => current + (value
|
|
223
|
+
const ends = [parameter.minimum, parameter.maximum].map(value => current + bindingDelta(value, parameter, binding))
|
|
217
224
|
if (ends.some(value => !Number.isFinite(value) || value <= 0)) errors.push(issue('RECIPE_BINDING_INVALID', path, 'Generator binding range must remain positive and finite'))
|
|
218
|
-
} else if (['entity', 'camera'].includes(binding.kind)) {
|
|
225
|
+
} else if (['entity', 'camera', 'curve-point'].includes(binding.kind)) {
|
|
219
226
|
const entity = bindingTarget(spec, binding)
|
|
220
227
|
const vector = bindingVector(entity, binding), axis = bindingAxis(binding)
|
|
221
|
-
if (!entity || (binding.property === 'dimensions' && (!['cube', 'rounded_box'].includes(entity.generator?.shape) || entity.generator.size !== undefined))
|
|
228
|
+
if (!entity || (binding.kind === 'curve-point' && entity.generator?.shape !== 'curve') || (binding.property === 'dimensions' && (!['cube', 'rounded_box'].includes(entity.generator?.shape) || entity.generator.size !== undefined))
|
|
222
229
|
|| !Array.isArray(vector) || vector.length !== 3 || !Number.isFinite(vector[axis])) {
|
|
223
230
|
errors.push(issue('RECIPE_BINDING_INVALID', path, 'Structural binding requires an explicit supported dimension, position or aim point'))
|
|
224
231
|
continue
|
|
225
232
|
}
|
|
226
|
-
const ends = [parameter.minimum, parameter.maximum].map(value => vector[axis] + (value
|
|
233
|
+
const ends = [parameter.minimum, parameter.maximum].map(value => vector[axis] + bindingDelta(value, parameter, binding))
|
|
227
234
|
if (ends.some(value => !Number.isFinite(value) || (binding.property === 'dimensions' && value <= 0))) {
|
|
228
235
|
errors.push(issue('RECIPE_BINDING_INVALID', path, 'The entire parameter range must produce finite values and positive dimensions'))
|
|
229
236
|
}
|
|
230
237
|
if (binding.kind === 'camera') {
|
|
231
238
|
const key = `${binding.cameraId}:${binding.property}.${binding.axis}`
|
|
232
239
|
const range = cameraRanges.get(key) ?? [vector[axis], vector[axis]]
|
|
233
|
-
const deltas = [parameter.minimum, parameter.maximum].map(value => (value
|
|
240
|
+
const deltas = [parameter.minimum, parameter.maximum].map(value => bindingDelta(value, parameter, binding))
|
|
234
241
|
range[0] += Math.min(...deltas); range[1] += Math.max(...deltas)
|
|
235
242
|
cameraRanges.set(key, range)
|
|
236
243
|
}
|
|
@@ -238,7 +245,7 @@ function bindingsAgainstScene(manifest, spec) {
|
|
|
238
245
|
const tracks = bindingTracks(spec, binding)
|
|
239
246
|
if (tracks.length && binding.offsetAnimation !== true) errors.push(issue('RECIPE_BINDING_INVALID', path, 'An animated location requires an explicit animation offset'))
|
|
240
247
|
if (binding.offsetAnimation === true && tracks.some(track => track.keyframes.some(keyframe => [parameter.minimum, parameter.maximum]
|
|
241
|
-
.some(value => !Number.isFinite(keyframe.value + (value
|
|
248
|
+
.some(value => !Number.isFinite(keyframe.value + bindingDelta(value, parameter, binding)))))) {
|
|
242
249
|
errors.push(issue('RECIPE_BINDING_INVALID', path, 'Animation offsets must remain finite throughout the parameter range'))
|
|
243
250
|
}
|
|
244
251
|
}
|
|
@@ -356,16 +363,16 @@ function resolveRecipe(manifest, checked, values) {
|
|
|
356
363
|
material.parameters[binding.property] = parameter.type === 'color'
|
|
357
364
|
? [...value, material.parameters.baseColor[3] ?? 1] : value
|
|
358
365
|
} else if (binding.kind === 'lathe-shell') {
|
|
359
|
-
const profiles = deformLatheShell(checked.sceneSpec, binding, (value
|
|
366
|
+
const profiles = deformLatheShell(checked.sceneSpec, binding, bindingDelta(value, parameter, binding))
|
|
360
367
|
spec.entities.find(entity => entity.id === binding.entityId).generator.profile = profiles.shell
|
|
361
368
|
spec.entities.find(entity => entity.id === binding.linerEntityId).generator.profile = profiles.liner
|
|
362
369
|
} else if (binding.kind === 'generator') {
|
|
363
370
|
bindingTarget(spec, binding).generator[binding.property] += (resolvedValues[parameter.id] - parameter.default) * binding.multiplier
|
|
364
|
-
} else if (['entity', 'camera'].includes(binding.kind)) {
|
|
371
|
+
} else if (['entity', 'camera', 'curve-point'].includes(binding.kind)) {
|
|
365
372
|
const vector = bindingVector(bindingTarget(spec, binding), binding)
|
|
366
373
|
// Preserve the input's exact default bytes and avoid cumulative edits.
|
|
367
374
|
if (value !== parameter.default) {
|
|
368
|
-
const delta = (value
|
|
375
|
+
const delta = bindingDelta(value, parameter, binding)
|
|
369
376
|
vector[bindingAxis(binding)] += delta
|
|
370
377
|
if (binding.offsetAnimation === true) for (const track of bindingTracks(spec, binding)) for (const keyframe of track.keyframes) keyframe.value += delta
|
|
371
378
|
}
|
package/lib/runtime-types.d.ts
CHANGED
|
@@ -81,6 +81,19 @@ export interface CompileSceneRequest extends RuntimeOptions {
|
|
|
81
81
|
onWorkingDirectory?: WorkingDirectoryCallback<CompileReport>;
|
|
82
82
|
}
|
|
83
83
|
export interface RenderOverrides { engine?: EngineKey; width?: number; height?: number; samples?: number }
|
|
84
|
+
/** Optional native inspection. Bounds are world-axis extents, not wall thickness or intrinsic dimensions. */
|
|
85
|
+
export interface GeometryInspectionRequest extends RuntimeOptions {
|
|
86
|
+
checkpointPath: string; checkpointSha256: string; entityIds: string[]; frame: number; jobId?: string;
|
|
87
|
+
}
|
|
88
|
+
export type GeometryInspectionObject = { entityId: string; type: string } & (
|
|
89
|
+
{ available: false; unavailableReason: 'viewport-disabled' | 'not-mesh' | 'empty-or-invalid-geometry' } |
|
|
90
|
+
{ available: true; worldBoundsMeters: { min: Vec3; max: Vec3 }; worldAxisExtentMm: Vec3;
|
|
91
|
+
worldMatrix: number[][]; scale: Vec3; vertexCount: number; polygonCount: number }
|
|
92
|
+
);
|
|
93
|
+
export interface GeometryInspectionReport {
|
|
94
|
+
schemaVersion: 'deepblend.geometry-inspection/v1'; checkpointSha256: string; checkpointUnchanged: true;
|
|
95
|
+
frame: number; blenderVersion: string; objects: GeometryInspectionObject[];
|
|
96
|
+
}
|
|
84
97
|
export interface RenderPreviewRequest extends RuntimeOptions, RenderOverrides {
|
|
85
98
|
checkpointPath: string; outputPath: string; cameraId?: string; frame?: number; jobId?: string;
|
|
86
99
|
session?: boolean;
|
|
@@ -202,6 +215,8 @@ export interface BlenderSession {
|
|
|
202
215
|
}
|
|
203
216
|
/** Optional local transport extensions. Remote runtimes need only implement BlenderRuntime. */
|
|
204
217
|
export interface LocalBlenderRuntime extends BlenderRuntime {
|
|
218
|
+
/** Optional native inspection extension; absent on older providers. Always uses an isolated batch. */
|
|
219
|
+
inspectGeometry?(request: GeometryInspectionRequest): Promise<RuntimeActionResult<GeometryInspectionReport>>;
|
|
205
220
|
runBootstrap(request: BlenderBootstrapRequest, options?: BootstrapOptions): Promise<BootstrapRunOutcome>;
|
|
206
221
|
openSession(options?: RuntimeOptions & { cwd?: string; args?: string[] }): Promise<BlenderSession>;
|
|
207
222
|
attachSession(socketPath: string, options?: { timeoutMs?: number }): Promise<BlenderSession>;
|
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: 45fa82b8cdab30e93ae35c1f8e3bfd6fdb0cc3647c3847365ebf87704d1312c3 */
|
|
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; }) | ({ "kind": "generator"; "entityId": string; "property": "height" | "radius" | "wallThickness" | "handleLower" | "handleUpper" | "handleRadius" | "rootRadius" | "rootLength"; "multiplier": number; }) | ({ "kind": "lathe-shell"; "entityId": string; "linerEntityId": string; "outerPointCount": number; "linerStart": number; "linerPointCount": number; "rimHeight": number; "neckAnchorHeight": number; "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; "inputFloor"?: number; }) | ({ "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; }) | ({ "kind": "lathe-shell"; "entityId": string; "linerEntityId": string; "outerPointCount": number; "linerStart": number; "linerPointCount": number; "rimHeight": number; "neckAnchorHeight": number; "multiplier": number; }) | ({ "kind": "curve-point"; "entityId": string; "pointIndex": number; "axis": "x" | "y" | "z"; "multiplier": number; "inputFloor"?: 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" | "recipe.generator-bindings" | "recipe.lathe-shell-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" | "recipe.lathe-shell-bindings" | "recipe.curve-point-bindings" | "recipe.threshold-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": 21,
|
|
101
101
|
"items": {
|
|
102
102
|
"enum": [
|
|
103
103
|
"geometry.primitive",
|
|
@@ -118,7 +118,9 @@
|
|
|
118
118
|
"animation.material",
|
|
119
119
|
"recipe.geometry-bindings",
|
|
120
120
|
"recipe.generator-bindings",
|
|
121
|
-
"recipe.lathe-shell-bindings"
|
|
121
|
+
"recipe.lathe-shell-bindings",
|
|
122
|
+
"recipe.curve-point-bindings",
|
|
123
|
+
"recipe.threshold-bindings"
|
|
122
124
|
]
|
|
123
125
|
}
|
|
124
126
|
}
|
|
@@ -273,6 +275,11 @@
|
|
|
273
275
|
"offsetAnimation": {
|
|
274
276
|
"type": "boolean",
|
|
275
277
|
"description": "Explicitly translate keyframe values on the bound location axis by the same delta, preserving the motion. Only valid for location bindings."
|
|
278
|
+
},
|
|
279
|
+
"inputFloor": {
|
|
280
|
+
"type": "number",
|
|
281
|
+
"minimum": -1000000,
|
|
282
|
+
"maximum": 1000000
|
|
276
283
|
}
|
|
277
284
|
}
|
|
278
285
|
},
|
|
@@ -410,6 +417,48 @@
|
|
|
410
417
|
}
|
|
411
418
|
},
|
|
412
419
|
"description": "Bounded paired shell and liner profile expansion with fixed neck. Correspondence is authored data, not code."
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
"type": "object",
|
|
423
|
+
"additionalProperties": false,
|
|
424
|
+
"required": [
|
|
425
|
+
"kind",
|
|
426
|
+
"entityId",
|
|
427
|
+
"pointIndex",
|
|
428
|
+
"axis",
|
|
429
|
+
"multiplier"
|
|
430
|
+
],
|
|
431
|
+
"properties": {
|
|
432
|
+
"kind": {
|
|
433
|
+
"const": "curve-point"
|
|
434
|
+
},
|
|
435
|
+
"entityId": {
|
|
436
|
+
"type": "string",
|
|
437
|
+
"pattern": "^[a-zA-Z][a-zA-Z0-9._-]{0,63}$"
|
|
438
|
+
},
|
|
439
|
+
"pointIndex": {
|
|
440
|
+
"type": "integer",
|
|
441
|
+
"minimum": 0,
|
|
442
|
+
"maximum": 127
|
|
443
|
+
},
|
|
444
|
+
"axis": {
|
|
445
|
+
"enum": [
|
|
446
|
+
"x",
|
|
447
|
+
"y",
|
|
448
|
+
"z"
|
|
449
|
+
]
|
|
450
|
+
},
|
|
451
|
+
"multiplier": {
|
|
452
|
+
"type": "number",
|
|
453
|
+
"minimum": -1000,
|
|
454
|
+
"maximum": 1000
|
|
455
|
+
},
|
|
456
|
+
"inputFloor": {
|
|
457
|
+
"type": "number",
|
|
458
|
+
"minimum": -1000000,
|
|
459
|
+
"maximum": 1000000
|
|
460
|
+
}
|
|
461
|
+
}
|
|
413
462
|
}
|
|
414
463
|
]
|
|
415
464
|
},
|