123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js - water flow map</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <link type="text/css" rel="stylesheet" href="main.css">
- </head>
- <body>
- <div id="container"></div>
- <div id="info">
- <a href="https://threejs.org" target="_blank" rel="noopener noreferrer">three.js</a> - water flow map
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import { GUI } from './jsm/libs/dat.gui.module.js';
- import { OrbitControls } from './jsm/controls/OrbitControls.js';
- import { Water } from './jsm/objects/Water2.js';
- var scene, camera, renderer, water;
- init();
- animate();
- function init() {
- // scene
- scene = new THREE.Scene();
- // camera
- camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 1000 );
- camera.position.set( 0, 25, 0 );
- camera.lookAt( scene.position );
- // ground
- var groundGeometry = new THREE.PlaneBufferGeometry( 20, 20, 10, 10 );
- var groundMaterial = new THREE.MeshBasicMaterial( { color: 0xcccccc } );
- var ground = new THREE.Mesh( groundGeometry, groundMaterial );
- ground.rotation.x = Math.PI * - 0.5;
- scene.add( ground );
- var textureLoader = new THREE.TextureLoader();
- textureLoader.load( 'textures/floors/FloorsCheckerboard_S_Diffuse.jpg', function ( map ) {
- map.wrapS = THREE.RepeatWrapping;
- map.wrapT = THREE.RepeatWrapping;
- map.anisotropy = 16;
- map.repeat.set( 4, 4 );
- groundMaterial.map = map;
- groundMaterial.needsUpdate = true;
- } );
- // water
- var waterGeometry = new THREE.PlaneBufferGeometry( 20, 20 );
- var flowMap = textureLoader.load( 'textures/water/Water_1_M_Flow.jpg' );
- water = new Water( waterGeometry, {
- scale: 2,
- textureWidth: 1024,
- textureHeight: 1024,
- flowMap: flowMap
- } );
- water.position.y = 1;
- water.rotation.x = Math.PI * - 0.5;
- scene.add( water );
- // flow map helper
- var helperGeometry = new THREE.PlaneBufferGeometry( 20, 20 );
- var helperMaterial = new THREE.MeshBasicMaterial( { map: flowMap } );
- var helper = new THREE.Mesh( helperGeometry, helperMaterial );
- helper.position.y = 1.01;
- helper.rotation.x = Math.PI * - 0.5;
- helper.visible = false;
- scene.add( helper );
- // renderer
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.setPixelRatio( window.devicePixelRatio );
- document.body.appendChild( renderer.domElement );
- //
- var gui = new GUI();
- gui.add( helper, 'visible' ).name( 'Show Flow Map' );
- gui.open();
- //
- var controls = new OrbitControls( camera, renderer.domElement );
- //
- window.addEventListener( 'resize', onResize, false );
- }
- function onResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- function animate() {
- requestAnimationFrame( animate );
- render();
- }
- function render() {
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|