three.js实现雷达扫描效果(纹理贴图)

three.js实现雷达扫描效果(纹理贴图)

图例

步骤

  1. 创建两个平面,分别纹理贴图,底图模型.add(光波模型)
  2. 关闭材质的深度测试
  3. 光波旋转

代码

javascript 复制代码
<template>
  <div class="app">
    <div ref="canvesRef" class="canvas-wrap"></div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";

const canvesRef = ref(null);
const canvasWidth = window.innerWidth;
const canvasHeight = window.innerHeight;
let scene;
let camera;
let renderer;
let axesHelper;
let cameraControls;
let mesh;
init();
render();
function init() {
  // 场景
  scene = new THREE.Scene();

  // 相机
  camera = new THREE.PerspectiveCamera(
    45,
    canvasWidth / canvasHeight,
    1,
    10000
  );
  camera.position.set(300, 300, 300);
  camera.lookAt(0, 0, 0);
  // 模型
  addModel();
  // 坐标辅助对象
  axesHelper = new THREE.AxesHelper(200);
  scene.add(axesHelper);

  // 渲染器
  //antialias - 是否执行抗锯齿。默认为false.
  renderer = new THREE.WebGLRenderer();
  renderer.setSize(canvasWidth, canvasHeight);
  // 相机轨道控制器
  cameraControls = new OrbitControls(camera, renderer.domElement);
}

function addModel() {
  // 底图
  const g = new THREE.PlaneGeometry(50, 50);
  const texture = new THREE.TextureLoader().load(
    "../src/assets/img/雷达扫描-底图.png"
  );
  const m = new THREE.MeshBasicMaterial({
    map: texture,
    side: THREE.DoubleSide,
    color: 0x00ffff,
    transparent: true,
    opacity: 0.6,
    depthTest: false, //是否在渲染此材质时启用深度测试
  });
  const baseMesh = new THREE.Mesh(g, m);
  baseMesh.rotateX(-Math.PI / 2);
  scene.add(baseMesh);

  // 光
  const texture2 = new THREE.TextureLoader().load(
    "../src/assets/img/雷达扫描-光波.png"
  );
  const m2 = new THREE.MeshBasicMaterial({
    map: texture2,
    side: THREE.DoubleSide,
    color: 0x00ffff,
    transparent: true,
    opacity: 0.6,
    depthTest: false,
  });
  mesh = new THREE.Mesh(g, m2);
  // mesh.position.set(0, 10, 0);
  baseMesh.add(mesh);
}

function render() {
  renderer.render(scene, camera);
  mesh.rotateZ(0.02);
  requestAnimationFrame(render);
}
onMounted(() => {
  canvesRef.value.appendChild(renderer.domElement);
});
</script>

<style lang="scss" scoped>
.app {
  position: relative;
}
</style>

图片(透明的)


相关推荐
Felicity_Gao3 小时前
uni-app VOD 与 COS 选型、开发笔记
前端·笔记·uni-app
我狸才不是赔钱货4 小时前
前端技术栈全景图:从HTML到现代框架的演进之路
前端·html
百花~5 小时前
前端三剑客之一 HTML~
前端·html
lang201509285 小时前
Spring远程调用与Web服务全解析
java·前端·spring
Sheldon一蓑烟雨任平生6 小时前
Vue3 依赖注入(provide 和 inject)
vue.js·inject·provide·vue3 依赖注入·跨级别组件通信
孤狼warrior7 小时前
爬虫进阶 JS逆向基础超详细,解锁加密数据
javascript·爬虫
前端炒粉7 小时前
18.矩阵置零(原地算法)
javascript·线性代数·算法·矩阵
listhi5207 小时前
利用React Hooks简化状态管理
前端·javascript·react.js
paopaokaka_luck7 小时前
基于SpringBoot+Vue的助农扶贫平台(AI问答、WebSocket实时聊天、快递物流API、协同过滤算法、Echarts图形化分析、分享链接到微博)
java·vue.js·spring boot·后端·websocket·spring
一点一木7 小时前
🚀 2025 年 10 月 GitHub 十大热门项目排行榜 🔥
前端·人工智能·github