仿黑神话悟空跑动-脚下波纹特效(键盘wasd控制走动)

devtools/2024/9/24 7:09:22/

vue使用three.js实现仿黑神话悟空跑动-脚下波纹特效

<template><div ref="container" class="container"></div>
</template><script>
import * as THREE from "three";
export default {name: "WaterRipple",data() {return {scene: null,camera: null,renderer: null,player: null,clock: new THREE.Clock(),keyboard: {},rippleMaterial: null,ripples: []};},mounted() {this.init();this.animate();document.addEventListener("keydown", this.onDocumentKeyDown, false);document.addEventListener("keyup", this.onDocumentKeyUp, false);},beforeDestroy() {document.removeEventListener("keydown", this.onDocumentKeyDown, false);document.removeEventListener("keyup", this.onDocumentKeyUp, false);},methods: {init() {// 创建场景this.scene = new THREE.Scene();// 创建相机this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);this.camera.position.set(0, 50, 100);this.camera.lookAt(0, 0, 0);// 创建渲染器this.renderer = new THREE.WebGLRenderer();this.renderer.setSize(window.innerWidth, window.innerHeight);this.$refs.container.appendChild(this.renderer.domElement);// 创建平面const geometry = new THREE.PlaneGeometry(200, 200, 32, 32);const material = new THREE.MeshBasicMaterial({ color: 0x00ff00, wireframe: true });const plane = new THREE.Mesh(geometry, material);plane.rotation.x = -Math.PI / 2;this.scene.add(plane);// 创建玩家const playerGeometry = new THREE.SphereGeometry(1, 32, 32);const playerMaterial = new THREE.MeshBasicMaterial({ color: 0x0000ff });this.player = new THREE.Mesh(playerGeometry, playerMaterial);this.player.position.y = 1;this.scene.add(this.player);// 窗口调整window.addEventListener('resize', this.onWindowResize, false);},onWindowResize() {this.camera.aspect = window.innerWidth / window.innerHeight;this.camera.updateProjectionMatrix();this.renderer.setSize(window.innerWidth, window.innerHeight);},createRipple(x, z) {const rippleGeometry = new THREE.RingGeometry(0.1, 0.5, 32);const rippleMaterial = new THREE.MeshBasicMaterial({ color: 0x0000ff, transparent: true, opacity: 1, wireframe: true });const ripple = new THREE.Mesh(rippleGeometry, rippleMaterial);ripple.position.set(x, 0.1, z);ripple.rotation.x = -Math.PI / 2;ripple.scale.set(1, 1, 1);this.scene.add(ripple);this.ripples.push({ mesh: ripple, startTime: this.clock.getElapsedTime() });},onDocumentKeyDown(event) {this.keyboard[event.key] = true;},onDocumentKeyUp(event) {this.keyboard[event.key] = false;},animate() {requestAnimationFrame(this.animate);const delta = this.clock.getDelta();const elapsedTime = this.clock.getElapsedTime();const step = 10 * delta;if (this.keyboard['w']) {this.player.position.z -= step;this.createRipple(this.player.position.x, this.player.position.z);}if (this.keyboard['a']) {this.player.position.x -= step;this.createRipple(this.player.position.x, this.player.position.z);}if (this.keyboard['s']) {this.player.position.z += step;this.createRipple(this.player.position.x, this.player.position.z);}if (this.keyboard['d']) {this.player.position.x += step;this.createRipple(this.player.position.x, this.player.position.z);}// 更新水波纹this.ripples.forEach(ripple => {const age = elapsedTime - ripple.startTime;ripple.mesh.scale.set(1 + age * 10, 1 + age * 10, 1 + age * 10);ripple.mesh.material.opacity = Math.max(0, 1 - age / 0.5); // 水波纹消散更快ripple.mesh.material.color.setHSL(0.6, 1, 0.5 * (1 - age / 0.5)); // 颜色随着扩散变淡});this.ripples = this.ripples.filter(ripple => ripple.mesh.material.opacity > 0);this.renderer.render(this.scene, this.camera);}}
};
</script><style scoped>
.container {width: 100vw;height: 100vh;overflow: hidden;
}
</style>

http://www.ppmy.cn/devtools/116383.html

相关文章

基于YOLOv5s的无人机航拍输电线瓷瓶检测(附数据集与操作步骤)

本文主要内容:详细介绍了无人机航拍输电线瓷瓶检测的整个过程&#xff0c;从创建数据集到训练模型再到预测结果全部可视化操作与分析。 文末有数据集获取方式&#xff0c;请先看检测效果 现状 输电线路绝缘瓷瓶的检测主要依赖人工巡检。巡检人员需携带专业设备&#xff0c;攀…

Linux网络之UDP与TCP协议详解

文章目录 UDP协议UDP协议数据报报头 TCP协议确认应答缓冲区 超时重传三次握手其他问题 四次挥手滑动窗口流量控制拥塞控制 UDP协议 前面我们只是说了UDP协议的用法,但是并没有涉及到UDP协议的原理 毕竟知道冰箱的用法和知道冰箱的原理是两个层级的事情 我们首先知道计算机网…

观成科技:新版suo5隧道工具加密流量跟踪分析

1、工具简介 suo5是一个高性能的http隧道代理工具&#xff0c;支持全双工半双工模式&#xff0c;具有很高的传输性能&#xff0c;现在越来越多的webshell管理工具与内存马生成工具都支持了生成suo5木马的功能。从v1.1.0版本开始&#xff0c;其TLS协议传输功能中&#xff0c;增…

Vue 3 中 `$emit` 的使用示例

在 Vue 3 中&#xff0c;$emit 用于子组件向父组件发送事件&#xff0c;这样父组件可以监听并响应子组件触发的事件。 1. 子组件示例&#xff1a;ChildComponent.vue <template><button click"handleClick">点击我</button> </template>&l…

跨站脚本攻击(XSS)

免责申明 本文仅是用于学习测试自己搭建的XSS注入漏洞使用,请勿用在非法途径上,若将其用于非法目的,所造成的一切后果由您自行承担,产生的一切风险和后果与笔者无关;本文开始前请认真详细学习《‌中华人民共和国网络安全法》‌及其所在国家地区相关法规内容【学法时习之丨…

ubuntu内网穿透后在公网使用ssh登录

需求&#xff1a; 我有一台内网可以通过ssh 22端口访问的设备操作系统是ubuntu server我还有1台拥有公网IP的服务器&#xff0c;IP地址是 6.66.666.6666我想随时从其他网段通过ssh访问我的ubuntu server设备 实现&#xff1a; 工具准备&#xff1a;frp 网址&#xff1a;https…

Python 复制Excel 中的行、列、单元格

在Excel中&#xff0c;复制行、列和单元格是日常工作中经常需要进行的操作&#xff0c;它可以帮助你快速调整数据布局、复制数据模板或进行数据的批量处理。 本文将详细介绍如何使用Python将Excel中的行、列、或单元格范围复制到指定位置。 所需Python库 要使用Python操作Exc…

得物App荣获新奖项,科技创新助力高质量发展

近日&#xff0c;备受瞩目的2024中国国际服务贸易交易会&#xff08;简称“服贸会”&#xff09;在北京盛大开幕&#xff0c;这一全球唯一的国家级、国际性、综合型服务贸易盛会再次汇聚了全球服务贸易领域的精英与前沿成果。服贸会由商务部和北京市政府携手打造&#xff0c;并…