当前位置:网站首页>Threejs realizes the simulation of river, surface flow, pipe flow and sea surface
Threejs realizes the simulation of river, surface flow, pipe flow and sea surface
2022-06-30 04:23:00 【Zuo Ben】
1, Introduce
Use Three.js introduce Water.js, Realize the simulation of river surface , Piped water .
The renderings are as follows :
Reference cases :three.js webgl - shaders - ocean (threejs.org)
https://threejs.org/examples/webgl_shaders_ocean.html
three.js - water (threejs.org)
https://threejs.org/examples/webgl_water.html
2, Implementation notes
1, The river implementation needs to create an irregular geometry , Then create Water Object incoming Geometry
2, Simulating pipe flow requires creating two pipes , A pipe simulates the flow of water , A pipe is wrapped outside
// Create a smooth 2D spline
const curve = new THREE.SplineCurve([
new THREE.Vector2(1520, 2850),
new THREE.Vector2(420, 180),
new THREE.Vector2(220, 280),
new THREE.Vector2(100, -380),
new THREE.Vector2(-500, 780),
]);
// Returns the set of points at a given position on a curve
const points = curve.getPoints(1000);
// Points to create a smooth 3D spline
const curves = new THREE.CatmullRomCurve3([
new THREE.Vector3(100, 0, 100),
new THREE.Vector3(0, 0, 100),
new THREE.Vector3(0, -100, 100),
]);
// Create pipe Geometry
const geometryTube1 = new THREE.TubeGeometry(curves, 200, 10, 50);
const geometryTube = new THREE.TubeGeometry(curves, 200, 9, 50);
// Create materials
const materialTube = new THREE.MeshBasicMaterial({
color: "#00aa00", // Tube color
transparent: true, // Whether the pipe is transparent
side: THREE.DoubleSide,
opacity: 0.5, // Tube transparency
});
// Create a tube object
const meshTube = new THREE.Mesh(geometryTube1, materialTube);
meshTube.position.x = -300;
meshTube.rotation.y = Math.PI;
// Add to scene
scene.add(meshTube);
water = new Water(geometryTube, {
textureWidth: 112, // Water turbidity , density
textureHeight: 112, // Water turbidity , density
waterNormals: new THREE.TextureLoader().load('assets/textures/waternormals.jpg', function(texture) {
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
}),
waterColor: "#ffffff",
});
water.position.x = -300;
water.rotation.y = Math.PI;
scene.add(water);
let splineShape = new THREE.Shape(points);
let geometry = new THREE.ShapeGeometry(splineShape);
water1 = new Water(geometry, {
textureWidth: 1512, // Water turbidity , density
textureHeight: 1512, // Water turbidity , density
waterNormals: new THREE.TextureLoader().load('assets/textures/waternormals.jpg', function(texture) {
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
}),
waterColor: "#ffffff", // Water color
});
water1.position.y = -90;
water1.position.x = -200;
water1.rotation.x = Math.PI * -0.5;
scene.add(water1);
Finally, pay attention to whether the water surface can have wave effect , stay render Add the following code
water.material.uniforms['time'].value += 2.0 / 60.0;边栏推荐
猜你喜欢

基于海康EhomeDemo工具排查公网部署出现的视频播放异常问题

Troubleshoot abnormal video playback problems in public network deployment based on Haikang ehomedemo tool

I spent three years in a big factory outsourcing, which subverted my understanding!
![Tea mall system based on SSM framework [project source code + database script + report]](/img/d9/0a46c0da9839a7186bd3a9ae55f0a5.png)
Tea mall system based on SSM framework [project source code + database script + report]

Junior students summarize JS advanced interview questions

Grasp grpc communication framework in simple terms
![[Thesis reading | deep reading] dane:deep attributed network embedding](/img/c7/60f36c2748b8cd7544b7ef14dc309e.png)
[Thesis reading | deep reading] dane:deep attributed network embedding

iMile 利用 Zadig 多云环境周部署千次,跨云跨地域持续交付全球业务

MySQL DDL change

SQLyog导入数据库时报错,求帮解决!
随机推荐
SQLyog导入数据库时报错,求帮解决!
Myrpc version 0
Everyone, Flink 1.13.6, mysql-cdc2.2.0, the datetime (6) class extracted
Slam mapping, automatic navigation and obstacle avoidance based on ROS (bingda robot)
【WEBRTC】ADM: rtc_ include_ internal_ audio_ Device triggers RTC_ Dcheck (ADM) assertion
Clients accessing the daytime service (TCP)
Iterator of JS
Matlab reads fig file and restores signal
Configure specific source IP in SLA detection of FortiGate sdwan
尝试链接数据库时出现链接超时报错,如何解决?
The same node code will cause duplicate data
Stack implementation integrated Calculator - code implementation
What is the difference between synchronized and lock
Tea mall system based on SSM framework [project source code + database script + report]
RPC correction based on arcpy API
idea灰屏问题
Salary management system based on servlet+jsp+mysql [source code + database]
OneNote production schedule
Day 10 data saving and loading
How to use div boxes to simulate line triangles