@deepblend/dsh-blender-bundle 0.28.1 → 0.30.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.
Files changed (2) hide show
  1. package/lib/client.js +233 -55
  2. package/package.json +7 -7
package/lib/client.js CHANGED
@@ -283,6 +283,10 @@ window.__ModuleLoader__.load({
283
283
  "assets.newMaterial": "创建新的基础材质并覆盖所选范围",
284
284
  "assets.nativeHelp": "原生节点没有可编辑的公共定义;需明确创建新材质覆盖所选范围。",
285
285
  "assets.replaceTexture": "用图片替换此材质的程序化纹理",
286
+ "assets.applyToTimberPartner": "也将此贴图和 UV 设置应用到 {name}",
287
+ "assets.replaceTimberTexture": "确认替换所选木条现有的程序化纹理",
288
+ "assets.saveTimberPair": "保存两组木条并预览",
289
+ "assets.timberPairUnavailable": "请选择一组具有可编辑材质的已保存半搭接木条,再选择要一起应用的木条。",
286
290
  "assets.localAnimated": "来源材质含动画,局部复制会丢失动画。请选择共享修改或明确创建新材质。",
287
291
  "assets.animatedChannel": "该通道由动画驱动,不能在此覆盖。",
288
292
  "assets.imageHelp": "保留其他通道;缺少 UV 时保存会明确失败。共享修改影响该材质所有使用者。",
@@ -539,7 +543,14 @@ window.__ModuleLoader__.load({
539
543
  'editor.uv.direction': '纹理方向',
540
544
  'editor.uv.scale': '纹理重复',
541
545
  'editor.uv.scaleInvalid': '请输入 0.0001 到 10000 之间的重复次数。',
542
- 'editor.uv.scaleHelp': '最长局部网格边界跨度内的重复次数。只改变纹理坐标,保存后查看实际预览。',
546
+ 'editor.uv.scaleHelp': '最长局部网格边界跨度内的重复次数。',
547
+ 'editor.uv.includePartner': '也重建 {name} 的 UV',
548
+ 'editor.uv.previewCamera': '预览机位',
549
+ 'editor.uv.preview': '预览纹理',
550
+ 'editor.uv.previewBusy': '正在渲染纹理…',
551
+ 'editor.uv.previewCaption': '草稿预览 · {camera} · 第 {frame} 帧',
552
+ 'editor.uv.previewImage': '两组木条的纹理草稿预览',
553
+ 'editor.uv.previewError': '纹理预览失败。{message}',
543
554
  'editor.halfLap.title': '半搭接',
544
555
  'editor.halfLap.partner': '搭接对象',
545
556
  'editor.halfLap.none': '无搭接',
@@ -1202,6 +1213,10 @@ window.__ModuleLoader__.load({
1202
1213
  "assets.newMaterial": "Create a new basic material and override this target",
1203
1214
  "assets.nativeHelp": "Native nodes have no editable public definition; explicitly create a replacement material for this target.",
1204
1215
  "assets.replaceTexture": "Replace this material’s procedural texture with image maps",
1216
+ "assets.applyToTimberPartner": "Apply these settings to {name} too",
1217
+ "assets.replaceTimberTexture": "Replace procedural textures on both groups",
1218
+ "assets.saveTimberPair": "Save both timber groups and preview",
1219
+ "assets.timberPairUnavailable": "Choose a member of a saved timber joint with editable materials, then select its partner.",
1205
1220
  "assets.localAnimated": "A local copy would lose source material animation. Choose shared editing or explicitly create a new material.",
1206
1221
  "assets.animatedChannel": "This channel is animated and cannot be overridden here.",
1207
1222
  "assets.imageHelp": "Other maps are preserved. Missing UVs cause an explicit save failure. Shared editing affects all material users.",
@@ -1458,7 +1473,14 @@ window.__ModuleLoader__.load({
1458
1473
  'editor.uv.direction': 'Texture direction',
1459
1474
  'editor.uv.scale': 'Texture repetitions',
1460
1475
  'editor.uv.scaleInvalid': 'Enter repetitions from 0.0001 to 10000.',
1461
- 'editor.uv.scaleHelp': 'Repetitions across the longest local mesh extent. Only texture coordinates change; check the saved preview.',
1476
+ 'editor.uv.scaleHelp': 'Repetitions across the longest local mesh extent.',
1477
+ 'editor.uv.includePartner': 'Also rebuild UVs on {name}',
1478
+ 'editor.uv.previewCamera': 'Preview camera',
1479
+ 'editor.uv.preview': 'Preview texture',
1480
+ 'editor.uv.previewBusy': 'Rendering texture…',
1481
+ 'editor.uv.previewCaption': 'Draft preview · {camera} · Frame {frame}',
1482
+ 'editor.uv.previewImage': 'Texture draft of both timber groups',
1483
+ 'editor.uv.previewError': 'Texture preview failed. {message}',
1462
1484
  'editor.halfLap.title': 'Half lap',
1463
1485
  'editor.halfLap.partner': 'Join with',
1464
1486
  'editor.halfLap.none': 'No joint',
@@ -2787,6 +2809,12 @@ window.__ModuleLoader__.load({
2787
2809
  && ['location', 'rotationEuler', 'scale'].includes(track.property?.split('.')[0]))
2788
2810
  }
2789
2811
 
2812
+ function editorTimberUvPartner(draft) {
2813
+ const partner = editorHalfLapPartner(draft.originalHalfLap, draft.entityId)
2814
+ return draft.entities.find(entity => entity.id === partner
2815
+ && entity.kind === 'generator' && entity.generator?.shape === 'mesh')
2816
+ }
2817
+
2790
2818
  function editorHalfLapPartners(draft) {
2791
2819
  const saved = editorHalfLapPartner(draft.originalHalfLap, draft.entityId)
2792
2820
  const canJoin = editorTimberCandidate(draft.entity, draft.tracks) && (saved || (draft.halfLaps?.length ?? 0) < 32)
@@ -2871,6 +2899,7 @@ window.__ModuleLoader__.load({
2871
2899
  if (draft.entity.kind !== 'generator' || generator?.shape !== 'mesh') bad(t('editor.uv.title'))
2872
2900
  scalar(draft.uvProjection.quarterTurns, t('editor.uv.direction'), 0, 3, true)
2873
2901
  scalar(draft.uvProjection.scale, t('editor.uv.scale'), 0.0001, 10000)
2902
+ if (draft.uvProjection.includePartner && !editorTimberUvPartner(draft)) bad(t('editor.uv.title'))
2874
2903
  }
2875
2904
  if (draft.halfLap) {
2876
2905
  scalar(Object.hasOwn(draft.halfLap, 'edgeWidth') ? draft.halfLap.edgeWidth : 0, t('editor.halfLap.edgeWidth'), 0, .005)
@@ -3002,7 +3031,12 @@ window.__ModuleLoader__.load({
3002
3031
  for (const key of ['location', 'rotationEuler']) if (!editorEqual(entity.transform[key], original.transform[key])) transform[key] = editorClone(entity.transform[key])
3003
3032
  if (Object.keys(transform).length > 2) operations.push(transform)
3004
3033
  if (!editorEqual(entity.generator, original.generator)) operations.push({ op: 'entity.generator.set', entityId: draft.entityId, generator: editorClone(entity.generator) })
3005
- if (draft.uvProjection != null) operations.push({ op: 'entity.uv.project', entityId: draft.entityId, ...editorClone(draft.uvProjection) })
3034
+ if (draft.uvProjection != null) {
3035
+ const { quarterTurns, scale, includePartner } = draft.uvProjection
3036
+ const projection = { op: 'entity.uv.project', quarterTurns, scale }
3037
+ operations.push({ ...projection, entityId: draft.entityId })
3038
+ if (includePartner) operations.push({ ...projection, entityId: editorTimberUvPartner(draft).id })
3039
+ }
3006
3040
  if (!editorEqual(entity.modifiers, original.modifiers)) operations.push({ op: 'entity.modifiers.set', entityId: draft.entityId, modifiers: editorClone(entity.modifiers) })
3007
3041
  const { halfLap, originalHalfLap } = draft
3008
3042
  if (halfLap?.lowerEntityId !== originalHalfLap?.lowerEntityId || halfLap?.upperEntityId !== originalHalfLap?.upperEntityId
@@ -3048,6 +3082,38 @@ window.__ModuleLoader__.load({
3048
3082
  return state.editorDrafts?.[editorKey(state.activeProjectId, state.editorEntityId)] || null
3049
3083
  }
3050
3084
 
3085
+ function timberUvPreviewCamera(scene, draft) {
3086
+ const cameras = scene?.nodes?.cameras ?? []
3087
+ const requested = draft.uvProjection?.cameraId ?? scene?.project?.activeCamera
3088
+ return cameras.find(camera => camera.id === requested) ?? cameras[0]
3089
+ }
3090
+
3091
+ function timberUvPreviewIntent(state, draft = editorDraftFor(state), patch) {
3092
+ const scene = state.selected?.scene
3093
+ if (!state.timberUvPreviewSupported || state.view !== 'scene' || !draft?.uvProjection?.includePartner
3094
+ || !scene || draft.baseRevision !== scene.revision || !/^[a-f0-9]{64}$/.test(scene.digest ?? '')
3095
+ || !/^[a-f0-9]{64}$/.test(state.storeIdentity ?? '')) return null
3096
+ const partner = editorTimberUvPartner(draft)
3097
+ const camera = timberUvPreviewCamera(scene, draft)
3098
+ if (!partner || !camera || !Number.isInteger(scene.project.frameStart)) return null
3099
+ try { patch ??= buildEditorPatch(draft) } catch { return null }
3100
+ const key = JSON.stringify([state.storeIdentity, scene.digest, camera.id, patch])
3101
+ return { key, patch, expectedDigest: scene.digest, expectedStoreIdentity: state.storeIdentity,
3102
+ cameraId: camera.id, frame: scene.project.frameStart, entities: [draft.entityId, partner.id] }
3103
+ }
3104
+
3105
+ function verifiedTimberUvPreview(preview, intent) {
3106
+ const image = preview?.image
3107
+ return preview?.schemaVersion === 'deepblend.timber-uv-preview/v1' && preview.projectId === intent.patch.projectId
3108
+ && preview.baseRevision === intent.patch.baseRevision && preview.baseDigest === intent.expectedDigest
3109
+ && preview.storeIdentity === intent.expectedStoreIdentity && /^[a-f0-9]{64}$/.test(preview.candidateSpecHash ?? '')
3110
+ && preview.cameraId === intent.cameraId && preview.frame === intent.frame && editorEqual(preview.entities, intent.entities)
3111
+ && Number.isInteger(image?.width) && image.width > 0 && image.width <= 720
3112
+ && Number.isInteger(image.height) && image.height > 0 && image.height <= 720
3113
+ && /^[a-f0-9]{64}$/.test(image.sha256 ?? '') && typeof image.pngBase64 === 'string'
3114
+ && image.pngBase64.length <= 4194304 && /^iVBORw0KGgo[A-Za-z0-9+/]+=*$/.test(image.pngBase64)
3115
+ }
3116
+
3051
3117
  function halfLapPreviewIntent(state, draft = editorDraftFor(state), patch) {
3052
3118
  const scene = state.selected?.scene
3053
3119
  if (!state.halfLapPreviewSupported || state.view !== 'scene' || !draft?.halfLap || !scene || draft.baseRevision !== scene.revision
@@ -3298,9 +3364,25 @@ window.__ModuleLoader__.load({
3298
3364
  editorSelectMaterial(editor, editorEffectiveMaterialId(editor))
3299
3365
  return editor
3300
3366
  }
3367
+ function pairedAssetEditor(draft, primary = assetEditor(draft)) {
3368
+ if (draft.kind !== 'image' || draft.channel !== 'baseColor'
3369
+ || draft.target !== 'entity' || draft.scope !== 'local' || draft.newMaterial) return null
3370
+ const joint = draft.scene.halfLaps?.find(pair => editorHalfLapPartner(pair, draft.entityId))
3371
+ const entityId = editorHalfLapPartner(joint, draft.entityId)
3372
+ if (!entityId) return null
3373
+ const partner = assetEditor({ ...draft, entityId })
3374
+ return [primary, partner].every(editor => {
3375
+ const entity = editor?.original, material = editor?.material.definition
3376
+ return entity?.kind === 'generator' && entity.generator?.shape === 'mesh' && !entity.locked
3377
+ && ['principled', 'glass'].includes(material?.shader)
3378
+ && !editor.tracks.some(track => track.targetKind === 'material' && track.targetId === material.id)
3379
+ }) ? partner : null
3380
+ }
3381
+
3301
3382
  function resetAssetBinding(draft) {
3302
3383
  const source = draft.newMaterial ? null : assetEditor(draft)?.material.definition
3303
3384
  draft.binding = editorClone(source?.images?.[draft.channel] || {})
3385
+ draft.includeTimberPartner = false
3304
3386
  draft.replaceTexture = false
3305
3387
  }
3306
3388
  function createAssetDraft(scene, projectId, entry, inspection, entityId) {
@@ -3316,6 +3398,47 @@ window.__ModuleLoader__.load({
3316
3398
  resetAssetBinding(draft)
3317
3399
  return draft
3318
3400
  }
3401
+ function appendImageAssetOperations(operations, draft, asset, fail, editor = assetEditor(draft)) {
3402
+ const target = editor?.original
3403
+ if (!editor || target.kind === 'empty' || target.locked) fail('target')
3404
+ if (!['entity', 'part', 'slot'].includes(draft.target) || !['local', 'shared'].includes(draft.scope)) fail('target scope')
3405
+ if (draft.target !== 'entity') {
3406
+ const part = target.assetParts?.find(item => item.partId === draft.partId)
3407
+ const sourceAsset = draft.scene.nodes.assets.find(item => item.id === target.assetId)
3408
+ if (target.kind !== 'asset-instance' || !part || part.selectorVersion !== 1 || !sourceAsset?.sha256 || part.assetSha256 !== sourceAsset.sha256) fail('source part inventory')
3409
+ if (draft.target === 'slot' && (draft.slotIndex === '' || !part.sourceMaterialSlots.some(slot => slot.index === Number(draft.slotIndex)))) fail('source slot')
3410
+ }
3411
+ const original = editor.material.definition
3412
+ if (!draft.newMaterial && (!original || !['principled', 'glass'].includes(original.shader))) throw new Error(t('assets.nativeHelp'))
3413
+ const animated = editor.tracks.filter(track => track.targetKind === 'material' && track.targetId === original?.id)
3414
+ if (!draft.newMaterial && draft.scope === 'local' && animated.length) throw new Error(t('assets.localAnimated'))
3415
+ if (!draft.newMaterial && animated.some(track => track.property === draft.channel || track.property?.startsWith(`${draft.channel}.`))) throw new Error(t('assets.animatedChannel'))
3416
+ if (!ASSET_CHANNELS.includes(draft.channel)) fail('image channel')
3417
+ const binding = { ...editorClone(draft.binding), assetId: asset.id }
3418
+ if (binding.uvMap !== undefined && (typeof binding.uvMap !== 'string' || !binding.uvMap.trim())) fail('UV name')
3419
+ for (const key of ['scale', 'offset']) if (binding[key] !== undefined && (!Array.isArray(binding[key]) || binding[key].length !== 3 || !binding[key].every(Number.isFinite))) fail(key)
3420
+ if (binding.channel !== undefined && (!['roughness', 'metallic', 'alpha'].includes(draft.channel) || !['r', 'g', 'b', 'a'].includes(binding.channel))) fail('image channel')
3421
+ if (binding.strength !== undefined && (draft.channel !== 'normal' || !Number.isFinite(binding.strength) || binding.strength < 0 || binding.strength > 10)) fail('normal strength')
3422
+ const material = draft.newMaterial ? { id: draft.newMaterialId, shader: 'principled', parameters: { baseColor: [0.8, 0.8, 0.8, 1], roughness: 0.5, metallic: 0 } } : editorClone(original)
3423
+ if (material.texture && !draft.replaceTexture) fail('procedural texture must be explicitly replaced')
3424
+ const images = { ...editorClone(material.images || {}), [draft.channel]: binding }
3425
+ let materialId = material.id
3426
+ if (draft.newMaterial || draft.scope === 'local') {
3427
+ materialId = draft.newMaterialId; material.id = materialId; material.images = images; delete material.texture
3428
+ operations.push({ op: 'material.add', material })
3429
+ if (draft.target === 'entity') operations.push({ op: 'entity.material.set', entityId: draft.entityId, materialId })
3430
+ else {
3431
+ const slotIndex = draft.target === 'slot' ? Number(draft.slotIndex) : undefined
3432
+ const bindings = editorClone(target.materialBindings || []).filter(binding => !(binding.partId === draft.partId && binding.slotIndex === slotIndex))
3433
+ bindings.push({ partId: draft.partId, ...(slotIndex === undefined ? {} : { slotIndex }), materialId })
3434
+ operations.push({ op: 'entity.materialBindings.set', entityId: draft.entityId, materialBindings: bindings })
3435
+ }
3436
+ } else {
3437
+ if (material.texture) operations.push({ op: 'material.texture.set', materialId, texture: null })
3438
+ operations.push({ op: 'material.images.set', materialId, images })
3439
+ }
3440
+ }
3441
+
3319
3442
  function buildAssetPatch(draft) {
3320
3443
  if (!draft) throw new Error(t('assets.invalid', { field: 'draft' }))
3321
3444
  const fail = field => { throw new Error(t('assets.invalid', { field })) }
@@ -3351,44 +3474,12 @@ window.__ModuleLoader__.load({
3351
3474
  operations.push({ op: 'world.set', world: { ...editorClone(draft.world), strength: draft.strength,
3352
3475
  environment: { ...editorClone(draft.world.environment || {}), assetId: asset.id, rotation: draft.rotation } } })
3353
3476
  } else {
3354
- const editor = assetEditor(draft), target = editor?.original
3355
- if (!editor || target.kind === 'empty' || target.locked) fail('target')
3356
- if (!['entity', 'part', 'slot'].includes(draft.target) || !['local', 'shared'].includes(draft.scope)) fail('target scope')
3357
- if (draft.target !== 'entity') {
3358
- const part = target.assetParts?.find(item => item.partId === draft.partId)
3359
- const sourceAsset = draft.scene.nodes.assets.find(item => item.id === target.assetId)
3360
- if (target.kind !== 'asset-instance' || !part || part.selectorVersion !== 1 || !sourceAsset?.sha256 || part.assetSha256 !== sourceAsset.sha256) fail('source part inventory')
3361
- if (draft.target === 'slot' && (draft.slotIndex === '' || !part.sourceMaterialSlots.some(slot => slot.index === Number(draft.slotIndex)))) fail('source slot')
3362
- }
3363
- const original = editor.material.definition
3364
- if (!draft.newMaterial && (!original || !['principled', 'glass'].includes(original.shader))) throw new Error(t('assets.nativeHelp'))
3365
- const animated = editor.tracks.filter(track => track.targetKind === 'material' && track.targetId === original?.id)
3366
- if (!draft.newMaterial && draft.scope === 'local' && animated.length) throw new Error(t('assets.localAnimated'))
3367
- if (!draft.newMaterial && animated.some(track => track.property === draft.channel || track.property?.startsWith(`${draft.channel}.`))) throw new Error(t('assets.animatedChannel'))
3368
- if (!ASSET_CHANNELS.includes(draft.channel)) fail('image channel')
3369
- const binding = { ...editorClone(draft.binding), assetId: asset.id }
3370
- if (binding.uvMap !== undefined && (typeof binding.uvMap !== 'string' || !binding.uvMap.trim())) fail('UV name')
3371
- for (const key of ['scale', 'offset']) if (binding[key] !== undefined && (!Array.isArray(binding[key]) || binding[key].length !== 3 || !binding[key].every(Number.isFinite))) fail(key)
3372
- if (binding.channel !== undefined && (!['roughness', 'metallic', 'alpha'].includes(draft.channel) || !['r', 'g', 'b', 'a'].includes(binding.channel))) fail('image channel')
3373
- if (binding.strength !== undefined && (draft.channel !== 'normal' || !Number.isFinite(binding.strength) || binding.strength < 0 || binding.strength > 10)) fail('normal strength')
3374
- const material = draft.newMaterial ? { id: draft.newMaterialId, shader: 'principled', parameters: { baseColor: [0.8, 0.8, 0.8, 1], roughness: 0.5, metallic: 0 } } : editorClone(original)
3375
- if (material.texture && !draft.replaceTexture) fail('procedural texture must be explicitly replaced')
3376
- const images = { ...editorClone(material.images || {}), [draft.channel]: binding }
3377
- let materialId = material.id
3378
- if (draft.newMaterial || draft.scope === 'local') {
3379
- materialId = draft.newMaterialId; material.id = materialId; material.images = images; delete material.texture
3380
- operations.push({ op: 'material.add', material })
3381
- if (draft.target === 'entity') operations.push({ op: 'entity.material.set', entityId: draft.entityId, materialId })
3382
- else {
3383
- const slotIndex = draft.target === 'slot' ? Number(draft.slotIndex) : undefined
3384
- const bindings = editorClone(target.materialBindings || []).filter(binding => !(binding.partId === draft.partId && binding.slotIndex === slotIndex))
3385
- bindings.push({ partId: draft.partId, ...(slotIndex === undefined ? {} : { slotIndex }), materialId })
3386
- operations.push({ op: 'entity.materialBindings.set', entityId: draft.entityId, materialBindings: bindings })
3387
- }
3388
- } else {
3389
- if (material.texture) operations.push({ op: 'material.texture.set', materialId, texture: null })
3390
- operations.push({ op: 'material.images.set', materialId, images })
3391
- }
3477
+ const partner = draft.includeTimberPartner ? pairedAssetEditor(draft) : null
3478
+ if (draft.includeTimberPartner && !partner) throw new Error(t('assets.timberPairUnavailable'))
3479
+ appendImageAssetOperations(operations, draft, asset, fail)
3480
+ if (partner) appendImageAssetOperations(operations, {
3481
+ ...draft, entityId: partner.original.id, newMaterialId: `${draft.newMaterialId}-partner`,
3482
+ }, asset, fail, partner)
3392
3483
  }
3393
3484
  return { projectId: draft.projectId, baseRevision: draft.baseRevision, saveCheckpoint: true, renderPreview: true, actor: 'ui', operations }
3394
3485
  }
@@ -3876,6 +3967,8 @@ window.__ModuleLoader__.load({
3876
3967
  editorDrafts: {},
3877
3968
  halfLapPreviewSupported: false,
3878
3969
  halfLapPreview: null,
3970
+ timberUvPreviewSupported: false,
3971
+ timberUvPreview: null,
3879
3972
  geometryMeasurements: {},
3880
3973
  editorLastEdits: {},
3881
3974
  editorComparison: null,
@@ -3965,6 +4058,7 @@ window.__ModuleLoader__.load({
3965
4058
  const cameraFitStorage = settings.cameraFitStorage ?? preferenceStorage
3966
4059
  const motionControllers = new Map()
3967
4060
  let halfLapPreviewController
4061
+ let timberUvPreviewController
3968
4062
  let imageProbeController = null
3969
4063
  const motionStorage = settings.motionStorage ?? preferenceStorage
3970
4064
  const motionWork = (key, changes) => set({ motionWork: { ...data.motionWork, [key]: { ...data.motionWork[key], ...changes } } })
@@ -4054,6 +4148,11 @@ window.__ModuleLoader__.load({
4054
4148
  halfLapPreviewController = undefined
4055
4149
  next.halfLapPreview = null
4056
4150
  }
4151
+ if (next.timberUvPreview && timberUvPreviewIntent(next)?.key !== next.timberUvPreview.key) {
4152
+ timberUvPreviewController?.abort()
4153
+ timberUvPreviewController = undefined
4154
+ next.timberUvPreview = null
4155
+ }
4057
4156
  data = next; notify()
4058
4157
  }
4059
4158
  /** Change one nested table. @param {'forms'|'busy'|'notices'} table @param {string} key @param {any} value */
@@ -4148,6 +4247,7 @@ window.__ModuleLoader__.load({
4148
4247
  stillImageDeliverySupported: payload.stillImageDeliverySupported === true,
4149
4248
  motionPreviewSupported: payload.motionPreviewSupported === true,
4150
4249
  halfLapPreviewSupported: payload.halfLapPreviewSupported === true,
4250
+ timberUvPreviewSupported: payload.timberUvPreviewSupported === true,
4151
4251
  imageInputProbeSupported: payload.imageInputProbeSupported === true,
4152
4252
  selectedReviewViewsSupported: payload.selectedReviewViewsSupported === true,
4153
4253
  creationRequestProtocol: payload.creationRequestProtocol ?? null,
@@ -5074,9 +5174,15 @@ window.__ModuleLoader__.load({
5074
5174
  updateAsset: (field, value) => {
5075
5175
  const projectId = data.activeProjectId, current = data.assetDrafts[projectId]
5076
5176
  if (!current || data.assetWork[projectId]?.busy) return
5077
- const allowed = ['newEntityId', 'location', 'rotationEuler', 'scale', 'hideEntityId', 'makeSubject', 'entityId', 'target', 'partId', 'slotIndex', 'scope', 'newMaterial', 'channel', 'binding', 'replaceTexture', 'strength', 'rotation']
5177
+ const allowed = ['newEntityId', 'location', 'rotationEuler', 'scale', 'hideEntityId', 'makeSubject', 'entityId', 'target', 'partId', 'slotIndex', 'scope', 'newMaterial', 'channel', 'binding', 'replaceTexture', 'includeTimberPartner', 'strength', 'rotation']
5078
5178
  if (!allowed.includes(field)) return
5179
+ if (field === 'includeTimberPartner' && (typeof value !== 'boolean' || !pairedAssetEditor(current))) return
5079
5180
  const draft = editorClone(current); draft[field] = editorClone(value)
5181
+ if (field === 'includeTimberPartner') draft.replaceTexture = false
5182
+ if (field === 'scope' && draft.includeTimberPartner && !pairedAssetEditor(draft)) {
5183
+ draft.includeTimberPartner = false
5184
+ draft.replaceTexture = false
5185
+ }
5080
5186
  if (['entityId', 'target'].includes(field)) { draft.partId = ''; draft.slotIndex = '' }
5081
5187
  if (field === 'partId') draft.slotIndex = ''
5082
5188
  if (['entityId', 'target', 'partId', 'slotIndex', 'channel', 'newMaterial'].includes(field)) resetAssetBinding(draft)
@@ -5531,7 +5637,7 @@ window.__ModuleLoader__.load({
5531
5637
  },
5532
5638
  previewHalfLap: async () => {
5533
5639
  const intent = halfLapPreviewIntent(data)
5534
- if (!intent || data.busy.editor || halfLapPreviewController) return
5640
+ if (!intent || data.busy.editor || halfLapPreviewController || timberUvPreviewController) return
5535
5641
  const controller = new AbortController()
5536
5642
  halfLapPreviewController = controller
5537
5643
  const { key, patch, expectedDigest, expectedStoreIdentity } = intent
@@ -5553,6 +5659,35 @@ window.__ModuleLoader__.load({
5553
5659
  if (halfLapPreviewController === controller) halfLapPreviewController = undefined
5554
5660
  }
5555
5661
  },
5662
+ cancelTimberUvPreview: () => {
5663
+ timberUvPreviewController?.abort()
5664
+ timberUvPreviewController = undefined
5665
+ set({ timberUvPreview: null })
5666
+ },
5667
+ previewTimberUv: async () => {
5668
+ const intent = timberUvPreviewIntent(data)
5669
+ if (!intent || data.busy.editor || timberUvPreviewController || halfLapPreviewController) return
5670
+ const controller = new AbortController()
5671
+ timberUvPreviewController = controller
5672
+ const { key, patch, expectedDigest, expectedStoreIdentity, cameraId } = intent
5673
+ const active = () => running && timberUvPreviewController === controller && !controller.signal.aborted
5674
+ set({ timberUvPreview: { key, busy: true } })
5675
+ try {
5676
+ const response = await fetchImpl(projectRoute(patch.projectId, '/timber-uv-preview'), {
5677
+ method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json' }, signal: controller.signal,
5678
+ body: JSON.stringify({ patch, expectedDigest, expectedStoreIdentity, cameraId }),
5679
+ })
5680
+ const payload = await response.json()
5681
+ if (!active()) return
5682
+ if (!response.ok || !payload.ok) throw new Error(payload.error?.message || response.status)
5683
+ if (!verifiedTimberUvPreview(payload.preview, intent)) throw new Error(t('inspection.mismatch'))
5684
+ set({ timberUvPreview: { key, result: payload.preview } })
5685
+ } catch (error) {
5686
+ if (active()) set({ timberUvPreview: { key, error: error.message || String(error) } })
5687
+ } finally {
5688
+ if (timberUvPreviewController === controller) timberUvPreviewController = undefined
5689
+ }
5690
+ },
5556
5691
  updateEditor: (section, path, value) => {
5557
5692
  const current = editorDraftFor(data)
5558
5693
  if (!current || data.busy.editor || !['transform', 'generator', 'modifiers', 'material', 'uvProjection'].includes(section)) return
@@ -5616,10 +5751,11 @@ window.__ModuleLoader__.load({
5616
5751
  try { patch = buildEditorPatch(draft) } catch (error) {
5617
5752
  setIn('notices', 'scene', { ok: false, message: error.message }); return
5618
5753
  }
5619
- if (!patch.operations.length || data.halfLapPreview?.busy) return
5620
- const inspection = data.halfLapPreview?.result
5621
- const inspected = inspection && halfLapPreviewIntent(data, draft, patch)?.key === data.halfLapPreview.key
5622
- const request = inspected ? { patch, expectedSpecHash: inspection.candidateSpecHash, expectedStoreIdentity: inspection.storeIdentity } : { patch }
5754
+ if (!patch.operations.length || data.halfLapPreview?.busy || data.timberUvPreview?.busy) return
5755
+ const slot = data.halfLapPreview, texture = data.timberUvPreview
5756
+ const inspection = texture?.result && timberUvPreviewIntent(data, draft, patch)?.key === texture.key
5757
+ ? texture.result : slot?.result && halfLapPreviewIntent(data, draft, patch)?.key === slot.key ? slot.result : null
5758
+ const request = inspection ? { patch, expectedSpecHash: inspection.candidateSpecHash, expectedStoreIdentity: inspection.storeIdentity } : { patch }
5623
5759
  const beforePreviews = editorClone(data.previews?.revisions?.find(item => item.revision === draft.baseRevision)?.previews || [])
5624
5760
  setIn('busy', 'editor', true)
5625
5761
  const outcome = await postJson(fetchImpl, projectRoute(draft.projectId, '/patch'), request)
@@ -5981,6 +6117,10 @@ window.__ModuleLoader__.load({
5981
6117
  motionControllers.clear()
5982
6118
  halfLapPreviewController?.abort()
5983
6119
  halfLapPreviewController = undefined
6120
+ timberUvPreviewController?.abort()
6121
+ timberUvPreviewController = undefined
6122
+ data = { ...data, timberUvPreview: null }
6123
+ snapshot = { ...snapshot, timberUvPreview: null }
5984
6124
  photographyControllers.clear()
5985
6125
  for (const controller of placementControllers.values()) controller.abort()
5986
6126
  placementControllers.clear()
@@ -6461,8 +6601,13 @@ window.__ModuleLoader__.load({
6461
6601
  const slotIntent = halfLapPreviewIntent(state, draft)
6462
6602
  const slotWork = slotIntent && state.halfLapPreview?.key === slotIntent.key ? state.halfLapPreview : null
6463
6603
  const slotResult = slotWork?.result
6604
+ const uvPartner = state.timberUvPreviewSupported ? editorTimberUvPartner(draft) : null
6605
+ const uvScene = state.selected?.scene
6606
+ const uvIntent = timberUvPreviewIntent(state, draft)
6607
+ const uvWork = uvIntent && state.timberUvPreview?.key === uvIntent.key ? state.timberUvPreview : null
6608
+ const uvResult = uvWork?.result
6464
6609
  const apply = Button({ action: 'editor-apply', tone: 'primary',
6465
- disabled: disabled || !dirty || errors.length > 0 || slotWork?.busy === true, onClick: actions.applyEditor, children: t('editor.apply') })
6610
+ disabled: disabled || !dirty || errors.length > 0 || slotWork?.busy === true || uvWork?.busy === true, onClick: actions.applyEditor, children: t('editor.apply') })
6466
6611
  const geometryField = key => {
6467
6612
  const bounds = generatorIntegerBounds(geometry, key)
6468
6613
  if (key === 'rootTension') return numeric(labels[key], `editor-generator-${key}`, geometry[key],
@@ -6540,6 +6685,8 @@ window.__ModuleLoader__.load({
6540
6685
  toggle(t('editor.uv.project'), 'editor-uv-project', draft.uvProjection != null,
6541
6686
  value => actions.updateEditor('uvProjection', [], value ? { quarterTurns: 0, scale: 1 } : null)),
6542
6687
  draft.uvProjection ? [
6688
+ uvPartner ? toggle(t('editor.uv.includePartner', { name: uvPartner.name || uvPartner.id }), 'editor-uv-partner',
6689
+ draft.uvProjection.includePartner === true, value => actions.updateEditor('uvProjection', ['includePartner'], value)) : null,
6543
6690
  el('p', { className: 'db-muted', key: 'uv-help' }, t('editor.uv.help')),
6544
6691
  choose(t('editor.uv.direction'), 'editor-uv-quarterTurns', String(draft.uvProjection.quarterTurns),
6545
6692
  [0, 1, 2, 3].map(turn => [String(turn), `${turn * 90}°`]), value => actions.updateEditor('uvProjection', ['quarterTurns'], Number(value))),
@@ -6548,6 +6695,12 @@ window.__ModuleLoader__.load({
6548
6695
  invalid: draft.uvProjection.scale < 0.0001 || draft.uvProjection.scale > 10000,
6549
6696
  error: t('editor.uv.scaleInvalid') }),
6550
6697
  el('p', { className: 'db-muted', key: 'uv-scale-help' }, t('editor.uv.scaleHelp')),
6698
+ draft.uvProjection.includePartner && uvPartner ? [
6699
+ uvScene?.nodes.cameras?.length > 1 ? choose(t('editor.uv.previewCamera'), 'editor-uv-camera',
6700
+ timberUvPreviewCamera(uvScene, draft)?.id, uvScene.nodes.cameras.map(camera => [camera.id, camera.name || camera.id]),
6701
+ value => actions.updateEditor('uvProjection', ['cameraId'], value)) : null,
6702
+ TimberUvPreview({ work: uvWork, apply, disabled: disabled || !uvIntent || slotWork?.busy === true, actions }),
6703
+ ] : null,
6551
6704
  ] : null),
6552
6705
  halfLapOptions.length ? el('fieldset', { key: 'half-lap', 'data-half-lap-editor': true, disabled, style: { border: 0, padding: 0, margin: '16px 0' } },
6553
6706
  el('legend', null, t('editor.halfLap.title')),
@@ -6560,7 +6713,7 @@ window.__ModuleLoader__.load({
6560
6713
  actions.setEditorHalfLapWidth, { factor: 1000, min: 0, max: 5, step: .05,
6561
6714
  invalid: halfLapEdgeWidth < 0 || halfLapEdgeWidth > .005, error: t('editor.halfLap.edgeInvalid') }) : null,
6562
6715
  halfLapPartner ? el('p', { className: 'db-muted', key: 'edge-width-help' }, t('editor.halfLap.edgeHelp')) : null,
6563
- slotIntent ? HalfLapPreview({ slotWork, apply, disabled, actions }) : null) : null] : null,
6716
+ slotIntent ? HalfLapPreview({ slotWork, apply: uvResult ? null : apply, disabled: disabled || uvWork?.busy === true, actions }) : null) : null] : null,
6564
6717
  el('p', { className: 'db-muted', key: 'local-size' }, t('editor.localDimensions', { scale: (draft.entity.transform.scale || [1, 1, 1]).join(' × ') })),
6565
6718
  geometry.shape === 'rounded_box' ? el('p', { className: 'db-muted', key: 'rounded' }, t('editor.roundedRequired')) : null,
6566
6719
  geometry.shape === 'handled_cup' ? el('p', { className: 'db-muted', key: 'cup-help' }, t('editor.cupHelp')) : null,
@@ -6670,13 +6823,30 @@ window.__ModuleLoader__.load({
6670
6823
  el('div', { className: 'db-inline' }, Object.entries(modifierNames).map(([type, name]) => Button({ action: `editor-modifier-add-${type}`, disabled: disabled || !canModify || draft.entity.modifiers.length >= 8,
6671
6824
  children: t('editor.add', { name }), onClick: () => actions.editEditorList('modifiers', 0, 'add', type) })))) : null,
6672
6825
  errors.length ? el('div', { className: 'db-error', 'data-editor-errors': true }, errors.join(' ')) : null,
6673
- el('div', { className: 'db-inline db-editor-actions' }, slotResult ? null : apply,
6826
+ el('div', { className: 'db-inline db-editor-actions' }, slotResult || uvResult ? null : apply,
6674
6827
  Button({ action: 'editor-reset', disabled: state.busy.editor, onClick: actions.resetEditor, children: t('editor.reset') }),
6675
6828
  Button({ action: 'editor-review-subject', disabled: disabled || draft.entity.visible === false || draft.entity.kind === 'empty'
6676
6829
  || state.briefWork[state.activeProjectId]?.saving || state.visualRuns[state.activeProjectId]?.busy,
6677
6830
  onClick: () => actions.setReviewSubject(draft.entityId), children: t('brief.subjectShortcut') }), restore))
6678
6831
  }
6679
6832
 
6833
+ function TimberUvPreview({ work, apply, disabled, actions }) {
6834
+ const result = work?.result
6835
+ return el('div', { key: 'uv-preview', 'data-timber-uv-preview': result ? 'ready' : work?.busy ? 'loading' : work?.error ? 'error' : 'idle',
6836
+ 'aria-busy': work?.busy === true },
6837
+ el('div', { className: 'db-inline' },
6838
+ Button({ action: 'timber-uv-preview', disabled: disabled || work?.busy === true,
6839
+ children: work?.busy ? t('editor.uv.previewBusy') : t('editor.uv.preview'), onClick: actions.previewTimberUv }),
6840
+ work?.busy ? Button({ action: 'timber-uv-preview-cancel', children: t('geometry.cancel'), onClick: actions.cancelTimberUvPreview }) : null),
6841
+ result ? el('figure', { style: { margin: '12px 0' } },
6842
+ el('img', { src: `data:image/png;base64,${result.image.pngBase64}`, alt: t('editor.uv.previewImage'),
6843
+ width: result.image.width, height: result.image.height, style: { display: 'block', width: '100%', height: 'auto' } }),
6844
+ el('figcaption', { className: 'db-muted', role: 'status', style: { overflowWrap: 'anywhere' } },
6845
+ t('editor.uv.previewCaption', { camera: result.cameraId, frame: result.frame }))) : null,
6846
+ result ? apply : null,
6847
+ work?.error ? el('p', { className: 'db-error', role: 'alert' }, t('editor.uv.previewError', { message: work.error })) : null)
6848
+ }
6849
+
6680
6850
  function HalfLapPreview({ slotWork, apply, disabled, actions }) {
6681
6851
  const result = slotWork?.result
6682
6852
  const picture = (role, caption, label) => el('figure', { style: { margin: '12px 0' } },
@@ -6716,21 +6886,26 @@ window.__ModuleLoader__.load({
6716
6886
  const choose = (label, field, value, entries, change) => el('label', { className: 'db-row' }, label,
6717
6887
  el('select', { className: 'db-input', 'aria-label': label, 'data-field': field, value, disabled: busy, onChange: event => change(event.target.value) },
6718
6888
  entries.map(([id, name]) => el('option', { value: id, key: id }, name))))
6719
- const check = (label, field, value, change) => el('label', { className: 'db-row' },
6720
- el('input', { type: 'checkbox', 'data-field': field, checked: value, disabled: busy, onChange: event => change(event.target.checked) }), label)
6889
+ const check = (label, field, value, change, inline = false) => el('label', {
6890
+ className: 'db-row', ...(inline ? { style: { flexWrap: 'nowrap', overflowWrap: 'anywhere' } } : {}),
6891
+ }, el('input', { type: 'checkbox', 'data-field': field, checked: value, disabled: busy,
6892
+ onChange: event => change(event.target.checked) }), label)
6721
6893
  const vector = (name, field, values, factor) => el('div', { className: 'db-inline' }, EDITOR_AXES.map((axis, index) => number(`${name} ${axis}`, `asset-${field}-${axis}`,
6722
6894
  values[index] === null ? '' : values[index] * factor, value => { const next = [...values]; next[index] = value === null ? null : value / factor; update(field, next) })))
6723
- let editor, material, part, error, affected = []
6895
+ let editor, material, partner, part, error, affected = []
6724
6896
  if (draft) {
6725
6897
  error = assetDraftError(draft)
6726
6898
  if (draft.kind === 'image') {
6727
6899
  editor = assetEditor(draft); material = editor?.material.definition
6900
+ partner = pairedAssetEditor(draft, editor)
6728
6901
  part = editor?.original.assetParts?.find(item => item.partId === draft.partId)
6729
6902
  affected = draft.scene.nodes.entities.filter(entity => entity.materialId === material?.id
6730
6903
  || entity.materialBindings?.some(binding => binding.materialId === material?.id)
6731
6904
  || entity.assetParts?.some(item => item.materialSlots?.some(slot => slot.materialId === material?.id))).map(entity => entity.id)
6732
6905
  }
6733
6906
  }
6907
+ const paired = draft?.includeTimberPartner && partner
6908
+ const replaceTexture = !draft?.newMaterial && (material?.texture || (paired && partner.material.definition.texture))
6734
6909
  const mapSetting = (key, value) => { const binding = editorClone(draft.binding); if (value === undefined) delete binding[key]; else binding[key] = value; update('binding', binding) }
6735
6910
  return el('section', { className: 'db-card', 'data-assets-library': projectId, 'data-asset-base-revision': draft?.baseRevision || '', 'data-asset-conflict': String(conflict) },
6736
6911
  el('h4', null, t('assets.title')), el('p', { className: 'db-muted' }, t('assets.help')),
@@ -6826,10 +7001,13 @@ window.__ModuleLoader__.load({
6826
7001
  ['roughness', 'metallic', 'alpha'].includes(draft.channel) ? choose(t('assets.scalarChannel'), 'asset-scalar-channel', draft.binding.channel || 'r', ['r', 'g', 'b', 'a'].map(value => [value, value]), value => mapSetting('channel', value)) : null,
6827
7002
  draft.channel === 'normal' ? number(t('assets.normalStrength'), 'asset-normal-strength', editorNumberDefault(draft.binding.strength, 1), value => mapSetting('strength', value), { min: 0, max: 10 }) : null,
6828
7003
  draft.channel === 'emissionColor' ? el('p', { className: 'db-muted' }, t('assets.emissionHelp')) : null,
6829
- !draft.newMaterial && material?.texture ? check(t('assets.replaceTexture'), 'asset-replace-texture', draft.replaceTexture, value => update('replaceTexture', value)) : null) : null,
7004
+ partner ? check(t('assets.applyToTimberPartner', { name: partner.original.name || partner.original.id }),
7005
+ 'asset-include-timber-partner', Boolean(paired), value => update('includeTimberPartner', value), true) : null,
7006
+ replaceTexture ? check(paired ? t('assets.replaceTimberTexture') : t('assets.replaceTexture'),
7007
+ 'asset-replace-texture', draft.replaceTexture, value => update('replaceTexture', value), Boolean(paired)) : null) : null,
6830
7008
  error ? el('p', { className: 'db-error' }, error) : null,
6831
7009
  el('div', { className: 'db-inline' }, Button({ action: 'asset-apply', tone: 'primary', disabled: busy || conflict || Boolean(error) || state.busy.editor || state.busy.patch || state.busy.restore || state.visualRuns[projectId]?.busy,
6832
- onClick: actions.applyAsset, children: t('assets.apply') }), Button({ action: 'asset-reset', disabled: busy, onClick: actions.discardAsset, children: t('assets.reset') }))) : null)
7010
+ onClick: actions.applyAsset, children: paired ? t('assets.saveTimberPair') : t('assets.apply') }), Button({ action: 'asset-reset', disabled: busy, onClick: actions.discardAsset, children: t('assets.reset') }))) : null)
6833
7011
  }
6834
7012
 
6835
7013
  function CameraFitEditor(ctx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepblend/dsh-blender-bundle",
3
- "version": "0.28.1",
3
+ "version": "0.30.0",
4
4
  "description": "Create Blender product scenes in DSH with editable recipes, model imports, previews and PNG/MP4 delivery; includes workbench and agent configuration.",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -44,12 +44,12 @@
44
44
  }
45
45
  },
46
46
  "dependencies": {
47
- "@deepblend/dsh-blender-contracts": "0.28.1",
48
- "@deepblend/dsh-blender-host": "0.28.1",
49
- "@deepblend/dsh-blender-preset": "0.28.1",
50
- "@deepblend/dsh-blender-provider-local": "0.28.1",
51
- "@deepblend/dsh-blender-tool": "0.28.1",
52
- "@deepblend/dsh-blender-ui": "0.28.1"
47
+ "@deepblend/dsh-blender-contracts": "0.30.0",
48
+ "@deepblend/dsh-blender-host": "0.30.0",
49
+ "@deepblend/dsh-blender-preset": "0.30.0",
50
+ "@deepblend/dsh-blender-provider-local": "0.30.0",
51
+ "@deepblend/dsh-blender-tool": "0.30.0",
52
+ "@deepblend/dsh-blender-ui": "0.30.0"
53
53
  },
54
54
  "type": "module",
55
55
  "license": "MIT",