forked from BabylonJS/Documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/PatrickRyanMS/Documentation
- Loading branch information
Showing
39 changed files
with
671 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "msedge", | ||
"request": "launch", | ||
"name": "Documentation (Edge)", | ||
"url": "http://localhost:3000", | ||
"preLaunchTask": "Dev" | ||
}, | ||
{ | ||
"type": "chrome", | ||
"request": "launch", | ||
"name": "Documentation (Chrome)", | ||
"url": "http://localhost:3000", | ||
"preLaunchTask": "Dev" | ||
} | ||
], | ||
"compounds": [ | ||
{ | ||
"name": "Default Launch", | ||
"configurations": ["Documentation (Edge)"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Dev", | ||
"type": "shell", | ||
"command": "npm run dev", | ||
"isBackground": true, | ||
"runOptions": { | ||
"instanceLimit": 1 | ||
}, | ||
"presentation": { | ||
"group": "watch" | ||
}, | ||
"problemMatcher": { | ||
"pattern": "$tsc", | ||
"background": { | ||
"activeOnStart": true, | ||
"beginsPattern": { | ||
"regexp": ".*Starting...", | ||
}, | ||
"endsPattern": { | ||
"regexp": ".*Ready in .*ms", | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
content/features/featuresDeepDive/importers/glTF/createExtensions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
title: Create glTF extensions | ||
image: | ||
description: Learn about creating new glTF loader extensions. | ||
keywords: diving deeper, import, importing assets, asset, glTF, extensions | ||
further-reading: ["https://babylonjs.medium.com/extending-the-gltf-loader-in-babylon-js-588e48fb692b"] | ||
video-overview: | ||
video-content: | ||
--- | ||
|
||
## Introduction | ||
|
||
The glTF format includes the concept of extensions. Usually glTF loader extensions map 1:1 with a corresponding glTF format extensions. However, it is possible to create custom glTF loader extensions are unrelated to glTF format extensions and simply perform some additional processing on the loaded glTF data. | ||
|
||
The glTF loader includes support for many glTF format extensions through built-in glTF loader extensions. It is also possible to create your own glTF loader extensions. | ||
|
||
## Extensions | ||
|
||
Extensions are defined by implementing the `IGLTFLoaderExtension` interface (from `@babylonjs/loaders/glTF/2.0`). An abbreviated example would look something like this: | ||
|
||
```typescript | ||
import { IGLTFLoaderExtension } from "@babylonjs/loaders/glTF/2.0"; | ||
|
||
class MyCustomExtension implements IGLTFLoaderExtension { | ||
public readonly name = "myCustomExtension"; | ||
public enabled = true; | ||
public order = 100; | ||
|
||
// Implement any of the optional functions, such as: | ||
public loadSceneAsync(): Nullable<Promise<void>> { | ||
// Modify the default behavior when loading scenes. | ||
} | ||
} | ||
``` | ||
|
||
## Extension Factories | ||
|
||
When you register a loader extension, you register an extension factory. The factory is a function that takes the glTF loader and returns an extension instance synchronously or asynchronously. This allows you to dynamically import your extension to avoid loading it until it is needed. A simple example might look something like this: | ||
|
||
```typescript | ||
import { registerGLTFExtension } from "@babylonjs/loaders/glTF/2.0"; | ||
|
||
registerGLTFExtension("myCustomExtension", true, async (loader) => { | ||
const { MyCustomExtension } = await import("./MyCustomExtension"); | ||
return new MyCustomExtension(loader); | ||
}); | ||
``` | ||
|
||
<Alert severity="info" title="glTF Format Extensions" description="The second parameter of registerGLTFExtension specifies whether the extension is associated with a glTF format extension. If it is, it will only be used when loading glTFs that use that extension. If it is not, it will be used when loading any glTF." /> | ||
|
||
## Extension Options | ||
|
||
To expose options for your custom glTF loader extension, you should first augment the `GLTFLoaderExtensionOptions` interface to add options for your extension. For example: | ||
|
||
```typescript | ||
type MyCustomExtensionOptions = { option1?: string, option2?: number }; | ||
|
||
declare module "@babylonjs/loaders" { | ||
export interface GLTFLoaderExtensionOptions { | ||
myCustomExtension: MyCustomImporterOptions; | ||
} | ||
} | ||
``` | ||
|
||
Then, when you register your extension, you can access the options like this: | ||
|
||
```typescript | ||
class MyCustomExtension implements IGLTFLoaderExtension { | ||
constructor (loader: GLTFLoader) { | ||
const options = loader.parent.extensionOptions["myCustomExtension"]; | ||
} | ||
} | ||
``` | ||
|
||
Finally, these options can be passed into one of the scene loader functions like this: | ||
|
||
```typescript | ||
await loadAssetContainerAsync("path/to/model", scene, { | ||
pluginOptions: { | ||
glTF: { | ||
extensionOptions: { | ||
myCustomExtension: { | ||
option1: "hello world", | ||
option2: 42, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.