How analyticalgraphicsinc/gltf-vscode works
Project type and purpose
• This is a Visual Studio Code Extension (“glTF Tools”) that provides:
• Preview and debug of glTF 1.0/2.0 models in multiple 3D engines (Babylon, Three, Cesium, Filament).
• Commands to import/export between .gltf/.glb, inspect data, validate against schemas and the Khronos Validator.
• A tree‐view outline, quick‐fixes, hover/tooltips, autocomplete, and an animation editor.
File structure
• Top‐level:
• package.json, tsconfig.json – extension manifest and build config
• src/ – TypeScript code for the VSCode extension host (commands, providers, validators, tree view)
• server/ – A small Node.js HTTP server (server.ts) that hosts the Webview UI assets (HTML/CSS/JS)
• pages/ – Static HTML, CSS, JS for each preview engine’s Webview (threeView, babylonView, etc.)
• engines/ – JavaScript/WASM decoder bundles for each 3D engine (Draco, Basis, Babylon)
• schemas/ – JSON Schema definitions for glTF 1.0/2.0 and extensions used for validation/autocomplete
• util/ – Helper scripts to import/generate schema files and mappings
• test/ – Unit tests for extension code
• resources/, environments/, images/ – UI assets and default environment maps for preview windows
README for additional insights
• Extension uses VSCode APIs (commands, content providers, diagnostics, webviews).
• Leverages external libraries: Babylon.js, Three.js, Cesium, Filament, Draco, Basis Universal, Knockout.js.
• Runs Khronos glTF Validator automatically or on demand.
• Supports quick‐fix code actions for specific validation codes.
a. Main components
1. VSCode Editor Host
– Extension Host Process (src/*.ts)
– Registers Commands, Language Features, Diagnostics
2. HTTP Server (server/server.ts)
– Serves Webview assets on localhost
3. Webview Frontend (pages/*.html, .js, .css)
– UI for 3D preview, debug tools, menus (uses Knockout for bindings)
4. 3D Engines & Decoders (engines/)
– BabylonJS, ThreeJS, Cesium, Filament, Draco, Basis (JS + WASM)
5. File System & Schemas
– glTF JSON Schemas (schemas/…), util scripts to manage them
– Read/write .gltf/.glb/.bin files, data‐URIs
6. External Validator
– Khronos glTF Validator (CLI/WASM)
7. Utility Scripts (util/)
– Schema imports, extension mappings, test harness
b. Relationships & data flow
• User triggers a command (Preview, Import, Export, Inspect) via Command Palette → routed to Extension Host
• Extension Host reads/writes files on disk (glTF, bin, images), updates text documents
• For Preview: Extension Host launches/ensures HTTP Server is running → opens Webview pointing to http://localhost:<port>/*
• Webview fetches HTML/CSS/JS + engine scripts from the HTTP Server → renders 3D scene using the selected engine
• For Validation: Extension Host invokes the Khronos Validator (spawn process or WASM), collects diagnostics → pushes to VSCode’s Problems panel
• Quick‐Fix actions are implemented in the Extension Host, editing JSON or binary URIs, and saving new files
c. Architectural patterns & design principles
– Extension Host / Webview separation (backend vs. frontend in VSCode extension model)
– Micro‐frontend style: separate web apps per engine under pages/
– Modular decoders (engines/) loaded dynamically in Webview
– JSON Schema‐driven validation & autocomplete
– Code‐actions (quick fixes) as discrete providers mapping validator codes to edits
d. Key technologies / libraries
– TypeScript, Node.js, VSCode Extension API
– Webview API → HTML/CSS/JS frontends
– JavaScript/WASM modules: Draco, Basis, zstd, meshopt
– 3D Engines: Babylon.js, Three.js, Cesium, Filament
– JSON Schema (Khronos glTF schemas)
– CLI/WASM glTF Validator
– Testing: Mocha/Jest via test/*.ts