animation1() {
this.mesh.position.x-=1;
this.camera.position.x = this.camera.position.x + 1;
this.renderer.render(this.scene, this.camera);
requestAnimationFrame(this.animation1);
}
此时会报错mesh的undefined
animation1() {
this.mesh.position.x-=1;
this.camera.position.x = this.camera.position.x + 1;
this.renderer.render(this.scene, this.camera);
requestAnimationFrame(this.animation1);
}
此时会报错mesh的undefined
参考GPT和自己的思路:
根据您提供的代码,出现undefined的可能原因是您没有正确地初始化mesh对象,导致在调用animation1()方法时访问mesh的属性时会报错。
请确保在调用animation1()方法之前,已经正确地实例化和初始化了mesh对象。如果您已经实例化了mesh对象,但仍然出现undefined错误,请检查您的代码逻辑和调用顺序是否正确。建议您在调用animation1()方法之前,先进行一些简单的测试,以确保mesh对象已经正确地被初始化。
同时,由于requestAnimationFrame方法在ngOnInit外部调用,也可能会影响代码的执行顺序,建议您在ngOnInit方法中调用animation1()方法,并且在该方法中正确地初始化mesh对象。