@deepblend/dsh-blender-contracts 0.19.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/lamp-placement.js +82 -0
- package/lib/recipe-parameters.js +10 -3
- package/package.json +1 -1
|
@@ -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
|
+
}
|
package/lib/recipe-parameters.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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]
|
package/package.json
CHANGED