|
@@ -1,17 +1,16 @@
|
|
|
# Babylon.js glTF File Loader
|
|
|
|
|
|
-# Usage
|
|
|
The glTF file loader is a SceneLoader plugin.
|
|
|
|
|
|
-[glTF2 Playground example](http://www.babylonjs-playground.com/#6MZV8R)
|
|
|
+[Simple Playground Example](http://www.babylonjs-playground.com/#2IK4U7)
|
|
|
|
|
|
-## Step 1 - Include the glTF File Loader
|
|
|
+## Setup
|
|
|
|
|
|
**Full Version**
|
|
|
|
|
|
This loader supports both glTF 1.0 and 2.0 and will use the correct loader based on the glTF version string.
|
|
|
|
|
|
-```
|
|
|
+```HTML
|
|
|
<script src="babylon.js"></script>
|
|
|
<script src="babylon.glTFFileLoader.js"></script>
|
|
|
```
|
|
@@ -20,7 +19,7 @@ This loader supports both glTF 1.0 and 2.0 and will use the correct loader based
|
|
|
|
|
|
This loader supports only glTF 1.0 and will fail to load glTF 2.0.
|
|
|
|
|
|
-```
|
|
|
+```HTML
|
|
|
<script src="babylon.js"></script>
|
|
|
<script src="babylon.glTF1FileLoader.js"></script>
|
|
|
```
|
|
@@ -29,75 +28,155 @@ This loader supports only glTF 1.0 and will fail to load glTF 2.0.
|
|
|
|
|
|
This loader supports only glTF 2.0 and will fail to load glTF 1.0.
|
|
|
|
|
|
-```
|
|
|
+```HTML
|
|
|
<script src="babylon.js"></script>
|
|
|
<script src="babylon.glTF2FileLoader.js"></script>
|
|
|
```
|
|
|
|
|
|
-## Step 2 - Call the Scene Loader
|
|
|
+## Loading the Scene
|
|
|
+The Load function loads a glTF asset into a new scene.
|
|
|
+```JavaScript
|
|
|
+BABYLON.SceneLoader.Load("./", "duck.gltf", engine, function (scene) {
|
|
|
+ // do something with the scene
|
|
|
+});
|
|
|
```
|
|
|
-BABYLON.SceneLoader.Load("./", "duck.gltf", engine, function (scene) {
|
|
|
- // do somethings with the scene
|
|
|
+
|
|
|
+The Append function appends a glTF file to an existing scene.
|
|
|
+```JavaScript
|
|
|
+BABYLON.SceneLoader.Append("./", "duck.gltf", scene, function (scene) {
|
|
|
+ // do something with the scene
|
|
|
});
|
|
|
```
|
|
|
|
|
|
-You can also call the ImportMesh function and import specific meshes
|
|
|
+The ImportMesh function imports specific meshes from a glTF asset to an existing scene and returns the imported meshes and skeletons.
|
|
|
+```JavaScript
|
|
|
+// The first parameter can be set to null to load all meshes and skeletons
|
|
|
+BABYLON.SceneLoader.ImportMesh(["myMesh1", "myMesh2"], "./", "duck.gltf", scene, function (meshes, particleSystems, skeletons) {
|
|
|
+ // do something with the meshes and skeletons
|
|
|
+ // particleSystems are always null for glTF assets
|
|
|
+});
|
|
|
```
|
|
|
-// meshesNames can be set to "null" to load all meshes and skeletons
|
|
|
-BABYLON.SceneLoader.ImportMesh(["myMesh1", "myMesh2", "..."], "./", "duck.gltf", scene, function (meshes, particleSystems, skeletons) {
|
|
|
- // do somethings with the meshes, particleSystems (not handled in glTF files) and skeletons
|
|
|
+
|
|
|
+## Advanced
|
|
|
+
|
|
|
+The SceneLoader returns the glTF loader instance to enable setting properties per instance.
|
|
|
+
|
|
|
+```JavaScript
|
|
|
+var loader = BABYLON.SceneLoader.Load("./", "duck.gltf", engine, function (scene) {
|
|
|
+ // do something with the scene
|
|
|
});
|
|
|
+
|
|
|
+// do something with the loader
|
|
|
+// loader.<option1> = <...>
|
|
|
+// loader.<option2> = <...>
|
|
|
+// loader.dispose();
|
|
|
```
|
|
|
|
|
|
-You can also append a glTF file to a scene. When using `SceneLoader.Append`, configure the scene to use right handed system by setting the property `useRightHandedSystem` to true.
|
|
|
+#### onParsed
|
|
|
+Raised when the asset has been parsed. The `data.json` property stores the glTF JSON. The `data.bin` property stores the BIN chunk from a glTF binary or null if the input is not a glTF binary.
|
|
|
|
|
|
+```JavaScript
|
|
|
+loader.onParsed = function (data) {
|
|
|
+ // do something with the data
|
|
|
+};
|
|
|
```
|
|
|
-// glTF Files use right handed system
|
|
|
-scene.useRightHandedSystem = true;
|
|
|
|
|
|
-// Append sample glTF model to scene
|
|
|
-BABYLON.SceneLoader.Append("https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/BoomBox/glTF/", "BoomBox.gltf", scene, function (scene) {
|
|
|
-}, null, function (scene) {
|
|
|
- alert("error");
|
|
|
-});
|
|
|
+### Version 1 Only
|
|
|
+
|
|
|
+#### IncrementalLoading
|
|
|
+Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders. Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled. Defaults to true.
|
|
|
+
|
|
|
+```JavaScript
|
|
|
+BABYLON.GLTFFileLoader.IncrementalLoading = false;
|
|
|
+```
|
|
|
+
|
|
|
+#### HomogeneousCoordinates
|
|
|
+Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters. Defaults to false.
|
|
|
+
|
|
|
+```JavaScript
|
|
|
+BABYLON.GLTFFileLoader.HomogeneousCoordinates = true;
|
|
|
+```
|
|
|
+
|
|
|
+### Version 2 Only
|
|
|
+
|
|
|
+#### coordinateSystemMode
|
|
|
+The coordinate system mode (AUTO, FORCE_RIGHT_HANDED). Defaults to AUTO.
|
|
|
+
|
|
|
+```JavaScript
|
|
|
+loader.coordinateSystemMode = BABYLON.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED;
|
|
|
```
|
|
|
|
|
|
-## Step 3 (V1 Only) - Optionally Specify Flags
|
|
|
+#### animationStartMode
|
|
|
+The animation start mode (NONE, FIRST, ALL). Defaults to FIRST.
|
|
|
|
|
|
-If you want to disable incremental loading, you can set the property `IncrementalLoading` to false.
|
|
|
-Then, you'll be able to be called back with all geometries and shaders loaded. Textures are always loaded asynchronously. For example, you can retrieve the real bounding infos of a mesh loaded when incremental loading is disabled.
|
|
|
+```JavaScript
|
|
|
+loader.animationStartMode = BABYLON.GLTFLoaderAnimationStartMode.NONE;
|
|
|
```
|
|
|
-BABYLON.GLTFFileLoader.IncrementalLoading = false; // true by default
|
|
|
+
|
|
|
+#### compileMaterials
|
|
|
+Set to true to compile materials before raising the success callback. Defaults to false.
|
|
|
+
|
|
|
+```JavaScript
|
|
|
+loader.compileMaterials = true;
|
|
|
+```
|
|
|
+
|
|
|
+#### useClipPlane
|
|
|
+Set to true to also compile materials with clip planes. Defaults to false.
|
|
|
+
|
|
|
+```JavaScript
|
|
|
+loader.useClipPlane = true;
|
|
|
```
|
|
|
|
|
|
-In order to work with homogeneous coordinates (that can be available with some converters and exporters):
|
|
|
+#### compileShadowGenerators
|
|
|
+Set to true to compile shadow generators before raising the success callback. Defaults to false.
|
|
|
+
|
|
|
+```JavaScript
|
|
|
+loader.compileShadowGenerators = true;
|
|
|
```
|
|
|
-BABYLON.GLTFFileLoader.HomogeneousCoordinates = true; // false by default
|
|
|
+
|
|
|
+#### onMeshLoaded
|
|
|
+Raised when the loader creates a mesh after parsing the glTF properties of the mesh.
|
|
|
+
|
|
|
+```JavaScript
|
|
|
+loader.onMeshLoaded = function (mesh) {
|
|
|
+ // do something with the mesh
|
|
|
+};
|
|
|
```
|
|
|
|
|
|
-# Supported Features
|
|
|
-* Load scenes (SceneLoader.Load and SceneLoader.Append)
|
|
|
-* Support of ImportMesh function
|
|
|
-* Import geometries
|
|
|
- * From binary files
|
|
|
- * From base64 buffers
|
|
|
-* Import lights (V1 only)
|
|
|
-* Import cameras
|
|
|
-* Import and set custom shaders (V1 only)
|
|
|
- * Automatically bind attributes
|
|
|
- * Automatically bind matrices
|
|
|
- * Set uniforms
|
|
|
-* Import and set animations
|
|
|
-* Skinning (BETA, sometimes wrong on tricky models)
|
|
|
- * Skeletons
|
|
|
- * Hardware skinning (shaders support)
|
|
|
- * Bones import
|
|
|
-* Handle dummy nodes (empty nodes)
|
|
|
-* PBR materials (V2 only)
|
|
|
+#### onTextureLoaded
|
|
|
+Raised when the loader creates a texture
|
|
|
+after parsing the glTF properties of the texture.
|
|
|
|
|
|
-# Future Improvements
|
|
|
-* Test on more geometries
|
|
|
-* Test on more animated models
|
|
|
-* Test on more skinned models
|
|
|
-* Improve shaders support (V1 only) (glitches with samplers can appear in particular configurations)
|
|
|
-* Add support for morph targets (V2 only)
|
|
|
+```JavaScript
|
|
|
+loader.onTextureLoaded = function (texture) {
|
|
|
+ // do something with the texture
|
|
|
+};
|
|
|
+```
|
|
|
+
|
|
|
+#### onMaterialLoaded
|
|
|
+Raised when the loader creates a material after parsing the glTF properties of the material.
|
|
|
+
|
|
|
+```JavaScript
|
|
|
+loader.onMaterialLoaded = function (material) {
|
|
|
+ // do something with the material
|
|
|
+};
|
|
|
+```
|
|
|
+
|
|
|
+#### onComplete
|
|
|
+Raised when the asset is completely loaded, immediately before the loader is disposed.
|
|
|
+For assets with LODs, raised when all of the LODs are complete.
|
|
|
+For assets without LODs, raised when the model is complete, immediately after onSuccess.
|
|
|
+
|
|
|
+```JavaScript
|
|
|
+loader.onComplete = function () {
|
|
|
+ // do something when loading is complete
|
|
|
+};
|
|
|
+```
|
|
|
+
|
|
|
+#### dispose
|
|
|
+Disposes the loader, releases resources during load, and cancels any outstanding requests.
|
|
|
+
|
|
|
+```JavaScript
|
|
|
+// Cancel loading of the current glTF asset.
|
|
|
+loader.dispose();
|
|
|
+```
|