|
|
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader' |
|
|
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader' |
|
|
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js' |
|
|
import * as THREE from 'three' |
|
|
|
|
|
const fbxLoader = new FBXLoader() |
|
|
export async function LoadFBXFile( |
|
|
url: string, |
|
|
onLoading?: (loaded: number) => void |
|
|
): Promise<THREE.Group> { |
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
fbxLoader.load( |
|
|
|
|
|
url, |
|
|
|
|
|
function (object) { |
|
|
resolve(object) |
|
|
}, |
|
|
|
|
|
function (xhr) { |
|
|
console.log((xhr.loaded / xhr.total) * 100 + '% loaded') |
|
|
onLoading?.((xhr.loaded / xhr.total) * 100) |
|
|
}, |
|
|
|
|
|
function (error) { |
|
|
console.log('An error happened') |
|
|
reject(error) |
|
|
} |
|
|
) |
|
|
}) |
|
|
} |
|
|
|
|
|
|
|
|
const loader = new OBJLoader() |
|
|
|
|
|
export async function LoadObjFile(url: string): Promise<THREE.Group> { |
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
loader.load( |
|
|
|
|
|
url, |
|
|
|
|
|
function (object) { |
|
|
resolve(object) |
|
|
}, |
|
|
|
|
|
function (xhr) { |
|
|
console.log((xhr.loaded / xhr.total) * 100 + '% loaded') |
|
|
}, |
|
|
|
|
|
function (error) { |
|
|
console.log('An error happened') |
|
|
reject(error) |
|
|
} |
|
|
) |
|
|
}) |
|
|
} |
|
|
|
|
|
export async function LoadGLTFile(url: string): Promise<GLTF> { |
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
new GLTFLoader().load( |
|
|
|
|
|
url, |
|
|
|
|
|
function (object) { |
|
|
resolve(object) |
|
|
}, |
|
|
|
|
|
function (xhr) { |
|
|
console.log((xhr.loaded / xhr.total) * 100 + '% loaded') |
|
|
}, |
|
|
|
|
|
function (error) { |
|
|
console.log('An error happened') |
|
|
reject(error) |
|
|
} |
|
|
) |
|
|
}) |
|
|
} |
|
|
|