-
-
Notifications
You must be signed in to change notification settings - Fork 18
Add targeted debug logs for blockId/blockKey mesh resolution #533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7eea8f1
8d886b4
7ac3c82
3ffbdc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,86 @@ export function getMeshesFromBlockKey(blockKey) { | |
| return set ? [...set] : []; | ||
| } | ||
|
|
||
| function getUserVariableNameFromBlock(block, fieldName = "ID_VAR") { | ||
| if (!block?.workspace || typeof block.getFieldValue !== "function") return null; | ||
| const variableId = block.getFieldValue(fieldName); | ||
| if (!variableId) return null; | ||
| const variableModel = block.workspace.getVariableById?.(variableId); | ||
| return variableModel?.name ?? null; | ||
| } | ||
|
|
||
| function findMeshesByBaseName(baseName) { | ||
| if (!baseName || !flock?.scene) return []; | ||
| const candidates = [baseName, baseName.replace(/[^a-zA-Z0-9._-]/g, "")]; | ||
| const seen = new Set(); | ||
| const matches = []; | ||
|
|
||
| for (const name of candidates) { | ||
| if (!name || seen.has(name)) continue; | ||
| seen.add(name); | ||
|
|
||
| const exact = flock.scene.getMeshByName?.(name); | ||
| if (exact) matches.push(exact); | ||
|
|
||
| for (const mesh of flock.scene.meshes ?? []) { | ||
| if ( | ||
| mesh?.name && | ||
| mesh.name !== name && | ||
| mesh.name.startsWith(`${name}_`) && | ||
| Number.isFinite(Number(mesh.name.slice(name.length + 1))) | ||
| ) { | ||
| matches.push(mesh); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return matches; | ||
| } | ||
|
|
||
| function rebindMeshesToBlockKey(meshes, blockKey) { | ||
| if (!blockKey || !Array.isArray(meshes) || meshes.length === 0) return; | ||
| for (const mesh of meshes) { | ||
| if (!mesh) continue; | ||
| mesh.metadata = mesh.metadata || {}; | ||
| mesh.metadata.blockKey = blockKey; | ||
| const descendants = mesh.getDescendants?.(false) ?? []; | ||
| for (const child of descendants) { | ||
| child.metadata = child.metadata || {}; | ||
| child.metadata.blockKey = blockKey; | ||
| } | ||
| } | ||
| _meshIndexDirty = true; | ||
| } | ||
|
Comment on lines
+229
to
+242
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fallback rebinding is too broad and leaves owner state stale. Line 235 rewrites every descendant's Also applies to: 269-270 🤖 Prompt for AI Agents |
||
|
|
||
| function getFallbackMeshesForLoadBlock(block, blockKey = null) { | ||
| if (!block) return []; | ||
| if (!["load_object", "load_multi_object", "load_character"].includes(block.type)) | ||
| return []; | ||
|
|
||
| const variableName = getUserVariableNameFromBlock(block, "ID_VAR"); | ||
| if (!variableName) return []; | ||
| const matches = findMeshesByBaseName(variableName); | ||
|
|
||
| const ws = block.workspace; | ||
| const mainWs = Blockly.getMainWorkspace?.(); | ||
| console.log("[mesh-lookup:fallback]", { | ||
| blockType: block.type, | ||
| blockId: block.id, | ||
| blockKey: blockKey || block.id, | ||
| workspaceId: ws?.id ?? null, | ||
| isFlyout: !!ws?.isFlyout, | ||
| isMainWorkspace: !!(ws && mainWs && ws === mainWs), | ||
| variableName, | ||
| matchedMeshes: matches.map((m) => ({ | ||
| name: m?.name, | ||
| blockKey: m?.metadata?.blockKey ?? null, | ||
| })), | ||
| }); | ||
|
Comment on lines
+255
to
+267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the new lookup tracing behind These traces are unconditional, unlike the rest of this file. Because 🧰 Suggested guard pattern- console.warn("[mesh-lookup:miss]", {
- blockType: block.type,
- blockId: block.id,
- blockKey,
- workspaceId: ws?.id ?? null,
- isFlyout: !!ws?.isFlyout,
- isMainWorkspace: !!(ws && mainWs && ws === mainWs),
- knownSceneKeys: [...new Set((flock.scene?.meshes ?? [])
- .map((m) => m?.metadata?.blockKey)
- .filter(Boolean))].slice(0, 50),
- });
+ if (flock.meshDebug) {
+ console.warn("[mesh-lookup:miss]", {
+ blockType: block.type,
+ blockId: block.id,
+ blockKey,
+ workspaceId: ws?.id ?? null,
+ isFlyout: !!ws?.isFlyout,
+ isMainWorkspace: !!(ws && mainWs && ws === mainWs),
+ knownSceneKeys: [...new Set((flock.scene?.meshes ?? [])
+ .map((m) => m?.metadata?.blockKey)
+ .filter(Boolean))].slice(0, 50),
+ });
+ }Also applies to: 324-355, 410-437 🤖 Prompt for AI Agents |
||
|
|
||
| rebindMeshesToBlockKey(matches, blockKey || block.id); | ||
| return matches; | ||
| } | ||
|
|
||
| export function getMeshFromBlock(block) { | ||
| if (!block) return null; | ||
|
|
||
|
|
@@ -241,8 +321,38 @@ export function getMeshFromBlock(block) { | |
|
|
||
| const blockKey = getBlockKeyFromBlock(block) || block.id; | ||
| if (!blockKey) return null; | ||
| const direct = getMeshFromBlockKey(blockKey); | ||
| if (direct) { | ||
| const ws = block.workspace; | ||
| const mainWs = Blockly.getMainWorkspace?.(); | ||
| console.log("[mesh-lookup:direct]", { | ||
| blockType: block.type, | ||
| blockId: block.id, | ||
| blockKey, | ||
| workspaceId: ws?.id ?? null, | ||
| isFlyout: !!ws?.isFlyout, | ||
| isMainWorkspace: !!(ws && mainWs && ws === mainWs), | ||
| meshName: direct.name, | ||
| meshBlockKey: direct.metadata?.blockKey ?? null, | ||
| }); | ||
| return direct; | ||
| } | ||
|
|
||
| const ws = block.workspace; | ||
| const mainWs = Blockly.getMainWorkspace?.(); | ||
| console.warn("[mesh-lookup:miss]", { | ||
| blockType: block.type, | ||
| blockId: block.id, | ||
| blockKey, | ||
| workspaceId: ws?.id ?? null, | ||
| isFlyout: !!ws?.isFlyout, | ||
| isMainWorkspace: !!(ws && mainWs && ws === mainWs), | ||
| knownSceneKeys: [...new Set((flock.scene?.meshes ?? []) | ||
| .map((m) => m?.metadata?.blockKey) | ||
| .filter(Boolean))].slice(0, 50), | ||
| }); | ||
|
|
||
| return getMeshFromBlockKey(blockKey); | ||
| return getFallbackMeshesForLoadBlock(block, blockKey)[0] ?? null; | ||
| } | ||
|
|
||
| export function getMeshesFromBlock(block) { | ||
|
|
@@ -297,8 +407,34 @@ export function getMeshesFromBlock(block) { | |
|
|
||
| const blockKey = getBlockKeyFromBlock(block) || block.id; | ||
| if (!blockKey) return []; | ||
| const meshes = getMeshesFromBlockKey(blockKey); | ||
| if (meshes.length > 0) { | ||
| const ws = block.workspace; | ||
| const mainWs = Blockly.getMainWorkspace?.(); | ||
| console.log("[mesh-lookup:direct-many]", { | ||
| blockType: block.type, | ||
| blockId: block.id, | ||
| blockKey, | ||
| workspaceId: ws?.id ?? null, | ||
| isFlyout: !!ws?.isFlyout, | ||
| isMainWorkspace: !!(ws && mainWs && ws === mainWs), | ||
| meshNames: meshes.map((m) => m?.name), | ||
| }); | ||
| return meshes; | ||
| } | ||
|
|
||
| const ws = block.workspace; | ||
| const mainWs = Blockly.getMainWorkspace?.(); | ||
| console.warn("[mesh-lookup:miss-many]", { | ||
| blockType: block.type, | ||
| blockId: block.id, | ||
| blockKey, | ||
| workspaceId: ws?.id ?? null, | ||
| isFlyout: !!ws?.isFlyout, | ||
| isMainWorkspace: !!(ws && mainWs && ws === mainWs), | ||
| }); | ||
|
|
||
| return getMeshesFromBlockKey(blockKey); | ||
| return getFallbackMeshesForLoadBlock(block, blockKey); | ||
| } | ||
|
|
||
| // Safe field getter. Returns null when field is missing or name is invalid. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't log imported filenames by default.
file.nameis user-supplied and can contain personal or project info. Emitting it on every drag-and-drop import exposes that data in normal browser console output; gate this behind a debug flag or omit the name.🤖 Prompt for AI Agents