three.js 实现围墙效果

2024-09-06 16:28
文章标签 实现 js 效果 three 围墙

本文主要是介绍three.js 实现围墙效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

import * as THREE from “three”;
import { OrbitControls } from “three/addons/controls/OrbitControls.js”;

const { innerWidth, innerHeight } = window;
const aspect = innerWidth / innerHeight;

class Base {
constructor() {
this.init();
this.main();
}
main() {
const geometry = new THREE.CylinderGeometry(30, 30, 20, 4, 64, true);
const material = new THREE.ShaderMaterial({
side: THREE.DoubleSide,
transparent: true,
depthWrite: false,
uniforms: {
uTime: this.deltaTime,
},
vertexShader: varying vec2 vUv; void main(){ vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0); } ,
fragmentShader: `
uniform float uTime;
varying vec2 vUv;
#define PI 3.14159265

                    void main(){vec4 baseColor = vec4(0.0,1.,0.5,1.);vec4 finalColor;float amplitude = 1.;float frequency = 10.;float x = vUv.x;float y = sin(x * frequency) ;float t = 0.01*(-uTime*130.0);y += sin(x*frequency*2.1 + t)*4.5;y += sin(x*frequency*1.72 + t*1.121)*4.0;y += sin(x*frequency*2.221 + t*0.437)*5.0;y += sin(x*frequency*3.1122+ t*4.269)*2.5;y *= amplitude*0.06;y /= 3.;y += 0.55;vec4 color = gl_FragColor.rgba;float r = step(0.5, fract(vUv.y - uTime));baseColor.a = step(vUv.y,y) * (y-vUv.y)/y;gl_FragColor = baseColor;}`,});const cylinder = new THREE.Mesh(geometry, material);cylinder.position.y += 10;this.scene.add(cylinder);
}
init() {this.clock = new THREE.Clock();this.renderer = new THREE.WebGLRenderer({antialias: true,logarithmicDepthBuffer: true,});this.renderer.setPixelRatio(window.devicePixelRatio);this.renderer.setSize(innerWidth, innerHeight);this.renderer.setAnimationLoop(this.animate.bind(this));document.body.appendChild(this.renderer.domElement);this.camera = new THREE.PerspectiveCamera(60, aspect, 0.01, 10000);this.camera.position.set(0, 40, 40);this.scene = new THREE.Scene();this.controls = new OrbitControls(this.camera, this.renderer.domElement);this.deltaTime = {value: 0,};const grid = new THREE.GridHelper(100);this.scene.add(grid);const light = new THREE.AmbientLight(0xffffff, 0.5);this.scene.add(light);
}
animate() {this.controls.update();this.renderer.render(this.scene, this.camera);this.deltaTime.value = this.clock.getElapsedTime();
}

}
new Base();

这篇关于three.js 实现围墙效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1142515

相关文章

JS常用组件收集

收集了一些平时遇到的前端比较优秀的组件,方便以后开发的时候查找!!! 函数工具: Lodash 页面固定: stickUp、jQuery.Pin 轮播: unslider、swiper 开关: switch 复选框: icheck 气泡: grumble 隐藏元素: Headroom

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

让树莓派智能语音助手实现定时提醒功能

最初的时候是想直接在rasa 的chatbot上实现,因为rasa本身是带有remindschedule模块的。不过经过一番折腾后,忽然发现,chatbot上实现的定时,语音助手不一定会有响应。因为,我目前语音助手的代码设置了长时间无应答会结束对话,这样一来,chatbot定时提醒的触发就不会被语音助手获悉。那怎么让语音助手也具有定时提醒功能呢? 我最后选择的方法是用threading.Time

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo

在JS中的设计模式的单例模式、策略模式、代理模式、原型模式浅讲

1. 单例模式(Singleton Pattern) 确保一个类只有一个实例,并提供一个全局访问点。 示例代码: class Singleton {constructor() {if (Singleton.instance) {return Singleton.instance;}Singleton.instance = this;this.data = [];}addData(value)

C#实战|大乐透选号器[6]:实现实时显示已选择的红蓝球数量

哈喽,你好啊,我是雷工。 关于大乐透选号器在前面已经记录了5篇笔记,这是第6篇; 接下来实现实时显示当前选中红球数量,蓝球数量; 以下为练习笔记。 01 效果演示 当选择和取消选择红球或蓝球时,在对应的位置显示实时已选择的红球、蓝球的数量; 02 标签名称 分别设置Label标签名称为:lblRedCount、lblBlueCount

Kubernetes PodSecurityPolicy:PSP能实现的5种主要安全策略

Kubernetes PodSecurityPolicy:PSP能实现的5种主要安全策略 1. 特权模式限制2. 宿主机资源隔离3. 用户和组管理4. 权限提升控制5. SELinux配置 💖The Begin💖点点关注,收藏不迷路💖 Kubernetes的PodSecurityPolicy(PSP)是一个关键的安全特性,它在Pod创建之前实施安全策略,确保P

防近视护眼台灯什么牌子好?五款防近视效果好的护眼台灯推荐

在家里,灯具是属于离不开的家具,每个大大小小的地方都需要的照亮,所以一盏好灯是必不可少的,每个发挥着作用。而护眼台灯就起了一个保护眼睛,预防近视的作用。可以保护我们在学习,阅读的时候提供一个合适的光线环境,保护我们的眼睛。防近视护眼台灯什么牌子好?那我们怎么选择一个优秀的护眼台灯也是很重要,才能起到最大的护眼效果。下面五款防近视效果好的护眼台灯推荐: 一:六个推荐防近视效果好的护眼台灯的