Is there a way to transform this Three.js ConvexGeometry into a non-convex geometry?

While I have experience with Three.JS, my work has not involved meshes before. I believe that I am on the right track in solving my current issue, but I still have some uncertainties.

The Objective

My goal is to create a 3D blob-like object with specific vertices. The positions of these vertices are fixed, while their distances from the center vary. This object can be visualized as a radial 3D audio equalizer.

I am willing to reconsider my approach and explore other methods if there is an easier way to achieve this.

Current Status

I found this example and customized it to suit my requirements. Below is the HTML and JavaScript code:

HTML (disco-ball.html)

<!DOCTYPE html>
<html>
  <head>
    <title>Disco Ball</title>
    <script type="text/javascript" src="../libs/three.js"></script>
    <script type="text/javascript" src="../libs/stats.js"></script>
    <script type="text/javascript" src="../libs/ConvexGeometry.js"></script>
    <script type="text/javascript" src="../libs/dat.gui.js"></script>
    <style type='text/css'>
      body { margin: 0; overflow: hidden; }
    </style>
  </head>
  <body>

    <div id="Stats-output"></div>
    <div id="WebGL-output"></div>
    <script type="text/javascript" src="01-app.js"></script>
  </body>
</html>

And the JavaScript (01-app.js):

... (omitted for brevity) ...

Challenges Faced

  1. In the current setup, certain points on the "ball" have double the radius, creating large spikes. However, due to using ConvexGeometry, some points are hidden because the shape is convex. How can I utilize a non-convex geometry to avoid hiding these spiked points?
  2. I would like to refine the mesh by introducing some subdivision for smoother transitions instead of just straight connections between vertices. How can I achieve this to make the spikes appear more blended and less pointed?
  3. It's essential for me to modify the mesh so that different points exhibit varying levels of spiking at intervals (based on provided data arrays). Is there a way to alter the geometry post-creation, possibly incorporating tweening effects for gradual changes?

Thank you for any guidance or suggestions!

Answer №1

Revolutionizing Mesh Animations

If you aspire to infuse dynamism and fluidity into mesh animations, Three.js offers a rich tapestry of possibilities to explore. While the insights shared here offer valuable guidance, immersing oneself in the Three.js documentation is crucial for tailoring your approach to meet specific requirements.

Essentially, a mesh consists of 3D points and an index array delineating each triangle. Once the mesh is constructed, simple updates to vertices prompt Three.js to autonomously manage shader attributes and mesh normals.

Your Queries Resolved

Q1. Opt for utilizing Three.Geometry when manipulating meshes.

Q2. During mesh creation, consider incorporating curve helpers like Three.CubicBezierCurve3, Three.QuadraticBezierCurve3, or potentially Three.SplineCurve. Alternatively, employ a modifier to generate a basic mesh and leverage Three.js for subdivision. Reference this example.

While not the most efficient solution, it can handle lower vertex counts without compromising frame rate performance.

Q3. By making use of Three.Geometry, define mesh morph targets by specifying an array of vertices. Alternatively, utilize a modifier alongside direct vertex modifications during each frame.

for ( var i = 0, l = geometry.vertices.length; i < l; i ++ ) {
    geometry.vertices[ i ].x = ?;
    geometry.vertices[ i ].y = ?;
    geometry.vertices[ i ].z = ?;
}
mesh.geometry.verticesNeedUpdate = true;

Diverse Approaches Explored

An array of methods exists to create dynamic mesh animations, catering to varied loads and complexities. Devote time to perusing the documentation, experimenting, and exploring different avenues.

Proposed Action Plan

To inject vigor into the animation while veering away from conventional curves, introducing a polynomial curve such as f(x) = x^2/(x^2 + (1-x)^2) can yield captivating outcomes. Consider the following blueprint:

If managing the vertex count proves feasible, contemplate employing Three.BufferGeometry and adjusting verts on a per-frame basis. Focus on subdividing verts to align with the aforementioned polynomial curve for a distinctive effect.

Adjustment example for weighted points:

// Implementation details
const p1 = {x,y,z};
const p2 = {x,y,z};

const pw1 = {x, y, z, dx, dy, dz, w : 1/3, wa : 0.1,wd : 0.7};
const pw2 = {x, y, z, dx, dy, dz, w : 2/3, wa : 0.1,wd : 0.7};

pw1.w = Math.pow(pw1.w,2) / ( Math.pow(pw1.w,2) + Math.pow(1 - pw1.w,2));
pw2.w = Math.pow(pw2.w,2) / ( Math.pow(pw2.w,2) + Math.pow(1 - pw2.w,2));

// Update process for weighted points
// Adjust positions based on new deltas

Execute this for all weighted points before updating `geometry.vertices`.

Fine-tune the `wa` and `wd` coefficients to suit preferences, ensuring their sum remains below 1 for controlled oscillations.

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

When attempting to add mp3 files to a Vue/TypeScript application, a "Module not found" error is triggered

I am encountering an error while trying to import .mp3 files into my Vue/Typescript app. Upon running 'npm serve', I am presented with the following message: ERROR in /Users/***/***/application/src/components/Sampler.vue(80,16): 80:16 Cannot fin ...

What causes delays in the calculation of element heights and widths by jQuery's height() and width() methods?

Recently, I've encountered a performance issue with jQuery's height() and width() methods taking too long to calculate an element's height and width. How can I optimize these methods for Internet Explorer 8+, as well as the latest versions o ...

Is it possible to retrieve a class's array of properties without creating an instance of it?

It appears that there might be a way to accomplish this task by dynamically constructing a form based on a class definition (Angular) without being dependent on the specific class itself. This approach would allow for scalability, enabling the addition of ...

Node version 6.11.0 experiencing JavaScript heap error even with zero memory usage in the program

Encountering an out of memory error even though only two variables (i & j) are being used. Can someone please provide clarification? I am not storing anything in memory or saving it to any storage; whatever is generated is outputted to the console and the ...

Navigating through an array containing references to object IDs with Mongoose

In my meanjs project, I am receiving user input on the server with a specific request body structure: { transaction: { heading: '', items: [Object] }, something: {}, somethingAgain: {} } The format of the items a ...

Tips for creating a script to calculate the population count of a 16-bit integer with either php or javascript

Looking to write a function that calculates the population count of a 16-bit integer in either php or javascript? Population count refers to the number of "turned on" bits, essentially counting the number of ones in the binary representation. For example, ...

Which specific transitionend (or animationend) event should I use for this application?

I'm feeling a bit lost when it comes to using transitionend (or if I should be using animationend in this scenario). I'm not sure whether to utilize var, node, or box. Essentially, I am a complete beginner in this case. My goal is to have my div ...

Is there a reliable method to acquire a user's IP address even if they are using a proxy server or a similar technology?

In my quest for an answer, I've found that the solutions are not always straightforward. Is there a foolproof method to obtain a user's IP address even if they are using a proxy, Tor, etc? I am particularly interested in a solution using ASP.NET ...

What is the procedure for updating a state property's value?

Currently, I am in the process of developing a small application that has the ability to fetch data, display it in the DOM, and allow users to select an item to view detailed information about the chosen user. To manage all these functionalities, I am util ...

Insert item at the end of the box and move all elements upwards

Hello! I'm experimenting with creating something using javascript's createElement method. My goal is to achieve an effect similar to this image: https://i.stack.imgur.com/itKUK.gif Currently, my code is functional, but the animation goes from to ...

Send FormData as JSON object array using ReactStrap Form and Express server

Currently in the process of learning the MERN stack, I find myself navigating through React and Express for the first time. One of my tasks involves utilizing an API that I had previously set up to update JSON data using React. To accomplish this, I' ...

Need assistance as require function is not functioning as anticipated

const THREE = require('three'); require('three/examples/js/loaders/OBJLoader.js'); Once I imported threejs from node_modules, I decided to utilize the provided OBJLoader, but encountered an unexpected error. THREE is not defined a ...

Display a concealed text box upon clicking BOTH radio buttons as well as a button

Below is the HTML code for two radio buttons and a button: <body> <input data-image="small" type="radio" id="small" name="size" value="20" class="radios1"> <label for=&qu ...

Utilizing Vue: Attaching click event to dynamically added elements

I am working on a Vue application that retrieves HTML content from an API. This HTML contains blocks with the class <div class="play-video">...</div> Using axios to call the API and a promise, I insert the content into the DOM like this: < ...

steps to create a personalized installation button for PWA

Looking to incorporate a customized install button for my progressive web app directly on the site. I've researched various articles and attempted their solutions, which involve using beforeinstallprompt. let deferredPrompt; window.addEventListener(& ...

Issue encountered while submitting form on JQuery Mobile framework

Currently, I am in the process of developing a small web application utilizing JQuery Mobile and Multi Page architecture. The issue arises on my form as the second page. Upon clicking the submit button, an error message is displayed on my console (error i ...

Combine various canvases into a single one (for exporting purposes) with pure Javascript

I'm currently faced with a unique challenge involving the creation of around 200 canvases, each showcasing an image captured from the user's webcam as part of an experimentation process for the "photo finish" technique. My task now is to export ...

What is the best way to adjust the height and width of an mp4 video in Internet Explorer?

I came across a code snippet that looks like this video { object-fit:fill; } <!DOCTYPE html> <html> <body> <video width="800" height="240" controls> <source src="http://www.w3schools.com/tags/movie.mp4" type="video/mp4" ...

Unexpected issue encountered when working with JSON in Node.js

I've searched through countless solutions on stackoverflow, but none of them seem to work for me. It's really frustrating not understanding what's going wrong. Below is the code I'm having trouble with: var data = ""; req.on('dat ...

Rotate the cylinder according to the normal vector of the tube endpoint

I'm working on creating a curved 3D arrow using three.js. My approach involves using a Tube along a curved path and a Cone shaped cylinder. Here's how they currently look: https://i.sstatic.net/jmVB6.png https://i.sstatic.net/P756z.png My goal ...