Three.js 海面教程 海面 ·Ocean Shader· ▶ 在线运行案例案例合集三维可视化功能案例threehub.cn开源仓库github地址https://github.com/z2586300277/three-cesium-examples400个案例代码:网盘链接你将学到什么官方Water对象examples/jsm/objects/Water.jswaterNormals法线贴图 RepeatWrappinguniforms.time驱动波浪lil-gui 调waterColor / sunColor / sunDirection效果说明万级平面海面荡漾天空盒反射GLTF 挖掘机模型设envMap与环境一致GUI 实时改水体与太阳参数。核心概念import { Water } from three/examples/jsm/objects/Water.js;const water new Water(waterGeometry, { textureWidth: 512, textureHeight: 512, waterNormals: new THREE.TextureLoader().load(waternormals.jpg, t { t.wrapS t.wrapT THREE.RepeatWrapping; }), sunDirection: new THREE.Vector3(), sunColor: 0xffffff, waterColor: 0x001e0f, distortionScale: 3.7, fog: scene.fog ! undefined, }); water.rotation.x -Math.PI / 2;动画water.material.uniforms[time].value 1.0 / 60.0;每帧递增timeWater 内部 shader 算法线偏移与反射。GUIgui.addColor(water.material.uniforms[waterColor], value);gui.add(water.material.uniforms[sunDirection].value, x, -1, 1);实现步骤PlaneGeometry 10000×10000 创建 WaterCubeTexture 天空盒 → background 模型 envMapGLTFLoader 加载场景模型animate 更新 time controls render代码要点import * as THREE from threeimport { 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.jsconst 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( FILE_HOST /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 (FILE_HOST 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()}完整源码GitHub小结本文提供海面完整 Three.js 源码与在线 Demo建议先运行案例再改 uniform/参数做二次实验更多 Three.js 实战案例见 three-cesium-examples 合集 与 GitHub 开源仓库

相关新闻

最新新闻

门禁控制接线原理

门禁控制接线原理

一、NO、NC 基础概念(触点开关)1. 定义NO(Normally Open):常开触点 设备未触发、继电器线圈断电常态下,线路断开;触发后导通。NC(Normally Closed):常闭触点 …

2026/7/7 11:22:29
KLayout Python API生产环境实战:自动化版图处理架构深度解析

KLayout Python API生产环境实战:自动化版图处理架构深度解析

KLayout Python API生产环境实战:自动化版图处理架构深度解析 【免费下载链接】klayout KLayout Main Sources 项目地址: https://gitcode.com/gh_mirrors/kl/klayout KLayout Python API(pya)为集成电路版图设计提供了企业级的自动化…

2026/7/7 11:22:29
Vim编辑器完全指南与Shell命令补充:从零到实战

Vim编辑器完全指南与Shell命令补充:从零到实战

前言 在Linux的世界里,文本编辑器是每位开发者、运维人员最亲密的伙伴。无论你是编写代码、修改配置文件,还是记录笔记,都离不开一款趁手的编辑器。 今天,我们将系统学习Linux中最核心的两类编辑器——Vim(专业级&…

2026/7/7 11:22:29
终极微信小程序图表库指南:wx-charts完整教程

终极微信小程序图表库指南:wx-charts完整教程

终极微信小程序图表库指南:wx-charts完整教程 【免费下载链接】wx-charts 微信小程序图表库,Charts for WeChat Mini Program 项目地址: https://gitcode.com/gh_mirrors/wx/wx-charts 微信小程序开发中,数据可视化一直是开发者面临的…

2026/7/7 11:22:29
计算机毕业设计之jsp某公司网络信息安全方案的设计

计算机毕业设计之jsp某公司网络信息安全方案的设计

快速发展的社会中,人们的生活水平都在提高,生活节奏也在逐渐加快。为了节省时间和提高工作效率,越来越多的人选择利用互联网进行线上打理各种事务,然后线上管理系统也就相继涌现。与此同时,人们开始接受方便的生活方式…

2026/7/7 11:22:29
Geo优化源代码部署开发流程技术分享

Geo优化源代码部署开发流程技术分享

1. 引言在当今快速迭代的软件开发环境中,高效的源代码部署流程是保障团队协作、提升交付质量和加速产品上线的关键。本文将围绕“Geo优化”这一主题,深入分享一套经过实践检验的源代码部署与开发流程优化方案。我们将从流程痛点分析入手,逐步…

2026/7/7 11:17:29

月新闻