I'm fairly new to Threejs and I am trying to organize my code by putting some of my threejs code in a separate JS file and then using it in my main.js file. Here is a simplified version of what I am trying to do:
main.js
import * as THREE from 'three'
import Box from './classes/Parts.js'
const box = new Box()
scene.add(box)
Parts.js
class Box {
constructor() {
this.geom = new THREE.BoxGeometry(2, 2, 2);
this.mat = new THREE.MeshBasicMaterial({
color: 0xff0000
});
this.mesh = new THREE.Mesh(this.geom, this.mat);
}
}
export default Box;
However, I am encountering the following error:
THREE.Object3D.add: object not an instance of THREE.Object3D.
What am I doing wrong here?