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>

图片(透明的)


相关推荐
o***Z44844 分钟前
前端性能优化案例
前端
张拭心1 小时前
前端没有实际的必要了?结合今年工作内容,谈谈我的看法
前端·ai编程
姜太小白1 小时前
【前端】CSS媒体查询响应式设计详解:@media (max-width: 600px) {……}
前端·css·媒体
weixin_411191841 小时前
flutter中WebView的使用及JavaScript桥接的问题记录
javascript·flutter
HIT_Weston1 小时前
39、【Ubuntu】【远程开发】拉出内网 Web 服务:构建静态网页(二)
linux·前端·ubuntu
百***06011 小时前
SpringMVC 请求参数接收
前端·javascript·算法
天外天-亮1 小时前
Vue + excel下载 + 水印
前端·vue.js·excel
起个名字逛街玩1 小时前
前端正在走向“工程系统化”:从页面开发到复杂产品架构的深度进化
前端·架构
用户47949283569152 小时前
React 渲染两次:是 Bug 还是 Feature?聊聊严格模式的“良苦用心”
前端·react.js·前端框架
用户47949283569152 小时前
Code Review 惊魂:同事的“优雅”重构,差点让管理员全部掉线
javascript