@deepblend/dsh-blender-contracts 0.18.0 → 0.20.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/index.js CHANGED
@@ -891,3 +891,5 @@ export { ASSET_BOUNDS_INSPECTION_VERSION, ASSET_BOUNDS_LIMITS, OBJECT_AXES_INSPE
891
891
  validateGeometrySelection, validateSurfaceSelection, verifySurfaceSamples, verifyGeometryReport } from './geometry-inspection.js'
892
892
  export { SHOT_CAMERA_SELECTION_VERSION, SHOT_CAMERA_SELECTION_LIMITS, buildShotCameraSelection,
893
893
  normalizeShotCameraSelection, shotCameraForFrame } from './shot-render-selection.js'
894
+ export { SURFACE_PLACEMENT_VERSION, SURFACE_PLACEMENT_LIMITS,
895
+ validateSurfacePlacementSelection, verifySurfacePlacementReport } from './surface-placement.js'
@@ -0,0 +1,82 @@
1
+ /** Continue the complete pinned 2.2 lamp after a static translation and upright yaw. */
2
+ import { RecipeError } from './recipe.js'
3
+
4
+ const source = '0d59d5340acc9334fbc9787a51fe1dc66fae39631534d581281770013e59c0b5'
5
+ const near = (a, b) => Array.isArray(a) && Array.isArray(b)
6
+ ? a.length === b.length && a.every((value, index) => near(value, b[index]))
7
+ : Number.isFinite(a) && Number.isFinite(b) && Math.abs(a - b) <= 1e-9
8
+ // SceneSpec uses XYZ Euler radians, so the object matrix is Rz * Ry * Rx.
9
+ const rotation = ([x, y, z]) => {
10
+ const cx = Math.cos(x), sx = Math.sin(x), cy = Math.cos(y), sy = Math.sin(y), cz = Math.cos(z), sz = Math.sin(z)
11
+ return [[cz*cy, cz*sy*sx-sz*cx, cz*sy*cx+sz*sx], [sz*cy, sz*sy*sx+cz*cx, sz*sy*cx-cz*sx], [-sy, cy*sx, cy*cx]]
12
+ }
13
+ const transpose = matrix => matrix[0].map((_, axis) => matrix.map(row => row[axis]))
14
+ const multiply = (matrix, point) => matrix.map(row => row.reduce((sum, value, axis) => sum + value*point[axis], 0))
15
+ const product = (a, b) => a.map(row => transpose(b).map(column => row.reduce((sum, value, axis) => sum + value*column[axis], 0)))
16
+ const transform = entity => ({ location: entity.transform?.location ?? [0, 0, 0],
17
+ rotationEuler: entity.transform?.rotationEuler ?? [0, 0, 0], scale: entity.transform?.scale ?? [1, 1, 1] })
18
+ const refuse = conflicts => {
19
+ throw new RecipeError('RECIPE_PARAMETER_CONFLICT',
20
+ 'Lamp parts must retain one complete, upright, unscaled static placement before resizing', { conflicts })
21
+ }
22
+
23
+ export function placedLampAssembly(lock, current, before, after) {
24
+ if (lock.manifestSha256 !== source) return { before, after }
25
+ current = structuredClone(current)
26
+ const parts = before.spec.entities.filter(entity => entity.id !== 'studio-floor')
27
+ const actualParts = new Map(current.entities.map(entity => [entity.id, entity]))
28
+ // Valid SceneSpecs may omit transform defaults; saved Host revisions include them.
29
+ // Give the existing binding checks the same values we validate without mutating input.
30
+ for (const original of parts) {
31
+ const actual = actualParts.get(original.id)
32
+ if (actual) actual.transform = structuredClone(transform(actual))
33
+ }
34
+ const anchor = parts.find(entity => entity.id === 'weighted-base'), actualAnchor = actualParts.get(anchor.id)
35
+ if (!actualAnchor) refuse([{ entityId: anchor.id, property: 'entity', expected: 'present', actual: 'missing' }])
36
+ const origin = transform(anchor), saved = transform(actualAnchor)
37
+ const matrix = product(rotation(saved.rotationEuler), transpose(rotation(origin.rotationEuler)))
38
+ // A product of rotation matrices is proper. Its Z basis must remain upright.
39
+ if (!near(multiply(matrix, [0, 0, 1]), [0, 0, 1])) {
40
+ refuse([{ entityId: anchor.id, property: 'upright-placement', expected: [0, 0, 1], actual: multiply(matrix, [0, 0, 1]) }])
41
+ }
42
+ // The fixed base absorbs any original rotation pivot as well as XYZ translation.
43
+ const point = location => multiply(matrix, location.map((value, axis) => value - origin.location[axis]))
44
+ .map((value, axis) => value + saved.location[axis])
45
+ const conflicts = []
46
+ for (const original of parts) {
47
+ const actual = actualParts.get(original.id)
48
+ const conflict = (property, expected, value) => conflicts.push({ entityId: original.id, property, expected, actual: value })
49
+ if (!actual) { conflict('entity', 'present', 'missing'); continue }
50
+ if (actual.type !== original.type) conflict('type', original.type, actual.type)
51
+ if (actual.generator?.shape !== original.generator?.shape) conflict('shape', original.generator?.shape, actual.generator?.shape)
52
+ const expected = transform(original), placed = transform(actual)
53
+ if (!near(placed.location, point(expected.location))) conflict('location', point(expected.location), placed.location)
54
+ const expectedRotation = product(matrix, rotation(expected.rotationEuler)), actualRotation = rotation(placed.rotationEuler)
55
+ if (!near(actualRotation, expectedRotation)) conflict('rotation', expectedRotation, actualRotation)
56
+ if (!near(placed.scale, [1, 1, 1])) conflict('scale', [1, 1, 1], placed.scale)
57
+ for (const field of ['armatureId', 'rigidBody', 'cloth', 'softBody', 'fluid']) {
58
+ if (actual[field] !== undefined) conflict(field, 'absent on static lamp parts', actual[field])
59
+ }
60
+ }
61
+ const memberIds = new Set(parts.map(entity => entity.id))
62
+ for (const track of current.animationTracks ?? []) {
63
+ if ((track.targetKind ?? 'entity') === 'entity' && memberIds.has(track.targetEntityId)
64
+ && /^(location|rotationEuler|scale)\.[xyz]$/.test(track.property)) {
65
+ conflicts.push({ entityId: track.targetEntityId, property: 'animated-placement',
66
+ expected: 'static transform', actual: { trackId: track.id, property: track.property } })
67
+ }
68
+ }
69
+ // Known source + invalid assembly must refuse, including unbound parts and no-op requests.
70
+ if (conflicts.length) refuse(conflicts)
71
+ const posedBefore = structuredClone(before), posedAfter = structuredClone(after)
72
+ for (const original of parts) {
73
+ const actual = actualParts.get(original.id)
74
+ // Keep exact saved transforms for the existing shell/path alignment checks.
75
+ posedBefore.spec.entities.find(entity => entity.id === original.id).transform = structuredClone(actual.transform)
76
+ const next = posedAfter.spec.entities.find(entity => entity.id === original.id)
77
+ const location = point(next.transform.location)
78
+ next.transform = { ...structuredClone(actual.transform), location }
79
+ }
80
+ // Generator paths remain local; only object locations use the placement matrix.
81
+ return { current, before: posedBefore, after: posedAfter, rigidPose: true }
82
+ }
@@ -1,6 +1,7 @@
1
1
  /** Plan existing-assembly edits as ordinary, bounded ScenePatch operations. */
2
2
  import { legacyLampAssembly } from './lamp-assembly-repair.js'
3
3
  import { translatedSpeakerAssembly } from './speaker-assembly.js'
4
+ import { placedLampAssembly } from './lamp-placement.js'
4
5
  import { placedCupCameras } from './cup-placement.js'
5
6
  import { latheShellTargets } from './lathe-shell.js'
6
7
  import { canonicalStringify, sha256Canonical } from './canonical.js'
@@ -41,7 +42,9 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
41
42
  const resolvedBefore = assembly && parameterState?.assemblyRepair ? instantiateRecipeLock(assembly.currentLock(currentLock)) : savedBefore
42
43
  const resolvedAfter = instantiateRecipeLock(assembly ? assembly.currentLock(currentLock) : currentLock, changes)
43
44
  const speaker = translatedSpeakerAssembly(lock, currentSpec, resolvedBefore, resolvedAfter)
44
- const cup = placedCupCameras(lock, currentSpec, speaker.before, speaker.after, parameterState)
45
+ const lamp = placedLampAssembly(lock, currentSpec, speaker.before, speaker.after)
46
+ currentSpec = lamp.current ?? currentSpec
47
+ const cup = placedCupCameras(lock, currentSpec, lamp.before, lamp.after, parameterState)
45
48
  const { before, after } = cup
46
49
  const parameters = recipeGeometryParameters(assembly?.manifest ?? lock.manifest)
47
50
  for (const id of Object.keys(changes)) {
@@ -122,9 +125,13 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
122
125
  if (!generators.has(actual.id)) generators.set(actual.id, structuredClone(actual.generator))
123
126
  generators.get(actual.id).dimensions[axis] = target.generator.dimensions[axis]
124
127
  } else {
125
- const axes = speaker.rigidPose ? [0, 1, 2] : [axis]
128
+ const axes = speaker.rigidPose || lamp.rigidPose ? [0, 1, 2] : [axis]
126
129
  for (const movedAxis of axes) {
127
- if (close(actual.transform.location[movedAxis], target.transform.location[movedAxis])) continue
130
+ // Match the lamp recognizer's absolute tolerance, independent of world position.
131
+ const unchanged = lamp.rigidPose
132
+ ? Math.abs(actual.transform.location[movedAxis] - target.transform.location[movedAxis]) <= 1e-9
133
+ : close(actual.transform.location[movedAxis], target.transform.location[movedAxis])
134
+ if (unchanged) continue
128
135
  if (!locations.has(actual.id)) locations.set(actual.id, structuredClone(actual.transform.location))
129
136
  const delta = target.transform.location[movedAxis] - entity(before.spec, actual.id).transform.location[movedAxis]
130
137
  locations.get(actual.id)[movedAxis] = target.transform.location[movedAxis]
@@ -112,6 +112,27 @@ export interface GeometryInspectionReport {
112
112
  objectAxisBasis?: 'evaluated-object-axes-scaled'; surfaceSamples?: unknown[]; checkpointSha256: string; checkpointUnchanged: true;
113
113
  frame: number; blenderVersion: string; objects: GeometryInspectionObject[];
114
114
  }
115
+ /** Read-only world-Z placement over complete evaluated meshes at one explicit frame. */
116
+ export type SurfacePlacementRequest = RuntimeOptions & {
117
+ checkpointPath: string; checkpointSha256: string; subjectEntityId: string; supportEntityId: string;
118
+ frame: number; clearanceMm?: number; jobId?: string;
119
+ } & ({ baselineCheckpointPath: string; baselineCheckpointSha256: string; expectedTranslationMeters: [0, 0, number] }
120
+ | { baselineCheckpointPath?: never; baselineCheckpointSha256?: never; expectedTranslationMeters?: never });
121
+ export interface SurfacePlacementObject {
122
+ meshObjectCount: number; vertexCount: number; triangleCount: number;
123
+ rootWorldMatrix: number[][]; worldBoundsMeters: { min: Vec3; max: Vec3 };
124
+ }
125
+ export interface SurfacePlacementReport {
126
+ schemaVersion: 'deepblend.surface-placement/v1'; axis: 'world-z';
127
+ checkpointSha256: string; checkpointUnchanged: true; frame: number; blenderVersion: string;
128
+ subjectEntityId: string; supportEntityId: string; clearanceMm: number; translationMeters: [0, 0, number];
129
+ subjectContactMeters: Vec3; supportContactMeters: Vec3; placedSubjectContactMeters: Vec3;
130
+ subjectTriangleIndex: number; supportTriangleIndex: number; statistics: { candidatePairs: number };
131
+ subject: SurfacePlacementObject; support: SurfacePlacementObject;
132
+ baselineVerification?: { checkpointSha256: string; checkpointUnchanged: true; translationMeters: [0, 0, number];
133
+ subjectRigidTranslation: true; supportUnchanged: true; subjectMaxErrorMeters: number; supportMaxErrorMeters: number;
134
+ toleranceMeters: number };
135
+ }
115
136
  export interface RenderPreviewRequest extends RuntimeOptions, RenderOverrides {
116
137
  checkpointPath: string; outputPath: string; cameraId?: string; frame?: number; jobId?: string;
117
138
  session?: boolean;
@@ -247,6 +268,8 @@ export interface BlenderSession {
247
268
  export interface LocalBlenderRuntime extends BlenderRuntime {
248
269
  /** Optional native inspection extension; absent on older providers. Always uses an isolated batch. */
249
270
  inspectGeometry?(request: GeometryInspectionRequest): Promise<RuntimeActionResult<GeometryInspectionReport>>;
271
+ /** Optional isolated measurement; baseline verification proves the saved rigid move before Host publication. */
272
+ inspectSurfacePlacement?(request: SurfacePlacementRequest): Promise<RuntimeActionResult<SurfacePlacementReport>>;
250
273
  runBootstrap(request: BlenderBootstrapRequest, options?: BootstrapOptions): Promise<BootstrapRunOutcome>;
251
274
  openSession(options?: RuntimeOptions & { cwd?: string; args?: string[] }): Promise<BlenderSession>;
252
275
  attachSession(socketPath: string, options?: { timeoutMs?: number }): Promise<BlenderSession>;
@@ -0,0 +1,79 @@
1
+ import { BlenderError, BlenderErrorCode } from './index.js'
2
+
3
+ export const SURFACE_PLACEMENT_VERSION = 'deepblend.surface-placement/v1'
4
+ export const SURFACE_PLACEMENT_LIMITS = Object.freeze({ meshes: 128, vertices: 2_000_000,
5
+ triangles: 2_000_000, candidatePairs: 1_000_000, checkpointBytes: 1024 ** 3,
6
+ reportBytes: 64 * 1024, toleranceMeters: .00002 })
7
+
8
+ const only = (v, keys) => v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).every(k => keys.includes(k))
9
+ const vector = (v, n = 3) => Array.isArray(v) && v.length === n && v.every(Number.isFinite)
10
+ const hash = v => typeof v === 'string' && /^[a-f0-9]{64}$/.test(v)
11
+ const id = v => typeof v === 'string' && /^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(v)
12
+ const integer = (v, low, high) => Number.isSafeInteger(v) && v >= low && v <= high
13
+ const near = (a, b, epsilon = 1e-6) => Math.abs(a - b) <= epsilon
14
+ const translation = v => vector(v) && v[0] === 0 && v[1] === 0
15
+ const refuse = (message, code = BlenderErrorCode.SCENE_VALIDATION_FAILED) => { throw new BlenderError(code, `Surface placement: ${message}`) }
16
+
17
+ /** A measurement is always tied to an explicit frame and exact native bytes. */
18
+ export function validateSurfacePlacementSelection(request) {
19
+ const invalid = message => refuse(message, BlenderErrorCode.SCENE_PATCH_INVALID)
20
+ if (!id(request?.subjectEntityId) || !id(request?.supportEntityId) || request.subjectEntityId === request.supportEntityId) invalid('select distinct subject and support entities.')
21
+ if (!integer(request.frame, 0, 1_000_000)) invalid('an explicit integer frame from 0 to 1000000 is required.')
22
+ if (!hash(request.checkpointSha256)) invalid('the expected checkpoint SHA256 is required.')
23
+ const clearanceMm = request.clearanceMm === undefined ? 0 : request.clearanceMm
24
+ if (!Number.isFinite(clearanceMm) || clearanceMm < 0 || clearanceMm > 1000) invalid('clearanceMm must be between 0 and 1000.')
25
+ const baseline = ['baselineCheckpointPath', 'baselineCheckpointSha256', 'expectedTranslationMeters'].map(k => request[k] !== undefined)
26
+ if (baseline.some(Boolean) && (!baseline.every(Boolean) ||
27
+ typeof request.baselineCheckpointPath !== 'string' || !request.baselineCheckpointPath ||
28
+ !hash(request.baselineCheckpointSha256) || !translation(request.expectedTranslationMeters))) invalid('baseline verification requires a checkpoint path, SHA256 and a world-Z translation together.')
29
+ }
30
+
31
+ function verifyObject(value) {
32
+ if (!only(value, ['meshObjectCount', 'vertexCount', 'triangleCount', 'rootWorldMatrix', 'worldBoundsMeters']) ||
33
+ !integer(value.meshObjectCount, 1, SURFACE_PLACEMENT_LIMITS.meshes) ||
34
+ !integer(value.vertexCount, 3, SURFACE_PLACEMENT_LIMITS.vertices) ||
35
+ !integer(value.triangleCount, 1, SURFACE_PLACEMENT_LIMITS.triangles) ||
36
+ !Array.isArray(value.rootWorldMatrix) || value.rootWorldMatrix.length !== 4 ||
37
+ !value.rootWorldMatrix.every(row => vector(row, 4)) ||
38
+ value.rootWorldMatrix.some(row => row.some(v => Math.abs(v) > 1e6)) ||
39
+ value.rootWorldMatrix[3].some((v, i) => v !== (i === 3 ? 1 : 0)) ||
40
+ !only(value.worldBoundsMeters, ['min', 'max']) ||
41
+ !vector(value.worldBoundsMeters.min) || !vector(value.worldBoundsMeters.max) ||
42
+ [...value.worldBoundsMeters.min, ...value.worldBoundsMeters.max].some(v => Math.abs(v) > 1e6) ||
43
+ value.worldBoundsMeters.min.some((v, i) => v > value.worldBoundsMeters.max[i])) refuse('invalid native mesh counts, transform or bounds.')
44
+ }
45
+
46
+ /** Accept actual surface witnesses, never a successful exit or a claimed scalar alone. */
47
+ export function verifySurfacePlacementReport(report, request) {
48
+ validateSurfacePlacementSelection(request)
49
+ if (!only(report, ['schemaVersion', 'axis', 'checkpointSha256', 'checkpointUnchanged', 'frame', 'blenderVersion',
50
+ 'subjectEntityId', 'supportEntityId', 'clearanceMm', 'translationMeters', 'subjectContactMeters', 'supportContactMeters',
51
+ 'placedSubjectContactMeters', 'subjectTriangleIndex', 'supportTriangleIndex', 'statistics', 'subject', 'support',
52
+ ...(request.baselineCheckpointPath === undefined ? [] : ['baselineVerification'])]) ||
53
+ Buffer.byteLength(JSON.stringify(report)) > SURFACE_PLACEMENT_LIMITS.reportBytes ||
54
+ report.schemaVersion !== SURFACE_PLACEMENT_VERSION || report.axis !== 'world-z' ||
55
+ report.checkpointSha256 !== request.checkpointSha256 || report.checkpointUnchanged !== true ||
56
+ report.frame !== request.frame || report.subjectEntityId !== request.subjectEntityId || report.supportEntityId !== request.supportEntityId ||
57
+ report.clearanceMm !== (request.clearanceMm ?? 0) || typeof report.blenderVersion !== 'string' || !report.blenderVersion ||
58
+ !translation(report.translationMeters) || !vector(report.subjectContactMeters) || !vector(report.supportContactMeters) || !vector(report.placedSubjectContactMeters) ||
59
+ !only(report.statistics, ['candidatePairs']) || !integer(report.statistics.candidatePairs, 1, SURFACE_PLACEMENT_LIMITS.candidatePairs)) refuse('the report differs from the requested source, frame, selection or bounded protocol.')
60
+ verifyObject(report.subject); verifyObject(report.support)
61
+ if (!integer(report.subjectTriangleIndex, 0, report.subject.triangleCount - 1) ||
62
+ !integer(report.supportTriangleIndex, 0, report.support.triangleCount - 1)) refuse('the contact triangle is outside the measured geometry.')
63
+ const s = report.subjectContactMeters, t = report.supportContactMeters, p = report.placedSubjectContactMeters
64
+ if (![0, 1].every(i => near(s[i], t[i])) || ![0, 1, 2].every(i => near(p[i], s[i] + report.translationMeters[i])) ||
65
+ !near(p[2] - t[2], report.clearanceMm / 1000)) refuse('contact witnesses do not establish the requested vertical clearance.')
66
+ for (const [point, object] of [[s, report.subject], [t, report.support]]) {
67
+ if (point.some((v, i) => v < object.worldBoundsMeters.min[i] - 1e-6 || v > object.worldBoundsMeters.max[i] + 1e-6)) refuse('a contact witness is outside its native bounds.')
68
+ }
69
+ if (request.baselineCheckpointPath !== undefined) {
70
+ const b = report.baselineVerification
71
+ if (!only(b, ['checkpointSha256', 'checkpointUnchanged', 'translationMeters', 'subjectRigidTranslation', 'supportUnchanged',
72
+ 'subjectMaxErrorMeters', 'supportMaxErrorMeters', 'toleranceMeters']) || b.checkpointSha256 !== request.baselineCheckpointSha256 ||
73
+ b.checkpointUnchanged !== true || b.subjectRigidTranslation !== true || b.supportUnchanged !== true ||
74
+ !translation(b.translationMeters) || b.translationMeters.some((v, i) => v !== request.expectedTranslationMeters[i]) ||
75
+ b.toleranceMeters !== SURFACE_PLACEMENT_LIMITS.toleranceMeters ||
76
+ ![b.subjectMaxErrorMeters, b.supportMaxErrorMeters].every(v => Number.isFinite(v) && v >= 0 && v <= b.toleranceMeters)) refuse('candidate geometry does not verify the pinned baseline translation.')
77
+ }
78
+ return report
79
+ }
package/lib/ui-api.js CHANGED
@@ -925,6 +925,7 @@ export const UI_TOOL_CARD_KEYS = Object.freeze([
925
925
  'blender_project_get',
926
926
  'blender_scene_get',
927
927
  'blender_scene_patch',
928
+ 'blender_place_on_surface',
928
929
  'blender_preview_render',
929
930
  'blender_scene_validate',
930
931
  'blender_revision_restore',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepblend/dsh-blender-contracts",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "type": "module",
5
5
  "description": "DeepBlend Studio Service Definition, protocol contracts, and stable error codes.",
6
6
  "main": "lib/index.js",