书接上回,这一节我们分模块说一说怎么写一个这样的游戏
1. 初始化场景、相机和渲染器这几乎是绘制three必须做的事情,我们有两套场景和相机,一个是主场景和相机,另一个是小地图的场景和相机(用来俯视建筑和小汽车),渲染器设置一级曝光,输出编码设置为sRGBEncoding,代码如下。
scene = new THREE.Scene(); scene.background = new THREE.Color(0x8FBCD4); scene.fog = new THREE.Fog(0x8FBCD4, 3000, 4000); camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 0.1, 10000); camera.position.set(10,10,10); scene2 = new THREE.Scene(); scene2.background = new THREE.Color(0xffffff); camera2 = new THREE.OrthographicCamera(-400, 400, 400, -400, 1, 1000); camera2.position.set(0, 1000, 0); camera2.lookAt(0,0,0); renderer = new THREE.WebGLRenderer({antialias: true}); renderer.setPixelRatio(window.devicePixelRatio); renderer.setSize(window.innerWidth, window.innerHeight); renderer.outputEncoding = THREE.sRGBEncoding; renderer.toneMapping = THREE.ACESFilmicToneMapping; renderer.toneMappingExposure = 1; this.$refs.box.appendChild(renderer.domElement);