I attempted to create ocean waves using three.js, but when I tried running it on a web browser, all I saw was a blank white screen.
https://i.sstatic.net/dhEsY.png
The code snippet I utilized for generating the ocean waves is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My first three.js app</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f1b071d0a0a2f5f415e5b5c">[email protected]</a>/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9aeef2e8ffffdaaab4abaea9">[email protected]</a>/examples/js/controls/OrbitControls.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="51253923343411617f606562">[email protected]</a>/examples/js/objects/Water.js"></script>
<script>
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.set( 0, 0, 50 );
camera.lookAt( 0, 0, 0 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const WaterGeometry = new THREE.PlaneGeometry( 45, 45 );
const texture = new THREE.TextureLoader().load( 'https://i.imgur.com/mK9cHLq.jpeg' );
const material = new THREE.MeshBasicMaterial( { map: texture, side: THREE.DoubleSide } );
const controls = new THREE.OrbitControls( camera, renderer.domElement );
const params = {
color: '#ffffff',
scale: 4,
flowX: 1,
flowY: 1
};
water = new THREE.Water( WaterGeometry, material, {
color: params.color,
scale: params.scale,
flowDirection: new THREE.Vector2( params.flowX, params.flowY ),
textureWidth: 1024,
textureHeight: 1024
} );
controls.update();
scene.add( water );
function animate()
{
requestAnimationFrame( animate );
water.rotation.x += 0.00;
water.rotation.y += 0.00;
water.rotation.z += 0.01;
renderer.render( scene, camera );
};
animate();
</script>
</body>
</html>
Where did I go wrong? All I see now is a slowly rotating black square.
Thank you in advance for any feedback and advice on resolving this issue!