This is an extension for Visual Studio Code to add support for editing glTF files.
Clone or download
Latest commit 3e3e7f3 Sep 20, 2018
Permalink
Failed to load latest commit information.
.vscode Add tslint and recommended extensions list. Sep 20, 2018
engines Update to 2.1.14 Jul 19, 2018
environments Babylon reflections readme Jul 19, 2017
images Rename part 2 Nov 29, 2017
pages Re-enable screen space panning in ThreeJS. Jun 1, 2018
resources cleanup expanding, icons Nov 13, 2017
schemas Re-run the importAll.sh script. Sep 20, 2018
server Update 2.1.16 Sep 20, 2018
src Tweak the wording of the validation report summary. Jun 1, 2018
test Initial "yo code" of gltf-vscode. Mar 15, 2017
util Update import scripts to pull in AGI_ extensions. Sep 20, 2018
.eslintignore Tweak eslint, also fix issue with MetalRoughSpheres getting flipped. Mar 21, 2018
.eslintrc.json Switch from jsHint to esLint, fix warnings. Dec 31, 2017
.gitattributes Add several glTF extensions to the schema. Sep 7, 2018
.gitignore Update .gitignore Jan 8, 2018
.npmrc Turn off package-lock.json. Nov 7, 2017
.vscodeignore Make sure CesiumUnminified stays out of the release. Mar 7, 2018
CHANGELOG.md Update 2.1.16 Sep 20, 2018
CODE_OF_CONDUCT.md updated for code of conduct check Jan 18, 2018
CONTRIBUTING.md updated for code of conduct check Jan 18, 2018
CONTRIBUTORS.md fixed gammasettings in threejs Apr 3, 2018
LICENSE.md Update LICENSE.md so GitHub reports Apache 2.0 license Jun 14, 2017
README.md CHANGELOG and README Sep 20, 2018
package.json Update 2.1.16 Sep 20, 2018
tsconfig.json Removing these lines prevents a strange npm error Sep 25, 2017
tslint.json Add tslint and recommended extensions list. Sep 20, 2018
vsc-extension-quickstart.md Initial "yo code" of gltf-vscode. Mar 15, 2017

README.md

glTF Extension for Visual Studio Code

GitHub issues Gitter chat GitHub license VS Code marketplace

Preview glTF 3D models directly in the editor

Damaged Helmet by theblueturtle_

Command name: glTF: Preview 3D Model, default keybinding: ALT + G

The above model, other sample models, and associated licenses can be obtained from the glTF-Sample-Models repository.

You can preview glTF files in a number of different rendering engines: BabylonJS, Cesium, and ThreeJS. The ThreeJS engine will preview the saved model as opposed to the current content in your open VS Code tab. The Babylon and Cesium engines will first try to preview what is currently in your tab, and only if that fails will it fall back on displaying the version of the model saved on disk.

Import a binary .glb file as text-based .gltf and export text-based .gltf file to binary .glb file.

GLB conversion

Command name: glTF: Export to GLB (Binary file)
Command name: glTF: Import from GLB

The glTF 3D model format comes in two varieties: *.gltf is a JSON-based text file, easily editable with this VS Code extension, often with references to external files such as texturemaps and binary mesh data. *.glb is a binary version, typically smaller and self-contained, but not easily editable.

The glTF: Export to GLB (Binary file) command will export your text-based glTF from the editor to a binary .glb file. In the exported version, whitespace in the JSON is stripped out, external file references are read in and converted to GLB binary bufferViews, and the resulting file becomes a self-contained transportable file that can be easily shared.

The glTF: Import from GLB command will convert a binary .glb to JSON-based .gltf for editing, creating a separate file for the binary and additional files for each of the included images. Note that during import, some filenames are calculated based on the target filename of the output .gltf. For example, converting a sample file Lantern.glb to .gltf may create the following files:

  • Lantern.gltf - The JSON structure.
  • Lantern_data.bin - The binary mesh data
  • Lantern_img0.png - Image file(s) extracted from the GLB
  • Lantern_img1.png
  • Lantern_img2.png
  • Lantern_img3.png

The user is given a "Save As..." dialog for the base .gltf output filename only. The other files are saved to the same folder with names calculated by appending to the user's selected base name, and any pre-existing files with the same name will be overwritten.

Preview shaders, image files, binary data from files or data-URIs directly in the glTF document

Sample image preview of normal map

Command name: glTF: Inspect Data URI, default keybinding: ALT + D
Command name: Go to Definition, default keybinding: F12

Above, the user is previewing Accessor 0 and a normal map that is part of the BoomBox.gltf model from the official sample model repository. The preview works even if the filename is replaced by a data: ... formatted URI. Place the document cursor on a dataURI, or on a block that has been folded closed with a dataURI in its uri field, then press F12 or look for the command glTF: Inspect Data URI in VSCode's list of commands (CTRL + SHIFT + P) and use that.

If you plan to preview GLSL shader code, consider installing a 3rd-party syntax highlighter with support for the *.glsl extension, for example Shader Language Support for VSCode by slevesque, to enable syntax highlighting in shader previews.

Convert files to and from Data URIs

Sample conversion

In the list of commands (CTRL + SHIFT + P), there are two commands named glTF: Import file as Data URI and glTF: Export a Data URI to a file. To use these, place the document cursor on a block that contains a "uri" field. If the value of this field is a valid filename, Import will load that file, encode it to base64, and replace the filename with the dataURI in your document. Export is the reverse of this process, but first it will ask you for a filename to save to. It will save the file in the same folder as the glTF file, so it does not need a path, just a name. It will try to select an appropriate file extension based on the MIME type of the dataURI. It will also warn you if you are about to overwrite an existing file. If the save is successful, the dataURI will be replaced by the name of the newly created file.

Tree View of Scene Nodes

This displays an Explorer outline revealing the node structure of the glTF file. This allows easier navigation of the scene structure.

Gltf Outline

glTF Validation

Files can be validated three different ways:

  • The official Khronos glTF Validator runs automatically on glTF 2.0 files, and reports any issues it finds to the document's "Problems" window. All such messages are marked with a [glTF Validator] prefix. Check the bottom status bar for a small x in a circle next to a small ! in a triangle, these show numbers of errors and warnings, respectively. This goes far beyond simple JSON validation, as it reads in external data and image files, and looks at mesh data itself for structural errors.

  • The same glTF Validator can also run as a manual process, by issuing the command glTF: Validate a GLB or GLTF file. This can be done by right-clicking a file in the VSCode File Explorer sidebar, or just running the command stand-alone to open a file dialog. This is the only method in this extension to validate GLB files directly, without conversion. A summary of the validation report appears at the top, along with an option to save the JSON report.

  • The glTF JSON schema is registered with VSCode for *.gltf files, and VSCode will find schema violations using its own JSON schema validation, without help from the glTF Validator. This produces messages in the "Problems" window that are not marked [glTF Validator]. This is less thorough than full glTF validation, but is the only method available to glTF 1.0 files.

Other Features

Go to Definition command works for all indexed glTF references

Place the cursor on the 3 in "POSITION": 3 and press F12 to navigate to the defining Accessor.

• Tooltips for glTF enum values

Hover the mouse over a numeric enum to see its meaning.

Hover tooltips

• Autocomplete for glTF enum values

Press CTRL + SPACE on a blank field to pop up a list of suggested values. As you scroll through the list, the meaning of the selected value is revealed.

Property autocomplete

This works for arrays as well, for example the list of enabled render states. Here for example, a user is looking to enable a BLEND state.

Render states enable

• Animation editor

Press ALT + i on an animation sampler to import values into the glTF JSON.

"samplers": [
{
    "input": 6,
    "interpolation": "LINEAR",
    "output": 7,
    "extras": {
    "vscode_gltf_input": [
        1.25,
        2.5
    ],
    "vscode_gltf_type": "VEC4",
    "vscode_gltf_output": [
        0,
        0,
        0,
        -1,
        1,
        0,
        0,
        4.4896593387466766e-11
    ]
},

Modify the vscode_gltf_input and vscode_gltf_output arrays for your needs and then press ALT + o to rewrite the glTF buffer and JSON with new values. This will use a Data URI for the buffer so the changes can be completely undone; glTF: Export a Data URI to a file is available if a binary file is required. Save the edited document and use glTF: Preview 3D Model to view your changes.

New samplers can be created as well simply use -1 for the accessor references and new accessors will be automatically created.

Extension Settings

Default rendering engines

  • glTF.defaultV1Engine - Choose the default 3D engine that will render a glTF 1.0 model in the preview window.

  • glTF.defaultV2Engine - Choose the default 3D engine that will render a glTF 2.0 model in the preview window.

Reflection Environments

  • glTF.Babylon.environment - Override the default reflection map for the BabylonJS glTF preview window. This specifies a local path to a Babylon DDS environment file, such as one created by following steps in Creating a DDS Environment File From an HDR Image.

  • glTF.Three.environment - Override the default reflection map for the ThreeJS glTF preview window. There are 6 cube faces, with face names posx, negx, posy, negy, posz, and negz. The rest of the path and filename should be identical for all 6 files. The path and filename are specified as a single string, using {face} in place of the face name. The files must be in a format usable on the web, such as PNG or JPEG.

Files and Folders

  • glTF.showToolbar3D - Show a button on the toolbar to activate the 3D Preview window.

  • glTF.alwaysOverwriteDefaultFilename - Certain commands create new files, such as importing and exporting GLBs, exporting a DataURI, and creating a glTF Validation report. When true these files will be saved with their default names, which saves the step of interacting with a file dialog each time, but does make it trivial to overwrite existing files. It's safer to leave this set to false.

  • glTF.expandOutlineWithSelection - When the editor selection changes, the glTF outline will expand to include the current selection.

Automatic glTF Validation (only)

  • glTF.Validation.enable - When true, automatically run the glTF Validator and report any found issues to the document problems window.

  • glTF.Validation.debounce - The number of milliseconds to wait for multiple automatic requests to re-validate a glTF document.

Automatic and Manual glTF Validation (shared settings)

  • glTF.Validation.maxIssues - Controls the maximum number of issues reported by the Khronos glTF Validator (not counting any messages produced by VSCode's own JSON schema validation).

  • glTF.Validation.ignoredIssues - Array of issue codes to ignore during validation. The issues should be listed in the array by issue code, such as ACCESSOR_INDEX_TRIANGLE_DEGENERATE and NODE_EMPTY. See ISSUES.md for the full list, or run a manual glTF Validation of an existing file with messages reported to see their codes. For example, to completely disable reporting of empty nodes, one would use: [ "NODE_EMPTY" ]

  • glTF.Validation.severityOverrides - This is a JSON object that maps issue codes (as keys) to severity codes (as values). The issue codes are the same as for glTF.Validation.ignoredIssues above. The severity codes are: 0 for error, 1 for warning, 2 for information, and 3 for hint. For example, to reduce the severity of empty nodes to hint, one would specify: { "NODE_EMPTY" : 3 }

Supported glTF extensions

Certain glTF 2.0 extensions are supported by JSON schema validation in VSCode. This means that VSCode will provide hover tooltips, auto-complete (CTRL + space), and document problem indications for extension schema violations. This is separate from (and in addition to) any validation being performed by the official glTF Validator. The extension schemas shipping with this project currently are:

  • KHR_draco_mesh_compression
  • KHR_materials_pbrSpecularGlossiness
  • KHR_materials_unlit
  • KHR_techniques_webgl (Draft)
  • KHR_texture_transform
  • AGI_articulations
  • AGI_stk_metadata

Support for additional extensions can be requested by filing an issue or pull request to the GitHub repository.

Source code

on GitHub. See CONTRIBUTING.md.

Acknowledgements

This extension makes use of the following open source projects:

  • Cesium - One of the 3D engines used in the preview window
  • Babylon.js - One of the 3D engines used in the preview window
  • Three.js - One of the 3D engines used in the preview window
  • Knockout - Used to data-bind preview window's menu

License

Apache 2.0, see LICENSE.md.

Release Notes

See CHANGELOG.md.