【发布时间】:2022-06-10 17:45:18
【问题描述】:
我还是 Threejs 的新手...
我想将我的一些 threejs 代码放在另一个 JS 文件中,然后在我的 main.js 文件中使用它
这是一个简单的类似代码:
在main.js
import * as THREE from 'three'
import Player from './classes/player.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;
但我收到此错误:THREE.Object3D.add: object not an instance of THREE.Object3D.
【问题讨论】:
标签: javascript three.js webgl