常春岛资源网 Design By www.syssdc.com
粗暴一点,直接上代码:
第一步:
通过指令下载three.js
npm install three -S
第二步:
在组件中引用
import * as THREE from 'three'
第三步:
html部分
<div id="container"></div>
js部分
<script> import * as THREE from 'three'; var camera; var renderer; var scene; export default { name: 'panorama', data() { return { bigImg: require("../../../../../images/项目案例/001.jpg"),//全景图图片路径 } }, mounted() { // 调用全景图函数 this.$nextTick(() => { this.init(); this.animate(); }) }, methods: { // 全景图配置函数--------------- init() { var container = document.getElementById('container'); // 创建渲染器 renderer = new THREE.WebGLRenderer(); renderer.setPixelRatio(window.devicePixelRatio); // 设置画布的宽高 renderer.setSize(window.innerWidth, window.innerHeight); // 判断容器中子元素的长度 let childs = container.childNodes; if (container.childNodes.length > 0) { container.removeChild(childs[0]); container.appendChild(renderer.domElement); } else { container.appendChild(renderer.domElement); } // container.appendChild(renderer.domElement); // 创建场景 scene = new THREE.Scene(); // 创建相机 camera = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight, 0.1, 100); camera.position.set(0, 0, 0); var material = new THREE.MeshBasicMaterial();//材质 var texture = new THREE.TextureLoader().load(this.bigImg); material.map = texture; var skyBox = new THREE.Mesh( new THREE.SphereBufferGeometry(100, 100, 100), material ); skyBox.geometry.scale(1, 1, -1); scene.add(skyBox); window.addEventListener('resize', this.onWindowResize, false); var bMouseDown = false; var x = -1; var y = -1; // 添加鼠标事件 container.onmousedown = function (event) { event.preventDefault();//取消默认事件 x = event.clientX; y = event.clientY; bMouseDown = true; } container.onmouseup = function (event) { event.preventDefault(); bMouseDown = false; } container.onmousemove = function (event) { event.preventDefault(); if (bMouseDown) { skyBox.rotation.y += -0.005 * (event.clientX - x); skyBox.rotation.x += -0.005 * (event.clientY - y); if (skyBox.rotation.x > Math.PI / 2) { skyBox.rotation.x = Math.PI / 2 } if (skyBox.rotation.x < -Math.PI / 2) { skyBox.rotation.x = -Math.PI / 2 } x = event.clientX; y = event.clientY; } } container.onmousewheel = function (event) { event.preventDefault(); if (event.wheelDelta != 0) { camera.fov += event.wheelDelta > 0 ? 1 : -1; if (camera.fov > 150) { camera.fov = 150; } else if (camera.fov < 30) { camera.fov = 30; } camera.updateProjectionMatrix(); } } }, onWindowResize() { // 窗口缩放的时候,保证场景也跟着一起缩放 camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); }, animate() { requestAnimationFrame(this.animate); renderer.render(scene, camera); } }, } </script>
标签:
three.js实现全景图
常春岛资源网 Design By www.syssdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
常春岛资源网 Design By www.syssdc.com
暂无评论...
更新日志
2024年06月03日
2024年06月03日
- 罗斯特洛波维奇、布里顿《舒伯特-阿佩乔尼奏鸣曲》1995[WAV+CUE]
- 群星《超高品质流行女声大碟 静听女人心 2CD》[WAV+CUE][1.3GB]
- BEYOND《无悔这一生 2023》 [WAV+CUE][690MB]
- 群星《30首最发烧经典老歌 情牵男人心 2CD》[WAV+CUE][1.4GB]
- 群星《不老的情歌-至尊版2CD》WAV分轨
- 岁月留声机群星《七十年代人金曲回顾》(黑胶)2CD[WAV分轨]
- 群星-世纪难忘金曲(迪安唱片)5CD[WAV]
- HenrietteFaure-DebussyEstampesPrludes,LivreI(MonoVersion)[FLAC]
- 吕方1992-弯弯十八首[香港][WAV+CUE]
- 经典歌曲珍藏专辑《民歌30年·真情依旧》3CD[WAV+CUE]
- 群星《时尚流行发烧极品 非同凡响 第一辑 2CD》[WAV/分轨][1.3GB]
- 陈曦《多年以后》HQⅡ头版限量编号[WAV+CUE][520MB]
- 孙露《用情 HQⅡ 2023》[WAV+CUE][380MB]
- 电影原声《速度与激情9电影原声大碟》2021[WAV+CUE]
- 【瑞鸣音乐】群星《伶歌》[XRCD2][WAV+CUE]