@deepblend/dsh-blender-contracts 0.15.0 → 0.16.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 +47 -5
- package/lib/index.js +4 -1
- package/lib/runtime-types.d.ts +22 -4
- package/lib/scene-patch.js +16 -1
- package/lib/sdk.d.ts +6 -0
- package/lib/sdk.js +2 -0
- package/lib/shot-render-selection.js +52 -0
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { BlenderError, BlenderErrorCode } from './index.js'
|
|
2
2
|
|
|
3
3
|
export const GEOMETRY_INSPECTION_VERSION = 'deepblend.geometry-inspection/v1'
|
|
4
|
+
export const ASSET_BOUNDS_INSPECTION_VERSION = 'deepblend.geometry-inspection/v4'
|
|
5
|
+
export const ASSET_BOUNDS_LIMITS = Object.freeze({ meshes: 128, vertices: 2_000_000, polygons: 2_000_000 })
|
|
4
6
|
export const OBJECT_AXES_INSPECTION_VERSION = 'deepblend.geometry-inspection/v3'
|
|
5
7
|
export const OBJECT_AXES_BASIS = 'evaluated-object-axes-scaled'
|
|
6
8
|
export const SURFACE_INSPECTION_VERSION = 'deepblend.geometry-inspection/v2'
|
|
@@ -19,6 +21,16 @@ export function validateGeometrySelection(request) {
|
|
|
19
21
|
if (!Number.isSafeInteger(request.frame) || request.frame < 0 || request.frame > 1_000_000) refuse('an explicit integer frame from 0 to 1000000 is required.')
|
|
20
22
|
if (typeof request.checkpointSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(request.checkpointSha256)) refuse('the expected checkpoint SHA256 is required.')
|
|
21
23
|
if (request.objectAxes !== undefined && typeof request.objectAxes !== 'boolean') refuse('objectAxes must be boolean.')
|
|
24
|
+
if (request.cameraId !== undefined && (typeof request.cameraId !== 'string' || !/^[a-zA-Z][a-zA-Z0-9._-]{0,127}$/.test(request.cameraId) || request.objectAxes === true || request.surfaceSamples !== undefined)) refuse('cameraId requires one explicit camera without object axes or surface samples.')
|
|
25
|
+
if (request.cameraMargin !== undefined && (request.cameraId === undefined || !Number.isFinite(request.cameraMargin) || request.cameraMargin < 0 || request.cameraMargin > .25)) refuse('cameraMargin requires cameraId and a finite margin from 0 to 0.25.')
|
|
26
|
+
if (request.assetInstanceIds !== undefined) {
|
|
27
|
+
if (!Array.isArray(request.assetInstanceIds) || request.assetInstanceIds.length < 1 ||
|
|
28
|
+
new Set(request.assetInstanceIds).size !== request.assetInstanceIds.length ||
|
|
29
|
+
request.assetInstanceIds.some(id => !request.entityIds.includes(id)) ||
|
|
30
|
+
request.objectAxes === true || request.surfaceSamples !== undefined) {
|
|
31
|
+
refuse('assetInstanceIds must select distinct requested asset roots; aggregate bounds cannot be combined with object axes or surface samples.')
|
|
32
|
+
}
|
|
33
|
+
}
|
|
22
34
|
if (request.surfaceSamples !== undefined) validateSurfaceSelection(request)
|
|
23
35
|
}
|
|
24
36
|
|
|
@@ -101,28 +113,38 @@ export function verifyGeometryReport(report, request) {
|
|
|
101
113
|
validateGeometrySelection(request)
|
|
102
114
|
const allowed = (value, keys) => value && typeof value === 'object' && Object.keys(value).every(key => keys.includes(key))
|
|
103
115
|
if (!report || Buffer.byteLength(JSON.stringify(report)) > GEOMETRY_INSPECTION_LIMITS.reportBytes ||
|
|
104
|
-
report.schemaVersion !== (request.objectAxes === true ? OBJECT_AXES_INSPECTION_VERSION : request.surfaceSamples === undefined ? GEOMETRY_INSPECTION_VERSION : SURFACE_INSPECTION_VERSION) || report.checkpointSha256 !== request.checkpointSha256 ||
|
|
116
|
+
report.schemaVersion !== (request.assetInstanceIds !== undefined || request.cameraId !== undefined ? ASSET_BOUNDS_INSPECTION_VERSION : request.objectAxes === true ? OBJECT_AXES_INSPECTION_VERSION : request.surfaceSamples === undefined ? GEOMETRY_INSPECTION_VERSION : SURFACE_INSPECTION_VERSION) || report.checkpointSha256 !== request.checkpointSha256 ||
|
|
105
117
|
report.frame !== request.frame || report.checkpointUnchanged !== true ||
|
|
106
118
|
typeof report.blenderVersion !== 'string' || !report.blenderVersion ||
|
|
107
119
|
!Array.isArray(report.objects) || report.objects.length !== request.entityIds.length ||
|
|
108
|
-
!allowed(report, ['schemaVersion', 'checkpointSha256', 'checkpointUnchanged', 'frame', 'blenderVersion', 'objects', ...(request.objectAxes === true ? ['objectAxisBasis'] : []), ...(request.surfaceSamples === undefined ? [] : ['surfaceSamples'])])) refuse('the report does not match the requested source, frame or selection.')
|
|
120
|
+
!allowed(report, ['schemaVersion', 'checkpointSha256', 'checkpointUnchanged', 'frame', 'blenderVersion', 'objects', ...(request.cameraId === undefined ? [] : ['camera']), ...(request.objectAxes === true ? ['objectAxisBasis'] : []), ...(request.surfaceSamples === undefined ? [] : ['surfaceSamples'])])) refuse('the report does not match the requested source, frame or selection.')
|
|
121
|
+
if (request.cameraId !== undefined) {
|
|
122
|
+
const camera = report.camera
|
|
123
|
+
if (!allowed(camera, ['id', 'type', 'margin', 'clipStartMeters', 'clipEndMeters']) || camera?.id !== request.cameraId || camera.type !== 'PERSP' ||
|
|
124
|
+
camera.margin !== (request.cameraMargin ?? .03) || !Number.isFinite(camera.clipStartMeters) || camera.clipStartMeters <= 0 ||
|
|
125
|
+
!Number.isFinite(camera.clipEndMeters) || camera.clipEndMeters <= camera.clipStartMeters) refuse('camera calibration differs from the requested framing selection.')
|
|
126
|
+
}
|
|
109
127
|
if (request.objectAxes === true && report.objectAxisBasis !== OBJECT_AXES_BASIS) refuse('object-local basis differs from evaluated scaled object-axis coordinates.')
|
|
110
128
|
const vector = (v, length) => Array.isArray(v) && v.length === length && v.every(Number.isFinite)
|
|
111
129
|
for (const [index, object] of report.objects.entries()) {
|
|
130
|
+
const aggregate = request.assetInstanceIds?.includes(request.entityIds[index]) === true
|
|
112
131
|
if (object?.entityId !== request.entityIds[index] || typeof object.type !== 'string' || !object.type) refuse('object identity differs from the selection.')
|
|
113
132
|
const keys = object.available === false ? ['entityId', 'type', 'available', 'unavailableReason'] :
|
|
114
|
-
['entityId', 'type', 'available', 'worldBoundsMeters', 'worldAxisExtentMm', 'worldMatrix', 'scale', 'vertexCount', 'polygonCount', ...(request.objectAxes === true ? ['objectAxisStatus', 'objectAxisBoundsMeters', 'objectAxisExtentMm', 'objectAxisWorldMatrix'] : [])]
|
|
133
|
+
['entityId', 'type', 'available', 'worldBoundsMeters', 'worldAxisExtentMm', 'worldMatrix', 'scale', 'vertexCount', 'polygonCount', ...(request.cameraId === undefined ? [] : ['cameraProjection']), ...(aggregate ? ['meshObjectCount'] : []), ...(request.objectAxes === true ? ['objectAxisStatus', 'objectAxisBoundsMeters', 'objectAxisExtentMm', 'objectAxisWorldMatrix'] : [])]
|
|
115
134
|
if (!allowed(object, keys)) refuse('unsupported measurement fields are not accepted; this protocol does not establish wall thickness or clearance.')
|
|
116
135
|
if (object.available === false) {
|
|
117
|
-
if (!['viewport-disabled', 'not-mesh', 'empty-or-invalid-geometry'].includes(object.unavailableReason) ||
|
|
136
|
+
if (![...['viewport-disabled', 'not-mesh', 'empty-or-invalid-geometry'], ...(aggregate ? ['geometry-budget-exceeded', 'unsupported-hierarchy'] : [])].includes(object.unavailableReason) ||
|
|
118
137
|
['worldBoundsMeters', 'worldAxisExtentMm', 'worldMatrix', 'vertexCount', 'polygonCount', 'scale'].some(k => Object.hasOwn(object, k))) refuse('an unavailable object must not contain measurements.')
|
|
119
138
|
continue
|
|
120
139
|
}
|
|
121
|
-
if (object.available !== true || object.type !==
|
|
140
|
+
if (object.available !== true || object.type !== (aggregate ? 'ASSET_MESH_SET' : 'MESH') ||
|
|
141
|
+
(aggregate && (!Number.isSafeInteger(object.meshObjectCount) || object.meshObjectCount < 1 || object.meshObjectCount > ASSET_BOUNDS_LIMITS.meshes ||
|
|
142
|
+
object.vertexCount > ASSET_BOUNDS_LIMITS.vertices || object.polygonCount > ASSET_BOUNDS_LIMITS.polygons)) || !allowed(object.worldBoundsMeters, ['min', 'max']) || !vector(object.worldBoundsMeters?.min, 3) ||
|
|
122
143
|
!vector(object.worldBoundsMeters?.max, 3) || !vector(object.worldAxisExtentMm, 3) || !vector(object.scale, 3) ||
|
|
123
144
|
!Array.isArray(object.worldMatrix) || object.worldMatrix.length !== 4 || !object.worldMatrix.every(row => vector(row, 4)) ||
|
|
124
145
|
!Number.isSafeInteger(object.vertexCount) || object.vertexCount <= 0 ||
|
|
125
146
|
!Number.isSafeInteger(object.polygonCount) || object.polygonCount < 0) refuse('a measured object contains invalid or non-finite geometry facts.')
|
|
147
|
+
if (request.cameraId !== undefined) verifyCameraProjection(object.cameraProjection, report.camera)
|
|
126
148
|
if (request.objectAxes === true && object.objectAxisStatus === 'unsupported-object-axis-basis') {
|
|
127
149
|
if (['objectAxisBoundsMeters','objectAxisExtentMm','objectAxisWorldMatrix'].some(k=>Object.hasOwn(object,k))) refuse('unavailable object-axis measurements must not contain numbers.')
|
|
128
150
|
const m=object.worldMatrix, lengths=[0,1,2].map(i=>Math.hypot(...m.slice(0,3).map(r=>r[i])))
|
|
@@ -167,3 +189,23 @@ export function verifyGeometryReport(report, request) {
|
|
|
167
189
|
if (request.surfaceSamples !== undefined) verifySurfaceSamples(report.surfaceSamples, request, report.objects)
|
|
168
190
|
return report
|
|
169
191
|
}
|
|
192
|
+
|
|
193
|
+
function verifyCameraProjection(projection, camera) {
|
|
194
|
+
const base = ['status', 'nearestDepthMeters', 'farthestDepthMeters', 'containedInClip']
|
|
195
|
+
if (['unavailable-render-hidden', 'geometry-budget-exceeded'].includes(projection?.status)) {
|
|
196
|
+
if (!only(projection, ['status'])) refuse('hidden framing must not contain fabricated measurements.')
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
if (!['measured', 'not-fully-in-front'].includes(projection?.status) ||
|
|
200
|
+
!Number.isFinite(projection.nearestDepthMeters) || !Number.isFinite(projection.farthestDepthMeters) || projection.nearestDepthMeters > projection.farthestDepthMeters ||
|
|
201
|
+
projection.containedInClip !== (projection.nearestDepthMeters >= camera.clipStartMeters && projection.farthestDepthMeters <= camera.clipEndMeters)) refuse('camera depth or clip evidence is invalid.')
|
|
202
|
+
if (projection.status === 'not-fully-in-front') {
|
|
203
|
+
if (!only(projection, base) || projection.nearestDepthMeters > 1e-8) refuse('camera-plane crossing must not contain a partial projection.')
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
const bounds = projection.normalizedBounds
|
|
207
|
+
if (!only(projection, [...base, 'normalizedBounds', 'containedInFrame']) || projection.nearestDepthMeters <= 1e-8 || !only(bounds, ['min', 'max']) ||
|
|
208
|
+
!Array.isArray(bounds?.min) || !Array.isArray(bounds?.max) || bounds.min.length !== 2 || bounds.max.length !== 2 ||
|
|
209
|
+
![...bounds.min, ...bounds.max].every(Number.isFinite) || bounds.min.some((v, i) => v > bounds.max[i]) ||
|
|
210
|
+
projection.containedInFrame !== bounds.min.every((v, i) => v >= camera.margin && bounds.max[i] <= 1-camera.margin)) refuse('camera frame containment disagrees with measured vertex projections.')
|
|
211
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -719,6 +719,7 @@ export { assertKnownConfigKeys, declaredConfigKeys, describeUnknownConfigKeys }
|
|
|
719
719
|
|
|
720
720
|
export {
|
|
721
721
|
CAMERA_UPDATE_FIELDS,
|
|
722
|
+
CAMERA_TARGET_UPDATE_HINT,
|
|
722
723
|
SCENE_OPERATION_NAMES,
|
|
723
724
|
validateScenePatch,
|
|
724
725
|
applyPatchToSpec,
|
|
@@ -885,5 +886,7 @@ export {
|
|
|
885
886
|
export { RECIPE_SCHEMA_VERSION, RECIPE_CAPABILITIES, RECIPE_LIMITS, RecipeError, recipeCapabilitiesForScene, validateRecipeManifest, validateRecipePackage, instantiateRecipe, instantiateRecipeLock } from './recipe.js'
|
|
886
887
|
export { planRecipeGeometryEdit, recipeGeometryParameters } from './recipe-parameters.js'
|
|
887
888
|
|
|
888
|
-
export { OBJECT_AXES_INSPECTION_VERSION, OBJECT_AXES_BASIS, GEOMETRY_INSPECTION_VERSION, GEOMETRY_INSPECTION_LIMITS, SURFACE_INSPECTION_VERSION, SURFACE_INSPECTION_LIMITS,
|
|
889
|
+
export { ASSET_BOUNDS_INSPECTION_VERSION, ASSET_BOUNDS_LIMITS, OBJECT_AXES_INSPECTION_VERSION, OBJECT_AXES_BASIS, GEOMETRY_INSPECTION_VERSION, GEOMETRY_INSPECTION_LIMITS, SURFACE_INSPECTION_VERSION, SURFACE_INSPECTION_LIMITS,
|
|
889
890
|
validateGeometrySelection, validateSurfaceSelection, verifySurfaceSamples, verifyGeometryReport } from './geometry-inspection.js'
|
|
891
|
+
export { SHOT_CAMERA_SELECTION_VERSION, SHOT_CAMERA_SELECTION_LIMITS, buildShotCameraSelection,
|
|
892
|
+
normalizeShotCameraSelection, shotCameraForFrame } from './shot-render-selection.js'
|
package/lib/runtime-types.d.ts
CHANGED
|
@@ -94,15 +94,21 @@ export interface RenderOverrides { engine?: EngineKey; width?: number; height?:
|
|
|
94
94
|
/** Default world-axis bounds; optional physical object axes include native scale. Neither certifies semantic body dimensions or wall thickness. */
|
|
95
95
|
export interface GeometryInspectionRequest extends RuntimeOptions {
|
|
96
96
|
checkpointPath: string; checkpointSha256: string; entityIds: string[]; frame: number; jobId?: string; objectAxes?: boolean; surfaceSamples?: unknown[];
|
|
97
|
+
assetInstanceIds?: string[]; cameraId?: string; cameraMargin?: number;
|
|
97
98
|
}
|
|
99
|
+
export type CameraProjection = { status: 'unavailable-render-hidden' | 'geometry-budget-exceeded' } |
|
|
100
|
+
{ status: 'not-fully-in-front'; nearestDepthMeters: number; farthestDepthMeters: number; containedInClip: boolean } |
|
|
101
|
+
{ status: 'measured'; nearestDepthMeters: number; farthestDepthMeters: number; containedInClip: boolean;
|
|
102
|
+
normalizedBounds: { min: [number, number]; max: [number, number] }; containedInFrame: boolean };
|
|
98
103
|
export type GeometryInspectionObject = { entityId: string; type: string } & (
|
|
99
|
-
{ available: false; unavailableReason: 'viewport-disabled' | 'not-mesh' | 'empty-or-invalid-geometry' } |
|
|
104
|
+
{ available: false; unavailableReason: 'viewport-disabled' | 'not-mesh' | 'empty-or-invalid-geometry' | 'unsupported-hierarchy' | 'geometry-budget-exceeded' } |
|
|
100
105
|
{ available: true; worldBoundsMeters: { min: Vec3; max: Vec3 }; worldAxisExtentMm: Vec3;
|
|
101
106
|
objectAxisStatus?: 'measured' | 'unsupported-object-axis-basis'; objectAxisBoundsMeters?: { min: Vec3; max: Vec3 }; objectAxisExtentMm?: Vec3; objectAxisWorldMatrix?: number[][];
|
|
102
|
-
worldMatrix: number[][]; scale: Vec3; vertexCount: number; polygonCount: number }
|
|
107
|
+
worldMatrix: number[][]; scale: Vec3; vertexCount: number; polygonCount: number; meshObjectCount?: number; cameraProjection?: CameraProjection }
|
|
103
108
|
);
|
|
104
109
|
export interface GeometryInspectionReport {
|
|
105
|
-
schemaVersion: 'deepblend.geometry-inspection/v1' | 'deepblend.geometry-inspection/v2' | 'deepblend.geometry-inspection/v3';
|
|
110
|
+
schemaVersion: 'deepblend.geometry-inspection/v1' | 'deepblend.geometry-inspection/v2' | 'deepblend.geometry-inspection/v3' | 'deepblend.geometry-inspection/v4';
|
|
111
|
+
camera?: { id: string; type: 'PERSP'; margin: number; clipStartMeters: number; clipEndMeters: number };
|
|
106
112
|
objectAxisBasis?: 'evaluated-object-axes-scaled'; surfaceSamples?: unknown[]; checkpointSha256: string; checkpointUnchanged: true;
|
|
107
113
|
frame: number; blenderVersion: string; objects: GeometryInspectionObject[];
|
|
108
114
|
}
|
|
@@ -156,6 +162,13 @@ export interface FrameSequenceRequest extends RuntimeOptions {
|
|
|
156
162
|
profile?: RenderProfile; frameRange?: [number, number]; jobId?: string; attemptToken?: string;
|
|
157
163
|
filePrefix?: string; padding?: number;
|
|
158
164
|
}
|
|
165
|
+
export interface ShotCameraSelection {
|
|
166
|
+
schemaVersion: 'deepblend.shot-camera-selection/v1'; mode: 'shots';
|
|
167
|
+
shots: Array<{ id: string; cameraId: string; frameRange: [number, number] }>;
|
|
168
|
+
}
|
|
169
|
+
export interface ShotFrameSequenceRequest extends Omit<FrameSequenceRequest, 'cameraId'> {
|
|
170
|
+
cameraSelection: ShotCameraSelection;
|
|
171
|
+
}
|
|
159
172
|
export interface FrameSequenceRun {
|
|
160
173
|
handle: FrameSequenceHandle; jobDirectory: string; framesDirectory: string; requestPath: string; planPath: string;
|
|
161
174
|
resultPath: string; eventsPath: string; processPath: string; argv: string[]; startedAt: number;
|
|
@@ -171,14 +184,17 @@ export interface FrameWrittenEvent {
|
|
|
171
184
|
attemptToken: string;
|
|
172
185
|
/** SHA256 of the complete PNG bytes after structural verification. */
|
|
173
186
|
sha256: string;
|
|
187
|
+
/** Actual camera read back for the explicit shot action; absent stays unknown. */
|
|
188
|
+
cameraId?: string; shotId?: string;
|
|
174
189
|
}
|
|
175
190
|
export type FrameProvenanceEvent = FrameConfiguredEvent | FrameWrittenEvent;
|
|
176
191
|
/** Configuration read back by the renderer, with the launch identity that requested it. */
|
|
177
192
|
export interface FrameRenderSource {
|
|
178
193
|
id: string; attempt: number; revisionId: string; cameraId: string | null; checkpointSha256: string | null;
|
|
179
194
|
requestedSamples: number | null; effectiveProfile: RenderProfile; renderConfig: MeasuredRenderConfig;
|
|
195
|
+
cameraSelection?: ShotCameraSelection;
|
|
180
196
|
}
|
|
181
|
-
export interface FrameSourceBinding { frame: number; sourceId: string; sha256: string }
|
|
197
|
+
export interface FrameSourceBinding { frame: number; sourceId: string; sha256: string; cameraId?: string; shotId?: string }
|
|
182
198
|
/** Shared by canonical jobs and delivery manifests; known means configuration/PNG evidence, not per-pixel samples. */
|
|
183
199
|
export interface FrameProvenanceSummary {
|
|
184
200
|
schemaVersion: 'deepblend.frame-sources/v1';
|
|
@@ -207,6 +223,8 @@ export interface BlenderRuntime {
|
|
|
207
223
|
renderPreview(request: RenderPreviewRequest): Promise<RuntimeActionResult<PreviewReport>>;
|
|
208
224
|
renderViews(request: RenderViewsRequest): Promise<RenderViewsResult>;
|
|
209
225
|
startFrameSequence(request: FrameSequenceRequest): Promise<FrameSequenceRun>;
|
|
226
|
+
/** Optional explicit capability; the Host must refuse, never silently fall back. */
|
|
227
|
+
startShotFrameSequence?(request: ShotFrameSequenceRequest): Promise<FrameSequenceRun>;
|
|
210
228
|
awaitFrameSequence(run: FrameSequenceRun): Promise<FrameSequenceOutcome>;
|
|
211
229
|
dispose(): void;
|
|
212
230
|
}
|
package/lib/scene-patch.js
CHANGED
|
@@ -105,6 +105,14 @@ export function validateScenePatch(patch) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
for (const issue of structural) {
|
|
108
|
+
// Read projections use null for an absent target; write operations do not.
|
|
109
|
+
// Explain the valid alternatives without coercing the caller's intent.
|
|
110
|
+
const target = /^operations\[(\d+)\]\.(targetEntityId|targetPoint|clearTarget)$/.exec(issue.path)
|
|
111
|
+
const operation = target ? patch?.operations?.[Number(target[1])] : null
|
|
112
|
+
if (target && operation?.op === 'camera.update' && operation[target[2]] === null
|
|
113
|
+
&& ['type', 'const'].includes(issue.keyword)) {
|
|
114
|
+
issue.message += `. ${CAMERA_TARGET_UPDATE_HINT}`
|
|
115
|
+
}
|
|
108
116
|
errors.push({ code: 'PATCH_SCHEMA_INVALID', path: issue.path, message: `${issue.message} [${issue.keyword}]` })
|
|
109
117
|
}
|
|
110
118
|
if (errors.length > 0) {
|
|
@@ -177,7 +185,7 @@ export function validateScenePatch(patch) {
|
|
|
177
185
|
errors.push({
|
|
178
186
|
code: 'PATCH_CAMERA_TARGET_AMBIGUOUS',
|
|
179
187
|
path: at,
|
|
180
|
-
message: 'camera.update must choose one of targetEntityId, targetPoint or clearTarget',
|
|
188
|
+
message: 'camera.update must choose one of targetEntityId, targetPoint or clearTarget. ' + CAMERA_TARGET_UPDATE_HINT,
|
|
181
189
|
})
|
|
182
190
|
}
|
|
183
191
|
}
|
|
@@ -208,6 +216,13 @@ export function validateScenePatch(patch) {
|
|
|
208
216
|
* copies of one vocabulary is two too many, and the failure mode when they disagree is
|
|
209
217
|
* not a crash — it is a rejection that names the wrong problem.
|
|
210
218
|
*/
|
|
219
|
+
/** Shared model-facing recovery: invalid aim combinations stay refused. */
|
|
220
|
+
export const CAMERA_TARGET_UPDATE_HINT =
|
|
221
|
+
'Choose exactly one of targetEntityId, targetPoint or clearTarget when changing aim. ' +
|
|
222
|
+
'Set targetPoint alone for a world point, or targetEntityId alone for an entity; either replaces the previous target. ' +
|
|
223
|
+
'Use clearTarget: true only to remove targeting; do not pass null. ' +
|
|
224
|
+
'Retarget or clear cameras before removing their target entities.'
|
|
225
|
+
|
|
211
226
|
export const CAMERA_UPDATE_FIELDS = Object.freeze([
|
|
212
227
|
'lens', 'sensorWidth', 'clipping', 'transform', 'targetEntityId', 'targetPoint', 'clearTarget', 'fStop', 'role',
|
|
213
228
|
])
|
package/lib/sdk.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ import type {
|
|
|
5
5
|
} from './schema-types.js';
|
|
6
6
|
export type * from './schema-types.js';
|
|
7
7
|
export type * from './runtime-types.js';
|
|
8
|
+
import type { ShotCameraSelection } from './runtime-types.js';
|
|
9
|
+
export const SHOT_CAMERA_SELECTION_VERSION: 'deepblend.shot-camera-selection/v1';
|
|
10
|
+
export const SHOT_CAMERA_SELECTION_LIMITS: { readonly shots: 64; readonly bytes: 8192 };
|
|
11
|
+
export function buildShotCameraSelection(spec: Pick<SceneSpec, 'cameras' | 'shots'>, frames: number[]): ShotCameraSelection;
|
|
12
|
+
export function normalizeShotCameraSelection(value: unknown, frames?: number[]): ShotCameraSelection;
|
|
13
|
+
export function shotCameraForFrame(selection: ShotCameraSelection, frame: number): { shotId: string; cameraId: string };
|
|
8
14
|
|
|
9
15
|
export const BLENDER_PROTOCOL_VERSION: 'deepblend.blender/v1';
|
|
10
16
|
export const SCENE_SCHEMA_VERSION: 'deepblend.scene/v1';
|
package/lib/sdk.js
CHANGED
|
@@ -3,6 +3,8 @@ import { validateSceneSpec } from './scene-spec.js'
|
|
|
3
3
|
import { validateScenePatch } from './scene-patch.js'
|
|
4
4
|
import { BlenderError, BlenderErrorCode } from './index.js'
|
|
5
5
|
import { validateRecipeManifest, RecipeError } from './recipe.js'
|
|
6
|
+
export { SHOT_CAMERA_SELECTION_VERSION, SHOT_CAMERA_SELECTION_LIMITS, buildShotCameraSelection,
|
|
7
|
+
normalizeShotCameraSelection, shotCameraForFrame } from './shot-render-selection.js'
|
|
6
8
|
|
|
7
9
|
export {
|
|
8
10
|
BLENDER_PROTOCOL_VERSION, SCENE_SCHEMA_VERSION, SCENE_PATCH_VERSION, HOST_API_VERSION,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BlenderError, BlenderErrorCode } from './index.js'
|
|
2
|
+
|
|
3
|
+
export const SHOT_CAMERA_SELECTION_VERSION = 'deepblend.shot-camera-selection/v1'
|
|
4
|
+
export const SHOT_CAMERA_SELECTION_LIMITS = Object.freeze({ shots: 64, bytes: 8192 })
|
|
5
|
+
const id = value => typeof value === 'string' && /^[a-zA-Z][a-zA-Z0-9._-]{0,127}$/.test(value)
|
|
6
|
+
const fail = message => { throw new BlenderError(BlenderErrorCode.SCENE_SPEC_INVALID, `Shot camera selection: ${message}`) }
|
|
7
|
+
|
|
8
|
+
/** Resolve only a previously normalized selection; never choose a fallback camera. */
|
|
9
|
+
export function shotCameraForFrame(selection, frame) {
|
|
10
|
+
if (!Number.isSafeInteger(frame)) fail('requested frames must be integers.')
|
|
11
|
+
const matches = selection.shots.filter(shot => frame >= shot.frameRange[0] && frame <= shot.frameRange[1])
|
|
12
|
+
if (matches.length !== 1) fail(`frame ${frame} must belong to exactly one saved shot, found ${matches.length}.`)
|
|
13
|
+
return { shotId: matches[0].id, cameraId: matches[0].cameraId }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** A small immutable camera/range snapshot, without prompts or arbitrary shot metadata. */
|
|
17
|
+
export function normalizeShotCameraSelection(value, frames) {
|
|
18
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) ||
|
|
19
|
+
value.schemaVersion !== SHOT_CAMERA_SELECTION_VERSION || value.mode !== 'shots' ||
|
|
20
|
+
Object.keys(value).some(key => !['schemaVersion', 'mode', 'shots'].includes(key)) ||
|
|
21
|
+
!Array.isArray(value.shots) || value.shots.length < 1 || value.shots.length > SHOT_CAMERA_SELECTION_LIMITS.shots) {
|
|
22
|
+
fail('use an explicit saved-shot selection with 1–64 shots.')
|
|
23
|
+
}
|
|
24
|
+
const seen = new Set()
|
|
25
|
+
const shots = value.shots.map(shot => {
|
|
26
|
+
if (!shot || typeof shot !== 'object' || Array.isArray(shot) || !id(shot.id) || !id(shot.cameraId) ||
|
|
27
|
+
Object.keys(shot).some(key => !['id', 'cameraId', 'frameRange'].includes(key)) || seen.has(shot.id) ||
|
|
28
|
+
!Array.isArray(shot.frameRange) || shot.frameRange.length !== 2 || !shot.frameRange.every(Number.isSafeInteger) ||
|
|
29
|
+
shot.frameRange[0] > shot.frameRange[1]) fail('each distinct shot needs its saved ID, camera ID and ordered integer frameRange.')
|
|
30
|
+
seen.add(shot.id)
|
|
31
|
+
return { id: shot.id, cameraId: shot.cameraId, frameRange: [...shot.frameRange] }
|
|
32
|
+
}).sort((a, b) => a.frameRange[0] - b.frameRange[0] || a.id.localeCompare(b.id))
|
|
33
|
+
for (let n = 1; n < shots.length; n++) {
|
|
34
|
+
if (shots[n].frameRange[0] <= shots[n - 1].frameRange[1]) fail(`shots ${shots[n - 1].id} and ${shots[n].id} overlap.`)
|
|
35
|
+
}
|
|
36
|
+
const selection = { schemaVersion: SHOT_CAMERA_SELECTION_VERSION, mode: 'shots', shots }
|
|
37
|
+
if (new TextEncoder().encode(JSON.stringify(selection)).byteLength > SHOT_CAMERA_SELECTION_LIMITS.bytes) fail('selection exceeds its 8192-byte metadata budget.')
|
|
38
|
+
if (frames !== undefined) {
|
|
39
|
+
if (!Array.isArray(frames) || !frames.length || frames.length > 100_000 || !frames.every(Number.isSafeInteger)) fail('select 1–100000 integer frames.')
|
|
40
|
+
for (const frame of frames) shotCameraForFrame(selection, frame)
|
|
41
|
+
}
|
|
42
|
+
return selection
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function buildShotCameraSelection(spec, frames) {
|
|
46
|
+
if (!Array.isArray(spec?.shots) || spec.shots.some(shot => !shot || typeof shot !== 'object' || Array.isArray(shot))) fail('the saved revision has no valid shot list.')
|
|
47
|
+
const selection = normalizeShotCameraSelection({ schemaVersion: SHOT_CAMERA_SELECTION_VERSION, mode: 'shots',
|
|
48
|
+
shots: spec.shots.map(shot => ({ id: shot.id, cameraId: shot.cameraId, frameRange: shot.frameRange })) }, frames)
|
|
49
|
+
const cameras = new Set((Array.isArray(spec.cameras) ? spec.cameras : []).filter(camera => camera && typeof camera === 'object').map(camera => camera.id))
|
|
50
|
+
for (const shot of selection.shots) if (!cameras.has(shot.cameraId)) fail(`shot ${shot.id} names missing saved camera ${shot.cameraId}.`)
|
|
51
|
+
return selection
|
|
52
|
+
}
|
package/package.json
CHANGED