Why is only the peak of the wave visible? I am eager to showcase the full extent of its beauty

Having an issue with the appearance of a superposed wave using threejs. When displayed, the wave made from plane material only shows the upper half, but when turned upside down using mouse dragging, it appears correctly.

// Turn the wave plane upside down by dragging 
console.clear()
var scene = new THREE.Scene();
var W = window.innerWidth;
var H = window.innerHeight;
console.log("W "+W + "H"+ H)
var renderer = new THREE.WebGLRenderer();
//renderer.setClearColor(0xc482c4);
renderer.setSize(W, H);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap; 

var camera = new THREE.PerspectiveCamera(10, W / H, 1, 500);

var planeGeometry = new THREE.PlaneGeometry(200, 100, 200,100 );//planeの横、たて、横分割数、たて分割数
var planeMaterial = new THREE.MeshPhongMaterial({
          color: 0x6699FF,
           side: THREE.BackSide
        });

var plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.castShadow = true;
plane.receiveShadow = true;
plane.rotation.x = -0.4 * Math.PI;
plane.position.set(0, 0, 10);
scene.add(plane);

var dlight = new THREE.DirectionalLight( 0xC0C0C0,1 );
dlight.position.set(0,0,1);
dlight.castShadow = true;
scene.add(dlight);
var lights = [];
            lights[ 0 ] = new THREE.PointLight( 0xffffff, 1, 0 );
            lights[ 1 ] = new THREE.PointLight( 0xffffff, 1, 0 );
            lights[ 2 ] = new THREE.PointLight( 0xffffff, 1, 0 );
      lights[ 3 ] = new THREE.PointLight( 0xffffff, 1, 0 );

            lights[ 0 ].position.set( 0, 0, 20 );
            lights[ 1 ].position.set( 10, 20, 10 );
            lights[ 2 ].position.set( - 10, - 20,  -10 );
      lights[ 3 ].position.set( - 0, - 0,  -20 );

            scene.add( lights[ 0 ] );
            scene.add( lights[ 1 ] );
            scene.add( lights[ 2 ] );
      scene.add( lights[ 3 ] );

camera.position.set( 20, 0, 350 );
var controls = new THREE.OrbitControls( camera );
controls.enableZoom=true;
controls.update();
document.body.appendChild(renderer.domElement);

(function drawFrame(ts){
  var centerLeft = new THREE.Vector2(-21,0);
  var centerRight = new THREE.Vector2(21,0);
  window.requestAnimationFrame(drawFrame);
  var vLength = plane.geometry.vertices.length;
  for (var i = 0; i < vLength; i++) {
    var v = plane.geometry.vertices[i];
    var dist1 = new THREE.Vector2(v.x, v.y).sub(centerLeft);
    var dist2 = new THREE.Vector2(v.x, v.y).sub(centerRight);
    var size = 10.0;
    var magnitude = 7;
    v.z = 2*Math.sin(-2*Math.PI*dist1.length()/size + 2*Math.PI*(ts/2000)) +2*Math.sin(-2*Math.PI*dist2.length()/size+ 2*Math.PI*(ts/2000));
  }
  plane.geometry.verticesNeedUpdate = true;
  renderer.render(scene, camera);
}());

https://codepen.io/math_mountain_f/pen/Mdjvwx

Tried changing the "plane.position" but the plane did not move as expected.

Currently attempting to adjust the camera position without success.

Looking to display the entire wave from a top view perspective without the need for dragging.

Answer №1

To update the material orientation, change from THREE.BackSide to THREE.DoubleSide

var planeMaterial = new THREE.MeshPhongMaterial({
      color: 0x6699FF,
      side: THREE.DoubleSide
});

If you don't need to view the bottom side, you can use THREE.FrontSide since it's the default option.

You can also rotate the plane by 180°

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

converting code from JavaScript to Flask and then back to JavaScript, all within a single-page application

In order to make my single-page web app fully functional, I have completed the following tasks: Sent a json from .js to Flask (COMPLETED) Ran the input through a Python function called getString() and obtained a string output (COMPLET ...

Identical HTML elements appearing across multiple DOM pages

My question might seem silly, but I'm facing an issue. I have several HTML pages such as index.html and rooms.html, along with a main.js file containing scripts for all of these pages. The problem arises because I have variables like const HTMLelemen ...

The jQuery onchange function does not have the ability to limit the input to only

When using the script to sum the input value, everything seems to be working fine. However, I am facing an issue where clicking up and down on the "input#total_selfmark" does not change the value. Additionally, when I manually type in a number, the "input# ...

Is there a way to verify the presence of a particular value in a list?

I need to validate the content of all li tags within a ul list. If any list item contains the text "None," then I want to append specific text to a div. If no li tag includes "None," then different text should be added to the div. Upon checking my code, I ...

Anchor tags are not visible to Jquery

My issue is with integrating JQUERY and PHP. In my external PHP file, I have the following echo statement - `echo ("<a href='#' id='bb'>hello</a>"); Similarly, in my external js file, I have this JQUERY code - $(' ...

The importance of variables in Express Routing

I'm really diving into the intricacies of Express.js routing concepts. Here's an example that I've been pondering over: const routes = require('./routes'); const user = require('./routes/user'); const app = express(); a ...

I'm wondering how I can design a utility function within my Redux module that can extract a specific subset of read-only data from the current state

I am currently utilizing redux to create a "helper function" inside my redux module that is responsible for fetching filtered data from the state based on a specified index. This specific data will be used to generate a form consisting of inputs depending ...

Having trouble establishing a default route with React Router v5

I am facing an issue with setting the default route to the home page in react router v5. Despite trying several methods, I cannot get it to work as expected. Index.js import React from "react"; import ReactDOM from "react-dom"; import ...

The Angular Material md-menu element stubbornly refuses to close when clicked outside, especially if the target element has a fixed position and

I currently have a <md-menu> element implemented in my webpage. By default, the menu will close if clicked anywhere on the page. However, I have noticed that when clicking inside a fixed element with a specified z-index, the menu does not close. < ...

Accessing an array of objects within nested objects results in an undefined value

I am facing an issue with my JavaScript object that is retrieved from MySQL. The object has a property which contains an array of other objects, as demonstrated below: parentObject = { ID: "1", Desc: "A description", chi ...

What is the best way to group data by a specific value within a nested object when using ReactJS material-table?

I have a unique scenario where I possess an array of individuals featuring a nested object known as enterprise. My objective is to effectively group these individuals by the value of company.name within the confines of the Material-Table. const people = [ ...

Just starting out with JavaScript - updating the appearance of an element

Based on the value of a boolean, I am looking to control the visibility of specific tabs in my sidebar when the page loads. var someVar = true; function show_ifTrue() { if (Boolean(someVar) == true) { document.getElementById('x'). ...

Utilizing JavaScript Fetch with User Input to Integrate OpenWeather API Retains Previous Data on HTML Page

I have been working with JavaScript Fetch to retrieve data from the OpenWeather API. In my project, I have created a form where users can input the name of a city to view its weather information. However, I am facing an issue where the data from the previo ...

The Nuxt.js and Vue.js Watchers are caught in an infinite loop caused by fluctuations in the values

Currently, I am working on a project using Nuxt.js/Vue.js for creating an application that can efficiently convert XML to JSON and vice versa. Users have the ability to input values into textareas, which are managed by CodeMirror. The textarea is connecte ...

The hidden textbox loses its value when submitting

I have a form with fields and a RequiredFieldValidator. Additionally, I have another textbox that is hidden which gets populated by a JavaScript function: <script type="text/javascript"> $(document).ready(function (sender, args) { $("#myTextFiel ...

Tips for passing the id using jQuery in an AJAX request to execute a delete action

How can I remove an element from a list by clicking the delete button? https://i.sstatic.net/dQuOu.png I have created an ajax call for this purpose: .ajax({ type : "GET", url : 'getVenueList&apo ...

Tips for navigating through an array incrementally in a Controller using input provided by the user in the View

Greetings, I am currently working on a small website project using WAMPserver. The site is structured following an MVC design pattern. In one part of the process, I generate an array of strings in the controller. My goal is to display each element of this ...

VueJS together with Firebase: The guide to password validation

I am currently working on a web form developed using VueJS that enables authenticated users to modify their passwords. The backend system relies on Firebase, and I am facing a challenge in validating the user's current password before initiating the p ...

The browser is preventing a cross origin request in Fetch

Currently, I am utilizing node, express, and react to build a sign-in portal. In the frontend, I have created app.js and signin.js files. The partial code snippet in the signin.js file looks like this: onSubmitSignIn = () => { fetch("http://localhost:3 ...

What is the best way to animate an element when it comes into the user's view

In order to activate the animation of the skill-bars when the element is displayed on the website, I am seeking a solution where scrolling down through the section triggers the animation. Although I have managed to conceptualize and implement the idea with ...