@deepblend/dsh-blender-contracts 0.8.1 → 0.10.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.
@@ -0,0 +1,129 @@
1
+ import { BlenderError, BlenderErrorCode } from './index.js'
2
+
3
+ export const GEOMETRY_INSPECTION_VERSION = 'deepblend.geometry-inspection/v1'
4
+ export const SURFACE_INSPECTION_VERSION = 'deepblend.geometry-inspection/v2'
5
+ export const GEOMETRY_INSPECTION_LIMITS = Object.freeze({ entities: 8, checkpointBytes: 1024 ** 3, reportBytes: 64 * 1024 })
6
+ export const SURFACE_INSPECTION_LIMITS = Object.freeze({ samples: 8, vertices: 250_000, polygons: 250_000,
7
+ searchDistanceMm: 500, chordDistanceMm: 100, separationDistanceMm: 100, epsilonMm: .0001 })
8
+
9
+ function refuse(message) {
10
+ throw new BlenderError(BlenderErrorCode.SCRIPT_ERROR, `Geometry inspection: ${message}`)
11
+ }
12
+
13
+ export function validateGeometrySelection(request) {
14
+ if (!Array.isArray(request?.entityIds) || request.entityIds.length < 1 || request.entityIds.length > GEOMETRY_INSPECTION_LIMITS.entities ||
15
+ request.entityIds.some(id => typeof id !== 'string' || !id || id.trim() !== id || id.length > 128 || id.includes('\0')) ||
16
+ new Set(request.entityIds).size !== request.entityIds.length) refuse('select 1–8 distinct non-empty entity IDs.')
17
+ if (!Number.isSafeInteger(request.frame) || request.frame < 0 || request.frame > 1_000_000) refuse('an explicit integer frame from 0 to 1000000 is required.')
18
+ if (typeof request.checkpointSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(request.checkpointSha256)) refuse('the expected checkpoint SHA256 is required.')
19
+ if (request.surfaceSamples !== undefined) validateSurfaceSelection(request)
20
+ }
21
+
22
+ const vector3 = v => Array.isArray(v) && v.length === 3 && v.every(Number.isFinite)
23
+ const length = v => Math.hypot(...v)
24
+ const subtract = (a, b) => a.map((v, i) => v - b[i])
25
+ const near = (a, b, tolerance = 1e-6) => length(subtract(a, b)) <= tolerance
26
+ const only = (value, keys) => value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).every(k => keys.includes(k))
27
+ const unit = v => v.map(x => x / length(v))
28
+ const unavailable = ['not-mesh', 'viewport-disabled', 'empty-or-invalid-geometry', 'geometry-budget-exceeded', 'unsupported-topology-or-winding']
29
+ const sourceFailures = [...unavailable, 'no-entry', 'entry-not-inward', 'no-opposite-surface', 'exit-not-outward', 'below-resolution']
30
+ const targetFailures = [...unavailable, 'no-target-entry', 'target-not-inward', 'source-surface-before-target', 'below-resolution']
31
+
32
+ export function validateSurfaceSelection(request) {
33
+ const samples = request?.surfaceSamples
34
+ if (!Array.isArray(request?.entityIds)) refuse('surface samples require an explicit entity selection.')
35
+ if (!Array.isArray(samples) || samples.length < 1 || samples.length > SURFACE_INSPECTION_LIMITS.samples ||
36
+ new Set(samples.map(s => s?.sampleId)).size !== samples.length) refuse('select 1–8 distinct surface samples.')
37
+ for (const sample of samples) {
38
+ if (!only(sample, ['sampleId', 'entityId', 'targetEntityId', 'originMeters', 'direction', 'searchDistanceMm']) ||
39
+ typeof sample.sampleId !== 'string' || !/^[a-zA-Z0-9_-]{1,64}$/.test(sample.sampleId) ||
40
+ !request.entityIds.includes(sample.entityId) ||
41
+ (sample.targetEntityId !== undefined && (!request.entityIds.includes(sample.targetEntityId) || sample.targetEntityId === sample.entityId)) ||
42
+ !vector3(sample.originMeters) || sample.originMeters.some(x => Math.abs(x) > 1000) ||
43
+ !vector3(sample.direction) || length(sample.direction) < 1e-12 || length(sample.direction) > 1e6 ||
44
+ !Number.isFinite(sample.searchDistanceMm) || sample.searchDistanceMm < .01 || sample.searchDistanceMm > SURFACE_INSPECTION_LIMITS.searchDistanceMm) {
45
+ refuse('surface samples require selected source/target IDs, finite world seeds/directions and explicit searchDistanceMm from 0.01 to 500; arbitrary fields are refused.')
46
+ }
47
+ }
48
+ }
49
+
50
+ export function verifySurfaceSamples(samples, request, objects) {
51
+ validateSurfaceSelection(request)
52
+ if (!Array.isArray(samples) || samples.length !== request.surfaceSamples.length) refuse('surface sample count differs from the request.')
53
+ const point = v => vector3(v) && v.every(x => Math.abs(x) <= 1001)
54
+ const distance = (a, b, measured, maximum) => Number.isFinite(measured) && measured > 2 * SURFACE_INSPECTION_LIMITS.epsilonMm &&
55
+ measured <= maximum + .001 && Math.abs(length(subtract(a, b)) * 1000 - measured) <= .001
56
+ const along = (a, b, direction, maximum) => {
57
+ const delta = subtract(b, a), projection = delta.reduce((sum, v, i) => sum + v * direction[i], 0)
58
+ return projection >= -1e-6 && projection <= maximum / 1000 + 1e-6 && near(delta, direction.map(x => x * projection))
59
+ }
60
+ for (const [i, result] of samples.entries()) {
61
+ const q = request.surfaceSamples[i]
62
+ if (!result || result.sampleId !== q.sampleId || result.entityId !== q.entityId || result.targetEntityId !== q.targetEntityId ||
63
+ !vector3(result.originMeters) || !near(result.originMeters, q.originMeters, 0) || !vector3(result.direction) ||
64
+ !near(result.direction, unit(q.direction), 1e-6) || result.searchDistanceMm !== q.searchDistanceMm) refuse('surface identity, seed or search distance differs from the request.')
65
+ const base = ['sampleId', 'entityId', 'targetEntityId', 'originMeters', 'direction', 'searchDistanceMm', 'status']
66
+ if (result.status !== 'sampled') {
67
+ const object = objects.find(o => o.entityId === q.entityId)
68
+ if (!sourceFailures.includes(result.status) || !only(result, base) ||
69
+ (object?.available === false && result.status !== object.unavailableReason)) refuse('unavailable surface samples must not contain measurements or contradict object availability.')
70
+ continue
71
+ }
72
+ if (!only(result, [...base, 'entryMeters', 'exitMeters', 'inwardUnitNormal', 'normalSurfaceChordMm', 'gap']) ||
73
+ !point(result.entryMeters) || !point(result.exitMeters) || !vector3(result.inwardUnitNormal) ||
74
+ Math.abs(length(result.inwardUnitNormal) - 1) > 1e-6 ||
75
+ result.inwardUnitNormal.reduce((sum, v, axis) => sum + v * result.direction[axis], 0) <= 1e-6 ||
76
+ !along(q.originMeters, result.entryMeters, result.direction, q.searchDistanceMm) ||
77
+ !along(result.entryMeters, result.exitMeters, result.inwardUnitNormal, SURFACE_INSPECTION_LIMITS.chordDistanceMm) ||
78
+ !distance(result.entryMeters, result.exitMeters, result.normalSurfaceChordMm, SURFACE_INSPECTION_LIMITS.chordDistanceMm) ||
79
+ objects.find(o => o.entityId === q.entityId)?.available !== true) refuse('surface points, normal, distance or source availability disagree.')
80
+ if (q.targetEntityId === undefined) {
81
+ if (Object.hasOwn(result, 'gap')) refuse('an unrequested target separation is not accepted.')
82
+ } else {
83
+ const gap = result.gap
84
+ if (gap?.status === 'sampled') {
85
+ if (!only(gap, ['status', 'targetEntryMeters', 'normalRaySeparationMm']) || !point(gap.targetEntryMeters) ||
86
+ !along(result.exitMeters, gap.targetEntryMeters, result.inwardUnitNormal, SURFACE_INSPECTION_LIMITS.separationDistanceMm) ||
87
+ !distance(result.exitMeters, gap.targetEntryMeters, gap.normalRaySeparationMm, SURFACE_INSPECTION_LIMITS.separationDistanceMm) ||
88
+ objects.find(o => o.entityId === q.targetEntityId)?.available !== true) refuse('target surface points or distance disagree.')
89
+ } else if (!only(gap, ['status']) || !targetFailures.includes(gap.status) ||
90
+ (objects.find(o => o.entityId === q.targetEntityId)?.available === false && gap.status !== objects.find(o => o.entityId === q.targetEntityId).unavailableReason)) refuse('unavailable target separations must not contain measurements or contradict object availability.')
91
+ }
92
+ }
93
+ return samples
94
+ }
95
+
96
+ /** Verify measured values rather than trusting a successful process exit. */
97
+ export function verifyGeometryReport(report, request) {
98
+ validateGeometrySelection(request)
99
+ const allowed = (value, keys) => value && typeof value === 'object' && Object.keys(value).every(key => keys.includes(key))
100
+ if (!report || Buffer.byteLength(JSON.stringify(report)) > GEOMETRY_INSPECTION_LIMITS.reportBytes ||
101
+ report.schemaVersion !== (request.surfaceSamples === undefined ? GEOMETRY_INSPECTION_VERSION : SURFACE_INSPECTION_VERSION) || report.checkpointSha256 !== request.checkpointSha256 ||
102
+ report.frame !== request.frame || report.checkpointUnchanged !== true ||
103
+ typeof report.blenderVersion !== 'string' || !report.blenderVersion ||
104
+ !Array.isArray(report.objects) || report.objects.length !== request.entityIds.length ||
105
+ !allowed(report, ['schemaVersion', 'checkpointSha256', 'checkpointUnchanged', 'frame', 'blenderVersion', 'objects', ...(request.surfaceSamples === undefined ? [] : ['surfaceSamples'])])) refuse('the report does not match the requested source, frame or selection.')
106
+ const vector = (v, length) => Array.isArray(v) && v.length === length && v.every(Number.isFinite)
107
+ for (const [index, object] of report.objects.entries()) {
108
+ if (object?.entityId !== request.entityIds[index] || typeof object.type !== 'string' || !object.type) refuse('object identity differs from the selection.')
109
+ const keys = object.available === false ? ['entityId', 'type', 'available', 'unavailableReason'] :
110
+ ['entityId', 'type', 'available', 'worldBoundsMeters', 'worldAxisExtentMm', 'worldMatrix', 'scale', 'vertexCount', 'polygonCount']
111
+ if (!allowed(object, keys)) refuse('unsupported measurement fields are not accepted; this protocol does not establish wall thickness or clearance.')
112
+ if (object.available === false) {
113
+ if (!['viewport-disabled', 'not-mesh', 'empty-or-invalid-geometry'].includes(object.unavailableReason) ||
114
+ ['worldBoundsMeters', 'worldAxisExtentMm', 'worldMatrix', 'vertexCount', 'polygonCount', 'scale'].some(k => Object.hasOwn(object, k))) refuse('an unavailable object must not contain measurements.')
115
+ continue
116
+ }
117
+ if (object.available !== true || object.type !== 'MESH' || !allowed(object.worldBoundsMeters, ['min', 'max']) || !vector(object.worldBoundsMeters?.min, 3) ||
118
+ !vector(object.worldBoundsMeters?.max, 3) || !vector(object.worldAxisExtentMm, 3) || !vector(object.scale, 3) ||
119
+ !Array.isArray(object.worldMatrix) || object.worldMatrix.length !== 4 || !object.worldMatrix.every(row => vector(row, 4)) ||
120
+ !Number.isSafeInteger(object.vertexCount) || object.vertexCount <= 0 ||
121
+ !Number.isSafeInteger(object.polygonCount) || object.polygonCount < 0) refuse('a measured object contains invalid or non-finite geometry facts.')
122
+ for (let axis = 0; axis < 3; axis++) {
123
+ const extent = (object.worldBoundsMeters.max[axis] - object.worldBoundsMeters.min[axis]) * 1000
124
+ 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.')
125
+ }
126
+ }
127
+ if (request.surfaceSamples !== undefined) verifySurfaceSamples(report.surfaceSamples, request, report.objects)
128
+ return report
129
+ }
package/lib/index.js CHANGED
@@ -879,3 +879,6 @@ 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, SURFACE_INSPECTION_VERSION, SURFACE_INSPECTION_LIMITS,
884
+ validateGeometrySelection, validateSurfaceSelection, verifySurfaceSamples, 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
+ }
@@ -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 before = parameterState === undefined ? origin : instantiateRecipeLock(currentLock)
37
- const after = instantiateRecipeLock(currentLock, changes)
38
- const parameters = recipeGeometryParameters(lock.manifest)
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 === 'generator' && currentEntity?.generator?.shape !== oldEntity?.generator?.shape) {
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 === 'generator') {
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 === 'generator') {
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 bindingVector = (target, binding) => binding.property === 'dimensions' ? target?.generator?.dimensions
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 - parameter.default) * binding.multiplier)
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 - parameter.default) * binding.multiplier)
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 - parameter.default) * binding.multiplier)
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 - parameter.default) * binding.multiplier)
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 - parameter.default) * binding.multiplier))))) {
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 - parameter.default) * binding.multiplier)
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 - parameter.default) * binding.multiplier
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
  }
@@ -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>;
@@ -73,12 +73,12 @@ export namespace ScenePatchSchema {
73
73
  }
74
74
  export type ScenePatch = ScenePatchSchema.Document;
75
75
 
76
- /** Source SHA-256: 1f21c1c38be96020d05dd25b7b861248bf5f0b2dbb7df199dc5bbfa5b4a4f9d6 */
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": 19,
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
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepblend/dsh-blender-contracts",
3
- "version": "0.8.1",
3
+ "version": "0.10.0",
4
4
  "type": "module",
5
5
  "description": "DeepBlend Studio Service Definition, protocol contracts, and stable error codes.",
6
6
  "main": "lib/index.js",