Attempting to create a three-dimensional illusion using Three.js

I'm striving to create a mesmerizing effect similar to this masterpiece:

Here's my progress so far: https://codepen.io/routsou/pen/ZEGWJgR?editors=0010

/*--------------------
Setup
--------------------*/
console.clear();
const canvas = document.querySelector('#bubble');

//wobble
let mouseIsDown = false;
let wobbleAmount = 0;
let wobbleLimit = 0.25;

//ripple
let rippleAmount = 0;
let rippleRatio = 5;
let step = 0;
let sphereVerticesArray = [];
let sphereVerticesNormArray = [];

//raycaster
let raycaster;
let INTERSECTED = null;

let width = canvas.offsetWidth,
    height = canvas.offsetHeight;
const renderer = new THREE.WebGLRenderer({
  canvas: canvas,
  antialias: true,
  alpha: true
});
const scene = new THREE.Scene();

const initialize = () => {
  renderer.setPixelRatio( window.devicePixelRatio );
  renderer.setSize(width, height);
  renderer.setClearColor(0xebebeb, 0);
  renderer.shadowMap.enabled = true;
  renderer.shadowMapSoft = true;

  scene.fog = new THREE.Fog(0x000000, 10, 950);

  const aspectRatio = width / height;
....(content continues)....

For assistance, particularly regarding the mouse pointer "sculpting the geometry," and making the waves appear more organic and responsive to the pointer, your help would be greatly appreciated.

Thank you in advance.

Answer №1

Upon investigation, it has been discovered that there is an intersection with all six children in the scene, including the bubble shadow and the lights. Interestingly, the shadow also intersects with the mouse, triggering a false contact.

Regarding "sculpting the geometry," it has been observed that the ripple effect is hardcoded from a specific point on the bubble during its initial construction. This results in the sculpting effect always originating from that same point. A recommendation for rectifying this includes:

  • Removing the hard-coded sphereVerticesArray and sphereVerticesNormArray.
  • After determining the intersection with the mouse, identifying the face of the bubble that is being hit: intersections[0].point provides the point of intersection in world coordinates. Utilize this information to determine the contact face.
  • During the ripple effect, utilize the normal of the contact face as the starting point and orientation of the ripple.

For addressing the shadow intersection issue, the following code with accompanying comments can be implemented:

/*--------------------
Setup
--------------------*/

// Code to set up the scene, camera, and renderer

/*--------------------
Lights
--------------------*/

// Code to create and add lights to the scene

/*--------------------
Bubble
--------------------*/

// Code to create the bubble object with materials and vertices

/*--------------------
Plane
--------------------*/

// Code to create and position a plane in the scene

/*--------------------
Map
--------------------*/

// Code for mapping numerical values

/*--------------------
Distance
--------------------*/

// Code to calculate the distance between two points

/*--------------------
Mouse
--------------------*/

// Code handling mouse movement and interactions with the bubble object

/*--------------------
Spring
--------------------*/

// Code for mouse click events and ripple effects

/*--------------------
Resize
--------------------*/

// Code to handle resizing of the canvas and updating camera aspect ratio

/*--------------------
Noise
--------------------*/

// Code for updating vertices based on noise and mouse position

/*--------------------
Animate
--------------------*/

// Main rendering loop and functions for animating the scene

/*--------------------
Helpers
--------------------*/

// Additional helper functions for creating ripples in the bubble geometry

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

What is the reason behind the NgForOf directive in Angular not supporting union types?

Within my component, I have defined a property array as follows: array: number[] | string[] = ['1', '2']; In the template, I am using ngFor to iterate over the elements of this array: <div *ngFor="let element of array"> ...

Why doesn't the div click event trigger when the mouse hovers over an iframe?

My dilemma involves a div element with a click event. When the div is positioned over an iframe area (closer to the user than the iframe), the click event fails to trigger. However, if the div is located elsewhere and not above the iframe, the click event ...

What methods can be used to extend the distance measurement with the help of Google Maps

I've searched online for the answer, but still haven't found it. I'm currently developing a website where users can search and select a location using the Google Geocoding API. Once the user chooses a place, I retrieve its bounds, but then ...

JavaScript for Detecting Hits

I have recently ventured into coding as a beginner, and I have already created a calculator using Javascript, HTML, and CSS. Currently, I am working on developing a platformer game using JavaScript and HTML. I have set up the player, obstacles, canvas, fra ...

When the bounds are adjusted, removing markers in Vue Cookbook's Google Map

I've encountered an issue with clearing markers after updating new bounds on a map. Whenever I post a request with new bounds, new markers get added to the map while the old ones remain in place. This situation becomes quite awkward for me because the ...

"Building a dynamic form with ReactJS, Redux Form, and Material UI - Implementing an

Currently working on a nested form framework that utilizes the redux form and material UI framework. The components have been developed up to this point - https://codesandbox.io/s/bold-sunset-uc4t5 My goal is to incorporate an autocomplete field into the ...

The query parameter is not defined in the router of my Next.js app API

I'm currently working on building an API endpoint for making DELETE requests to remove albums from a user's document in the MongoDB Atlas database. Struggling with an error that keeps popping up, indicating that the albumName property is undefin ...

Observable - transforming two promises into an observable stream

I am facing a common scenario where I am looking to chain two promises together in such a way that if the first promise fails, the second promise needs to be canceled. In the world of 'Promises', the code would look something like this: Fn1.doPr ...

Is there a way to retrieve the $state object from ui router in the console?

I attempted to modify the route from the console by using this method to access the $state object: $inject = angular.injector(['ng', 'ui.router']); $inject.get('$state').go Unfortunately, I encountered an error: Uncaught Er ...

What is the most efficient method for sending query parameters through a URL in Vue.js with Axios?

My goal is to use Axios upon page load to retrieve a JSON object from the base URL. When a button is clicked, I want to append query parameters to the URL and fetch a different JSON object. For example, if the base URL is 'test.com', clicking the ...

A step-by-step guide on extracting all documents within a directory collection from the official national archives website using the R programming language

I'm currently seeking a way to scrape all available files for a data file series on archive.gov programmatically using R. It seems that archives.gov utilizes JavaScript. My objective is to extract the URL of each available file along with its name. T ...

Enhancing the building matrix with JavaScript (or jQuery)

I have created a custom Javascript function for extracting specific data from a matrix. The main purpose of the function is to retrieve data based on dates within a given range. Here's how it works: The matrix[0][i] stores date values I need to extr ...

JS custom scrollbar thumb size issues in relation to the scroll width of the element

I recently implemented a custom scrollbar for a component on my website. To determine the length of the scrollbar thumb, I use the formula viewportWidth / element.scrollWidth;. This provides me with a percentage value that I then apply to the thumb elemen ...

I want to learn how to display the rupee symbol instead of the default dollar symbol in AngularJS for specific currency symbols

When using 'currency' in AngularJS, I noticed that a dollar symbol is displayed. How can I change this to show the required currency symbol based on different requirements? Currently, I am looking for information on how to display a rupee symbol ...

Is there a method to incorporate a scroll event into the ng-multi-selectdropdown, a npm package?

Query: I need to incorporate a scroll event in the given html code that triggers when the div is scrolled. However, I am facing issues with implementing a scroll event that works when the elements are being scrolled. <ng-mult ...

What is the reason for the Express middleware using parenthesis syntax, whereas custom-made middleware does not?

What is the reason behind Express inbuilt middleware using a parenthesis syntax like app.use(express.json()) while custom-made middleware does not use parentheses like app.use(logger)? It seems to throw an error with parentheses. I'm uncertain if th ...

Error: The code is trying to access the property 'string' of an undefined variable. To fix this issue, make sure to

I encountered an issue after installing the https://github.com/yuanyan/boron library. The error message I received is: TypeError: Cannot read property 'string' of undefined Error details: push../node_modules/boron/modalFactory.js.module.expor ...

Executing a class function within the ajax success method

I am attempting to set a variable inside the success callback of an AJAX call. I understand that in order to assign the value, I need to use a callback function. However, I want that function to be within the class. Is it feasible to implement something li ...

What steps can be taken to resolve webpage loading issues following data insertion into a database using express and node?

My express app has a post route handler (/addpost) for adding data to a database. Everything works perfectly, but the window keeps loading. To prevent the browser from waiting for more data, I know I need to send a response. However, all I want is for th ...

Retrieve JSON object based on its unique identifier from a different JSON file

I am working with 2 API resources: and it returns JSON data like this: { "id": 771, "title": "Call to Alyce Herman - Engine Assembler", "assigned_with_person_id": 317, } provides ...