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.

feat(vscode-3d): animate, refine, optimize, compare and quality-check models inside the editor

nirholasae286b6f21c0
diff --git a/packages/vscode-3d/package-lock.json b/packages/vscode-3d/package-lock.json
index da780c22d..e7b7b76e2 100644
--- a/packages/vscode-3d/package-lock.json
+++ b/packages/vscode-3d/package-lock.json
@@ -1,16 +1,18 @@
{
- "name": "@three-ws/vscode-3d",
+ "name": "vscode-3d",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
- "name": "@three-ws/vscode-3d",
+ "name": "vscode-3d",
"version": "0.1.0",
"license": "Apache-2.0",
"dependencies": {
"@gltf-transform/core": "^4.4.0",
"@gltf-transform/extensions": "^4.4.0",
+ "@gltf-transform/functions": "^4.5.0",
+ "gifenc": "^1.0.3",
"meshoptimizer": "^1.1.1",
"three": "^0.184.0"
},
@@ -22,6 +24,16 @@
"vscode": "^1.85.0"
}
},
+ "node_modules/@emnapi/runtime": {
+ "version": "1.11.3",
+ "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz",
+ "integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
"node_modules/@esbuild/aix-ppc64": {
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz",
@@ -489,6 +501,529 @@
"url": "https://github.com/sponsors/donmccurdy"
}
},
+ "node_modules/@gltf-transform/functions": {
+ "version": "4.5.0",
+ "resolved": "https://registry.npmjs.org/@gltf-transform/functions/-/functions-4.5.0.tgz",
+ "integrity": "sha512-7sMOuEfksMyF+/NTwUnEOgh7djohJ5XfeYg8rzXDG+9JIdbGVUpvJUY3XVBJCUJJ04dusDvcTHloOi1wfM8lnw==",
+ "license": "MIT",
+ "dependencies": {
+ "@gltf-transform/core": "^4.5.0",
+ "@gltf-transform/extensions": "^4.5.0",
+ "ktx-parse": "^1.1.0",
+ "ndarray": "^1.0.19",
+ "ndarray-lanczos": "^0.3.0",
+ "ndarray-pixels": "^5.2.0"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/donmccurdy"
+ }
+ },
+ "node_modules/@img/colour": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz",
+ "integrity": "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@img/sharp-darwin-arm64": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.35.4.tgz",
+ "integrity": "sha512-Uhfl4V4lhP2nbUVF9+hyH1+luj86f1gUFeo8ALYxFoULoU+G87D43BfeMP8XHsk9boxAnCY/bf2EHwhA7MuGsA==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ },
+ "optionalDependencies": {
+ "@img/sharp-libvips-darwin-arm64": "1.3.3"
+ }
+ },
+ "node_modules/@img/sharp-darwin-x64": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.35.4.tgz",
+ "integrity": "sha512-hWniXY3bG5qKpkKrAwPe4y+VTPmf086YQAnkxWh7uA1YrlRouWGa0M0Mxj3ZjnXFkv7/TD1bTy9lGUK26vRvWw==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ },
+ "optionalDependencies": {
+ "@img/sharp-libvips-darwin-x64": "1.3.3"
+ }
+ },
+ "node_modules/@img/sharp-freebsd-wasm32": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-freebsd-wasm32/-/sharp-freebsd-wasm32-0.35.4.tgz",
+ "integrity": "sha512-lIsKw/BU+kjB4eZjxrYrZmwOJYi3Ajrv66iAlBmUPyKc3HpnloevB1g3wxGD9P/5BbQ1brBGl65VRRrCvQDEqA==",
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "dependencies": {
+ "@img/sharp-wasm32": "0.35.4"
+ },
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-libvips-darwin-arm64": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.3.3.tgz",
+ "integrity": "sha512-suTBPTDGrI9WodccaDdwZItTSaBYASlBk1NSfElSHrUfzu3szG6lvIF58+WiFvnfzuK8ZBFS5zE00PxqxnRiPg==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-libvips-darwin-x64": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.3.3.tgz",
+ "integrity": "sha512-FVJZ5mITMobmXIz/hPDTw0EintTW5H3WfrxwLqEqjiIihlu+hVRyGrFQ60xl0Lxn7Bt3zdpevPaQi0HEzqz9fw==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-libvips-linux-arm": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.3.3.tgz",
+ "integrity": "sha512-3rbU4vqXXc3hY/OiXdl52xZvT0F1yEngWfvqudtPJg/KkyiaQw2DRsFrNzpmLvfavbwOq3qXn36GP8obHRULQA==",
+ "cpu": [
+ "arm"
+ ],
+ "license": "LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-libvips-linux-arm64": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.3.3.tgz",
+ "integrity": "sha512-0DaL0A6Xu6sQSQFwe4iVCrKWU2cCTItnRsYsCdxAMm9NF6twAA9BKnoqy4hqz4+azQ0JHuA26qiUKsf1XJ/v5A==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-libvips-linux-ppc64": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-ppc64/-/sharp-libvips-linux-ppc64-1.3.3.tgz",
+ "integrity": "sha512-cdn1OvUBwsXhbC0zSzJnNzf5MZ/mTrobawDvNXBTxe8VtqKAm0sRuEY2Evzovb/w9JMk4TvRxqt1mekSuJz64w==",
+ "cpu": [
+ "ppc64"
+ ],
+ "license": "LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-libvips-linux-riscv64": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-riscv64/-/sharp-libvips-linux-riscv64-1.3.3.tgz",
+ "integrity": "sha512-HjPVx7yKz+0lqdhDlTw1tt90wamBoxhiXpvl1XZpJLiHH4RCJ5yDTqH+VlYPv2fwFs89JFw4c1IexYOcQUi4IQ==",
+ "cpu": [
+ "riscv64"
+ ],
+ "license": "LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-libvips-linux-s390x": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.3.3.tgz",
+ "integrity": "sha512-neWLh+3yCNThxnfy3c4BbVBeGgt9aftno+XbT56iK28RgeDs3UOFWviLWlUu0bArYVYJaFDK+RRohbicUNCm8Q==",
+ "cpu": [
+ "s390x"
+ ],
+ "license": "LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-libvips-linux-x64": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.3.3.tgz",
+ "integrity": "sha512-4vKmvAst9nrowcqquKFAyZJUDolUaIp8uRiN0mWFguJ1IplC9/pitXtlnnlU4aa/eJw3J7i67V+pwUL+wZGdsA==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-libvips-linuxmusl-arm64": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.3.3.tgz",
+ "integrity": "sha512-Y9kQaLMuNoB0bPYOOdcZMaseNrFpPodIWWMrx+CZyydf2xn68j9WYc6sWWRrDwNkzCQjKYfc68L7jKjGlHMibw==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-libvips-linuxmusl-x64": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.3.3.tgz",
+ "integrity": "sha512-fj8Mv0HHfD1Rr+4I68+3agJynxDWtBFgicTbSOb9Bke6pIwzGcJ+RX/yHjmiEGFMCavY/dxvem7MyNaJF+wDiw==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-linux-arm": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.35.4.tgz",
+ "integrity": "sha512-7OAS8gI0EReKGVN2HssHlM6umJgxF5VI3xN0p9FA91p/YO+ou5hiNghLdZ5BEHztwaaK5+bLKRf8x/o2L2nk9A==",
+ "cpu": [
+ "arm"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ },
+ "optionalDependencies": {
+ "@img/sharp-libvips-linux-arm": "1.3.3"
+ }
+ },
+ "node_modules/@img/sharp-linux-arm64": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.35.4.tgz",
+ "integrity": "sha512-De4jpEnAU8Hd5oT0j1G3uL4ZvTuipVMn7YC6vPaJhy6/7EwEae0SVAoBrUMYQbkLGDm85taVWwuPc1a44LTzCQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ },
+ "optionalDependencies": {
+ "@img/sharp-libvips-linux-arm64": "1.3.3"
+ }
+ },
+ "node_modules/@img/sharp-linux-ppc64": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-linux-ppc64/-/sharp-linux-ppc64-0.35.4.tgz",
+ "integrity": "sha512-2oYZJeIl4kCcMGk4ouZVjnkCtFrpQFlNEtJ6GbxzhHQchwH0NH/qEb9ykmOl29dqwMq+JhFdZn+1ak2FKhI9fQ==",
+ "cpu": [
+ "ppc64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ },
+ "optionalDependencies": {
+ "@img/sharp-libvips-linux-ppc64": "1.3.3"
+ }
+ },
+ "node_modules/@img/sharp-linux-riscv64": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-linux-riscv64/-/sharp-linux-riscv64-0.35.4.tgz",
+ "integrity": "sha512-cPbNChoRURAWdebDIHSenxRpgEdy7JkPydSnUxRm9VvKD7m0/xVaR/8Fzlu81pk5nHEvHH87UZUA7cTtwnbJSA==",
+ "cpu": [
+ "riscv64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ },
+ "optionalDependencies": {
+ "@img/sharp-libvips-linux-riscv64": "1.3.3"
+ }
+ },
+ "node_modules/@img/sharp-linux-s390x": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.35.4.tgz",
+ "integrity": "sha512-RY0JFY8Fd6RonCBtHz+DvadaPkXDSI1AUn6yWL9TipqkZ1vY8w8evqdgyDFnkm4/K1ve1TvZiaePP5oSd4+WVQ==",
+ "cpu": [
+ "s390x"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ },
+ "optionalDependencies": {
+ "@img/sharp-libvips-linux-s390x": "1.3.3"
+ }
+ },
+ "node_modules/@img/sharp-linux-x64": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.35.4.tgz",
+ "integrity": "sha512-9qvvEAuk8k89TfWUoX2htWjbAMX8p+NxCppjpcg5k6xMsjhBQPTsoIh36h9Qde4WRuGpJeYnOjdosDn/cnv+OA==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ },
+ "optionalDependencies": {
+ "@img/sharp-libvips-linux-x64": "1.3.3"
+ }
+ },
+ "node_modules/@img/sharp-linuxmusl-arm64": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.35.4.tgz",
+ "integrity": "sha512-KB5jxpfWQTr0nc3xdHtWChdbifHrBGsd2SM62Eyxrl8afikm+f5qGBU75SJIZBT/S1MC8XyacdlXBMSWq6OURA==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ },
+ "optionalDependencies": {
+ "@img/sharp-libvips-linuxmusl-arm64": "1.3.3"
+ }
+ },
+ "node_modules/@img/sharp-linuxmusl-x64": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.35.4.tgz",
+ "integrity": "sha512-f+eZJZIQNEEd26RPSW+76chwOf1XtA2Y/O+5ocVyLliHkeih3e+jhLVBdNTd2rS3IbNXK8+ug93Vf5ZXtF5Lxg==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ },
+ "optionalDependencies": {
+ "@img/sharp-libvips-linuxmusl-x64": "1.3.3"
+ }
+ },
+ "node_modules/@img/sharp-wasm32": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.35.4.tgz",
+ "integrity": "sha512-zQnl4Kwp7Q6NHsENtU2T/00Zi+w3AQNwz3+UaTyVBy2FpXrzXzGjndpK61onhZjRtRpQXxCTeqw19bVyXOh7jA==",
+ "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT",
+ "optional": true,
+ "dependencies": {
+ "@emnapi/runtime": "^1.11.3"
+ },
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-webcontainers-wasm32": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-webcontainers-wasm32/-/sharp-webcontainers-wasm32-0.35.4.tgz",
+ "integrity": "sha512-ESfNkywmCfPNyaZjxooddJQiQ+l/nTpGEOGthxiLnIHXC/CmcBixnfwUleX9mCz9ovrUUvKMap/pm8RYbzfwaA==",
+ "cpu": [
+ "wasm32"
+ ],
+ "license": "Apache-2.0",
+ "optional": true,
+ "dependencies": {
+ "@img/sharp-wasm32": "0.35.4"
+ },
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-win32-arm64": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-win32-arm64/-/sharp-win32-arm64-0.35.4.tgz",
+ "integrity": "sha512-iNdlBX9gLVvqe2I3uIJSIKTq6wckP/DYxZtcqxm09x5Gi24DnFBmPAWZmr60ZyYMG0xlzo6goG3670ar+RXvRw==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "Apache-2.0 AND LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-win32-ia32": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.35.4.tgz",
+ "integrity": "sha512-kqRsbaa5CS6KHlpxnN7WhE6vAAugXyZButpRdvDWetlv6Qv4N9WTcrWzF7tXfB9T7MsoadqdI8hmwLq6UlLvtw==",
+ "cpu": [
+ "ia32"
+ ],
+ "license": "Apache-2.0 AND LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": "^20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@img/sharp-win32-x64": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.35.4.tgz",
+ "integrity": "sha512-XtmnYhBcrORsJ4XJngyzr/EWP0hRZLAZRFaApdKuviyqF78+ylxh2y06ZmtULAMOnObJ3ucpN0AcwSWnMowTRg==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "Apache-2.0 AND LGPL-3.0-or-later",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ }
+ },
+ "node_modules/@types/ndarray": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/@types/ndarray/-/ndarray-1.1.0.tgz",
+ "integrity": "sha512-go+C6vHBUuO9jH6Tj6qEZ63JEGoMSxFdmd+6QAtthGD6xumBfIz3RbNDDs2aoRVLf9naH8lk5jnWy2UHHKgYQQ==",
+ "license": "MIT"
+ },
"node_modules/@types/vscode": {
"version": "1.136.0",
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.136.0.tgz",
@@ -496,6 +1031,24 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/cwise-compiler": {
+ "version": "1.1.3",
+ "resolved": "https://registry.npmjs.org/cwise-compiler/-/cwise-compiler-1.1.3.tgz",
+ "integrity": "sha512-WXlK/m+Di8DMMcCjcWr4i+XzcQra9eCdXIJrgh4TUgh0pIS/yJduLxS9JgefsHJ/YVLdgPtXm9r62W92MvanEQ==",
+ "license": "MIT",
+ "dependencies": {
+ "uniq": "^1.0.0"
+ }
+ },
+ "node_modules/detect-libc": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
+ "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
+ "license": "Apache-2.0",
+ "engines": {
+ "node": ">=8"
+ }
+ },
"node_modules/esbuild": {
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz",
@@ -538,6 +1091,24 @@
"@esbuild/win32-x64": "0.28.2"
}
},
+ "node_modules/gifenc": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/gifenc/-/gifenc-1.0.3.tgz",
+ "integrity": "sha512-xdr6AdrfGBcfzncONUOlXMBuc5wJDtOueE3c5rdG0oNgtINLD+f2iFZltrBRZYzACRbKr+mSVU/x98zv2u3jmw==",
+ "license": "MIT"
+ },
+ "node_modules/iota-array": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/iota-array/-/iota-array-1.0.0.tgz",
+ "integrity": "sha512-pZ2xT+LOHckCatGQ3DcG/a+QuEqvoxqkiL7tvE8nn3uuu+f6i1TtpB5/FtWFbxUuVr5PZCx8KskuGatbJDXOWA==",
+ "license": "MIT"
+ },
+ "node_modules/is-buffer": {
+ "version": "1.1.6",
+ "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
+ "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
+ "license": "MIT"
+ },
"node_modules/ktx-parse": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/ktx-parse/-/ktx-parse-1.1.0.tgz",
@@ -550,17 +1121,132 @@
"integrity": "sha512-davRZeIJbxJrE24cwQle7ZDsxjdk/OphNOV83oX+efQinyoHY9Jcyz3MHbaoG0qySZajldGztNZ1RN/T19PZsg==",
"license": "MIT"
},
+ "node_modules/ndarray": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/ndarray/-/ndarray-1.1.1.tgz",
+ "integrity": "sha512-AsE8w/M2MS+0pD3nP5qbRRtJFeJJJaJ+qXZaZr0XjVGXhy6LIj2TERTlkpdK2AI3WufoOP+pwPk3q2ilAJcZ9g==",
+ "license": "MIT",
+ "dependencies": {
+ "iota-array": "^1.0.0",
+ "is-buffer": "^1.0.2"
+ }
+ },
+ "node_modules/ndarray-lanczos": {
+ "version": "0.3.0",
+ "resolved": "https://registry.npmjs.org/ndarray-lanczos/-/ndarray-lanczos-0.3.0.tgz",
+ "integrity": "sha512-5kBmmG3Zvyj77qxIAC4QFLKuYdDIBJwCG+DukT6jQHNa1Ft74/hPH1z5mbQXeHBt8yvGPBGVrr3wEOdJPYYZYg==",
+ "license": "MIT",
+ "dependencies": {
+ "@types/ndarray": "^1.0.11",
+ "ndarray": "^1.0.19"
+ }
+ },
+ "node_modules/ndarray-ops": {
+ "version": "1.2.2",
+ "resolved": "https://registry.npmjs.org/ndarray-ops/-/ndarray-ops-1.2.2.tgz",
+ "integrity": "sha512-BppWAFRjMYF7N/r6Ie51q6D4fs0iiGmeXIACKY66fLpnwIui3Wc3CXiD/30mgLbDjPpSLrsqcp3Z62+IcHZsDw==",
+ "license": "MIT",
+ "dependencies": {
+ "cwise-compiler": "^1.0.0"
+ }
+ },
+ "node_modules/ndarray-pixels": {
+ "version": "5.2.0",
+ "resolved": "https://registry.npmjs.org/ndarray-pixels/-/ndarray-pixels-5.2.0.tgz",
+ "integrity": "sha512-lTh4tFKziAatVTa9crIsidUyn+lqujVOQpzfdBWvdFu2wo9Uo6z261lVX7SgMyP89xGmj3TMTPbbxl9YDnV4SA==",
+ "license": "MIT",
+ "dependencies": {
+ "@types/ndarray": "^1.0.14",
+ "ndarray": "^1.0.19",
+ "ndarray-ops": "^1.2.2",
+ "sharp": "^0.35.0"
+ }
+ },
"node_modules/property-graph": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/property-graph/-/property-graph-4.1.0.tgz",
"integrity": "sha512-AvPcP7XECNWy4LGmFQ77k7un4lSKM4eS29PTvW4ck95uYeLxXPWJM7hLuBqK91FaHqCcgJvIUCuNJjjxKE7VKQ==",
"license": "MIT"
},
+ "node_modules/semver": {
+ "version": "7.8.5",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",
+ "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",
+ "license": "ISC",
+ "bin": {
+ "semver": "bin/semver.js"
+ },
+ "engines": {
+ "node": ">=10"
+ }
+ },
+ "node_modules/sharp": {
+ "version": "0.35.4",
+ "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.35.4.tgz",
+ "integrity": "sha512-n++8XWcj+jCOr2IOl7h8LbKnGBDY4aPbmprMONBNFdn0ImXqpGVv5zliDs0V9HbmbCQLpbuo2ej9rAoOQTvMDA==",
+ "license": "Apache-2.0",
+ "dependencies": {
+ "@img/colour": "^1.1.0",
+ "detect-libc": "^2.1.2",
+ "semver": "^7.8.5"
+ },
+ "engines": {
+ "node": ">=20.9.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/libvips"
+ },
+ "optionalDependencies": {
+ "@img/sharp-darwin-arm64": "0.35.4",
+ "@img/sharp-darwin-x64": "0.35.4",
+ "@img/sharp-freebsd-wasm32": "0.35.4",
+ "@img/sharp-libvips-darwin-arm64": "1.3.3",
+ "@img/sharp-libvips-darwin-x64": "1.3.3",
+ "@img/sharp-libvips-linux-arm": "1.3.3",
+ "@img/sharp-libvips-linux-arm64": "1.3.3",
+ "@img/sharp-libvips-linux-ppc64": "1.3.3",
+ "@img/sharp-libvips-linux-riscv64": "1.3.3",
+ "@img/sharp-libvips-linux-s390x": "1.3.3",
+ "@img/sharp-libvips-linux-x64": "1.3.3",
+ "@img/sharp-libvips-linuxmusl-arm64": "1.3.3",
+ "@img/sharp-libvips-linuxmusl-x64": "1.3.3",
+ "@img/sharp-linux-arm": "0.35.4",
+ "@img/sharp-linux-arm64": "0.35.4",
+ "@img/sharp-linux-ppc64": "0.35.4",
+ "@img/sharp-linux-riscv64": "0.35.4",
+ "@img/sharp-linux-s390x": "0.35.4",
+ "@img/sharp-linux-x64": "0.35.4",
+ "@img/sharp-linuxmusl-arm64": "0.35.4",
+ "@img/sharp-linuxmusl-x64": "0.35.4",
+ "@img/sharp-webcontainers-wasm32": "0.35.4",
+ "@img/sharp-win32-arm64": "0.35.4",
+ "@img/sharp-win32-ia32": "0.35.4",
+ "@img/sharp-win32-x64": "0.35.4"
+ },
+ "peerDependenciesMeta": {
+ "@types/node": {
+ "optional": true
+ }
+ }
+ },
"node_modules/three": {
"version": "0.184.0",
"resolved": "https://registry.npmjs.org/three/-/three-0.184.0.tgz",
"integrity": "sha512-wtTRjG92pM5eUg/KuUnHsqSAlPM296brTOcLgMRqEeylYTh/CdtvKUvCyyCQTzFuStieWxvZb8mVTMvdPyUpxg==",
"license": "MIT"
+ },
+ "node_modules/tslib": {
+ "version": "2.8.1",
+ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
+ "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
+ "license": "0BSD",
+ "optional": true
+ },
+ "node_modules/uniq": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz",
+ "integrity": "sha512-Gw+zz50YNKPDKXs+9d+aKAjVwpjNwqzvNpLigIruT4HA9lMZNdMqs9x07kKHB/L9WRzqp4+DlTU5s4wG2esdoA==",
+ "license": "MIT"
}
}
}
diff --git a/packages/vscode-3d/package.json b/packages/vscode-3d/package.json
index f5611b4ad..d38a69ed6 100644
--- a/packages/vscode-3d/package.json
+++ b/packages/vscode-3d/package.json
@@ -48,8 +48,12 @@
"viewType": "threews3d.modelViewer",
"displayName": "three.ws 3D Viewer",
"selector": [
- { "filenamePattern": "*.glb" },
- { "filenamePattern": "*.gltf" }
+ {
+ "filenamePattern": "*.glb"
+ },
+ {
+ "filenamePattern": "*.gltf"
+ }
],
"priority": "default"
}
@@ -218,13 +222,21 @@
},
"threews3d.tier": {
"type": "string",
- "enum": ["draft", "standard", "high"],
+ "enum": [
+ "draft",
+ "standard",
+ "high"
+ ],
"default": "draft",
"description": "Detail level for text to 3D generation. Higher tiers take longer; all of them are free."
},
"threews3d.environment": {
"type": "string",
- "enum": ["studio", "neutral", "none"],
+ "enum": [
+ "studio",
+ "neutral",
+ "none"
+ ],
"default": "studio",
"description": "Image-based lighting used to light the model in the viewer."
},
@@ -256,6 +268,8 @@
"dependencies": {
"@gltf-transform/core": "^4.4.0",
"@gltf-transform/extensions": "^4.4.0",
+ "@gltf-transform/functions": "^4.5.0",
+ "gifenc": "^1.0.3",
"meshoptimizer": "^1.1.1",
"three": "^0.184.0"
},
diff --git a/packages/vscode-3d/src/active-panel.js b/packages/vscode-3d/src/active-panel.js
index 580067d44..077423ff7 100644
--- a/packages/vscode-3d/src/active-panel.js
+++ b/packages/vscode-3d/src/active-panel.js
@@ -1,19 +1,25 @@
// Which viewer a palette command acts on.
//
// Custom editors and remote panels both register here, so "Save a PNG snapshot"
-// works the same whether the model came from the workspace or from a URL.
+// or "Try a library animation" works the same whether the model came from the
+// workspace or from a URL. Each panel carries a `threews` record (its resource,
+// remote URL, byte reader, and latest stats) that the commands read.
let current = null;
+const listeners = new Set();
/** @param {import('vscode').WebviewPanel} panel */
export function trackPanel(panel) {
current = panel;
+ notify();
panel.onDidChangeViewState(() => {
if (panel.active) current = panel;
else if (current === panel) current = null;
+ notify();
});
panel.onDidDispose(() => {
if (current === panel) current = null;
+ notify();
});
return panel;
}
@@ -21,3 +27,13 @@ export function trackPanel(panel) {
export function activeViewer() {
return current;
}
+
+/** Called whenever the active viewer changes or its stats update. */
+export function onActiveViewerChanged(fn) {
+ listeners.add(fn);
+ return { dispose: () => listeners.delete(fn) };
+}
+
+export function notify() {
+ for (const fn of [...listeners]) fn(current);
+}
diff --git a/packages/vscode-3d/src/animations.js b/packages/vscode-3d/src/animations.js
new file mode 100644
index 000000000..7a0a92686
--- /dev/null
+++ b/packages/vscode-3d/src/animations.js
@@ -0,0 +1,164 @@
+// The three.ws motion library and the text to animation lane.
+//
+// The library is 2,800+ clips baked onto the canonical humanoid skeleton, the
+// same clips the /animations gallery and the <agent-3d> embed play. A clip is a
+// three.js AnimationClip serialised as JSON, so the viewer parses it with
+// AnimationClip.parse and retargets it onto whatever rig is open with the
+// platform's own retargeter. Text to animation samples a motion model on the
+// three.ws GPU fleet and returns a clip in the same format.
+
+import { normalizeOrigin } from './studio.js';
+import { slugFromPrompt } from './naming.js';
+
+const PAGE = 1000;
+const MOTION_POLL_MS = 3000;
+const MOTION_TIMEOUT_MS = 6 * 60_000;
+
+/**
+ * @typedef {object} LibraryClip
+ * @property {string} name stable id, e.g. "mx-happy-idle-c9cd...";
+ * @property {string} label human title, e.g. "Happy Idle"
+ * @property {boolean} loop whether the clip is meant to cycle
+ * @property {number} duration seconds
+ * @property {string} url the clip JSON on the CDN
+ * @property {string|null} thumb preview image
+ */
+
+/**
+ * Every clip in the library. Pages through the manifest so a growing catalogue
+ * never produces one oversized response.
+ *
+ * @param {string} origin
+ * @param {{ signal?: AbortSignal }} [opts]
+ * @returns {Promise<LibraryClip[]>}
+ */
+export async function listLibrary(origin, { signal } = {}) {
+ const base = normalizeOrigin(origin);
+ const clips = [];
+ let offset = 0;
+ for (let page = 0; page < 20; page++) {
+ const url = new URL('/api/animations/library', base);
+ url.searchParams.set('limit', String(PAGE));
+ url.searchParams.set('offset', String(offset));
+ const body = await getJson(url.href, { signal, what: 'the animation library' });
+ for (const row of Array.isArray(body?.clips) ? body.clips : []) {
+ const clip = normalizeClip(row);
+ if (clip) clips.push(clip);
+ }
+ if (body?.next_offset === null || body?.next_offset === undefined) break;
+ offset = Number(body.next_offset);
+ if (!Number.isFinite(offset)) break;
+ }
+ return clips;
+}
+
+/** One manifest row, validated. Rows without a fetchable clip URL are dropped. */
+export function normalizeClip(row) {
+ const url = row?.url;
+ if (typeof url !== 'string' || !/^https?:\/\//.test(url)) return null;
+ const label = String(row.label || row.name || '').trim();
+ if (!label) return null;
+ return {
+ name: String(row.name || label),
+ label,
+ loop: Boolean(row.loop),
+ duration: Number(row.duration) || 0,
+ url,
+ thumb: typeof row.thumb === 'string' ? row.thumb : null,
+ };
+}
+
+/**
+ * Fetch one clip's JSON.
+ * @param {string} url
+ * @param {{ signal?: AbortSignal }} [opts]
+ */
+export async function fetchClip(url, { signal } = {}) {
+ const clip = await getJson(url, { signal, what: 'the animation clip' });
+ if (!Array.isArray(clip?.tracks) || !clip.tracks.length) {
+ throw new Error('the clip has no animation tracks');
+ }
+ return clip;
+}
+
+/** A file-safe stem for a clip: "Happy Idle" -> "happy-idle". */
+export function clipSlug(label) {
+ return slugFromPrompt(String(label || '').replace(/^mx-/, ''), 'clip').replace(/-[0-9a-f]{12}(-\d+)?$/, '');
+}
+
+/**
+ * Generate an animation clip from a text prompt.
+ *
+ * POST /api/forge-motion starts the job; GET ?job= polls it. Resolves with the
+ * finished clip JSON plus its URL.
+ *
+ * @param {string} origin
+ * @param {string} prompt
+ * @param {{ signal?: AbortSignal, durationSeconds?: number, onStatus?: (message: string) => void }} [opts]
+ * @returns {Promise<{ clipUrl: string, clip: object }>}
+ */
+export async function generateMotion(origin, prompt, { signal, durationSeconds = 4, onStatus } = {}) {
+ const base = normalizeOrigin(origin);
+ const start = await fetch(new URL('/api/forge-motion', base).href, {
+ method: 'POST',
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
+ body: JSON.stringify({ prompt, duration_seconds: durationSeconds }),
+ signal,
+ }).catch((err) => {
+ throw new Error(`could not reach the motion lane: ${err?.message || err}`);
+ });
+ const started = await start.json().catch(() => null);
+ if (start.status === 503) {
+ throw new Error(started?.message || 'text to animation is not available on this origin right now');
+ }
+ if (!start.ok || !started?.job_id) {
+ throw new Error(started?.message || `the motion lane returned HTTP ${start.status}`);
+ }
+
+ const deadline = Date.now() + MOTION_TIMEOUT_MS;
+ const poll = new URL('/api/forge-motion', base);
+ poll.searchParams.set('job', started.job_id);
+ while (Date.now() < deadline) {
+ await sleep(MOTION_POLL_MS, signal);
+ const status = await getJson(poll.href, { signal, what: 'the motion job' });
+ if (status?.status === 'failed') {
+ throw new Error(status.error || 'the motion model could not animate that prompt');
+ }
+ if (status?.clip_url) {
+ onStatus?.('retargeting the clip…');
+ const clip = await fetchClip(status.clip_url, { signal });
+ return { clipUrl: status.clip_url, clip };
+ }
+ onStatus?.(status?.status === 'running' ? 'the motion model is sampling…' : 'queued on the GPU fleet…');
+ }
+ throw new Error('the motion job did not finish within six minutes');
+}
+
+async function getJson(url, { signal, what }) {
+ let res;
+ try {
+ res = await fetch(url, { headers: { accept: 'application/json' }, signal });
+ } catch (err) {
+ if (signal?.aborted) throw new Error('cancelled');
+ throw new Error(`could not reach ${what}: ${err?.message || err}`);
+ }
+ if (!res.ok) throw new Error(`${what} returned HTTP ${res.status}`);
+ const body = await res.json().catch(() => null);
+ if (body === null) throw new Error(`${what} returned a non-JSON body`);
+ return body;
+}
+
+function sleep(ms, signal) {
+ return new Promise((resolve, reject) => {
+ if (signal?.aborted) return reject(new Error('cancelled'));
+ const timer = setTimeout(() => {
+ signal?.removeEventListener('abort', onAbort);
+ resolve();
+ }, ms);
+ const onAbort = () => {
+ clearTimeout(timer);
+ reject(new Error('cancelled'));
+ };
+ signal?.addEventListener('abort', onAbort, { once: true });
+ });
+}
diff --git a/packages/vscode-3d/src/bake-clip.js b/packages/vscode-3d/src/bake-clip.js
new file mode 100644
index 000000000..d72829e9d
--- /dev/null
+++ b/packages/vscode-3d/src/bake-clip.js
@@ -0,0 +1,117 @@
+// Write an animation clip into a GLB.
+//
+// The viewer retargets a library clip onto the open model's skeleton and hands
+// back a three.js AnimationClip as JSON. This module turns that into real glTF
+// animation samplers and channels on the model's nodes with glTF-Transform, so
+// the saved file plays the clip in any engine, not just this viewer. Runs in the
+// extension host; nothing leaves the machine.
+
+import { WebIO } from '@gltf-transform/core';
+import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
+import { MeshoptDecoder, MeshoptEncoder } from 'meshoptimizer';
+
+/** three.js track property -> glTF channel path and element size. */
+const PATHS = Object.freeze({
+ position: { path: 'translation', type: 'VEC3', size: 3 },
+ quaternion: { path: 'rotation', type: 'VEC4', size: 4 },
+ scale: { path: 'scale', type: 'VEC3', size: 3 },
+});
+
+/** three.js InterpolateDiscrete / InterpolateLinear / InterpolateSmooth. */
+const INTERPOLATION = Object.freeze({ 2300: 'STEP', 2301: 'LINEAR', 2302: 'LINEAR' });
+
+/**
+ * GLTFLoader renames every node before an animation can bind to it, so track
+ * names carry the sanitised form. Mirrors three's PropertyBinding.sanitizeNodeName.
+ */
+export function sanitizeNodeName(name) {
+ return String(name || '')
+ .replace(/\s/g, '_')
+ .replace(/[\[\].:/]/g, '');
+}
+
+/**
+ * Parse a three.js track name into its node and property.
+ * "Hips.quaternion" -> { node: "Hips", property: "quaternion" }
+ * Morph-target and indexed tracks return null: they have no node channel.
+ */
+export function parseTrackName(name) {
+ const match = /^(.+)\.(position|quaternion|scale)$/.exec(String(name || ''));
+ if (!match) return null;
+ return { node: match[1], property: match[2] };
+}
+
+async function createIO() {
+ await MeshoptDecoder.ready;
+ await MeshoptEncoder.ready;
+ return new WebIO()
+ .registerExtensions(ALL_EXTENSIONS)
+ .registerDependencies({ 'meshopt.decoder': MeshoptDecoder, 'meshopt.encoder': MeshoptEncoder });
+}
+
+/**
+ * Add (or replace) an animation on a GLB.
+ *
+ * @param {Uint8Array} bytes the model
+ * @param {{ name?: string, duration?: number, tracks: Array<{ name: string, type: string, times: number[], values: number[], interpolation?: number }> }} clipJson
+ * the output of THREE.AnimationClip.toJSON on the retargeted clip
+ * @param {{ name?: string }} [opts] animation name; defaults to the clip's
+ * @returns {Promise<{ bytes: Uint8Array, channels: number, dropped: string[], name: string }>}
+ */
+export async function writeClipIntoGlb(bytes, clipJson, opts = {}) {
+ if (!Array.isArray(clipJson?.tracks) || !clipJson.tracks.length) {
+ throw new Error('the clip has no tracks to write');
+ }
+ const io = await createIO();
+ const doc = await io.readBinary(bytes);
+ const root = doc.getRoot();
+ const name = String(opts.name || clipJson.name || 'clip').trim() || 'clip';
+
+ const nodes = new Map();
+ for (const node of root.listNodes()) {
+ const key = sanitizeNodeName(node.getName());
+ if (key && !nodes.has(key)) nodes.set(key, node);
+ }
+
+ for (const existing of root.listAnimations()) {
+ if (existing.getName() === name) existing.dispose();
+ }
+
+ const buffer = root.listBuffers()[0] || doc.createBuffer();
+ const animation = doc.createAnimation(name);
+ const dropped = [];
+ let channels = 0;
+
+ for (const track of clipJson.tracks) {
+ const parsed = parseTrackName(track.name);
+ const spec = parsed && PATHS[parsed.property];
+ const node = parsed && (nodes.get(parsed.node) || nodes.get(sanitizeNodeName(parsed.node)));
+ if (!spec || !node) {
+ dropped.push(track.name);
+ continue;
+ }
+ const times = Float32Array.from(track.times);
+ const values = Float32Array.from(track.values);
+ if (!times.length || values.length !== times.length * spec.size) {
+ dropped.push(track.name);
+ continue;
+ }
+ const input = doc.createAccessor(`${name}/${track.name}/in`).setType('SCALAR').setArray(times).setBuffer(buffer);
+ const output = doc.createAccessor(`${name}/${track.name}/out`).setType(spec.type).setArray(values).setBuffer(buffer);
+ const sampler = doc
+ .createAnimationSampler()
+ .setInput(input)
+ .setOutput(output)
+ .setInterpolation(INTERPOLATION[track.interpolation] || 'LINEAR');
+ const channel = doc.createAnimationChannel().setSampler(sampler).setTargetNode(node).setTargetPath(spec.path);
+ animation.addSampler(sampler).addChannel(channel);
+ channels++;
+ }
+
+ if (!channels) {
+ animation.dispose();
+ throw new Error('none of the clip tracks matched a node in this model');
+ }
+
+ return { bytes: await io.writeBinary(doc), channels, dropped, name };
+}
diff --git a/packages/vscode-3d/src/compare.js b/packages/vscode-3d/src/compare.js
new file mode 100644
index 000000000..417d8fed3
--- /dev/null
+++ b/packages/vscode-3d/src/compare.js
@@ -0,0 +1,57 @@
+// Compare a model with the version git has.
+//
+// A pull request that touches a .glb shows a binary blob changed and nothing
+// else. This reads the committed bytes straight out of git and runs the
+// three.ws structural differ (@three-ws/glb-diff, the package behind the
+// glb-diff CLI) over both, so the review says what actually moved: geometry,
+// materials, textures, skeleton, animations, and how badly a consumer breaks.
+
+import { execFile } from 'node:child_process';
+import { dirname, basename } from 'node:path';
+import { diffModels, formatMarkdown } from '../../glb-diff/src/index.js';
+
+/**
+ * The file's bytes at a git ref, read without checking anything out.
+ *
+ * @param {string} fsPath absolute path of the working-tree file
+ * @param {string} [ref] defaults to HEAD
+ * @returns {Promise<Uint8Array>}
+ */
+export function committedBytes(fsPath, ref = 'HEAD') {
+ const dir = dirname(fsPath);
+ // "./name" resolves relative to -C's directory, whatever the repo root is.
+ const spec = `${ref}:./${basename(fsPath)}`;
+ return new Promise((resolve, reject) => {
+ execFile(
+ 'git',
+ ['-C', dir, 'show', spec],
+ { encoding: 'buffer', maxBuffer: 512 * 1024 * 1024 },
+ (err, stdout, stderr) => {
+ if (err) {
+ const detail = String(stderr || err.message || '').trim();
+ if (/not in|does not exist|exists on disk, but not in/i.test(detail)) {
+ return reject(new Error(`${basename(fsPath)} is not committed yet, so there is no version to compare against`));
+ }
+ if (/not a git repository/i.test(detail)) {
+ return reject(new Error('this file is not inside a git repository'));
+ }
+ return reject(new Error(detail || 'git show failed'));
+ }
+ resolve(new Uint8Array(stdout.buffer, stdout.byteOffset, stdout.byteLength));
+ },
+ );
+ });
+}
+
+/**
+ * Diff two models and render the review.
+ *
+ * @param {Uint8Array} before
+ * @param {Uint8Array} after
+ * @param {{ nameA?: string, nameB?: string }} [names]
+ * @returns {Promise<{ changeset: any, markdown: string }>}
+ */
+export async function compareModels(before, after, { nameA = 'committed', nameB = 'working tree' } = {}) {
+ const changeset = await diffModels(before, after, { nameA, nameB });
+ return { changeset, markdown: formatMarkdown(changeset) };
+}
diff --git a/packages/vscode-3d/src/embed-language.js b/packages/vscode-3d/src/embed-language.js
new file mode 100644
index 000000000..ad108880a
--- /dev/null
+++ b/packages/vscode-3d/src/embed-language.js
@@ -0,0 +1,400 @@
+// Language support for <agent-3d> embeds. Pure: no vscode, so every rule is
+// unit tested against strings and character offsets; extension.js maps the
+// offsets to editor positions and wires the providers.
+//
+// Covers the two tags an embed is made of: the element itself, and the
+// <script> that loads the library. The rules encode what docs/embedding.md says
+// goes wrong in practice: an element with no source shows nothing, an element
+// with no size collapses to zero, a "latest" script changes under a production
+// page, and a pinned script whose integrity hash has drifted is refused by the
+// browser outright.
+
+/** Every attribute the element reads, with the docs a hover or completion shows. */
+export const ATTRIBUTES = Object.freeze([
+ attr('src', 'On-chain agent URI, the canonical source: `agent://base/42`. Also accepts a bare GLB URL.', { source: true }),
+ attr('agent-id', 'Agent id: numeric token id (with `chain-id`), CAIP-10 (`eip155:8453:0xReg…:42`), or a backend id (`a_abc123`).', { source: true }),
+ attr('chain-id', 'Chain id that a numeric `agent-id` lives on, e.g. `8453` for Base.'),
+ attr('avatar-id', 'A three.ws avatar id. Loads the avatar without an agent persona.', { source: true }),
+ attr('manifest', 'IPFS or HTTPS URL of an agent manifest.', { source: true }),
+ attr('body', 'HTTPS URL of a bare GLB for an ad-hoc agent. Viewer-only unless `brain` is set.', { source: true }),
+ attr('brain', '`free` gives an ad-hoc `body` embed a real conversation with no API key, routed through the host-paid free tier.', { values: ['free'] }),
+ attr('instructions', 'System prompt for the `brain`: who the agent is and how it should behave.'),
+ attr('mode', 'Layout: `inline` (default, flows with the document), `floating` (fixed bubble), `section` (fills its parent), `fullscreen`.', { values: ['inline', 'floating', 'section', 'fullscreen'] }),
+ attr('position', 'Corner for `mode="floating"`.', { values: ['bottom-right', 'bottom-left', 'top-right', 'top-left', 'bottom-center'] }),
+ attr('offset', 'Distance from the edges for `mode="floating"`, e.g. `24px 24px`.'),
+ attr('width', 'CSS width for `mode="floating"`, e.g. `320px`. Inline embeds size through CSS instead.'),
+ attr('height', 'CSS height for `mode="floating"`, e.g. `420px`.'),
+ attr('responsive', 'Scale the layout with the container width.'),
+ attr('framing', 'Camera framing of the avatar: `full`, `bust`, or `face`.', { values: ['full', 'bust', 'face'] }),
+ attr('clip', 'Animation clip to play on load, by name.'),
+ attr('background', 'Background colour or `transparent`.'),
+ attr('poster', 'Image shown while the model loads (also available as the `poster` slot).'),
+ attr('name-plate', 'Show the agent name over the avatar.'),
+ attr('voice', 'Enable voice: the agent speaks its replies and listens to the mic.'),
+ attr('voice-server', 'URL of a self-hosted voice server.'),
+ attr('chat', 'Show the built-in chat panel.'),
+ attr('avatar-chat', 'Chat through the avatar (speech bubbles) instead of a panel.'),
+ attr('avatar-walk', 'Let the avatar walk around the page.'),
+ attr('sign-language', 'Sign replies in ASL alongside speech.'),
+ attr('wallet', 'Enable the agent wallet affordance.'),
+ attr('tracked-mint', 'Token mint the agent reacts to (price, holders).'),
+ attr('skills', 'Comma-separated skill URIs to install on load.'),
+ attr('skill-trust', 'Trust policy for installed skills.'),
+ attr('memory', 'Enable persistent conversation memory.'),
+ attr('memory-key', 'Storage key that scopes the memory, e.g. per user.'),
+ attr('api-base', 'Origin of a self-hosted three.ws API, for private deployments.'),
+ attr('api-key', 'API key for a self-hosted brain. Prefer `key-proxy` on public pages.'),
+ attr('key-proxy', 'URL of your own proxy that adds the API key server-side so it never ships in HTML.'),
+ attr('rpc-url', 'Custom RPC endpoint for on-chain lookups.'),
+ attr('registry', 'Agent registry contract to resolve `agent-id` against.'),
+ attr('name', 'Display name override.'),
+ attr('eager', 'Boot immediately instead of waiting to scroll into view.', { flag: true }),
+ attr('keep-alive', 'Keep the GL context running while off-screen.', { flag: true }),
+ attr('kiosk', 'Hide all chrome for a public display.', { flag: true }),
+ attr('viewer', 'Viewer-only: no chat, no voice, no brain.', { flag: true }),
+]);
+
+function attr(name, doc, extra = {}) {
+ return Object.freeze({ name, doc, values: extra.values || null, flag: Boolean(extra.flag), source: Boolean(extra.source) });
+}
+
+export const SOURCE_ATTRIBUTES = Object.freeze(ATTRIBUTES.filter((a) => a.source).map((a) => a.name));
+
+/** Attributes any HTML element takes, never flagged as unknown. */
+const GLOBAL_ATTRIBUTE = /^(id|class|style|slot|title|hidden|lang|dir|tabindex|role|part|is|data-[\w-]+|aria-[\w-]+|on[a-z]+)$/i;
+
+const ELEMENT_RE = /<agent-3d\b([^>]*?)(\/?)>/gi;
+const SCRIPT_RE = /<script\b([^>]*)>/gi;
+const ATTR_RE = /([^\s"'<>\/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|(\{[^}]*\})|([^\s"'<>`]+)))?/g;
+const LIBRARY_SRC_RE = /^(https?:)?\/\/([^/]+)\/agent-3d\/([^/]+)\/agent-3d(\.umd\.cjs|\.js)$/;
+const EXACT_VERSION_RE = /^\d+\.\d+\.\d+$/;
+
+/**
+ * @typedef {object} Attr
+ * @property {string} name
+ * @property {string|null} value null for a bare flag
+ * @property {number} start offset of the name
+ * @property {number} end offset after the whole attribute
+ * @property {number} nameEnd
+ * @property {boolean} expression true for a JSX `{…}` value
+ */
+
+/**
+ * Every <agent-3d> tag in the text.
+ * @param {string} text
+ * @returns {Array<{ start: number, end: number, tagEnd: number, attrsStart: number, attrs: Attr[] }>}
+ */
+export function findEmbeds(text) {
+ const out = [];
+ ELEMENT_RE.lastIndex = 0;
+ let m;
+ while ((m = ELEMENT_RE.exec(text))) {
+ const start = m.index;
+ const tagEnd = start + '<agent-3d'.length;
+ const attrsStart = tagEnd;
+ out.push({ start, end: start + m[0].length, tagEnd, attrsStart, attrs: parseAttrs(m[1], attrsStart) });
+ }
+ return out;
+}
+
+/**
+ * Every <script> that loads the agent-3d library.
+ * @param {string} text
+ * @returns {Array<{ start: number, end: number, src: Attr, channel: string, host: string, integrity: Attr|null, exact: boolean }>}
+ */
+export function findLibraryScripts(text) {
+ const out = [];
+ SCRIPT_RE.lastIndex = 0;
+ let m;
+ while ((m = SCRIPT_RE.exec(text))) {
+ const attrs = parseAttrs(m[1], m.index + '<script'.length);
+ const src = attrs.find((a) => a.name.toLowerCase() === 'src' && a.value);
+ const lib = src && LIBRARY_SRC_RE.exec(src.value.trim());
+ if (!lib) continue;
+ const channel = lib[3];
+ out.push({
+ start: m.index,
+ end: m.index + m[0].length,
+ src,
+ host: lib[2],
+ channel,
+ exact: EXACT_VERSION_RE.test(channel),
+ integrity: attrs.find((a) => a.name.toLowerCase() === 'integrity') || null,
+ });
+ }
+ return out;
+}
+
+/** @param {string} chunk @param {number} base offset of chunk[0] in the document */
+export function parseAttrs(chunk, base) {
+ const attrs = [];
+ ATTR_RE.lastIndex = 0;
+ let m;
+ while ((m = ATTR_RE.exec(chunk))) {
+ if (!m[0].trim()) continue;
+ const name = m[1];
+ const expression = m[4] !== undefined;
+ const value = m[2] ?? m[3] ?? m[4] ?? m[5] ?? null;
+ attrs.push({
+ name,
+ value,
+ expression,
+ start: base + m.index,
+ nameEnd: base + m.index + name.length,
+ end: base + m.index + m[0].length,
+ });
+ }
+ return attrs;
+}
+
+/** Which attribute of an embed the cursor is on, if any. */
+export function attributeAt(embed, offset) {
+ return embed.attrs.find((a) => offset >= a.start && offset <= a.end) || null;
+}
+
+/** Where in an embed the cursor sits: 'name' (typing an attribute), 'value' of an attribute, or null. */
+export function completionContext(text, offset) {
+ for (const embed of findEmbeds(text)) {
+ if (offset <= embed.tagEnd || offset > embed.end) continue;
+ for (const a of embed.attrs) {
+ if (a.value !== null && offset > a.nameEnd && offset <= a.end) {
+ const def = ATTRIBUTES.find((d) => d.name === a.name.toLowerCase());
+ return { kind: 'value', attr: a, def: def || null, embed };
+ }
+ }
+ const before = text.slice(embed.attrsStart, offset);
+ if (/[\s]$/.test(before) || /[\s][^\s="']*$/.test(before)) return { kind: 'name', embed };
+ }
+ // An unterminated tag the user is still typing.
+ const open = text.lastIndexOf('<agent-3d', offset);
+ if (open !== -1 && text.indexOf('>', open) === -1 || (open !== -1 && text.indexOf('>', open) >= offset)) {
+ const before = text.slice(open + '<agent-3d'.length, offset);
+ if (/[\s][^\s="']*$/.test(before) || /[\s]$/.test(before)) {
+ return { kind: 'name', embed: { start: open, tagEnd: open + '<agent-3d'.length, attrsStart: open + '<agent-3d'.length, end: offset, attrs: parseAttrs(before, open + '<agent-3d'.length) } };
+ }
+ }
+ return null;
+}
+
+/**
+ * @typedef {object} Finding
+ * @property {string} code
+ * @property {'error'|'warning'|'information'|'hint'} severity
+ * @property {string} message
+ * @property {number} start
+ * @property {number} end
+ * @property {{ title: string, start: number, end: number, text: string }|null} fix a single text replacement
+ */
+
+/**
+ * Run every rule.
+ *
+ * @param {string} text
+ * @param {{ release?: { channel: string, integrity: string|null } | null, origin?: string }} [ctx]
+ * release is the current library release from /agent-3d/versions.json; when
+ * absent (offline) the pinning rules that need it are skipped.
+ * @returns {Finding[]}
+ */
+export function diagnose(text, ctx = {}) {
+ const findings = [];
+ const release = ctx.release && EXACT_VERSION_RE.test(ctx.release.channel) ? ctx.release : null;
+
+ for (const embed of findEmbeds(text)) {
+ const names = embed.attrs.map((a) => a.name.toLowerCase());
+ const hasSource = names.some((n) => SOURCE_ATTRIBUTES.includes(n));
+ const hasSpread = embed.attrs.some((a) => a.expression && /^\{\s*\.\.\./.test(a.name) || /^\{\.\.\./.test(a.name));
+ if (!hasSource && !hasSpread) {
+ findings.push({
+ code: 'no-source',
+ severity: 'error',
+ message: `<agent-3d> has nothing to show. Set one of ${SOURCE_ATTRIBUTES.map((n) => `\`${n}\``).join(', ')}.`,
+ start: embed.start,
+ end: embed.tagEnd,
+ fix: null,
+ });
+ }
+
+ const mode = valueOf(embed, 'mode');
+ const style = valueOf(embed, 'style') || '';
+ const sized =
+ (/\bwidth\s*:/.test(style) && /\bheight\s*:/.test(style)) ||
+ (names.includes('width') && names.includes('height')) ||
+ names.includes('responsive') ||
+ (mode && mode !== 'inline') ||
+ hasSpread ||
+ embed.attrs.some((a) => a.name.toLowerCase() === 'style' && a.expression) ||
+ names.includes('class') || names.includes('classname');
+ if (!sized) {
+ findings.push({
+ code: 'no-size',
+ severity: 'warning',
+ message: 'The element has no intrinsic size and will collapse to 0×0. Give it a width and height (inline style, a class, or the width/height attributes).',
+ start: embed.start,
+ end: embed.tagEnd,
+ fix: {
+ title: 'Add an inline size (400×500)',
+ start: embed.tagEnd,
+ end: embed.tagEnd,
+ text: ' style="width: 400px; height: 500px; display: block;"',
+ },
+ });
+ }
+
+ for (const a of embed.attrs) {
+ const lower = a.name.toLowerCase();
+ if (a.expression && /^\{/.test(a.name)) continue;
+ const def = ATTRIBUTES.find((d) => d.name === lower);
+ if (!def) {
+ if (GLOBAL_ATTRIBUTE.test(lower) || lower === 'classname' || lower === 'key' || lower === 'ref') continue;
+ const guess = closest(lower);
+ findings.push({
+ code: 'unknown-attribute',
+ severity: 'information',
+ message: `\`${a.name}\` is not an attribute <agent-3d> reads.${guess ? ` Did you mean \`${guess}\`?` : ''}`,
+ start: a.start,
+ end: a.nameEnd,
+ fix: guess ? { title: `Rename to ${guess}`, start: a.start, end: a.nameEnd, text: guess } : null,
+ });
+ continue;
+ }
+ if (def.values && a.value !== null && !a.expression && !def.values.includes(a.value.trim())) {
+ findings.push({
+ code: 'bad-value',
+ severity: 'warning',
+ message: `\`${a.name}\` takes ${def.values.map((v) => `\`${v}\``).join(', ')}; \`${a.value}\` will be ignored.`,
+ start: a.nameEnd,
+ end: a.end,
+ fix: null,
+ });
+ }
+ if (lower === 'api-key' && a.value && !a.expression) {
+ findings.push({
+ code: 'key-in-html',
+ severity: 'warning',
+ message: 'An API key in HTML ships to every visitor. Use `key-proxy` to add it server-side, or `brain="free"`.',
+ start: a.start,
+ end: a.end,
+ fix: null,
+ });
+ }
+ }
+ }
+
+ for (const script of findLibraryScripts(text)) {
+ const target = release ? release.channel : null;
+ if (!script.exact) {
+ const moving = script.channel === 'latest';
+ findings.push({
+ code: 'unpinned-library',
+ severity: moving ? 'warning' : 'hint',
+ message: moving
+ ? 'The `latest` channel is for demos: a release can change this page under you. Pin an exact version for production.'
+ : `Channel \`${script.channel}\` follows new releases automatically. Pin an exact version if this page must not change on its own.`,
+ start: script.src.start,
+ end: script.src.end,
+ fix: target
+ ? pinFix(text, script, release)
+ : null,
+ });
+ continue;
+ }
+ if (!script.integrity) {
+ const known = release && release.channel === script.channel && release.integrity;
+ findings.push({
+ code: 'missing-integrity',
+ severity: 'hint',
+ message: 'Pinned, but without an `integrity` hash the browser cannot verify the bytes. Add the release hash.',
+ start: script.src.start,
+ end: script.src.end,
+ fix: known
+ ? { title: `Add integrity for ${release.channel}`, start: script.src.end, end: script.src.end, text: `\n integrity="${release.integrity}"\n crossorigin="anonymous"` }
+ : null,
+ });
+ } else if (release && release.channel === script.channel && release.integrity && script.integrity.value?.trim() !== release.integrity) {
+ findings.push({
+ code: 'stale-integrity',
+ severity: 'error',
+ message: `The integrity hash does not match release ${release.channel}. The browser will refuse to run the library.`,
+ start: script.integrity.start,
+ end: script.integrity.end,
+ fix: { title: `Use the published hash for ${release.channel}`, start: script.integrity.start, end: script.integrity.end, text: `integrity="${release.integrity}"` },
+ });
+ } else if (release && release.channel !== script.channel && newer(release.channel, script.channel)) {
+ findings.push({
+ code: 'newer-release',
+ severity: 'hint',
+ message: `Release ${release.channel} is available (this page pins ${script.channel}).`,
+ start: script.src.start,
+ end: script.src.end,
+ fix: pinFix(text, script, release),
+ });
+ }
+ }
+
+ return findings;
+}
+
+function pinFix(text, script, release) {
+ if (!release?.integrity) return null;
+ // Replace the whole tag so channel and hash change together.
+ const tag = text.slice(script.start, script.end);
+ const type = /\btype\s*=\s*["']module["']/i.test(tag) ? 'module' : null;
+ const src = script.src.value.replace(/\/agent-3d\/[^/]+\/agent-3d/, `/agent-3d/${release.channel}/agent-3d`);
+ const lines = ['<script', ...(type ? [` type="${type}"`] : []), ` src="${src}"`, ` integrity="${release.integrity}"`, ' crossorigin="anonymous"', '>'];
+ return { title: `Pin to ${release.channel} with its integrity hash`, start: script.start, end: script.end, text: lines.join('\n') };
+}
+
+function valueOf(embed, name) {
+ const a = embed.attrs.find((x) => x.name.toLowerCase() === name);
+ return a && a.value !== null && !a.expression ? a.value : null;
+}
+
+function newer(a, b) {
+ const pa = a.split('.').map(Number);
+ const pb = b.split('.').map(Number);
+ for (let i = 0; i < 3; i++) {
+ if (pa[i] !== pb[i]) return pa[i] > pb[i];
+ }
+ return false;
+}
+
+/** Nearest known attribute by edit distance, for "did you mean". */
+export function closest(name) {
+ let best = null;
+ let bestScore = Infinity;
+ for (const a of ATTRIBUTES) {
+ const d = levenshtein(name, a.name);
+ if (d < bestScore) {
+ bestScore = d;
+ best = a.name;
+ }
+ }
+ return bestScore <= Math.max(2, Math.floor(name.length / 4)) ? best : null;
+}
+
+function levenshtein(a, b) {
+ const m = a.length;
+ const n = b.length;
+ const row = Array.from({ length: n + 1 }, (_, i) => i);
+ for (let i = 1; i <= m; i++) {
+ let prev = row[0];
+ row[0] = i;
+ for (let j = 1; j <= n; j++) {
+ const tmp = row[j];
+ row[j] = Math.min(row[j] + 1, row[j - 1] + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1));
+ prev = tmp;
+ }
+ }
+ return row[n];
+}
+
+/** Hover text for the tag itself. */
+export function tagHover(origin = 'https://three.ws') {
+ return [
+ '**`<agent-3d>`**: a live three.ws agent (3D avatar that can talk, gesture, and run skills).',
+ '',
+ `Point it at an agent with \`src\`, \`agent-id\`, \`avatar-id\`, \`manifest\`, or a bare GLB with \`body\`. Give it a width and height.`,
+ '',
+ `[Embedding guide](${origin}/docs/embedding) · [Widget Studio](${origin}/studio)`,
+ ].join('\n');
+}
diff --git a/packages/vscode-3d/src/links.js b/packages/vscode-3d/src/links.js
index 6bd2ca880..87abdee87 100644
--- a/packages/vscode-3d/src/links.js
+++ b/packages/vscode-3d/src/links.js
@@ -1,31 +1,57 @@
-// Remembers where a local model came from.
+// Remembers where a local model came from, and what it is.
//
// A generated or imported GLB has a public URL on the three.ws CDN. That URL is
-// what the embed snippet and the rigger need, and it cannot be recovered from
-// the bytes on disk, so it is recorded when the file is written and looked up
-// later by workspace-relative path (absolute paths break when a repo is cloned
-// somewhere else or opened over a remote).
+// what the embed snippet, the rigger, and the refiner need, and it cannot be
+// recovered from the bytes on disk, so it is recorded when the file is written
+// and looked up later by workspace-relative path (absolute paths break when a
+// repo is cloned somewhere else or opened over a remote). Refinement also
+// records the prompt that made the model and the version lineage, so the next
+// refinement extends the same history instead of starting a new one.
import * as vscode from 'vscode';
const KEY = 'threews3d.modelLinks';
+/**
+ * @typedef {object} ModelMeta
+ * @property {string} url public URL of the model
+ * @property {string|null} prompt the prompt that produced it, when known
+ * @property {import('./refine.js').LineageVersion[]|null} lineage refinement history
+ */
+
export class ModelLinks {
/** @param {vscode.Memento} memento */
constructor(memento) {
this.memento = memento;
}
- /** @param {vscode.Uri} uri */
+ /** The public URL for a local model, or null. @param {vscode.Uri} uri */
get(uri) {
- const map = this.memento.get(KEY, {});
- return map[keyFor(uri)] || null;
+ return this.meta(uri)?.url || null;
+ }
+
+ /** Everything recorded about a local model, or null. @param {vscode.Uri} uri @returns {ModelMeta|null} */
+ meta(uri) {
+ const raw = this.memento.get(KEY, {})[keyFor(uri)];
+ if (!raw) return null;
+ // Entries written by 0.1.0 are bare URL strings.
+ if (typeof raw === 'string') return { url: raw, prompt: null, lineage: null };
+ return { url: raw.url, prompt: raw.prompt || null, lineage: Array.isArray(raw.lineage) ? raw.lineage : null };
}
- /** @param {vscode.Uri} uri @param {string} url */
- async set(uri, url) {
+ /**
+ * @param {vscode.Uri} uri
+ * @param {string} url
+ * @param {{ prompt?: string|null, lineage?: import('./refine.js').LineageVersion[]|null }} [extra]
+ */
+ async set(uri, url, extra = {}) {
const map = { ...this.memento.get(KEY, {}) };
- map[keyFor(uri)] = url;
+ const previous = this.meta(uri);
+ map[keyFor(uri)] = {
+ url,
+ prompt: extra.prompt ?? previous?.prompt ?? null,
+ lineage: extra.lineage ?? previous?.lineage ?? null,
+ };
await this.memento.update(KEY, map);
}
}
diff --git a/packages/vscode-3d/src/optimize.js b/packages/vscode-3d/src/optimize.js
new file mode 100644
index 000000000..9ba3473ff
--- /dev/null
+++ b/packages/vscode-3d/src/optimize.js
@@ -0,0 +1,83 @@
+// Web optimization, locally.
+//
+// The report tells a developer what is wrong with a model; this acts on it. The
+// same glTF-Transform passes the three.ws asset pipeline runs on every avatar it
+// serves (dedup, prune, weld, resample, optional quantize, meshopt) run in the
+// extension host and write a sibling file, so a 40 MB export becomes something a
+// phone can load without the file ever leaving the machine.
+
+import { WebIO } from '@gltf-transform/core';
+import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
+import { dedup, meshopt, prune, quantize, resample, weld } from '@gltf-transform/functions';
+import { MeshoptDecoder, MeshoptEncoder } from 'meshoptimizer';
+import { inspectModel } from '../../../src/gltf-inspect.js';
+
+/** The two presets offered in the editor. */
+export const PRESETS = Object.freeze({
+ balanced: {
+ label: 'Balanced',
+ detail: 'Dedup, prune, weld, resample animations, meshopt compression. Geometry keeps full precision.',
+ quantize: false,
+ },
+ compact: {
+ label: 'Compact',
+ detail: 'Everything in Balanced plus vertex quantization (KHR_mesh_quantization): smallest files, tiny precision loss.',
+ quantize: true,
+ },
+});
+
+async function createIO() {
+ await MeshoptDecoder.ready;
+ await MeshoptEncoder.ready;
+ return new WebIO()
+ .registerExtensions(ALL_EXTENSIONS)
+ .registerDependencies({ 'meshopt.decoder': MeshoptDecoder, 'meshopt.encoder': MeshoptEncoder });
+}
+
+/**
+ * @param {Uint8Array} bytes
+ * @param {{ preset?: keyof typeof PRESETS }} [opts]
+ * @returns {Promise<{ bytes: Uint8Array, before: Summary, after: Summary }>}
+ * @typedef {{ fileSize: number, vertices: number, triangles: number, extensions: string[] }} Summary
+ */
+export async function optimizeGlb(bytes, { preset = 'balanced' } = {}) {
+ const settings = PRESETS[preset] || PRESETS.balanced;
+ const io = await createIO();
+ const doc = await io.readBinary(bytes);
+ const passes = [dedup(), prune(), weld(), resample()];
+ if (settings.quantize) passes.push(quantize());
+ passes.push(meshopt({ encoder: MeshoptEncoder, level: 'medium' }));
+ await doc.transform(...passes);
+ const out = await io.writeBinary(doc);
+ const [before, after] = await Promise.all([summarize(bytes), summarize(out)]);
+ return { bytes: out, before, after };
+}
+
+async function summarize(bytes) {
+ const info = await inspectModel(bytes, { fileSize: bytes.byteLength });
+ return {
+ fileSize: bytes.byteLength,
+ vertices: info.counts.totalVertices,
+ triangles: info.counts.totalTriangles,
+ extensions: info.extensionsUsed,
+ };
+}
+
+/** One line for the notification: "12.4 MB → 3.1 MB (−75%), 210k → 98k vertices". */
+export function describeSavings(before, after) {
+ const pct = before.fileSize ? Math.round((1 - after.fileSize / before.fileSize) * 100) : 0;
+ const size = `${mb(before.fileSize)} → ${mb(after.fileSize)} (${pct >= 0 ? '−' : '+'}${Math.abs(pct)}%)`;
+ const verts =
+ before.vertices !== after.vertices
+ ? `, ${k(before.vertices)} → ${k(after.vertices)} vertices`
+ : '';
+ return size + verts;
+}
+
+function mb(n) {
+ return n < 1024 * 1024 ? `${(n / 1024).toFixed(0)} KB` : `${(n / 1024 / 1024).toFixed(1)} MB`;
+}
+
+function k(n) {
+ return n >= 1000 ? `${(n / 1000).toFixed(n >= 100_000 ? 0 : 1)}k` : String(n);
+}
diff --git a/packages/vscode-3d/src/quality.js b/packages/vscode-3d/src/quality.js
new file mode 100644
index 000000000..56bba32a5
--- /dev/null
+++ b/packages/vscode-3d/src/quality.js
@@ -0,0 +1,85 @@
+// AI quality check for the model on screen.
+//
+// The viewer renders the model, the render goes to /api/forge-quality-check,
+// and a vision model scores realism and completeness against the subject and
+// names the defects it can see. Because the request carries an image rather
+// than a URL, it works for a model that exists only on this disk.
+
+import { normalizeOrigin } from './studio.js';
+
+/**
+ * @param {string} origin
+ * @param {{ image: string, prompt?: string|null }} args image is a data: URL of the render
+ * @param {{ signal?: AbortSignal }} [opts]
+ * @returns {Promise<{ verdict: Verdict, retry: object|null }>}
+ * @typedef {{ pass: boolean, score: number|null, realism: number|null, completeness: number|null,
+ * subject: string, subject_detected: string|null, defects: string[], reason: string,
+ * suggested_retry_hint: string|null, qa_available: boolean, provider: string|null, model: string|null }} Verdict
+ */
+export async function checkQuality(origin, { image, prompt }, { signal } = {}) {
+ if (!/^data:image\/(png|jpeg|webp);base64,/.test(String(image || ''))) {
+ throw new Error('the quality check needs a PNG, JPEG, or WebP render');
+ }
+ const url = new URL('/api/forge-quality-check', normalizeOrigin(origin)).href;
+ let res;
+ try {
+ res = await fetch(url, {
+ method: 'POST',
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
+ body: JSON.stringify({ image, ...(prompt ? { prompt } : {}) }),
+ signal,
+ });
+ } catch (err) {
+ if (signal?.aborted) throw new Error('cancelled');
+ throw new Error(`could not reach the quality check: ${err?.message || err}`);
+ }
+ const body = await res.json().catch(() => null);
+ if (res.status === 429) throw new Error(body?.message || 'the quality check is rate limited right now; try again in a minute');
+ if (!res.ok || !body?.verdict) throw new Error(body?.message || `the quality check returned HTTP ${res.status}`);
+ return { verdict: body.verdict, retry: body.retry || null };
+}
+
+/**
+ * The verdict as a Markdown document for the editor.
+ * @param {Verdict} verdict
+ * @param {{ modelName: string, prompt?: string|null }} ctx
+ */
+export function qualityMarkdown(verdict, { modelName, prompt }) {
+ const lines = [`# Quality check: ${modelName}`, ''];
+ if (!verdict.qa_available) {
+ lines.push(
+ 'The scoring model was not reachable, so no verdict was produced. Nothing about the model failed;',
+ 'the check itself could not run. Try again in a moment.',
+ '',
+ `Reason: \`${verdict.reason || 'unknown'}\``,
+ );
+ return lines.join('\n');
+ }
+ lines.push(
+ `**${verdict.pass ? 'Passes' : 'Below'} the realism bar** · score ${fmt(verdict.score)}/100`,
+ '',
+ '| | |',
+ '|---|---|',
+ `| Realism | ${fmt(verdict.realism)} |`,
+ `| Completeness | ${fmt(verdict.completeness)} |`,
+ `| Subject | ${verdict.subject_detected || verdict.subject || 'unknown'}${prompt ? ` (asked for: ${prompt})` : ''} |`,
+ `| Photoreal | ${verdict.is_photoreal === null || verdict.is_photoreal === undefined ? 'n/a' : verdict.is_photoreal ? 'yes' : 'no'} |`,
+ `| Judge | ${[verdict.provider, verdict.model].filter(Boolean).join(' · ') || 'n/a'} |`,
+ '',
+ '## Reading',
+ '',
+ verdict.reason || '',
+ );
+ if (verdict.defects?.length) {
+ lines.push('', '## Defects', '');
+ for (const d of verdict.defects) lines.push(`- ${d}`);
+ }
+ if (verdict.suggested_retry_hint) {
+ lines.push('', '## To fix it', '', verdict.suggested_retry_hint, '', 'Run **3D: Refine this Model** with that instruction to generate a corrected version anchored to this one.');
+ }
+ return lines.join('\n');
+}
+
+function fmt(n) {
+ return n === null || n === undefined || Number.isNaN(Number(n)) ? 'n/a' : String(Math.round(Number(n)));
+}
diff --git a/packages/vscode-3d/src/refine.js b/packages/vscode-3d/src/refine.js
new file mode 100644
index 000000000..f0de1d8c9
--- /dev/null
+++ b/packages/vscode-3d/src/refine.js
@@ -0,0 +1,97 @@
+// Conversational refinement: carry a model forward with a described change.
+//
+// refine_model re-generates anchored to the parent (its prompt is folded into
+// the new one) and records every version in a lineage the client passes back,
+// so a sequence of refinements in the editor is one history the user can walk.
+
+import { TOOLS, rpc, textOf } from './studio.js';
+
+/** The studio holds a generation open this long before it answers "pending". */
+const CHECK_POLL_MS = 8000;
+const CHECK_TIMEOUT_MS = 6 * 60_000;
+
+/**
+ * @typedef {object} LineageVersion
+ * @property {number} index
+ * @property {number|null} parentIndex
+ * @property {string} glbUrl
+ * @property {string|null} prompt
+ * @property {string|null} instruction
+ */
+
+/**
+ * @param {string} origin
+ * @param {{ glbUrl: string, instruction: string, parentPrompt?: string|null, lineage?: LineageVersion[]|null }} args
+ * @param {{ signal?: AbortSignal, onStatus?: (message: string) => void }} [opts]
+ * @returns {Promise<{ glbUrl: string, prompt: string|null, instruction: string, lineage: LineageVersion[] }>}
+ */
+export async function refineModel(origin, { glbUrl, instruction, parentPrompt, lineage }, opts = {}) {
+ const args = { glb_url: glbUrl, instruction };
+ if (parentPrompt) args.parent_prompt = parentPrompt;
+ if (Array.isArray(lineage) && lineage.length) args.parent_lineage = lineage;
+
+ let payload = await rpc(origin, call(TOOLS.refine, args), { signal: opts.signal });
+ let result = readRefineResult(payload.result);
+
+ // A slow generation comes back pending; check_job collects it once done.
+ const deadline = Date.now() + CHECK_TIMEOUT_MS;
+ while (result.pending) {
+ if (Date.now() > deadline) throw new Error('the refinement did not finish within six minutes');
+ opts.onStatus?.('still generating the new version…');
+ await sleep(CHECK_POLL_MS, opts.signal);
+ payload = await rpc(origin, call(TOOLS.check, { job_id: result.jobId }), { signal: opts.signal });
+ result = readRefineResult(payload.result);
+ }
+ return result;
+}
+
+/**
+ * Pull the refined model and its lineage out of a tools/call result.
+ * @param {any} result
+ */
+export function readRefineResult(result) {
+ const structured = result?.structuredContent;
+ if (structured?.status === 'pending' && structured.jobId) {
+ return { pending: true, jobId: String(structured.jobId) };
+ }
+ const glbUrl = structured?.glbUrl || structured?.glb_url;
+ if (typeof glbUrl === 'string' && /^https?:\/\//.test(glbUrl)) {
+ const lineage = Array.isArray(structured.lineage)
+ ? structured.lineage.map((v, i) => ({
+ index: Number.isInteger(v.index) ? v.index : i,
+ parentIndex: v.parentIndex ?? (i > 0 ? i - 1 : null),
+ glbUrl: String(v.glbUrl || ''),
+ prompt: v.prompt || null,
+ instruction: v.instruction || null,
+ }))
+ : [];
+ return {
+ pending: false,
+ glbUrl,
+ prompt: typeof structured.prompt === 'string' ? structured.prompt : null,
+ instruction: typeof structured.instruction === 'string' ? structured.instruction : '',
+ lineage,
+ };
+ }
+ const text = textOf(result);
+ throw new Error(text || (result?.isError ? 'the studio refused the refinement' : 'the studio returned no model'));
+}
+
+function call(name, args) {
+ return { jsonrpc: '2.0', id: Date.now(), method: 'tools/call', params: { name, arguments: args } };
+}
+
+function sleep(ms, signal) {
+ return new Promise((resolve, reject) => {
+ if (signal?.aborted) return reject(new Error('cancelled'));
+ const timer = setTimeout(() => {
+ signal?.removeEventListener('abort', onAbort);
+ resolve();
+ }, ms);
+ const onAbort = () => {
+ clearTimeout(timer);
+ reject(new Error('cancelled'));
+ };
+ signal?.addEventListener('abort', onAbort, { once: true });
+ });
+}
diff --git a/packages/vscode-3d/src/status-bar.js b/packages/vscode-3d/src/status-bar.js
new file mode 100644
index 000000000..c257b89ec
--- /dev/null
+++ b/packages/vscode-3d/src/status-bar.js
@@ -0,0 +1,53 @@
+// The model's weight, always in view.
+//
+// While a viewer is the active editor the status bar shows triangles and file
+// size, the two numbers that decide whether an asset ships. Clicking it opens
+// the report.
+
+import * as vscode from 'vscode';
+import { onActiveViewerChanged } from './active-panel.js';
+import { formatBytes } from './naming.js';
+
+export function createStatusBar() {
+ const item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 90);
+ item.name = 'three.ws 3D';
+ item.command = 'threews3d.toggleReport';
+ const sub = onActiveViewerChanged((panel) => render(item, panel));
+ render(item, null);
+ return {
+ dispose() {
+ sub.dispose();
+ item.dispose();
+ },
+ };
+}
+
+function render(item, panel) {
+ const stats = panel?.threews?.stats;
+ if (!panel || !stats) {
+ item.hide();
+ return;
+ }
+ const parts = [`$(symbol-color) ${num(stats.triangles)} tris`];
+ if (panel.threews.fileSize) parts.push(formatBytes(panel.threews.fileSize));
+ if (stats.bones) parts.push(`${num(stats.bones)} bones`);
+ if (stats.animations) parts.push(`${stats.animations} clip${stats.animations === 1 ? '' : 's'}`);
+ item.text = parts.join(' · ');
+ item.tooltip = new vscode.MarkdownString(
+ [
+ `**${panel.title}**`,
+ '',
+ `- Triangles: ${num(stats.triangles)}`,
+ `- Meshes: ${num(stats.meshes)} · Materials: ${num(stats.materials)} · Textures: ${num(stats.textures)}`,
+ stats.bones ? `- Bones: ${num(stats.bones)}` : '- No skeleton',
+ `- Animations: ${num(stats.animations)}`,
+ '',
+ 'Click to toggle the report.',
+ ].join('\n'),
+ );
+ item.show();
+}
+
+function num(n) {
+ return Number(n || 0).toLocaleString('en-US');
+}