当前位置: 首页 > news >正文

three.js跟着教程实现VR效果(四)

参照教程:https://juejin.cn/post/6973865268426571784(作者:大帅老猿)

1.WebGD3D引擎 用three.js
(1)使用立方体6面图 camera放到 立方体的中间 like “回” 让贴图向内翻转
(2)使用球体(sphere)实现 需要一张全景图片 贴到球体上 其他同上 “回” 反贴 进入球体

2.css3D 更轻量的3D引擎 css3d-engine 只有14kb 用div+css来搭建3维场景 比较容易添加信息点(标签点击事件那种)

3.图片信息点多 高清图 不占地儿的解决方案 pano2vr
要花钱买 是一个所见即所得的全景VR制作软件 可以直接输出HTML5静态网页

按照大佬的教程 我实现的效果
在这里插入图片描述
在这里插入图片描述

import * as THREE from '../../build/three.module.js';window.THREE = THREE;import {OrbitControls} from 'https://threejsfundamentals.org/threejs/resources/threejs/r122/examples/jsm/controls/OrbitControls.js';// 1. 创建渲染器,指定渲染的分辨率和尺寸,然后添加到body中const renderer = new THREE.WebGLRenderer({ antialias: true });renderer.pixelRatio = window.devicePixelRatio;renderer.setSize(window.innerWidth, window.innerHeight);document.body.append(renderer.domElement);// 2. 创建场景const scene = new THREE.Scene();// 3. 创建相机const camera = new THREE.PerspectiveCamera(75,window.innerWidth / window.innerHeight,0.1,1000);camera.position.set(5, 5, 10);camera.lookAt(0, 0, 0);const ambientLight = new THREE.AmbientLight(0xffffff, 0.4);scene.add(ambientLight);const directionalLight = new THREE.DirectionalLight(0xffffff, 1);directionalLight.position.set(10, 10, 10)scene.add(directionalLight);const textloader = new THREE.TextureLoader();var texture = textloader.load('./images/scene.jpg');var sphereMaterial = new THREE.MeshBasicMaterial({map: texture});var sphereGeometry = new THREE.SphereGeometry(/*半径*/1, 50, 50);sphereGeometry.scale(1, 1, -1);var sphere = new THREE.Mesh(sphereGeometry,sphereMaterial);// sphere.material.wireframe  = true;scene.add(sphere);const controls = new OrbitControls(camera, renderer.domElement);controls.update();const clock = new THREE.Clock();function animate() {requestAnimationFrame(animate);const elapsedTime = clock.getElapsedTime(); // 返回已经过去的时间, 以秒为单位sphere.rotation.y = elapsedTime * 0.1; // 两秒自转一圈renderer.render(scene, camera);}animate() 

图片素材
在这里插入图片描述

http://www.lryc.cn/news/337111.html

相关文章:

  • AI预测体彩排3第1弹【2024年4月12日预测--第1套算法开始计算第1次测试】
  • spring 中的控制反转
  • GO并发总是更快吗?
  • echarts折线图自定义打点标记小工具
  • 【图论】Leetcode 200. 岛屿数量【中等】
  • 酒店大厅装水离子雾化壁炉前和装后对比
  • 城市内涝与海绵城市规划设计中的水文水动力模拟
  • C++项目实战与经验分享
  • Day17_学点JavaEE_转发、重定向、Get、POST、乱码问题总结
  • Mouse IFN-α ELISA kit (Quick Test)
  • AMD Tensile 简介与示例
  • Rust语言
  • 排序算法之冒泡排序
  • js打印页面源码 ,打印选取的容器里的内容,打印指定内容
  • 算法练习第五十天|123.买卖股票的最佳时机III、188.买卖股票的最佳时机IV
  • 细胞世界:4.细胞分化(划区域)与细胞衰老(设施磨损)
  • c语言:操作符
  • 谷歌seo自然搜索排名怎么提升快?
  • Golang | Leetcode Golang题解之第13题罗马数字转整数
  • 说说我理解的数据库中的Schema吧
  • nginx 如何对用户屏蔽网站首页但是对蜘蛛开放
  • 【vue】ref 和 reactive 对比
  • 爬虫现在还有那么吃香嘛?
  • MobaXterm无法登陆oracle cloud的问题
  • VLL: a lock manager redesign for main memory database systems阅读
  • REST API实战演练之JavaScript使用Rest API
  • 期货量化交易软件:MQL5 中的范畴论 (第 15 部分)函子与图论
  • 2024妈妈杯数学建模B题思路-甲骨文智能识别中原始拓片单字自动分割与识别研究
  • sql 之 索引
  • 创建基于Node的WebSocket服务