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

海南房产网站开发网站页面优化签象客

海南房产网站开发,网站页面优化签象客,wordpress伪静态 page,wordpress插件查看这次讲一个经常遇到的使用场景#xff0c;让模型沿着轨迹运动#xff0c;这个场景需要解决两个问题#xff0c;第一是让模型沿着轨迹运动#xff0c;第二是在沿着轨迹运动的同时#xff0c;要保持模型的头部也时刻保持前方#xff0c;而不是单纯的只是更新模型位置。 还是…        这次讲一个经常遇到的使用场景让模型沿着轨迹运动这个场景需要解决两个问题第一是让模型沿着轨迹运动第二是在沿着轨迹运动的同时要保持模型的头部也时刻保持前方而不是单纯的只是更新模型位置。 还是先创建一个场景添加相机灯光渲染器等然后需要创建一个轨迹这里用CatmullRomCurve3创建一个3维曲线这个的好处是等会可以将此曲线拆解成多个同等份的点因为我们需要不断更新模型在此曲线的位置实际上就是不停的切换此曲线上连接的多个点来实现位置的不断更新。 首先根据四个点创建曲线并将曲线分解为多个点再用这些点绘制成一条曲线并加入到场景中方便后面观察模型的运动轨迹。 this.cameraCurve new THREE.CatmullRomCurve3([new THREE.Vector3(-300, 40, 200),new THREE.Vector3(300, 40, 200),new THREE.Vector3(300, 40, -200),new THREE.Vector3(-300, 40, -200),],true);//参考路径上取1000个点每个点上添加蓝色小球const pathPoints this.cameraCurve.getPoints(this.pathIndex);//绘制一条路径参考线与上面的线重合方便查看小车的行动轨迹const geometry new THREE.BufferGeometry().setFromPoints(pathPoints);const material new THREE.LineBasicMaterial({ color: #000000, linewidth: 1, });//设置线条的颜色和宽度const curveObject new THREE.Line(geometry, material);scene.add(curveObject); 此时场景中就出现一条曲线作为模型运动的轨迹 接着需要在场景中添加一个模型我这添加一个agv车更方便观察车的车头方向因为是外部模型需要加载GLTFLoader缩放到适合的大小并将车的位置放在曲线的第一个点位置防止在运动前突然闪现到开始运动的点开始运动。 //在场景中加载一个agv小车并将agv小车放在曲线的第一个点上const loader new GLTFLoader()loader.load(/static/model/agv.gltf, (gltf) {this.agv gltf.scene;this.agv.position.set(pathPoints[0].x, pathPoints[0].y, pathPoints[0].z) // 模型位置this.agv.scale.set(0.1,0.1,0.1)scene.add(this.agv) // 加入场景}) 曲线和车都加好了需要开始设置动画了也是最关键的部分运动的部分比较简单因为获取到了曲线的多个连续点只需要不断地更新车的位置到每个点就好了保持车头方向需要先获取车所在点向量的切线位置向量和切线向量相加即为所需朝向的点向量。 if (this.agv) {// 判断agv加载完成后开始不断更新agv的位置const sphereCurveIndex this.pathIndex / 1000; // //取相参考径上当前点的坐标取值0~1const positionVec this.cameraCurve.getPointAt(sphereCurveIndex);//获取曲线上位置的点传值为0-1的小数表示整个线段的位置this.agv.position.set( positionVec.x, positionVec.y, positionVec.z);//设置新的agv位置const tangent this.cameraCurve.getTangentAt(sphereCurveIndex); // 返回一个点t在曲线上位置向量的法线向量getTangentAt是返回曲线上某个点的切线const lookAtVec tangent.add(positionVec);// 位置向量和切线向量相加即为所需朝向的点向量this.agv.lookAt(lookAtVec);//设置agv的模型朝向为切线的方向} 完整的代码如下 templatedivdiv idcontainer/div/div /templatescript import * as THREE from three import {OrbitControls} from three/addons/controls/OrbitControls; import {GLTFLoader} from three/addons/loaders/GLTFLoader;let scene; export default {name: agv-single,data() {return{camera:null,cameraCurve:null,renderer:null,container:null,controls:null,pathIndex:1000,//小车的运动轨迹点索引agv:null}},methods:{initScene(){scene new THREE.Scene();},initCamera(){this.camera new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 10000);this.camera.position.set(500,500,500);},initLight(){//添加两个平行光const directionalLight1 new THREE.DirectionalLight(0xffffff, 1.5);directionalLight1.position.set(-300,-300,600)scene.add(directionalLight1);const directionalLight2 new THREE.DirectionalLight(0xffffff, 1.5);directionalLight2.position.set(600,200,600)scene.add(directionalLight2);},initRound(){//通过CatmullRomCurve3连接4个点绘制一条曲线且闭合this.cameraCurve new THREE.CatmullRomCurve3([new THREE.Vector3(-300, 40, 200),new THREE.Vector3(300, 40, 200),new THREE.Vector3(300, 40, -200),new THREE.Vector3(-300, 40, -200),],true);//参考路径上取1000个点每个点上添加蓝色小球const pathPoints this.cameraCurve.getPoints(this.pathIndex);//绘制一条路径参考线与上面的线重合方便查看小车的行动轨迹const geometry new THREE.BufferGeometry().setFromPoints(pathPoints);const material new THREE.LineBasicMaterial({ color: #000000, linewidth: 1, });//设置线条的颜色和宽度const curveObject new THREE.Line(geometry, material);scene.add(curveObject);//在场景中加载一个agv小车并将agv小车放在曲线的第一个点上const loader new GLTFLoader()loader.load(/static/model/agv.gltf, (gltf) {this.agv gltf.scene;this.agv.position.set(pathPoints[0].x, pathPoints[0].y, pathPoints[0].z) // 模型位置this.agv.scale.set(0.1,0.1,0.1)scene.add(this.agv) // 加入场景})},initRenderer(){this.renderer new THREE.WebGLRenderer({ antialias: true });this.container document.getElementById(container)this.renderer.setSize(this.container.clientWidth, this.container.clientHeight);this.renderer.setClearColor(#AAAAAA, 1.0);this.container.appendChild(this.renderer.domElement);},initControl(){this.controls new OrbitControls(this.camera, this.renderer.domElement);this.controls.enableDamping true;this.controls.maxPolarAngle Math.PI / 2.2; // // 最大角度},initAnimate() {//参考路径的索引在1001~0中往复减少以实现小车循环行驶if (this.pathIndex 0) {this.pathIndex 1001;}this.pathIndex - 1;if (this.agv) {// 判断agv加载完成后开始不断更新agv的位置const sphereCurveIndex this.pathIndex / 1000; // //取相参考径上当前点的坐标取值0~1const positionVec this.cameraCurve.getPointAt(sphereCurveIndex);//获取曲线上位置的点传值为0-1的小数表示整个线段的位置this.agv.position.set( positionVec.x, positionVec.y, positionVec.z);//设置新的agv位置const tangent this.cameraCurve.getTangentAt(sphereCurveIndex); // 返回一个点t在曲线上位置向量的法线向量getTangentAt是返回曲线上某个点的切线const lookAtVec tangent.add(positionVec);// 位置向量和切线向量相加即为所需朝向的点向量this.agv.lookAt(lookAtVec);//设置agv的模型朝向为切线的方向}requestAnimationFrame(this.initAnimate);this.renderer.render(scene, this.camera);},initPage(){this.initScene();this.initCamera();this.initLight();this.initRenderer();this.initControl();this.initRound();this.initAnimate();}},mounted() {this.initPage()} } /scriptstyle scoped #container{position: absolute;width:100%;height:100%;overflow: hidden; }/style效果如下 模型沿着曲线运动
http://www.pierceye.com/news/872705/

相关文章:

  • 虚拟电脑可以做网站吗中国建设行业信息网站
  • 网站设计建设合同公司网页设计实例教程
  • 仿起点小说网站开发网站图片优化工具
  • 在线做logo的网站泉州做网站哪家好
  • 知名企业网站人才招聘情况如何网络系统集成
  • 做灯带的网站重庆有哪些好玩的地方
  • 小孩子做手工做游戏的网站百度账号设置
  • 大庆做网站公司巩义网站建设方案报价
  • 该网站受海外服务器保护品牌营销型网站建设公司
  • 免费做一建或二建题目的网站郑州企业建站系统模板
  • 想自己建个网站徐州做网站软件
  • 蓝色系网站设计企业应对承包商的施工方案尤其是
  • 旅游网站 源码 织梦导购网站开发
  • 头像制作网站开源低代码平台
  • 网站到期域名怎么解决办法自己动手建立网站3
  • 比较有名的网站建设平台吉林建设网站
  • 网站服务器解决方案wamp安装wordpress
  • 义乌制作网站赣州网站建设公司
  • 东莞网站平台后缀建设淘宝客网站
  • 深圳龙华新区住房和建设局网站示范校建设专题网站
  • 成都制作网站的公司简介wordpress录入表单写数据库
  • 中山网站设计收费标准互联网保险发展现状和趋势
  • 公司网站发布流程简述企业网络建设的步骤
  • 哪些网站可以做问卷第1063章 自己做视频网站
  • 电子商务网站 费用做p2p网站
  • 网站建设 猴王网络厦门app开发网站开发公司电话
  • 做3d图的网站有哪些比wordpress更好的网站程序
  • 仿做网站可以整站下载器吧网络网站建设公司
  • 网站流量用完wordpress page 父页面
  • 旅游地网站制作有没有做网站的高手