Reputation: 767
I am trying to import an STL file to Three.js, but the three-stl-loader
npm-module does not find the THREE
object.
This code:
import * as THREE from 'three'
import * as THREESTLLoader from 'three-stl-loader'
var STLLoader = new THREESTLLoader()
var loader = new STLLoader(THREE)
loader.load('path/to/file.stl', function (geometry: any) {})
On line 45 in index.js (in the stl-loader), the three-stl-loader
module makes use of the THREE
object, but it seems like the module does not know about the THREE
object at all:
The project is compiled with TypeScript in Webpack. I think there may be a problem with the way it is compiled.
Upvotes: 1
Views: 1841
Reputation: 767
Seems like i found the missing part.
As the module, and not the constructor, has to receive the THREE
object, I only needed to add THREE
to the module instead:
import * as THREE from 'three'
import * as THREESTLLoader from 'three-stl-loader'
var STLLoader = new THREESTLLoader(THREE) // Added THREE
var loader = new STLLoader() // Removed THREE
loader.load('path/to/file.stl', function (geometry: any) {})
Upvotes: 2