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>

图片(透明的)


相关推荐
我是Superman丶1 小时前
【技巧】前端VUE用中文方法名调用没效果的问题
前端·javascript·vue.js
斯~内克1 小时前
Vue 3 中 watch 的使用与深入理解
前端·javascript·vue.js
蜡笔小柯南3 小时前
解决:npm install报错,reason: certificate has expired
前端·npm·node.js
lqj_本人4 小时前
鸿蒙OS&UniApp制作多选框与单选框组件#三方框架 #Uniapp
前端·javascript·uni-app
@PHARAOH5 小时前
WHAT - 前端开发流程 SOP(标准操作流程)参考
前端·领导力
松树戈6 小时前
plus-ui&RuoYi-Vue-Plus 基于pgSql本地运行实践
前端·vue.js·spring boot·ui
new6669996 小时前
css画图形
前端·css
Yvonne爱编码7 小时前
CSS- 1.1 css选择器
前端·css·状态模式·html5·hbuilder
SHIPKING3937 小时前
【HTML】个人博客页面
javascript·css·html
山河故人1637 小时前
uniapp使用npm下载
前端·npm·uni-app