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

three.js中加载ply格式的文件,并使用tween.js插件按照json姿态文件运动

先贴一下文件地址:

aa.ply 文件: https://download.csdn.net/download/yinge0508/89595650?spm=1001.2014.3001.5501

 new.json

https://download.csdn.net/download/yinge0508/89595641?spm=1001.2014.3001.5501

代码:

<template><div><el-container><el-main><div class="box-card-left"><div id="threejs"></div><button @click="iterateArray" style="position:fixed;top:0;right:0;">开始动画</button></div></el-main></el-container></div>
</template>s
<script>
// 引入轨道控制器扩展库OrbitControls.js
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
import { PLYLoader } from "three/examples/jsm/loaders/PLYLoader.js";
import TWEEN from "@tweenjs/tween.js";
import jsonData from "@/assets/new.json";
export default {data() {return {scene: null,mesh: null,camera: null,renderer: null,res1: null,res2: null,index: 0,};},created() {},mounted() {this.name = this.$route.query.name;this.init();},methods: {goBack() {this.$router.go(-1);},init() {// 场景this.scene = new this.$three.Scene();const spotLight = new this.$three.AmbientLight(0xffffff, 10);this.scene.add(spotLight);const spotLight1 = new this.$three.SpotLight(0xffffff, 1);// 设置聚光源位置spotLight1.position.set(1000, 1000, 1000);// 设置聚光源指向的目标位置this.scene.add(spotLight1);const axesHelper = new this.$three.AxesHelper(1000);this.scene.add(axesHelper);const material = new this.$three.MeshBasicMaterial({color: 0x00aadd,side: this.$three.DoubleSide,});// 相机this.camera = new this.$three.PerspectiveCamera(60, 1, 0.01, 2000);this.camera.position.set(1000, 1000, 1000);this.camera.lookAt(0, 0, 0);const loader = new PLYLoader();loader.load("/models/aa.ply", // URL of the PLY file(object) => {// 4, 创建网格模型对象this.mesh = new this.$three.Mesh(object, material);this.scene.add(this.mesh);this.renderer.render(this.scene, this.camera);// Called when the loading is completed},(xhr) => {// Optional progress callbackconsole.log((xhr.loaded / xhr.total) * 100 + "% loaded");},(error) => {// Optional error callbackconsole.error("An error happened", error);});this.renderer = new this.$three.WebGLRenderer();// this.renderer.setClearColor(0xffffff, 0.4); //设置背景颜色和透明度this.renderer.setSize(2000, 1200);this.renderer.render(this.scene, this.camera);window.document.getElementById("threejs").appendChild(this.renderer.domElement);// 渲染场景this.render();// 建相机空间轨道控制器对象const controls = new OrbitControls(this.camera, this.renderer.domElement);controls.addEventListener("change", () => {this.renderer.render(this.scene, this.camera);});},render() {// requestAnimationFrame(this.render);this.renderer.render(this.scene, this.camera);},// 假设这是你的数组// 这是你想要执行的方法processItem(item, index, callback) {setTimeout(() => {callback(); // 当方法执行完毕后调用回调函数}, 2000);
},// 开始遍历数组iterateArray() {this.next(); // 开始遍历
},
next() {if (this.index < jsonData.length) {const item = jsonData[this.index];this.processItem(item, this.index, () => {this.start();this.index++; // 更新索引this.next(); // 继续遍历});} else {console.log('All items processed.');}},start() {if (jsonData) {this.loop();if (this.index >= jsonData.length) {return;}let ele1 = JSON.parse(JSON.stringify(jsonData[this.index]));let ele = ele1[0].concat(ele1[1]).concat(ele1[2]).concat(ele1[3]);const mat4 = new this.$three.Matrix4();mat4.elements = ele;const tween0 = new TWEEN.Tween(this.camera.position);let new_p = JSON.parse(JSON.stringify(this.camera.position));const p = new this.$three.Vector3(new_p.x, new_p.y, new_p.z);p.applyMatrix4(mat4);tween0.to({x: p.x, y: p.y, z: p.z}, 2000).easing(TWEEN.Easing.Quadratic.Out);tween0.start()}},loop() {TWEEN.update();this.renderer.render(this.scene, this.camera);window.requestAnimationFrame(this.loop);},},
};
</script>
<style lang="less" scoped>
.box-card-left {display: flex;align-items: flex-start;flex-direction: row;width: 100%;.box-right {img {width: 500px;user-select: none;}}
}
</style>

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • vue项目上线打包后出现的问题
  • 实战之oss附件批量下载---springboot 实现压缩阿里云oss附件并下载
  • shapeit填充
  • 免费好用的 CI/CD 工具有哪些?
  • C++ //练习 16.6 你认为接受一个数组实参的标准库函数begin和end是如何工作的?定义你自己版本的begin和end。
  • CSP:内容安全策略的前端深入解析
  • SeaCMS海洋影视管理系统远程代码执行漏洞复现
  • 经典文献阅读之--GraphAD(端到端自动驾驶的交互场景图)
  • 【笔记:3D航路规划算法】二、RRT*
  • UnityShaderUI编辑器扩展
  • 手撕数据结构---栈和队列的概念以及实现
  • go语言怎么实现dataauth?
  • “八股文”在实际工作中是助力、阻力还是空谈?
  • c程序杂谈系列(职责链模式与if_else)
  • Spring中使用到的设计模式及其源码分析
  • css的样式优先级
  • Javascripit类型转换比较那点事儿,双等号(==)
  • Java比较器对数组,集合排序
  • Transformer-XL: Unleashing the Potential of Attention Models
  • vue-router的history模式发布配置
  • Vue组件定义
  • 对象管理器(defineProperty)学习笔记
  • 关于Android中设置闹钟的相对比较完善的解决方案
  • ------- 计算机网络基础
  • 精益 React 学习指南 (Lean React)- 1.5 React 与 DOM
  • 前端相关框架总和
  • 微信端页面使用-webkit-box和绝对定位时,元素上移的问题
  • 一道闭包题引发的思考
  • 看到一个关于网页设计的文章分享过来!大家看看!
  • ​一、什么是射频识别?二、射频识别系统组成及工作原理三、射频识别系统分类四、RFID与物联网​
  • # Redis 入门到精通(八)-- 服务器配置-redis.conf配置与高级数据类型
  • #70结构体案例1(导师,学生,成绩)
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • (03)光刻——半导体电路的绘制
  • (35)远程识别(又称无人机识别)(二)
  • (论文阅读40-45)图像描述1
  • (转)C#调用WebService 基础
  • .net core Swagger 过滤部分Api
  • .NET Core 发展历程和版本迭代
  • .net core开源商城系统源码,支持可视化布局小程序
  • .Net Memory Profiler的使用举例
  • .NET 通过系统影子账户实现权限维持
  • .NET6 命令行启动及发布单个Exe文件
  • .NET技术成长路线架构图
  • .Net转Java自学之路—SpringMVC框架篇六(异常处理)
  • @JoinTable会自动删除关联表的数据
  • [000-01-030].Zookeeper学习大纲
  • [2024] 十大免费电脑数据恢复软件——轻松恢复电脑上已删除文件
  • [AutoSAR系列] 1.3 AutoSar 架构
  • [AX]AX2012 R2 出差申请和支出报告
  • [BZOJ1178][Apio2009]CONVENTION会议中心
  • [C++]: std::move
  • [C++]priority_queue的介绍及模拟实现
  • [C++]STL之map
  • [Day 63] 區塊鏈與人工智能的聯動應用:理論、技術與實踐