首先,不再?gòu)U話了,什么是three.js,是干什么的,知道的就是知道,不知道的就百度吧。
小編為大家推薦一篇:Three.js快速入門教程
昨兒發(fā)現(xiàn)three.js中的3D視野的縮小和放大效果可以用照相機(jī)的遠(yuǎn)近焦來(lái)實(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(); }
Copyright ? 2019- 91gzw.com 版權(quán)所有 湘ICP備2023023988號(hào)-2
違法及侵權(quán)請(qǐng)聯(lián)系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市萬(wàn)商天勤律師事務(wù)所王興未律師提供法律服務(wù)