|
@@ -3,7 +3,19 @@ import { useLoader } from '@tresjs/core'
|
|
|
import { Object3D } from 'three'
|
|
|
|
|
|
export interface GLTFLoaderOptions {
|
|
|
+ /**
|
|
|
+ * Whether to use Draco compression.
|
|
|
+ *
|
|
|
+ * @type {boolean}
|
|
|
+ * @memberof GLTFLoaderOptions
|
|
|
+ */
|
|
|
draco?: boolean
|
|
|
+ /**
|
|
|
+ * The path to the Draco decoder.
|
|
|
+ *
|
|
|
+ * @type {string}
|
|
|
+ * @memberof GLTFLoaderOptions
|
|
|
+ */
|
|
|
decoderPath?: string
|
|
|
}
|
|
|
|
|
@@ -16,6 +28,13 @@ export interface GLTFResult {
|
|
|
|
|
|
let dracoLoader: DRACOLoader | null = null
|
|
|
|
|
|
+/**
|
|
|
+ * Sets the extensions for the GLTFLoader.
|
|
|
+ *
|
|
|
+ * @param {GLTFLoaderOptions} options
|
|
|
+ * @param {(loader: GLTFLoader) => void} [extendLoader]
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
function setExtensions(options: GLTFLoaderOptions, extendLoader?: (loader: GLTFLoader) => void) {
|
|
|
return (loader: GLTFLoader) => {
|
|
|
if (extendLoader) {
|
|
@@ -30,6 +49,18 @@ function setExtensions(options: GLTFLoaderOptions, extendLoader?: (loader: GLTFL
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Loads a GLTF file and returns a THREE.Object3D.
|
|
|
+ *
|
|
|
+ * @export
|
|
|
+ * @param {(string | string[])} path
|
|
|
+ * @param {GLTFLoaderOptions} [options={
|
|
|
+ * draco: false,
|
|
|
+ * }]
|
|
|
+ * @param {(loader: GLTFLoader) => void} [extendLoader]
|
|
|
+ * @return {*} {Promise<GLTFResult>}
|
|
|
+ */
|
|
|
export async function useGLTF(
|
|
|
path: string | string[],
|
|
|
options: GLTFLoaderOptions = {
|