GLTFLoader.js includes three.js via an import-statement:
import {
AnimationClip,
...
} from 'three';
This import causes webpack to load the three.js library a second time. As a consequence, the Mesh instances created by the GLTFLoader fail type checking when I try to use them, e.g. val obj = entry as Mesh, which is compiled to var obj = Kotlin.isType(tmp$ = entry, Mesh) ? tmp$ : throwCCE(); throws an IllegalCast exception.
How can I configure my project so GLTFLoader.js does not load three.js a second time?
By the way, do you use some kind of wrapper for three-js? I use a slightly modified version of that was formerly maintained by @laht90. But if there are several users, it is better to have a commonly maintained wrapper.
The package.json of three.js tells webpack to use three.cjs when the request is issued from CommonJs/AMD syntax or similar resp. three.module.js when the request is issued from ESM syntax or similar:
By the way, do you use some kind of wrapper for three-js?
I use my own handcrafted wrapper.
I also self made a wrapper for Cannon.JS. Let me know, if you’re interested in that one.
Apart from that, I only have some 500 lines of generic three-js related Kotlin code
(which is an indication of the high degree of completeness of three-js IMHO),
including syntactic sugar like
operator fun Vector3.plusAssign(v: Vector3) {
this.add(v)
}
inline infix fun Vector3.apply(quaternion: Quaternion) = applyQuaternion(quaternion)
operator fun Array<Object3D>.get(name: String) = firstOrNull { it.name == name }
val Object3D.geometry
get() = when (this) {
is Mesh -> geometry
is Line -> geometry
is Sprite -> geometry
else -> null
}