@deepblend/dsh-blender-bundle 0.29.0 → 0.31.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/client.js +210 -91
- package/package.json +7 -7
package/lib/client.js
CHANGED
|
@@ -283,6 +283,14 @@ 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.rebuildTimberUvs": "同时重建两组 UV",
|
|
290
|
+
"assets.rebuildTimberUvsHelp": "使用同一 UV 层的其他贴图也会按新坐标渲染。",
|
|
291
|
+
"assets.rebuildDefaultUv": "重建时请选择 UVMap,或留空使用默认 UV 层。",
|
|
292
|
+
"assets.rebuildUvUnavailable": "当前宿主无法重建 UV。取消勾选后即可保存贴图。",
|
|
293
|
+
"assets.timberPairUnavailable": "请选择一组具有可编辑材质的已保存半搭接木条,再选择要一起应用的木条。",
|
|
286
294
|
"assets.localAnimated": "来源材质含动画,局部复制会丢失动画。请选择共享修改或明确创建新材质。",
|
|
287
295
|
"assets.animatedChannel": "该通道由动画驱动,不能在此覆盖。",
|
|
288
296
|
"assets.imageHelp": "保留其他通道;缺少 UV 时保存会明确失败。共享修改影响该材质所有使用者。",
|
|
@@ -1209,6 +1217,14 @@ window.__ModuleLoader__.load({
|
|
|
1209
1217
|
"assets.newMaterial": "Create a new basic material and override this target",
|
|
1210
1218
|
"assets.nativeHelp": "Native nodes have no editable public definition; explicitly create a replacement material for this target.",
|
|
1211
1219
|
"assets.replaceTexture": "Replace this material’s procedural texture with image maps",
|
|
1220
|
+
"assets.applyToTimberPartner": "Apply these settings to {name} too",
|
|
1221
|
+
"assets.replaceTimberTexture": "Replace procedural textures on both groups",
|
|
1222
|
+
"assets.saveTimberPair": "Save both timber groups and preview",
|
|
1223
|
+
"assets.rebuildTimberUvs": "Rebuild both UV maps",
|
|
1224
|
+
"assets.rebuildTimberUvsHelp": "Other images on the same UV layer will follow the new coordinates.",
|
|
1225
|
+
"assets.rebuildDefaultUv": "Choose UVMap or leave the layer blank to rebuild the default UVs.",
|
|
1226
|
+
"assets.rebuildUvUnavailable": "This host cannot rebuild UVs. Clear the checkbox to save the image map.",
|
|
1227
|
+
"assets.timberPairUnavailable": "Choose a member of a saved timber joint with editable materials, then select its partner.",
|
|
1212
1228
|
"assets.localAnimated": "A local copy would lose source material animation. Choose shared editing or explicitly create a new material.",
|
|
1213
1229
|
"assets.animatedChannel": "This channel is animated and cannot be overridden here.",
|
|
1214
1230
|
"assets.imageHelp": "Other maps are preserved. Missing UVs cause an explicit save failure. Shared editing affects all material users.",
|
|
@@ -3080,18 +3096,23 @@ window.__ModuleLoader__.load({
|
|
|
3080
3096
|
return cameras.find(camera => camera.id === requested) ?? cameras[0]
|
|
3081
3097
|
}
|
|
3082
3098
|
|
|
3083
|
-
function
|
|
3099
|
+
function timberUvPreviewSource(state, draft) {
|
|
3084
3100
|
const scene = state.selected?.scene
|
|
3085
|
-
if (!state.timberUvPreviewSupported || state.view !== 'scene' || !draft
|
|
3101
|
+
if (!state.timberUvPreviewSupported || state.view !== 'scene' || !draft
|
|
3086
3102
|
|| !scene || draft.baseRevision !== scene.revision || !/^[a-f0-9]{64}$/.test(scene.digest ?? '')
|
|
3087
|
-
|| !/^[a-f0-9]{64}$/.test(state.storeIdentity ?? '')) return null
|
|
3088
|
-
const partner = editorTimberUvPartner(draft)
|
|
3103
|
+
|| !/^[a-f0-9]{64}$/.test(state.storeIdentity ?? '') || !Number.isInteger(scene.project.frameStart)) return null
|
|
3089
3104
|
const camera = timberUvPreviewCamera(scene, draft)
|
|
3090
|
-
|
|
3105
|
+
return camera ? { expectedDigest: scene.digest, expectedStoreIdentity: state.storeIdentity,
|
|
3106
|
+
cameraId: camera.id, frame: scene.project.frameStart } : null
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
function timberUvPreviewIntent(state, draft = editorDraftFor(state), patch) {
|
|
3110
|
+
if (!draft?.uvProjection?.includePartner) return null
|
|
3111
|
+
const source = timberUvPreviewSource(state, draft), partner = editorTimberUvPartner(draft)
|
|
3112
|
+
if (!source || !partner) return null
|
|
3091
3113
|
try { patch ??= buildEditorPatch(draft) } catch { return null }
|
|
3092
|
-
const key = JSON.stringify([
|
|
3093
|
-
return { key, patch,
|
|
3094
|
-
cameraId: camera.id, frame: scene.project.frameStart, entities: [draft.entityId, partner.id] }
|
|
3114
|
+
const key = JSON.stringify(['editor', source, patch])
|
|
3115
|
+
return { ...source, kind: 'editor', key, patch, entities: [draft.entityId, partner.id] }
|
|
3095
3116
|
}
|
|
3096
3117
|
|
|
3097
3118
|
function verifiedTimberUvPreview(preview, intent) {
|
|
@@ -3356,9 +3377,26 @@ window.__ModuleLoader__.load({
|
|
|
3356
3377
|
editorSelectMaterial(editor, editorEffectiveMaterialId(editor))
|
|
3357
3378
|
return editor
|
|
3358
3379
|
}
|
|
3380
|
+
function pairedAssetEditor(draft, primary = assetEditor(draft)) {
|
|
3381
|
+
if (draft.kind !== 'image' || draft.channel !== 'baseColor'
|
|
3382
|
+
|| draft.target !== 'entity' || draft.scope !== 'local' || draft.newMaterial) return null
|
|
3383
|
+
const joint = draft.scene.halfLaps?.find(pair => editorHalfLapPartner(pair, draft.entityId))
|
|
3384
|
+
const entityId = editorHalfLapPartner(joint, draft.entityId)
|
|
3385
|
+
if (!entityId) return null
|
|
3386
|
+
const partner = assetEditor({ ...draft, entityId })
|
|
3387
|
+
return [primary, partner].every(editor => {
|
|
3388
|
+
const entity = editor?.original, material = editor?.material.definition
|
|
3389
|
+
return entity?.kind === 'generator' && entity.generator?.shape === 'mesh' && !entity.locked
|
|
3390
|
+
&& ['principled', 'glass'].includes(material?.shader)
|
|
3391
|
+
&& !editor.tracks.some(track => track.targetKind === 'material' && track.targetId === material.id)
|
|
3392
|
+
}) ? partner : null
|
|
3393
|
+
}
|
|
3394
|
+
|
|
3359
3395
|
function resetAssetBinding(draft) {
|
|
3360
3396
|
const source = draft.newMaterial ? null : assetEditor(draft)?.material.definition
|
|
3361
3397
|
draft.binding = editorClone(source?.images?.[draft.channel] || {})
|
|
3398
|
+
draft.includeTimberPartner = false
|
|
3399
|
+
draft.uvProjection = null
|
|
3362
3400
|
draft.replaceTexture = false
|
|
3363
3401
|
}
|
|
3364
3402
|
function createAssetDraft(scene, projectId, entry, inspection, entityId) {
|
|
@@ -3374,6 +3412,47 @@ window.__ModuleLoader__.load({
|
|
|
3374
3412
|
resetAssetBinding(draft)
|
|
3375
3413
|
return draft
|
|
3376
3414
|
}
|
|
3415
|
+
function appendImageAssetOperations(operations, draft, asset, fail, editor = assetEditor(draft)) {
|
|
3416
|
+
const target = editor?.original
|
|
3417
|
+
if (!editor || target.kind === 'empty' || target.locked) fail('target')
|
|
3418
|
+
if (!['entity', 'part', 'slot'].includes(draft.target) || !['local', 'shared'].includes(draft.scope)) fail('target scope')
|
|
3419
|
+
if (draft.target !== 'entity') {
|
|
3420
|
+
const part = target.assetParts?.find(item => item.partId === draft.partId)
|
|
3421
|
+
const sourceAsset = draft.scene.nodes.assets.find(item => item.id === target.assetId)
|
|
3422
|
+
if (target.kind !== 'asset-instance' || !part || part.selectorVersion !== 1 || !sourceAsset?.sha256 || part.assetSha256 !== sourceAsset.sha256) fail('source part inventory')
|
|
3423
|
+
if (draft.target === 'slot' && (draft.slotIndex === '' || !part.sourceMaterialSlots.some(slot => slot.index === Number(draft.slotIndex)))) fail('source slot')
|
|
3424
|
+
}
|
|
3425
|
+
const original = editor.material.definition
|
|
3426
|
+
if (!draft.newMaterial && (!original || !['principled', 'glass'].includes(original.shader))) throw new Error(t('assets.nativeHelp'))
|
|
3427
|
+
const animated = editor.tracks.filter(track => track.targetKind === 'material' && track.targetId === original?.id)
|
|
3428
|
+
if (!draft.newMaterial && draft.scope === 'local' && animated.length) throw new Error(t('assets.localAnimated'))
|
|
3429
|
+
if (!draft.newMaterial && animated.some(track => track.property === draft.channel || track.property?.startsWith(`${draft.channel}.`))) throw new Error(t('assets.animatedChannel'))
|
|
3430
|
+
if (!ASSET_CHANNELS.includes(draft.channel)) fail('image channel')
|
|
3431
|
+
const binding = { ...editorClone(draft.binding), assetId: asset.id }
|
|
3432
|
+
if (binding.uvMap !== undefined && (typeof binding.uvMap !== 'string' || !binding.uvMap.trim())) fail('UV name')
|
|
3433
|
+
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)
|
|
3434
|
+
if (binding.channel !== undefined && (!['roughness', 'metallic', 'alpha'].includes(draft.channel) || !['r', 'g', 'b', 'a'].includes(binding.channel))) fail('image channel')
|
|
3435
|
+
if (binding.strength !== undefined && (draft.channel !== 'normal' || !Number.isFinite(binding.strength) || binding.strength < 0 || binding.strength > 10)) fail('normal strength')
|
|
3436
|
+
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)
|
|
3437
|
+
if (material.texture && !draft.replaceTexture) fail('procedural texture must be explicitly replaced')
|
|
3438
|
+
const images = { ...editorClone(material.images || {}), [draft.channel]: binding }
|
|
3439
|
+
let materialId = material.id
|
|
3440
|
+
if (draft.newMaterial || draft.scope === 'local') {
|
|
3441
|
+
materialId = draft.newMaterialId; material.id = materialId; material.images = images; delete material.texture
|
|
3442
|
+
operations.push({ op: 'material.add', material })
|
|
3443
|
+
if (draft.target === 'entity') operations.push({ op: 'entity.material.set', entityId: draft.entityId, materialId })
|
|
3444
|
+
else {
|
|
3445
|
+
const slotIndex = draft.target === 'slot' ? Number(draft.slotIndex) : undefined
|
|
3446
|
+
const bindings = editorClone(target.materialBindings || []).filter(binding => !(binding.partId === draft.partId && binding.slotIndex === slotIndex))
|
|
3447
|
+
bindings.push({ partId: draft.partId, ...(slotIndex === undefined ? {} : { slotIndex }), materialId })
|
|
3448
|
+
operations.push({ op: 'entity.materialBindings.set', entityId: draft.entityId, materialBindings: bindings })
|
|
3449
|
+
}
|
|
3450
|
+
} else {
|
|
3451
|
+
if (material.texture) operations.push({ op: 'material.texture.set', materialId, texture: null })
|
|
3452
|
+
operations.push({ op: 'material.images.set', materialId, images })
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
|
|
3377
3456
|
function buildAssetPatch(draft) {
|
|
3378
3457
|
if (!draft) throw new Error(t('assets.invalid', { field: 'draft' }))
|
|
3379
3458
|
const fail = field => { throw new Error(t('assets.invalid', { field })) }
|
|
@@ -3409,49 +3488,33 @@ window.__ModuleLoader__.load({
|
|
|
3409
3488
|
operations.push({ op: 'world.set', world: { ...editorClone(draft.world), strength: draft.strength,
|
|
3410
3489
|
environment: { ...editorClone(draft.world.environment || {}), assetId: asset.id, rotation: draft.rotation } } })
|
|
3411
3490
|
} else {
|
|
3412
|
-
const
|
|
3413
|
-
if (
|
|
3414
|
-
|
|
3415
|
-
if (
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
if (!draft.newMaterial && draft.scope === 'local' && animated.length) throw new Error(t('assets.localAnimated'))
|
|
3425
|
-
if (!draft.newMaterial && animated.some(track => track.property === draft.channel || track.property?.startsWith(`${draft.channel}.`))) throw new Error(t('assets.animatedChannel'))
|
|
3426
|
-
if (!ASSET_CHANNELS.includes(draft.channel)) fail('image channel')
|
|
3427
|
-
const binding = { ...editorClone(draft.binding), assetId: asset.id }
|
|
3428
|
-
if (binding.uvMap !== undefined && (typeof binding.uvMap !== 'string' || !binding.uvMap.trim())) fail('UV name')
|
|
3429
|
-
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)
|
|
3430
|
-
if (binding.channel !== undefined && (!['roughness', 'metallic', 'alpha'].includes(draft.channel) || !['r', 'g', 'b', 'a'].includes(binding.channel))) fail('image channel')
|
|
3431
|
-
if (binding.strength !== undefined && (draft.channel !== 'normal' || !Number.isFinite(binding.strength) || binding.strength < 0 || binding.strength > 10)) fail('normal strength')
|
|
3432
|
-
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)
|
|
3433
|
-
if (material.texture && !draft.replaceTexture) fail('procedural texture must be explicitly replaced')
|
|
3434
|
-
const images = { ...editorClone(material.images || {}), [draft.channel]: binding }
|
|
3435
|
-
let materialId = material.id
|
|
3436
|
-
if (draft.newMaterial || draft.scope === 'local') {
|
|
3437
|
-
materialId = draft.newMaterialId; material.id = materialId; material.images = images; delete material.texture
|
|
3438
|
-
operations.push({ op: 'material.add', material })
|
|
3439
|
-
if (draft.target === 'entity') operations.push({ op: 'entity.material.set', entityId: draft.entityId, materialId })
|
|
3440
|
-
else {
|
|
3441
|
-
const slotIndex = draft.target === 'slot' ? Number(draft.slotIndex) : undefined
|
|
3442
|
-
const bindings = editorClone(target.materialBindings || []).filter(binding => !(binding.partId === draft.partId && binding.slotIndex === slotIndex))
|
|
3443
|
-
bindings.push({ partId: draft.partId, ...(slotIndex === undefined ? {} : { slotIndex }), materialId })
|
|
3444
|
-
operations.push({ op: 'entity.materialBindings.set', entityId: draft.entityId, materialBindings: bindings })
|
|
3445
|
-
}
|
|
3446
|
-
} else {
|
|
3447
|
-
if (material.texture) operations.push({ op: 'material.texture.set', materialId, texture: null })
|
|
3448
|
-
operations.push({ op: 'material.images.set', materialId, images })
|
|
3491
|
+
const partner = draft.includeTimberPartner ? pairedAssetEditor(draft) : null
|
|
3492
|
+
if (draft.includeTimberPartner && !partner) throw new Error(t('assets.timberPairUnavailable'))
|
|
3493
|
+
appendImageAssetOperations(operations, draft, asset, fail)
|
|
3494
|
+
if (partner) appendImageAssetOperations(operations, {
|
|
3495
|
+
...draft, entityId: partner.original.id, newMaterialId: `${draft.newMaterialId}-partner`,
|
|
3496
|
+
}, asset, fail, partner)
|
|
3497
|
+
if (draft.uvProjection) {
|
|
3498
|
+
const { quarterTurns, scale } = draft.uvProjection
|
|
3499
|
+
if (!partner || !Number.isInteger(quarterTurns) || quarterTurns < 0 || quarterTurns > 3) fail(t('editor.uv.direction'))
|
|
3500
|
+
if (!Number.isFinite(scale) || scale < 0.0001 || scale > 10000) throw new Error(t('editor.uv.scaleInvalid'))
|
|
3501
|
+
if (draft.binding.uvMap && draft.binding.uvMap !== 'UVMap') throw new Error(t('assets.rebuildDefaultUv'))
|
|
3502
|
+
for (const entityId of [draft.entityId, partner.original.id]) operations.push({ op: 'entity.uv.project', entityId, quarterTurns, scale })
|
|
3449
3503
|
}
|
|
3450
3504
|
}
|
|
3451
3505
|
return { projectId: draft.projectId, baseRevision: draft.baseRevision, saveCheckpoint: true, renderPreview: true, actor: 'ui', operations }
|
|
3452
3506
|
}
|
|
3453
3507
|
function assetDraftError(draft) { try { buildAssetPatch(draft); return null } catch (error) { return error.message } }
|
|
3454
3508
|
|
|
3509
|
+
function assetTimberUvPreviewIntent(state, draft = state.assetDrafts?.[state.activeProjectId], patch) {
|
|
3510
|
+
if (!draft?.includeTimberPartner || !draft.uvProjection) return null
|
|
3511
|
+
const source = timberUvPreviewSource(state, draft), partner = pairedAssetEditor(draft)
|
|
3512
|
+
if (!source || !partner) return null
|
|
3513
|
+
try { patch ??= buildAssetPatch(draft) } catch { return null }
|
|
3514
|
+
const key = JSON.stringify(['asset', source, patch])
|
|
3515
|
+
return { ...source, kind: 'asset', key, patch, entities: [draft.entityId, partner.original.id] }
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3455
3518
|
function inspectionForm(state) {
|
|
3456
3519
|
const scene = state.selected?.scene
|
|
3457
3520
|
if (!scene) return null
|
|
@@ -4115,13 +4178,40 @@ window.__ModuleLoader__.load({
|
|
|
4115
4178
|
halfLapPreviewController = undefined
|
|
4116
4179
|
next.halfLapPreview = null
|
|
4117
4180
|
}
|
|
4118
|
-
if (next.timberUvPreview
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4181
|
+
if (next.timberUvPreview) {
|
|
4182
|
+
const intent = next.timberUvPreview.kind === 'asset' ? assetTimberUvPreviewIntent(next) : timberUvPreviewIntent(next)
|
|
4183
|
+
if (intent?.key !== next.timberUvPreview.key) {
|
|
4184
|
+
timberUvPreviewController?.abort()
|
|
4185
|
+
timberUvPreviewController = undefined
|
|
4186
|
+
next.timberUvPreview = null
|
|
4187
|
+
}
|
|
4122
4188
|
}
|
|
4123
4189
|
data = next; notify()
|
|
4124
4190
|
}
|
|
4191
|
+
|
|
4192
|
+
async function renderTimberUvPreview(intent) {
|
|
4193
|
+
if (!intent || data.busy.editor || timberUvPreviewController || halfLapPreviewController) return
|
|
4194
|
+
const controller = new AbortController()
|
|
4195
|
+
timberUvPreviewController = controller
|
|
4196
|
+
const { kind, key, patch, expectedDigest, expectedStoreIdentity, cameraId } = intent
|
|
4197
|
+
const active = () => running && timberUvPreviewController === controller && !controller.signal.aborted
|
|
4198
|
+
set({ timberUvPreview: { kind, key, busy: true } })
|
|
4199
|
+
try {
|
|
4200
|
+
const response = await fetchImpl(projectRoute(patch.projectId, '/timber-uv-preview'), {
|
|
4201
|
+
method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json' }, signal: controller.signal,
|
|
4202
|
+
body: JSON.stringify({ patch, expectedDigest, expectedStoreIdentity, cameraId }),
|
|
4203
|
+
})
|
|
4204
|
+
const payload = await response.json()
|
|
4205
|
+
if (!active()) return
|
|
4206
|
+
if (!response.ok || !payload.ok) throw new Error(payload.error?.message || response.status)
|
|
4207
|
+
if (!verifiedTimberUvPreview(payload.preview, intent)) throw new Error(t('inspection.mismatch'))
|
|
4208
|
+
set({ timberUvPreview: { kind, key, result: payload.preview } })
|
|
4209
|
+
} catch (error) {
|
|
4210
|
+
if (active()) set({ timberUvPreview: { kind, key, error: error.message || String(error) } })
|
|
4211
|
+
} finally {
|
|
4212
|
+
if (timberUvPreviewController === controller) timberUvPreviewController = undefined
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
4125
4215
|
/** Change one nested table. @param {'forms'|'busy'|'notices'} table @param {string} key @param {any} value */
|
|
4126
4216
|
const setIn = (table, key, value) => { data = { ...data, [table]: { ...data[table], [key]: value } }; notify() }
|
|
4127
4217
|
|
|
@@ -5141,9 +5231,20 @@ window.__ModuleLoader__.load({
|
|
|
5141
5231
|
updateAsset: (field, value) => {
|
|
5142
5232
|
const projectId = data.activeProjectId, current = data.assetDrafts[projectId]
|
|
5143
5233
|
if (!current || data.assetWork[projectId]?.busy) return
|
|
5144
|
-
const allowed = ['newEntityId', 'location', 'rotationEuler', 'scale', 'hideEntityId', 'makeSubject', 'entityId', 'target', 'partId', 'slotIndex', 'scope', 'newMaterial', 'channel', 'binding', 'replaceTexture', 'strength', 'rotation']
|
|
5234
|
+
const allowed = ['newEntityId', 'location', 'rotationEuler', 'scale', 'hideEntityId', 'makeSubject', 'entityId', 'target', 'partId', 'slotIndex', 'scope', 'newMaterial', 'channel', 'binding', 'replaceTexture', 'includeTimberPartner', 'uvProjection', 'strength', 'rotation']
|
|
5145
5235
|
if (!allowed.includes(field)) return
|
|
5236
|
+
if (field === 'includeTimberPartner' && (typeof value !== 'boolean' || !pairedAssetEditor(current))) return
|
|
5237
|
+
if (field === 'uvProjection' && value && (!data.timberUvPreviewSupported || !current.includeTimberPartner || !pairedAssetEditor(current))) return
|
|
5146
5238
|
const draft = editorClone(current); draft[field] = editorClone(value)
|
|
5239
|
+
if (field === 'includeTimberPartner') {
|
|
5240
|
+
draft.replaceTexture = false
|
|
5241
|
+
if (!value) draft.uvProjection = null
|
|
5242
|
+
}
|
|
5243
|
+
if (field === 'scope' && draft.includeTimberPartner && !pairedAssetEditor(draft)) {
|
|
5244
|
+
draft.includeTimberPartner = false
|
|
5245
|
+
draft.uvProjection = null
|
|
5246
|
+
draft.replaceTexture = false
|
|
5247
|
+
}
|
|
5147
5248
|
if (['entityId', 'target'].includes(field)) { draft.partId = ''; draft.slotIndex = '' }
|
|
5148
5249
|
if (field === 'partId') draft.slotIndex = ''
|
|
5149
5250
|
if (['entityId', 'target', 'partId', 'slotIndex', 'channel', 'newMaterial'].includes(field)) resetAssetBinding(draft)
|
|
@@ -5157,13 +5258,20 @@ window.__ModuleLoader__.load({
|
|
|
5157
5258
|
},
|
|
5158
5259
|
applyAsset: async () => {
|
|
5159
5260
|
const projectId = data.activeProjectId, draft = data.assetDrafts[projectId]
|
|
5261
|
+
const texture = data.timberUvPreview
|
|
5160
5262
|
if (!draft || data.assetWork[projectId]?.busy || data.busy.editor || data.busy.patch || data.busy.restore
|
|
5263
|
+
|| (texture?.kind === 'asset' && texture.busy)
|
|
5161
5264
|
|| data.visualRuns[projectId]?.busy || draft.baseRevision !== data.selected?.scene?.revision) return
|
|
5162
5265
|
let patch
|
|
5163
|
-
try {
|
|
5266
|
+
try {
|
|
5267
|
+
if (draft.uvProjection && !data.timberUvPreviewSupported) throw new Error(t('assets.rebuildUvUnavailable'))
|
|
5268
|
+
patch = buildAssetPatch(draft)
|
|
5269
|
+
} catch (error) { assetWork(projectId, { error: error.message }); return }
|
|
5270
|
+
const inspection = texture?.result && assetTimberUvPreviewIntent(data, draft, patch)?.key === texture.key ? texture.result : null
|
|
5271
|
+
const request = inspection ? { patch, expectedSpecHash: inspection.candidateSpecHash, expectedStoreIdentity: inspection.storeIdentity } : { patch }
|
|
5164
5272
|
const beforePreviews = editorClone(data.previews?.revisions?.find(item => item.revision === draft.baseRevision)?.previews || [])
|
|
5165
5273
|
assetWork(projectId, { busy: 'saving', error: null, message: null }); setIn('busy', 'editor', true)
|
|
5166
|
-
const outcome = await postJson(fetchImpl, projectRoute(projectId, '/patch'),
|
|
5274
|
+
const outcome = await postJson(fetchImpl, projectRoute(projectId, '/patch'), request)
|
|
5167
5275
|
setIn('busy', 'editor', false); assetWork(projectId, { busy: null })
|
|
5168
5276
|
if (outcome.ok) {
|
|
5169
5277
|
const revision = outcome.payload.revision.revision, drafts = { ...data.assetDrafts }; delete drafts[projectId]
|
|
@@ -5625,30 +5733,8 @@ window.__ModuleLoader__.load({
|
|
|
5625
5733
|
timberUvPreviewController = undefined
|
|
5626
5734
|
set({ timberUvPreview: null })
|
|
5627
5735
|
},
|
|
5628
|
-
previewTimberUv:
|
|
5629
|
-
|
|
5630
|
-
if (!intent || data.busy.editor || timberUvPreviewController || halfLapPreviewController) return
|
|
5631
|
-
const controller = new AbortController()
|
|
5632
|
-
timberUvPreviewController = controller
|
|
5633
|
-
const { key, patch, expectedDigest, expectedStoreIdentity, cameraId } = intent
|
|
5634
|
-
const active = () => running && timberUvPreviewController === controller && !controller.signal.aborted
|
|
5635
|
-
set({ timberUvPreview: { key, busy: true } })
|
|
5636
|
-
try {
|
|
5637
|
-
const response = await fetchImpl(projectRoute(patch.projectId, '/timber-uv-preview'), {
|
|
5638
|
-
method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json' }, signal: controller.signal,
|
|
5639
|
-
body: JSON.stringify({ patch, expectedDigest, expectedStoreIdentity, cameraId }),
|
|
5640
|
-
})
|
|
5641
|
-
const payload = await response.json()
|
|
5642
|
-
if (!active()) return
|
|
5643
|
-
if (!response.ok || !payload.ok) throw new Error(payload.error?.message || response.status)
|
|
5644
|
-
if (!verifiedTimberUvPreview(payload.preview, intent)) throw new Error(t('inspection.mismatch'))
|
|
5645
|
-
set({ timberUvPreview: { key, result: payload.preview } })
|
|
5646
|
-
} catch (error) {
|
|
5647
|
-
if (active()) set({ timberUvPreview: { key, error: error.message || String(error) } })
|
|
5648
|
-
} finally {
|
|
5649
|
-
if (timberUvPreviewController === controller) timberUvPreviewController = undefined
|
|
5650
|
-
}
|
|
5651
|
-
},
|
|
5736
|
+
previewTimberUv: () => renderTimberUvPreview(timberUvPreviewIntent(data)),
|
|
5737
|
+
previewAssetTimberUv: () => !data.assetWork[data.activeProjectId]?.busy && renderTimberUvPreview(assetTimberUvPreviewIntent(data)),
|
|
5652
5738
|
updateEditor: (section, path, value) => {
|
|
5653
5739
|
const current = editorDraftFor(data)
|
|
5654
5740
|
if (!current || data.busy.editor || !['transform', 'generator', 'modifiers', 'material', 'uvProjection'].includes(section)) return
|
|
@@ -6660,7 +6746,8 @@ window.__ModuleLoader__.load({
|
|
|
6660
6746
|
uvScene?.nodes.cameras?.length > 1 ? choose(t('editor.uv.previewCamera'), 'editor-uv-camera',
|
|
6661
6747
|
timberUvPreviewCamera(uvScene, draft)?.id, uvScene.nodes.cameras.map(camera => [camera.id, camera.name || camera.id]),
|
|
6662
6748
|
value => actions.updateEditor('uvProjection', ['cameraId'], value)) : null,
|
|
6663
|
-
TimberUvPreview({ work: uvWork, apply, disabled: disabled || !uvIntent ||
|
|
6749
|
+
TimberUvPreview({ work: uvWork, apply, disabled: disabled || !uvIntent || state.halfLapPreview?.busy === true
|
|
6750
|
+
|| (state.timberUvPreview?.kind === 'asset' && state.timberUvPreview.busy), actions }),
|
|
6664
6751
|
] : null,
|
|
6665
6752
|
] : null),
|
|
6666
6753
|
halfLapOptions.length ? el('fieldset', { key: 'half-lap', 'data-half-lap-editor': true, disabled, style: { border: 0, padding: 0, margin: '16px 0' } },
|
|
@@ -6674,7 +6761,7 @@ window.__ModuleLoader__.load({
|
|
|
6674
6761
|
actions.setEditorHalfLapWidth, { factor: 1000, min: 0, max: 5, step: .05,
|
|
6675
6762
|
invalid: halfLapEdgeWidth < 0 || halfLapEdgeWidth > .005, error: t('editor.halfLap.edgeInvalid') }) : null,
|
|
6676
6763
|
halfLapPartner ? el('p', { className: 'db-muted', key: 'edge-width-help' }, t('editor.halfLap.edgeHelp')) : null,
|
|
6677
|
-
slotIntent ? HalfLapPreview({ slotWork, apply: uvResult ? null : apply, disabled: disabled ||
|
|
6764
|
+
slotIntent ? HalfLapPreview({ slotWork, apply: uvResult ? null : apply, disabled: disabled || state.timberUvPreview?.busy === true, actions }) : null) : null] : null,
|
|
6678
6765
|
el('p', { className: 'db-muted', key: 'local-size' }, t('editor.localDimensions', { scale: (draft.entity.transform.scale || [1, 1, 1]).join(' × ') })),
|
|
6679
6766
|
geometry.shape === 'rounded_box' ? el('p', { className: 'db-muted', key: 'rounded' }, t('editor.roundedRequired')) : null,
|
|
6680
6767
|
geometry.shape === 'handled_cup' ? el('p', { className: 'db-muted', key: 'cup-help' }, t('editor.cupHelp')) : null,
|
|
@@ -6791,14 +6878,16 @@ window.__ModuleLoader__.load({
|
|
|
6791
6878
|
onClick: () => actions.setReviewSubject(draft.entityId), children: t('brief.subjectShortcut') }), restore))
|
|
6792
6879
|
}
|
|
6793
6880
|
|
|
6794
|
-
function TimberUvPreview({ work, apply, disabled, actions }) {
|
|
6881
|
+
function TimberUvPreview({ work, apply, disabled, actions, asset = false }) {
|
|
6795
6882
|
const result = work?.result
|
|
6796
|
-
|
|
6883
|
+
const action = asset ? 'asset-timber-uv-preview' : 'timber-uv-preview'
|
|
6884
|
+
return el('div', { key: 'uv-preview', [`data-${action}`]: result ? 'ready' : work?.busy ? 'loading' : work?.error ? 'error' : 'idle',
|
|
6797
6885
|
'aria-busy': work?.busy === true },
|
|
6798
6886
|
el('div', { className: 'db-inline' },
|
|
6799
|
-
Button({ action
|
|
6800
|
-
children: work?.busy ? t('editor.uv.previewBusy') : t('editor.uv.preview'),
|
|
6801
|
-
|
|
6887
|
+
Button({ action, disabled: disabled || work?.busy === true,
|
|
6888
|
+
children: work?.busy ? t('editor.uv.previewBusy') : t('editor.uv.preview'),
|
|
6889
|
+
onClick: asset ? actions.previewAssetTimberUv : actions.previewTimberUv }),
|
|
6890
|
+
work?.busy ? Button({ action: `${action}-cancel`, children: t('geometry.cancel'), onClick: actions.cancelTimberUvPreview }) : null),
|
|
6802
6891
|
result ? el('figure', { style: { margin: '12px 0' } },
|
|
6803
6892
|
el('img', { src: `data:image/png;base64,${result.image.pngBase64}`, alt: t('editor.uv.previewImage'),
|
|
6804
6893
|
width: result.image.width, height: result.image.height, style: { display: 'block', width: '100%', height: 'auto' } }),
|
|
@@ -6847,21 +6936,33 @@ window.__ModuleLoader__.load({
|
|
|
6847
6936
|
const choose = (label, field, value, entries, change) => el('label', { className: 'db-row' }, label,
|
|
6848
6937
|
el('select', { className: 'db-input', 'aria-label': label, 'data-field': field, value, disabled: busy, onChange: event => change(event.target.value) },
|
|
6849
6938
|
entries.map(([id, name]) => el('option', { value: id, key: id }, name))))
|
|
6850
|
-
const check = (label, field, value, change) => el('label', {
|
|
6851
|
-
|
|
6939
|
+
const check = (label, field, value, change, inline = false) => el('label', {
|
|
6940
|
+
className: 'db-row', ...(inline ? { style: { flexWrap: 'nowrap', overflowWrap: 'anywhere' } } : {}),
|
|
6941
|
+
}, el('input', { type: 'checkbox', 'data-field': field, checked: value, disabled: busy,
|
|
6942
|
+
onChange: event => change(event.target.checked) }), label)
|
|
6852
6943
|
const vector = (name, field, values, factor) => el('div', { className: 'db-inline' }, EDITOR_AXES.map((axis, index) => number(`${name} ${axis}`, `asset-${field}-${axis}`,
|
|
6853
6944
|
values[index] === null ? '' : values[index] * factor, value => { const next = [...values]; next[index] = value === null ? null : value / factor; update(field, next) })))
|
|
6854
|
-
let editor, material, part, error, affected = []
|
|
6945
|
+
let editor, material, partner, part, error, affected = []
|
|
6855
6946
|
if (draft) {
|
|
6856
|
-
error = assetDraftError(draft)
|
|
6947
|
+
error = draft.uvProjection && !state.timberUvPreviewSupported ? t('assets.rebuildUvUnavailable') : assetDraftError(draft)
|
|
6857
6948
|
if (draft.kind === 'image') {
|
|
6858
6949
|
editor = assetEditor(draft); material = editor?.material.definition
|
|
6950
|
+
partner = pairedAssetEditor(draft, editor)
|
|
6859
6951
|
part = editor?.original.assetParts?.find(item => item.partId === draft.partId)
|
|
6860
6952
|
affected = draft.scene.nodes.entities.filter(entity => entity.materialId === material?.id
|
|
6861
6953
|
|| entity.materialBindings?.some(binding => binding.materialId === material?.id)
|
|
6862
6954
|
|| entity.assetParts?.some(item => item.materialSlots?.some(slot => slot.materialId === material?.id))).map(entity => entity.id)
|
|
6863
6955
|
}
|
|
6864
6956
|
}
|
|
6957
|
+
const paired = draft?.includeTimberPartner && partner
|
|
6958
|
+
const replaceTexture = !draft?.newMaterial && (material?.texture || (paired && partner.material.definition.texture))
|
|
6959
|
+
const canRebuildUvs = paired && state.timberUvPreviewSupported
|
|
6960
|
+
const uv = canRebuildUvs && draft.uvProjection
|
|
6961
|
+
const uvIntent = uv && assetTimberUvPreviewIntent(state, draft)
|
|
6962
|
+
const uvWork = uvIntent && state.timberUvPreview?.key === uvIntent.key ? state.timberUvPreview : null
|
|
6963
|
+
const cameraChoices = state.selected?.scene?.nodes?.cameras || []
|
|
6964
|
+
const sharesUv = uv && [material, partner.material.definition].some(item =>
|
|
6965
|
+
Object.entries(item.images || {}).some(([channel, binding]) => channel !== 'baseColor' && (!binding.uvMap || binding.uvMap === 'UVMap')))
|
|
6865
6966
|
const mapSetting = (key, value) => { const binding = editorClone(draft.binding); if (value === undefined) delete binding[key]; else binding[key] = value; update('binding', binding) }
|
|
6866
6967
|
return el('section', { className: 'db-card', 'data-assets-library': projectId, 'data-asset-base-revision': draft?.baseRevision || '', 'data-asset-conflict': String(conflict) },
|
|
6867
6968
|
el('h4', null, t('assets.title')), el('p', { className: 'db-muted' }, t('assets.help')),
|
|
@@ -6957,10 +7058,28 @@ window.__ModuleLoader__.load({
|
|
|
6957
7058
|
['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,
|
|
6958
7059
|
draft.channel === 'normal' ? number(t('assets.normalStrength'), 'asset-normal-strength', editorNumberDefault(draft.binding.strength, 1), value => mapSetting('strength', value), { min: 0, max: 10 }) : null,
|
|
6959
7060
|
draft.channel === 'emissionColor' ? el('p', { className: 'db-muted' }, t('assets.emissionHelp')) : null,
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
7061
|
+
partner ? check(t('assets.applyToTimberPartner', { name: partner.original.name || partner.original.id }),
|
|
7062
|
+
'asset-include-timber-partner', Boolean(paired), value => update('includeTimberPartner', value), true) : null,
|
|
7063
|
+
replaceTexture ? check(paired ? t('assets.replaceTimberTexture') : t('assets.replaceTexture'),
|
|
7064
|
+
'asset-replace-texture', draft.replaceTexture, value => update('replaceTexture', value), Boolean(paired)) : null,
|
|
7065
|
+
canRebuildUvs || draft.uvProjection ? check(t('assets.rebuildTimberUvs'), 'asset-rebuild-timber-uvs', Boolean(draft.uvProjection),
|
|
7066
|
+
value => update('uvProjection', value ? { quarterTurns: 0, scale: 1 } : null), true) : null,
|
|
7067
|
+
uv ? [
|
|
7068
|
+
sharesUv ? el('p', { key: 'uv-help', className: 'db-muted' }, t('assets.rebuildTimberUvsHelp')) : null,
|
|
7069
|
+
choose(t('editor.uv.direction'), 'asset-uv-direction', String(uv.quarterTurns),
|
|
7070
|
+
[0, 1, 2, 3].map(turn => [String(turn), `${turn * 90}°`]), value => update('uvProjection', { ...uv, quarterTurns: Number(value) })),
|
|
7071
|
+
number(t('editor.uv.scale'), 'asset-uv-repeats', uv.scale, value => update('uvProjection', { ...uv, scale: value }),
|
|
7072
|
+
{ min: 0.0001, max: 10000, 'aria-invalid': !Number.isFinite(uv.scale) || uv.scale < 0.0001 || uv.scale > 10000 }),
|
|
7073
|
+
cameraChoices.length > 1 ? choose(t('editor.uv.previewCamera'), 'asset-uv-camera',
|
|
7074
|
+
timberUvPreviewCamera(state.selected.scene, draft)?.id, cameraChoices.map(camera => [camera.id, camera.name || camera.id]),
|
|
7075
|
+
value => update('uvProjection', { ...uv, cameraId: value })) : null,
|
|
7076
|
+
TimberUvPreview({ work: uvWork, actions, asset: true,
|
|
7077
|
+
disabled: busy || conflict || !uvIntent || state.busy.editor || state.halfLapPreview?.busy === true
|
|
7078
|
+
|| (state.timberUvPreview?.kind === 'editor' && state.timberUvPreview.busy) }),
|
|
7079
|
+
] : null) : null,
|
|
7080
|
+
error ? el('p', { className: 'db-error', role: 'alert' }, error) : null,
|
|
7081
|
+
el('div', { className: 'db-inline' }, Button({ action: 'asset-apply', tone: 'primary', disabled: busy || conflict || Boolean(error) || uvWork?.busy === true || state.busy.editor || state.busy.patch || state.busy.restore || state.visualRuns[projectId]?.busy,
|
|
7082
|
+
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)
|
|
6964
7083
|
}
|
|
6965
7084
|
|
|
6966
7085
|
function CameraFitEditor(ctx) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepblend/dsh-blender-bundle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.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.
|
|
48
|
-
"@deepblend/dsh-blender-host": "0.
|
|
49
|
-
"@deepblend/dsh-blender-preset": "0.
|
|
50
|
-
"@deepblend/dsh-blender-provider-local": "0.
|
|
51
|
-
"@deepblend/dsh-blender-tool": "0.
|
|
52
|
-
"@deepblend/dsh-blender-ui": "0.
|
|
47
|
+
"@deepblend/dsh-blender-contracts": "0.31.0",
|
|
48
|
+
"@deepblend/dsh-blender-host": "0.31.0",
|
|
49
|
+
"@deepblend/dsh-blender-preset": "0.31.0",
|
|
50
|
+
"@deepblend/dsh-blender-provider-local": "0.31.0",
|
|
51
|
+
"@deepblend/dsh-blender-tool": "0.31.0",
|
|
52
|
+
"@deepblend/dsh-blender-ui": "0.31.0"
|
|
53
53
|
},
|
|
54
54
|
"type": "module",
|
|
55
55
|
"license": "MIT",
|