@deepblend/dsh-blender-contracts 0.10.0 → 0.11.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/recipe-parameters.js +9 -2
- package/lib/speaker-assembly.js +41 -0
- package/package.json +1 -1
package/lib/recipe-parameters.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Plan existing-assembly edits as ordinary, bounded ScenePatch operations. */
|
|
2
2
|
import { legacyLampAssembly } from './lamp-assembly-repair.js'
|
|
3
|
+
import { translatedSpeakerAssembly } from './speaker-assembly.js'
|
|
3
4
|
import { latheShellTargets } from './lathe-shell.js'
|
|
4
5
|
import { canonicalStringify, sha256Canonical } from './canonical.js'
|
|
5
6
|
import { instantiateRecipeLock, RecipeError } from './recipe.js'
|
|
@@ -36,8 +37,9 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
|
|
|
36
37
|
}
|
|
37
38
|
const savedBefore = parameterState === undefined ? origin : instantiateRecipeLock(currentLock)
|
|
38
39
|
const assembly = legacyLampAssembly(lock, parameterState)
|
|
39
|
-
const
|
|
40
|
-
const
|
|
40
|
+
const resolvedBefore = assembly && parameterState?.assemblyRepair ? instantiateRecipeLock(assembly.currentLock(currentLock)) : savedBefore
|
|
41
|
+
const resolvedAfter = instantiateRecipeLock(assembly ? assembly.currentLock(currentLock) : currentLock, changes)
|
|
42
|
+
const { before, after } = translatedSpeakerAssembly(lock, currentSpec, resolvedBefore, resolvedAfter)
|
|
41
43
|
const parameters = recipeGeometryParameters(assembly?.manifest ?? lock.manifest)
|
|
42
44
|
for (const id of Object.keys(changes)) {
|
|
43
45
|
if (!parameters.some(parameter => parameter.id === id)) {
|
|
@@ -69,6 +71,11 @@ export function planRecipeGeometryEdit(lock, currentSpec, parameterState, change
|
|
|
69
71
|
property: 'shell-alignment', expected: oldEntity?.transform, actual: currentEntity?.transform })
|
|
70
72
|
}
|
|
71
73
|
if (binding.property === 'dimensions' || ['generator', 'curve-point'].includes(binding.kind)) {
|
|
74
|
+
if (binding.property === 'dimensions' && (currentEntity?.generator?.shape !== oldEntity?.generator?.shape
|
|
75
|
+
|| !close(currentEntity?.transform?.rotationEuler ?? [0, 0, 0], oldEntity?.transform?.rotationEuler ?? [0, 0, 0]))) {
|
|
76
|
+
conflicts.push({ parameterId: parameter.id, entityId: binding.entityId,
|
|
77
|
+
property: 'dimension-alignment', expected: oldEntity?.transform?.rotationEuler, actual: currentEntity?.transform?.rotationEuler })
|
|
78
|
+
}
|
|
72
79
|
const oldScale = oldEntity?.transform?.scale ?? [1, 1, 1]
|
|
73
80
|
const scale = currentEntity?.transform?.scale ?? [1, 1, 1]
|
|
74
81
|
if (!scale?.every((value, axis) => close(value, oldScale[axis]))) {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Recognize a rigidly translated, pinned speaker without changing its origin lock. */
|
|
2
|
+
const sources = new Set([
|
|
3
|
+
'e760a69e9f79f626205655445f24a3f254a53942ed55128554129ad18a2148f3',
|
|
4
|
+
'2810f8a9581d4fe48ef9581180168b087f798bd4400c86cd83a9f82b74acfae8',
|
|
5
|
+
])
|
|
6
|
+
const close = (a, b) => Number.isFinite(a) && Number.isFinite(b) && Math.abs(a - b) <= 1e-9
|
|
7
|
+
|
|
8
|
+
export function translatedSpeakerAssembly(lock, current, before, after) {
|
|
9
|
+
if (!sources.has(lock.manifestSha256)) return { before, after }
|
|
10
|
+
const parts = before.spec.entities.filter(entity => entity.id !== 'studio-floor')
|
|
11
|
+
const anchor = parts.find(entity => entity.id === 'cabinet-shell')
|
|
12
|
+
const actualAnchor = current.entities.find(entity => entity.id === anchor.id)
|
|
13
|
+
if (!actualAnchor?.transform?.location) return { before, after }
|
|
14
|
+
const offset = actualAnchor.transform.location.map((value, axis) => value - anchor.transform.location[axis])
|
|
15
|
+
if (offset.every(value => close(value, 0))) return { before, after }
|
|
16
|
+
// A partial move must remain a conflict, including axes without parameter bindings.
|
|
17
|
+
if (!parts.every(original => {
|
|
18
|
+
const actual = current.entities.find(entity => entity.id === original.id)
|
|
19
|
+
return actual?.transform?.location && original.transform.location.every((value, axis) => close(actual.transform.location[axis], value + offset[axis]))
|
|
20
|
+
})) return { before, after }
|
|
21
|
+
const tracks = before.spec.animationTracks.filter(track => (track.targetKind ?? 'entity') === 'entity'
|
|
22
|
+
&& parts.some(entity => entity.id === track.targetEntityId) && /^location\.[xyz]$/.test(track.property))
|
|
23
|
+
if (!tracks.every(original => {
|
|
24
|
+
const actual = (current.animationTracks ?? []).find(track => track.id === original.id)
|
|
25
|
+
const axis = ['x', 'y', 'z'].indexOf(original.property.at(-1))
|
|
26
|
+
// The authored rest anchor must follow the assembly. Later press timing and
|
|
27
|
+
// travel can be custom; the planner offsets those actual keys, never replaces them.
|
|
28
|
+
return actual && actual.targetEntityId === original.targetEntityId && actual.property === original.property
|
|
29
|
+
&& (actual.targetKind ?? 'entity') === 'entity'
|
|
30
|
+
&& actual.keyframes[0]?.frame === original.keyframes[0].frame
|
|
31
|
+
&& close(actual.keyframes[0]?.value, original.keyframes[0].value + offset[axis])
|
|
32
|
+
})) return { before, after }
|
|
33
|
+
const translate = resolved => {
|
|
34
|
+
const result = structuredClone(resolved)
|
|
35
|
+
for (const entity of result.spec.entities) if (entity.id !== 'studio-floor') {
|
|
36
|
+
entity.transform.location = entity.transform.location.map((value, axis) => value + offset[axis])
|
|
37
|
+
}
|
|
38
|
+
return result
|
|
39
|
+
}
|
|
40
|
+
return { before: translate(before), after: translate(after) }
|
|
41
|
+
}
|
package/package.json
CHANGED