Three.js 实现海面效果

server/2025/2/7 18:22:28/

Three.js 实现海面效果
https://threehub.cn/#/codeMirror?navigation=ThreeJS&classify=shader&id=oceanShader
在这里插入图片描述

import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
import { Water } from 'three/examples/jsm/objects/Water.js';
import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'const box = document.getElementById('box')const scene = new THREE.Scene()const camera = new THREE.PerspectiveCamera(50, box.clientWidth / box.clientHeight, 0.1, 1000000)camera.position.set(6, 3, 15)const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true, logarithmicDepthBuffer: true })renderer.setSize(box.clientWidth, box.clientHeight)box.appendChild(renderer.domElement)const controls = new OrbitControls(camera, renderer.domElement)controls.enableDamping = trueconst waterGeometry = new THREE.PlaneGeometry(10000, 10000);const water = new Water(waterGeometry,{textureWidth: 512,textureHeight: 512,waterNormals: new THREE.TextureLoader().load(  `https://file.threehub.cn/` +  '/images/texture/waternormals.jpg', function (texture) {texture.wrapS = texture.wrapT = THREE.RepeatWrapping;}),sunDirection: new THREE.Vector3(),sunColor: 0xffffff,waterColor: 0x001e0f,distortionScale: 3.7,fog: scene.fog !== undefined}
);water.rotation.x = - Math.PI / 2;scene.add(water);// 文件地址
const urls = [0, 1, 2, 3, 4, 5].map(k => (`https://file.threehub.cn/` + 'files/sky/skyBox0/' + (k + 1) + '.png'));const textureCube = new THREE.CubeTextureLoader().load(urls);scene.background = textureCube;new GLTFLoader().load('https://z2586300277.github.io/3d-file-server/models/glb/wajueji.glb',gltf => {gltf.scene.traverse(child => {if (child.isMesh) {child.material.envMap = textureCube}})scene.add(gltf.scene)})const gui = new GUI();gui.addColor(water.material.uniforms['waterColor'], 'value').name('waterColor');gui.addColor(water.material.uniforms['sunColor'], 'value').name('sunColor');gui.add(water.material.uniforms['sunDirection'].value, 'x', - 1, 1).name('sunX');animate()function animate() {water.material.uniforms['time'].value += 1.0 / 60.0;requestAnimationFrame(animate)controls.update()renderer.render(scene, camera)}window.onresize = () => {renderer.setSize(box.clientWidth, box.clientHeight)camera.aspect = box.clientWidth / box.clientHeightcamera.updateProjectionMatrix()}/*** title: Ocean Shader* author: Elegant https://z2586300277.github.io/
*/

http://www.ppmy.cn/server/165730.html

相关文章

Vue - shallowRef 和 shallowReactive

一、shallowRef 和 shallowReactive (一)shallowRef 在 Vue 3 中,shallowRef 是一个用于创建响应式引用的 API,它与 ref 相似,但它只会使引用的基本类型(如对象、数组等)表现为响应式&#xf…

IM 即时通讯系统-43-简单的仿QQ聊天安卓APP

IM 开源系列 IM 即时通讯系统-41-开源 野火IM 专注于即时通讯实时音视频技术,提供优质可控的IMRTC能力 IM 即时通讯系统-42-基于netty实现的IM服务端,提供客户端jar包,可集成自己的登录系统 IM 即时通讯系统-43-简单的仿QQ聊天安卓APP IM 即时通讯系统-44-仿QQ即…

1.1 学习代理(Agent)分为几步?

文章目录 前言一、什么是UVM中的代理(Agent)二、如何理解Agent三、如何使用Agent1、创建Agent类2、实例化组件3、配置Agent4、连接组件 四、示例代码分析 前言 从Agent的概念入手,这个应该比较容易解释,就是把Driver、Monitor和S…

MS SQL Server partition by 函数实战二 编排考场人员

目录 需求 输出效果 范例运行环境 表及视图样本设计 功能实现 生成考场数据 生成重复的SQL语句 封装为统计视图 编写存储过程实现统计 小结 需求 假设有若干已分配准考证号的考生,准考证号示例(01010001)共计8位,前4位…

【C++】B2115 密码翻译

博客主页: [小ᶻ☡꙳ᵃⁱᵍᶜ꙳] 本文专栏: C 文章目录 💯前言💯题目解析💯1. 老师的做法代码实现:思路解析: 💯2. 我的做法代码实现:思路分析: 💯3. 老师…

Linux权限大揭秘:深入理解系统安全

W...Y的主页 😊 代码仓库分享💕 🍔前言: 在之前的内容中,我们了解了Linux中的一些简单权限,如root超级账号与普通账户的区别、Linux文件权限管理、文件类型和访问权限以及许多关于修改权限的指令及其规则…

深入解析 Chrome 浏览器的多进程架构:标签页是进程还是线程?(中英双语)

深入解析 Chrome 浏览器的多进程架构:标签页是进程还是线程? 1. 引言 Google Chrome 作为全球最流行的浏览器之一,以其稳定性、安全性和多任务处理能力而闻名。而其高效的表现,很大程度上归功于其独特的多进程架构(M…

一篇关于高等数理统计结合机器学习论文的撰写(如何撰写?)

前言 在大学或者研究生阶段,大家可能都会遇到一个问题就是,在上高等数理统计课程时,老师总会让同学们写一些大作业,比如论文什么的,接下来我会从计算机领域的角度,带领大家开启一篇从0到1的高等数理统计文…