Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(vscode): stop the viewer overwriting snapshots and the model tree flashing empty

nirholas7fde3b95cee0
diff --git a/packages/vscode-3d/src/models-tree.js b/packages/vscode-3d/src/models-tree.js
index f077e0b1a..0281b6132 100644
--- a/packages/vscode-3d/src/models-tree.js
+++ b/packages/vscode-3d/src/models-tree.js
@@ -16,7 +16,6 @@ export class ModelsProvider {
this.onDidChangeTreeData = this._emitter.event;
this._files = [];
this._error = '';
- this._loading = true;
this._watcher = vscode.workspace.createFileSystemWatcher(GLOB);
const bump = () => this.refresh();
this._watcher.onDidCreate(bump);
@@ -29,8 +28,8 @@ export class ModelsProvider {
}
async refresh() {
- this._loading = true;
- this._emitter.fire();
+ // The previous list stays on screen while the rescan runs, so the welcome
+ // view does not flash in and out every time a model is written.
try {
const uris = await vscode.workspace.findFiles(GLOB, EXCLUDE, 2000);
const stats = await Promise.all(
@@ -49,7 +48,6 @@ export class ModelsProvider {
this._error = err?.message || String(err);
this._files = [];
}
- this._loading = false;
this._emitter.fire();
}
@@ -58,7 +56,6 @@ export class ModelsProvider {
}
getChildren(node) {
- if (this._loading) return [];
if (this._error) return [infoNode(`Could not scan the workspace: ${this._error}`, 'error')];
if (!node) return this._groups();
return (node.files || []).map((file) => this._modelNode(file));
diff --git a/packages/vscode-3d/src/viewer.js b/packages/vscode-3d/src/viewer.js
index 5ce8f83f4..1cc91c13a 100644
--- a/packages/vscode-3d/src/viewer.js
+++ b/packages/vscode-3d/src/viewer.js
@@ -7,6 +7,7 @@
import * as vscode from 'vscode';
import { reportFor } from './inspect.js';
import { trackPanel } from './active-panel.js';
+import { uniqueName } from './naming.js';
export const VIEW_TYPE = 'threews3d.modelViewer';
@@ -89,6 +90,11 @@ export function openRemoteModel(context, links, output, url, title) {
readBytes: async () => {
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
+ const declared = Number(res.headers.get('content-length') || 0);
+ if (declared > MAX_INSPECT_BYTES) {
+ res.body?.cancel();
+ throw new Error(`model is ${declared} bytes, too large to inspect`);
+ }
return new Uint8Array(await res.arrayBuffer());
},
});
@@ -170,7 +176,14 @@ async function saveSnapshot(dataUrl, resource, output) {
return;
}
const stem = resource ? path(resource).replace(/\.(glb|gltf)$/i, '') : 'model';
- const target = vscode.Uri.joinPath(folder, `${stem}.png`);
+ const taken = await vscode.workspace.fs.readDirectory(folder).then(
+ (entries) => new Set(entries.map(([name]) => name.toLowerCase())),
+ () => new Set(),
+ );
+ const target = vscode.Uri.joinPath(
+ folder,
+ uniqueName(stem, '.png', (name) => taken.has(name.toLowerCase())),
+ );
await vscode.workspace.fs.writeFile(target, bytes);
output.appendLine(`snapshot written to ${target.fsPath}`);
const open = await vscode.window.showInformationMessage(
diff --git a/packages/vscode-3d/webview/main.js b/packages/vscode-3d/webview/main.js
index 66f16967b..5575cbb35 100644
--- a/packages/vscode-3d/webview/main.js
+++ b/packages/vscode-3d/webview/main.js
@@ -68,7 +68,7 @@ key.position.set(3, 6, 4);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.bias = -0.0005;
-scene.add(key, new THREE.HemisphereLight(0xffffff, 0x404040, 0.6));
+scene.add(key, key.target, new THREE.HemisphereLight(0xffffff, 0x404040, 0.6));
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(1, 1),
@@ -209,7 +209,6 @@ function resetView() {
controls.update();
key.target.position.set(0, height / 2, 0);
key.target.updateMatrixWorld();
- scene.add(key.target);
const span = Math.max(r * 3, height * 1.5);
key.shadow.camera.left = -span;
key.shadow.camera.right = span;