three.js实现管道漫游

news2024/9/22 17:17:40

先看效果:

<template>
  <div>
    <el-container>
      <el-main>
        <div class="box-card-left">
          <div id="threejs" style="border: 1px solid red"></div>
          <div class="box-right">
            <pre style="font-size: 16px"></pre>
            <el-button type="primary" @click="start">开始漫游</el-button>
            <el-button type="primary" @click="end">结束漫游</el-button>
          </div>
        </div>
      </el-main>
    </el-container>
  </div>
</template>
<script>
import Drawer from "@/components/Drawer.vue";
// 引入轨道控制器扩展库OrbitControls.js
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";

export default {
  components: { Drawer },
  data() {
    return {
      name: "",
      cameraX: 200,
      cameraY: 200,
      cameraZ: 200,
      scene: null,
      camera: null,
      renderer: null,
      mesh: null,
      mesh_sun: null,
      geometry: null,
      group: null,
      axis: null,
      texture: null,
      loader: null,
      animationId: null,
      line: null,
      lineFlag: true,
      circleFlag: true,
      catmullRowCurve3: null,
      controls: null,
      request: null,
      r: 300,
      angle: 0,
      i: 0,
      points:[]
    };
  },
  created() {},
  mounted() {
    this.name = this.$route.query.name;
    this.init();
  },
  methods: {
    end(){
      window.cancelAnimationFrame(this.request)
    },
    goBack() {
      this.$router.go(-1);
    },
    start() {
      this.points = this.catmullRowCurve3.getPoints(220);
      this.render();
    },
    render() {
      if(this.i < this.points.length-1) {
        this.camera.position.copy(this.points[this.i]);
        this.camera.lookAt(this.points[this.i+1]);
        this.camera.updateProjectionMatrix();
        this.controls.target.copy(this.points[this.i+1]);
        this.controls.update();
        this.i++;
      } else {
        this.i = 0;
      }
      this.renderer.render(this.scene, this.camera);
      this.request = requestAnimationFrame(this.render);
    },
    // 管道漫游案例:首先创建一个管道;管道使用纹理贴图;获取管道的扫描线上的 n个点;相机固定在 i 点, lookAt i+1 点位置;
    init() {
      // 1,创建场景对象
      this.scene = new this.$three.Scene();
      // 创建缓存几何体对象
      this.geomery = new this.$three.BufferGeometry();
      // 通过 Vector3(x,y,z) 创建顶点数据
      var pointsArr = [
        new this.$three.Vector3(0, 0, 0),
        new this.$three.Vector3(100, 0, 0),
        new this.$three.Vector3(100, 0, 100),
        new this.$three.Vector3(0, 100, 100),
        new this.$three.Vector3(-50, 50, 50),
        new this.$three.Vector3(0, 0, 0),
      ];
      // 创建三维样条曲线对象(参数是三维点数组)
      this.catmullRowCurve3 = new this.$three.CatmullRomCurve3(pointsArr);
      // 获取三维样条曲线上的100个点
      const points = this.catmullRowCurve3.getPoints(220);
      // 设置缓存点模型的点数据
      this.geomery.setFromPoints(points);
      // 创建线材质对象
      this.material = new this.$three.LineBasicMaterial({ color: 0xaabb11 });
      // 创建线模型对象
      this.line = new this.$three.Line(this.geomery, this.material);
      this.scene.add(this.line);

      // 创建管道缓冲几何体
      const tubeGeometry = new this.$three.TubeGeometry(this.catmullRowCurve3, 104, 10, 36, false);
      // 创建网格材质对象
      const meshBasicMaterial = new this.$three.PointsMaterial({
        color: 0xbbddff,
        // side: this.$three.DoubleSide
      });
      const mesh = new this.$three.Points(tubeGeometry,meshBasicMaterial);
      this.scene.add(mesh);

      // 创建透视投影相机对象
      this.camera = new this.$three.PerspectiveCamera(90, 1, 0.01, 3000);
      this.camera.position.set(200, 200, 200);
      this.camera.lookAt(0, 0, 0);
      // 创建辅助坐标轴对象
      const axesHelper = new this.$three.AxesHelper(150);
      this.scene.add(axesHelper);
      // 创建渲染器对象
      this.renderer = new this.$three.WebGLRenderer();
      this.renderer.setSize(1000, 800);
      this.renderer.render(this.scene, this.camera);
      document.getElementById("threejs").appendChild(this.renderer.domElement);

      // 创建空间轨道控制器对象
      this.controls = new OrbitControls(this.camera, this.renderer.domElement);
      this.controls.addEventListener("change", () => {
        this.renderer.render(this.scene, this.camera);
      });
    },
  },
};
</script>
//
<style lang="less" scoped>
.msg {
  padding: 20px;
  text-align: left;
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  .span {
    margin: 0 30px 30px 0;
    // white-space: nowrap;
  }
  .p {
    text-align: left;
  }
}
.box-card-left {
  display: flex;
  align-items: flex-start;
  flex-direction: row;

  width: 100%;
  .box-right {
    text-align: left;
    padding: 10px;
    .xyz {
      width: 100px;
      margin-left: 20px;
    }
    .box-btn {
      margin-left: 20px;
    }
  }
}
</style>

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1230515.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【LeetCode】104. 二叉树的最大深度

104. 二叉树的最大深度 难度&#xff1a;简单 题目 给定一个二叉树 root &#xff0c;返回其最大深度。 二叉树的 最大深度 是指从根节点到最远叶子节点的最长路径上的节点数。 示例 1&#xff1a; 输入&#xff1a;root [3,9,20,null,null,15,7] 输出&#xff1a;3示例 …

Java(三)(static,代码块,单例设计模式,继承)

目录 static 有无static修饰的成员变量 有无static修饰的成员方法 static的注意事项 代码块 静态代码块 实例代码块 单例设计模式 饿汉式单例写法 懒汉式单例写法 继承 基本概念 注意事项 权限修饰符 单继承 object 方法重写 子类方法中访问其他成员(成员变量…

Maven工程继承关系,多个模块要使用同一个框架,它们应该是同一个版本,项目中使用的框架版本需要统一管理。

1、父工程pom.xml <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apache.org/PO…

Android studio run 手机或者模拟器安装失败,但是生成了debug.apk

错误信息如下&#xff1a;Error Installation did not succeed. The application could not be installed&#xff1a;List of apks 出现中文乱码&#xff1b; 我首先尝试了打包&#xff0c;能正常安装&#xff0c;再次尝试了debug的安装包&#xff0c;也正常安装&#xff1…

C#基础教程 多线程编程入门 Thread/Task/async/await

private void button1_Click(object sender, EventArgs e){//控制主线程(单线程操作)MessageBox.Show("开始做菜", "友情提示");Thread.Sleep(3000);//主线程休眠MessageBox.Show("素菜做好了","友情提示");Thread.Sleep(5000);Messag…

linux上安装qt creator

linux上安装Qt Creator 1 Qt Creator 的下载 下载地址为&#xff1a;http://download.qt.io/archive/qt/ 根据自己的需求选择Qt Creator版本&#xff0c;这里我下载的是5.12.9&#xff0c;如下图所示&#xff1a; 在ubuntu上可以使用wget命令下载安装包&#xff1a; wget h…

el-table实现表格内嵌套表格

文章目录 一、效果图二、使用场景三、所用组件元素&#xff08;Elementui&#xff09;四、代码部分 一、效果图 二、使用场景 &#x1f6c0;el-form 表单内嵌套el-table表格 &#x1f6c0;el-table 表格内又嵌套el-table表格 三、所用组件元素&#xff08;Elementui&#xff…

BLE协议栈入门学习

蓝牙LE栈 物理层 频带 蓝牙LE在2400MHz到2483.5MHz范围内的2.4GHz免授权频段工作&#xff0c;该频段分为40个信道&#xff0c;每个信道间隔为2MHz。 时分 蓝牙LE是半双工的&#xff0c;可以发送和接收&#xff0c;但不能同时发送和接收&#xff0c;然而&#xff0c;所有的设…

“绵柔的,好喝的”海之蓝畅销20年的经典秘诀:做大众喜爱的好酒

执笔 | 尼 奥 编辑 | 萧 萧 在中国白酒历史长河中&#xff0c;有的品牌如大浪淘沙而灰飞烟灭&#xff0c;也有的白酒品牌因为不断创新而经久不衰。我们时常在思考一个产业命题&#xff1a;白酒品牌常青的秘诀到底是什么&#xff1f; 经过20多年的产业发展&#xff0c;中国…

4-2计算小于1000的正整数的平方根

#include<stdio.h> #include<math.h> int main() {int i;int t;printf("请输入一个数:");scanf("%d",&i);if(i>1000){printf("请重新输入一个数&#xff1a;");scanf("%d",&i);}tsqrt(i);printf("%d的平方…

要事第一:如何通过6个步骤确定项目的优先级

当收到很多项目请求并且每个请求都是重中之重时&#xff0c;该怎么办&#xff1f;从最易完成的开始&#xff1f;还是先解决最大的问题&#xff1f; 实际上两种做法都不对。确定项目优先级的更好方法是评估以下内容&#xff0c;而不是关注项目规模或完成时长&#xff1a; ● 每…

论文导读 | 大语言模型与知识图谱复杂逻辑推理

前 言 大语言模型&#xff0c;尤其是基于思维链提示词&#xff08;Chain-of Thought Prompting&#xff09;[1]的方法&#xff0c;在多种自然语言推理任务上取得了出色的表现&#xff0c;但不擅长解决比示例问题更难的推理问题上。本文首先介绍复杂推理的两个分解提示词方法&a…

滚珠螺杆在航天工业领域中的重要性

滚珠螺杆是重要的航天工业配件之一&#xff0c;在航天工业领域中具有非常重要的地位和作用。 首先&#xff0c;滚珠螺杆作为一种高精度、高刚度的传动元件&#xff0c;能够提供准确的传动和定位精度&#xff0c;从而保证航天器的可靠性和性能。航天器在飞行过程中需要精确控制其…

【STM32】W25Q64 SPI(串行外设接口)

一、SPI通信 0.IIC与SPI的优缺点 https://blog.csdn.net/weixin_44575952/article/details/124182011 1.SPI介绍 同步&#xff08;有时钟线&#xff09;&#xff0c;高速&#xff0c;全双工&#xff08;数据发送和数据接收各占一条线&#xff09; 1&#xff09;SCK:时钟线--&…

软件数据采集使用代理IP的好处用哪些?

随着互联网的快速发展&#xff0c;越来越多的企业开始通过软件数据采集来获取目标客户的信息。然而&#xff0c;在进行数据采集的过程中&#xff0c;由于不同网站的访问规则和限制&#xff0c;经常会遇到一些问题。这时候&#xff0c;使用代理IP就可以很好地解决这些问题。下面…

震惊!这个网站几分钟就能制作出电子画册

一直以来&#xff0c;制作电子画册都是一项繁琐且耗时的任务&#xff0c;需要专业的设计技能和大量的时间。 但是现在&#xff0c;有了这个神奇的网站&#xff0c;FLBOOK在线制作电子杂志平台。一切都变得如此简单&#xff01;它不仅提供了丰富的模板和素材&#xff0c;还支持在…

封装实现unordered_map和set

什么是哈希思想 首先哈希是一个关联式容器&#xff0c;各个数据之间是具有关系的&#xff0c;和vector那些序列式容器不一样。 首先unordered_map中的迭代器是一个单向的迭代器。 其次在unorderede_map和set中是无序的&#xff08;因为底层不是红黑树&#xff0c;而是哈希了…

接口自动化项目落地之HTTPBin网站

原文&#xff1a;https://www.cnblogs.com/df888/p/16011061.html 接口自动化项目落地系列 找个开源网站或开源项目&#xff0c;用tep实现整套pytest接口自动化项目落地&#xff0c;归档到电子书&#xff0c;作为tep完整教程的项目篇一部分。自从tep完整教程发布以后&#…

【广州华锐互动】VR虚拟现实技术助力太空探险:穿越时空,探索宇宙奥秘

随着科技的不断发展&#xff0c;虚拟现实&#xff08;VR&#xff09;技术已经逐渐走进我们的生活。在教育领域&#xff0c;VR技术的应用也日益广泛&#xff0c;为学生提供了更加生动、直观的学习体验。本文将以利用VR开展太空探险学习为主题&#xff0c;探讨如何将这一先进技术…

3D 纹理渲染如何帮助设计师有效、清晰地表达设计理念

在线工具推荐&#xff1a; 三维数字孪生场景工具 - GLTF/GLB在线编辑器 - Three.js AI自动纹理化开发 - YOLO 虚幻合成数据生成器 - 3D模型在线转换 - 3D模型预览图生成服务 定义 3D 渲染可视化及其用途 3D 可视化是一种艺术形式。这是一个机会。这是进步。借助 3D 纹理…