【发布时间】:2019-08-08 22:46:20
【问题描述】:
我想使用threeJS,所以我使用npm i three --save 安装它。我按照threeJS文档中的基本教程进行操作,但出现错误。
mounted () {
this.initThree();
},
methods: {
initThree() {
this.scene = new THREE.Scene();
this.camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
this.renderer = new THREE.WebGLRenderer( { canvas: document.getElementById( "background" ), alpha: true, antialias: true } );
this.renderer.setSize( window.innerWidth, window.innerHeight );
let geometry = new THREE.BoxGeometry( 1, 1, 1 );
let material = new THREE.MeshBasicMaterial( { color: 0x0000ff } );
this.cube = new THREE.Mesh( geometry, material );
this.scene.add( this.cube );
this.camera.position.z = 5;
this.animate()
},
animate() {
this.cube.rotation.x += 0.01;
this.renderer.render( this.scene, this.camera );
requestAnimationFrame( this.animate() );
}
}
}
【问题讨论】:
-
我认为您需要在 main.js 中初始化三个。不在组件中。或许可以考虑github.com/fritx/vue-threejs
-
我初始化threejs没有问题,但是当我使用递归函数时。你的链接也许可以解决我的问题,我会试试的,谢谢
-
您在哪里以及如何导入/声明您的三个模块?