请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

background没有显示

6.20 之前的章节,能够正常运行。
所有参数设置都是按照老师给的数值设置的。
但是在background这里碰到了点问题。
现在往 cameraInstance.add(backgroundInstance), 没有反应展示background,也有没有报错。
老师能帮忙看看吗。

正在回答 回答被采纳积分+3

插入代码

3回答

郭小新 2021-02-10 17:34:50

看看是不是没有把相机添加到场景中
https://img1.sycdn.imooc.com/szimg/6023a88509cf50ee10020272.jpg

1 回复 有任何疑惑可以回复我~
郭小新 2021-02-10 17:14:05

同不显示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// background.js
// 背景
import sceneConf from '../confs/scene-conf';
 
class Background {
constructor() {}
 
init() {
const geometry = new THREE.PlaneGeometry(sceneConf.frustumSize * 2, window.innerHeight / window.innerWidth * sceneConf.frustumSize * 2);
const material = new THREE.MeshBasicMaterial({
color: 0xd7dbe6,
opacity: 1,
transparent: true
});
 
this.instance = new THREE.Mesh(geometry, material);
}
}
 
export default new Background();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// scene.js
import camera from './camera';
import light from './light';
import background from '../objects/background';
 
class Scene {
constructor() {}
 
init() {
this.instance = new THREE.Scene();
this.camera = camera;
this.camera.init();
this.renderer = new THREE.WebGLRenderer({
canvas: canvas,
antialias: true// 抗锯齿
});
 
const axesHelper = new THREE.AxesHelper( 100 );
this.instance.add( axesHelper );
 
this.renderer.setClearColor(new THREE.Color(0x000000));
// this.renderer.setSize(400, 400);
 
// 加入光照
this.light = light;
this.light.init();
this.instance.add( this.light.instance.ambientLight );
this.instance.add( this.light.instance.directionLight );
this.instance.add( this.light.instance.shadowTarget );
 
// 加入背景,因为是正对相机,所以添加到相机坐标系下
this.background = background;
this.background.init();
this.background.instance.position.z = 0;
this.camera.instance.add( this.background.instance );
}
 
render() {
this.renderer.render(this.instance, this.camera.instance);
}
}
 
export default new Scene();


1 回复 有任何疑惑可以回复我~
千迦 2019-12-02 06:41:47

代码发来看看呢

1 回复 有任何疑惑可以回复我~

相似问题

登录后可查看更多问答,登录/注册

问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号