@deepblend/dsh-blender-contracts 0.11.0 → 0.13.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,72 @@
1
+ /** Continue the pinned cup's default camera rig in its saved object pose. */
2
+ import { canonicalStringify } from './canonical.js'
3
+ import { compileSceneSpec } from './scene-spec.js'
4
+
5
+ const source = 'db9859743b99e6f18329c7e7b10d67879f1a8b0a0d2174ba0a074eb0cede7971'
6
+ const near = (a, b) => Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((v, i) => Number.isFinite(v) && Number.isFinite(b[i]) && Math.abs(v - b[i]) <= 1e-9)
7
+ const rotation = ([x, y, z]) => {
8
+ 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)
9
+ 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]]
10
+ }
11
+ const multiply = (m, p) => m.map(row => row.reduce((s, v, i) => s + v*p[i], 0))
12
+ const transpose = m => m[0].map((_, i) => m.map(row => row[i]))
13
+
14
+ export function placedCupCameras(lock, current, before, after, parameterState) {
15
+ if (lock.manifestSha256 !== source) return { before, after }
16
+ current = compileSceneSpec(current).spec
17
+ const anchor = before.spec.entities.find(e => e.id === 'cup'), actual = current.entities.find(e => e.id === 'cup')
18
+ if (!actual || actual.type !== anchor.type || actual.generator?.shape !== anchor.generator.shape ||
19
+ !near(actual.transform.scale, anchor.transform.scale)) return { before, after }
20
+ const origin = anchor.transform.location, destination = actual.transform.location
21
+ const originalRotation = rotation(anchor.transform.rotationEuler), currentRotation = rotation(actual.transform.rotationEuler)
22
+ const point = p => multiply(currentRotation, multiply(transpose(originalRotation), p.map((v, i) => v-origin[i]))).map((v, i) => v+destination[i])
23
+ const move = camera => {
24
+ const result = structuredClone(camera)
25
+ result.transform.location = point(camera.transform.location)
26
+ if (camera.targetPoint) result.targetPoint = point(camera.targetPoint)
27
+ return result
28
+ }
29
+ const sameRigCamera = (expected, saved) => {
30
+ if (!saved || !near(expected.transform.location, saved.transform.location) ||
31
+ !near(expected.targetPoint, saved.targetPoint)) return false
32
+ const stripPoints = camera => {
33
+ const copy = structuredClone(camera); delete copy.transform.location; delete copy.targetPoint; return copy
34
+ }
35
+ return canonicalStringify(stripPoints(expected)) === canonicalStringify(stripPoints(saved))
36
+ }
37
+ const result = { before: structuredClone(before), after: structuredClone(after), protectedCameraIds: [], recognizedCameraIds: [] }
38
+ for (const camera of before.spec.cameras) {
39
+ if (current.animationTracks.some(track => track.targetKind === 'camera' && track.targetEntityId === camera.id)) {
40
+ result.protectedCameraIds.push(camera.id); continue
41
+ }
42
+ const saved = current.cameras.find(c => c.id === camera.id)
43
+ const rig = parameterState?.cupCameraRig
44
+ let expected = move(camera)
45
+ if (camera.id === 'hero' && rig?.schemaVersion === 'deepblend.cup-camera-rig/v1'
46
+ && rig.camera?.id === 'hero' && rig.anchor?.location?.length === 3 && rig.anchor?.rotationEuler?.length === 3
47
+ && [...rig.anchor.location, ...rig.anchor.rotationEuler].every(Number.isFinite)) {
48
+ const previousRotation = rotation(rig.anchor.rotationEuler)
49
+ const previousPoint = p => multiply(currentRotation, multiply(transpose(previousRotation), p.map((v, i) => v-rig.anchor.location[i]))).map((v, i) => v+destination[i])
50
+ const fitted = structuredClone(rig.camera)
51
+ if (Array.isArray(fitted.transform?.location) && Array.isArray(fitted.targetPoint)) {
52
+ fitted.transform.location = previousPoint(fitted.transform.location)
53
+ fitted.targetPoint = previousPoint(fitted.targetPoint)
54
+ // The receipt may exempt only coordinates, never a lens/target style edit.
55
+ const defaultAtPose = move(camera)
56
+ const strip = value => { const copy = structuredClone(value); delete copy.transform.location; delete copy.targetPoint; return copy }
57
+ if (canonicalStringify(strip(fitted)) === canonicalStringify(strip(defaultAtPose))) expected = fitted
58
+ }
59
+ }
60
+ if (!sameRigCamera(move(camera), saved) && !sameRigCamera(expected, saved)) continue
61
+ result.recognizedCameraIds.push(camera.id)
62
+ // Only coordinates in a recognized default rig may follow dimensions.
63
+ // Keep every other authored camera field and all unrelated scene data intact.
64
+ result.before.spec.cameras.find(c => c.id === camera.id).transform = structuredClone(saved.transform)
65
+ result.before.spec.cameras.find(c => c.id === camera.id).targetPoint = structuredClone(saved.targetPoint)
66
+ const target = result.after.spec.cameras.find(c => c.id === camera.id)
67
+ const moved = move(target)
68
+ if (![...moved.transform.location, ...moved.targetPoint].every(Number.isFinite)) return { before, after }
69
+ target.transform.location = moved.transform.location; target.targetPoint = moved.targetPoint
70
+ }
71
+ return result
72
+ }
@@ -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 { placedCupCameras } from './cup-placement.js'
4
5
  import { latheShellTargets } from './lathe-shell.js'
5
6
  import { canonicalStringify, sha256Canonical } from './canonical.js'
6
7
  import { instantiateRecipeLock, RecipeError } from './recipe.js'
@@ -39,7 +40,9 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
39
40
  const assembly = legacyLampAssembly(lock, parameterState)
40
41
  const resolvedBefore = assembly && parameterState?.assemblyRepair ? instantiateRecipeLock(assembly.currentLock(currentLock)) : savedBefore
41
42
  const resolvedAfter = instantiateRecipeLock(assembly ? assembly.currentLock(currentLock) : currentLock, changes)
42
- const { before, after } = translatedSpeakerAssembly(lock, currentSpec, resolvedBefore, resolvedAfter)
43
+ const speaker = translatedSpeakerAssembly(lock, currentSpec, resolvedBefore, resolvedAfter)
44
+ const cup = placedCupCameras(lock, currentSpec, speaker.before, speaker.after, parameterState)
45
+ const { before, after } = cup
43
46
  const parameters = recipeGeometryParameters(assembly?.manifest ?? lock.manifest)
44
47
  for (const id of Object.keys(changes)) {
45
48
  if (!parameters.some(parameter => parameter.id === id)) {
@@ -97,7 +100,7 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
97
100
  const actual = currentSpec.cameras?.find(item => item.id === binding.cameraId)
98
101
  const original = before.spec.cameras?.find(item => item.id === binding.cameraId)
99
102
  // Independently authored photography remains intact, including deleted cameras.
100
- if (!actual || canonicalStringify(actual) !== canonicalStringify(original)) {
103
+ if (!actual || cup.protectedCameraIds?.includes(binding.cameraId) || canonicalStringify(actual) !== canonicalStringify(original)) {
101
104
  protectedCameras.add(binding.cameraId); continue
102
105
  }
103
106
  if (!cameras.has(binding.cameraId)) cameras.set(binding.cameraId, { op: 'camera.update', cameraId: binding.cameraId })
@@ -140,9 +143,14 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
140
143
  ...cameras.values(),
141
144
  ...[...tracks.values()].map(track => ({ op: 'animation.track.set', track })),
142
145
  ]
143
- return { operations, changedParameters: changed.map(parameter => parameter.id),
146
+ return { operations,
147
+ ...(changed.length > 0 && cup.recognizedCameraIds?.includes('hero') && !protectedCameras.has('hero')
148
+ ? { cameraFraming: { entityId: 'cup', cameraId: 'hero', margin: 0.03 } } : {}),
149
+ changedParameters: changed.map(parameter => parameter.id),
144
150
  preservedCameraIds: [...protectedCameras], parameterState: {
145
151
  schemaVersion: 'deepblend.recipe-parameters/v1', manifestSha256: lock.manifestSha256,
152
+ ...(!cameras.has('hero') && cup.recognizedCameraIds?.includes('hero') && parameterState?.cupCameraRig
153
+ ? { cupCameraRig: structuredClone(parameterState.cupCameraRig) } : {}),
146
154
  ...(assembly ? { assemblyRepair: 'metal-lamp-clearance/v1' } : {}),
147
155
  values: after.values, valuesSha256: sha256Canonical(after.values),
148
156
  } }
@@ -57,7 +57,15 @@ export interface MeasuredRenderConfig {
57
57
  exposure?: number; viewTransform?: string; look?: string; gamma?: number;
58
58
  [key: string]: unknown;
59
59
  }
60
+ export interface CupHeroFramingSelection { entityId: 'cup'; cameraId: 'hero'; margin: 0.03 }
61
+ export interface CupHeroFramingReport extends CupHeroFramingSelection {
62
+ schemaVersion: 'deepblend.camera-framing/v1'; frame: number; resolution: number[];
63
+ resolutionPercentage: number; pixelAspect: number[]; cameraLocation: Vec3;
64
+ cameraType: 'PERSP'; lens: number; sensorWidth: number; backoffM: number;
65
+ vertices: number; nearestDepthM: number; farthestDepthM: number; scope: string;
66
+ }
60
67
  export interface CompileReport {
68
+ cameraFraming?: CupHeroFramingReport;
61
69
  validation: { ok: boolean; errors: unknown[]; [key: string]: unknown };
62
70
  sceneFingerprint: { totalPolygons: number; [key: string]: unknown };
63
71
  objects?: CompiledObject[]; renderConfig?: MeasuredRenderConfig;
@@ -74,6 +82,8 @@ export interface RuntimeActionResult<Report> {
74
82
  report: Report; envelope: BlenderBootstrapEnvelope<Report>; durationMs: number; stdout: string; stderr: string;
75
83
  }
76
84
  export interface CompileSceneRequest extends RuntimeOptions {
85
+ /** Optional bounded native measurement; it does not modify a camera or source scene. */
86
+ cameraFraming?: CupHeroFramingSelection;
77
87
  sceneSpecPath: string; projectRoot?: string; profile?: string; jobId?: string;
78
88
  /** false runs a separate batch process, preserving a user's live Blender session. */
79
89
  session?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepblend/dsh-blender-contracts",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "description": "DeepBlend Studio Service Definition, protocol contracts, and stable error codes.",
6
6
  "main": "lib/index.js",