Im trying to import the GLTFLoader into my existing angular project. I tried several plugins, i.e. thisplugin but none did work. I read and tested all stackoverflow threads i found… nothings works. Now updating my project to 102, i found the jsm folder in examples. Im including it like this:
import * as THREE from 'three'
import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader'
this.gltfLoader = new GLTFLoader(this.loadingManager)
this.gltfLoader.load(path, (model)=> {
this.models.push({
path: path,
model: model.scene,
texturePath: texturePath
})
if(this.models.length > 1)
this.models = Utility.removeDuplicates(this.models)
let clone = model.scene.clone()
onLoad(clone)
}, undefined, (error)=> {
console.error('Error',error)
})
Throwing this Error when loading:
THREE is not defined
modelmanager.ts:164 Error ReferenceError: THREE is not defined at GLTFLoader.js:2715 at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388) at Object.onInvoke (core.js:16963) at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387) at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138) at zone.js:872 at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:16954) at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420) at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
What else can I provide? Please I really need to get this to work. This is frustrating me for days now. Thanks in advance
Hey already tested it, but its also throwing an error saying GLTFLoader is not a constructor.
I also tried GLTF2Loader (three-gltf2-loader on npm) but basicly getting the same error
Hi @Fluqz, I’m having the same issue where I can’t seem to access the GLTFLoader. I’m a bit confused what I’m supposed to do - I have my imports like so:
import * as THREE from 'three';
import 'three/examples/js/loaders/GLTFLoader';
If you’re using typescript you need the modulized GLTFLoader from examples/jsm/GLTFLoader.js, which doesnt work in r102 yet. But there is a dev version for r103 which works. Just replace the code of the GLTFLoader.js with it.
I don’t think this has something to do with TypeScript. You always have to use the GLTFLoader in the jsm directory if you want to import it as a module.
@8Observer8 this thread is about ES Modules. If you need help with the older AMD/Require.js import system, I think you’ll need to create a new thread and provide details for reproducing the problem.