UNPKG

@enable3d/three-graphics

Version:

3D library wrapping three.js and ammo.js

31 lines 1.32 kB
import { Mesh, MeshStandardMaterial, PlaneGeometry, Vector2 } from 'three'; import { Water } from 'three/examples/jsm/objects/Water2.js'; const addWater = (scene, renderer, config = {}) => { const { width = 20, height = 20, x = 0, y = 0, z = 0, color = '#ffffff', scale = 4, flowX = 1, flowY = 1, normalMap0 = undefined, normalMap1 = undefined } = config; //ground const groundGeometry = new PlaneGeometry(width, height); // #0077be (also known as Ocean Boat Blue) const groundMaterial = new MeshStandardMaterial({ color: 0x0077be, transparent: true, opacity: 0.8 }); const ground = new Mesh(groundGeometry, groundMaterial); ground.position.set(x, y, z); ground.rotation.x = Math.PI * -0.5; scene.add(ground); // water const waterGeometry = new PlaneGeometry(width, height); const water = new Water(waterGeometry, { color: color, scale: scale, flowDirection: new Vector2(flowX, flowY), textureWidth: 1024, textureHeight: 1024, normalMap0: normalMap0, normalMap1: normalMap1 // encoding: renderer.outputEncoding }); water.position.set(x, y + 0.1, z); water.rotation.x = Math.PI * -0.5; scene.add(water); return { ground, water }; }; export { addWater }; //# sourceMappingURL=water.js.map