首先,不再廢話了,什么是three.js,是干什么的,知道的就是知道,不知道的就百度吧。
小編為大家推薦一篇:Three.js快速入門教程
昨兒發(fā)現(xiàn)three.js中的3D視野的縮小和放大效果可以用照相機(jī)的遠(yuǎn)近焦來實(shí)現(xiàn)。

縮小后:

這里采用的是透視照相機(jī):
//照相機(jī)配置 var fov = 40;//拍攝距離 var near = 1;//最小范圍 var far = 1000;//最大范圍 var camera = new THREE.PerspectiveCamera(fov, window.innerWidth / window.innerHeight, near, far);
在這里可以改變fov的值,并更新這個(gè)照相機(jī)就可以了。
camera.fov = fov;//fov是變量哦 camera.updateProjectionMatrix();renderer.render(scene, camera);
另外:咱們都是習(xí)慣用鼠標(biāo)上下滑輪實(shí)現(xiàn)放大縮小效果,so看代碼
canvas.addEventListener('mousewheel', mousewheel, false); //鼠標(biāo)滑輪 function mousewheel(e) { e.preventDefault(); //e.stopPropagation(); if (e.wheelDelta) { //判斷瀏覽器IE,谷歌滑輪事件 if (e.wheelDelta > 0) { //當(dāng)滑輪向上滾動(dòng)時(shí) fov -= (near < fov ? 1 : 0); } if (e.wheelDelta < 0) { //當(dāng)滑輪向下滾動(dòng)時(shí) fov += (fov < far ? 1 : 0); } } else if (e.detail) { //Firefox滑輪事件 if (e.detail > 0) { //當(dāng)滑輪向上滾動(dòng)時(shí) fov -= 1; } if (e.detail < 0) { //當(dāng)滑輪向下滾動(dòng)時(shí) fov += 1; } } camera.fov = fov; camera.updateProjectionMatrix(); renderer.render(scene, camera); //updateinfo(); }以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注