Displaying spherical objects (or individual points) within a particle network

In my project, I am utilizing the Three.JS library to showcase a point cloud on a web browser. The point cloud is created once at the beginning and remains static with no additional points being added or removed. However, it does require functionality for rotation, panning, and zooming. I have referred to a tutorial on creating particles in Three.js which has been quite helpful here

Upon experimentating with the example provided, I was able to generate particles in the form of squares or utilize an image of a sphere as a texture. While the image option aligns more closely with my vision, I am curious if it is feasible to produce the point clouds without relying on an image, such as using a sphere geometry.

One issue encountered with using images is that when dealing with a large number of points, they tend to overlap each other around the edges, presumably due to the black region in a point's PNG file blocking the underlying image right behind the current point (though transparent to points farther back).

To address this overlapping concern, I made attempts to swap out particles = new THREE.Geometry() with

THREE.SphereGeometry(radius, segments, rings)
, aiming to alter the vertices into spheres.

Therefore, my query is how can I tweak the sample code to render spheres (or points) instead of squares? Additionally, I am uncertain whether a particle system remains the most efficient choice for my specific scenario, or would it be better to directly generate the particles and set their individual positions. It's worth noting that the points are generated only once, following which they are subjected to rotation, zooming, and panning (utilizing the TrackBall sample code for mouse event integration).

I appreciate any guidance you can provide.

Answer №1

Using a particle system instead of rendering a point cloud with spheres can greatly improve efficiency. You could utilize a texture or a small canvas program to draw circles for a more optimized approach.

Take a look at one of the initial examples in three.js that employs a canvas program:

var PI2 = Math.PI * 2;
var program = function ( context )
{
    context.beginPath();
    context.arc( 0, 0, 1, 0, PI2, true );
    context.closePath();
    context.fill();    
};
var particle = new THREE.Particle( new THREE.ParticleCanvasMaterial( {
    color: Math.random() * 0x808008 + 0x808080,
    program: program
} ) );

Feel free to modify the code for use with the WebGL renderer.

Another innovative approach I've come across in the examples is utilizing an encoded webm video to store data and passing it to a GLSL shader for rendering through a particle system in three.js

If you are working with a Kinect-generated point cloud, these resources may be helpful:

  1. DepthCam
  2. KinectJS

Answer №2

Upon reviewing my code in comparison to this example on the Three.js website, I noticed one key discrepancy:

vec4 outColor = texture2D( texture, gl_PointCoord );
if ( outColor.a < 0.5 ) discard;
gl_FragColor = outColor;

Including this snippet in the fragment shader resolved the issue.

The problem was not related to z-fighting as some corners were mysteriously overlapping distant particles. material.alphaTest = 0.5 failed to resolve it, and disabling depth writes/tests caused visual scrambling in terms of object rendering order.

Answer №3

An issue with the image arises when there are numerous points, as they can sometimes block each other along the edges. It appears that the black region in a point's png file obstructs the immediate area behind the point, but not those further away.

To solve the problem of overlapping transparency in the background square structure, you can disable

depthTest:false

However, this may lead to issues if additional objects are added to the scene, as the depth-testing will fail and the PointCloud may end up rendering in front of other objects regardless of their actual order. To address this, you can also disable

depthWrite:false

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

Ways to establish a default option in a dropdown menu using JavaScript

I am currently attempting to link a JSON object to a dropdown in the following manner: JSON data "securityQuestions": [ "First Pet's Name", "City I was born in", "Mother's Maiden Name", "Favorite teacher's Name" ] This i ...

Ways to ensure CSS affects icon inside main element?

Struggling to match the background color of Material-UI icons with the rest of the list items on hover. The CSS is not applying to both the icon and text despite styling the overall class (className= "dd-content-item"). Any assistance would be greatly appr ...

Navigating through an array of objects with Node.js

Recently, I integrated the ChartJS library into my Node web app to visualize data. The following is nested in a script tag on an EJS template page: <script> let playerStatChart = new Chart(myChart, { type: 'bar', data: { la ...

The Ajax readyState consistently displaying a value of 0

I am encountering an issue with my Ajax code as it always returns 0 when I access 'readyState'. I have not been able to identify the source of the problem yet. Any assistance on this matter would be greatly appreciated: var xhr = null; function ...

It appears that the collection.add() method in connector/node.js only successfully executes one time

Currently, I am experimenting with MySQL Document Store to compare it with our relational tables. To achieve this comparison, I am working on transforming our existing table into a collection. The table contains approximately 320K records that I need to ...

Using JavaScript to Generate Formatting Tags Based on User Selections from a Multiselect Dropdown

When a user selects formatting options (such as bold, italic, underline) from a multiselect dropdown, I need to generate corresponding formatting tags. For example, if the user selects bold and italic, I should create a tag like <b><i></i&g ...

Converting a TypeScript class to a plain JavaScript object using class-transformer

I have a few instances of TypeScript classes in my Angular app that I need to save to Firebase. However, Firebase does not support custom classes, so I stumbled upon this library: https://github.com/typestack/class-transformer which seems to be a good fit ...

What could be the reason for the Express function Router() returning a value of undefined?

Currently, I am working with TypeScript and Express to develop an API that adheres to the principles of Clean Architecture. To organize my application, I have structured each route in separate folders and then imported them all into an index.ts file where ...

MongoDB not being updated

Currently, I am a student delving into the world of full-stack JavaScript development. One resource that I have found particularly helpful is a LinkedIn course where the project involves creating a blog with an "upvoting" feature. However, I have encounter ...

Transferring variables from the $(document).ready(function(){}) to the $(window).load(function(){} allows for seamless and

Just think about if I successfully create percent_pass at the time of document.ready, how can I transfer that variable to window.load? $(document).ready(function() { jQuery(function() { var ques_count = $('.question-body').length; va ...

JS Tips for using the .push() function with Multidimensional Arrays in JavaScript

After coming across this code example online, I decided to give it a try. The code snippet involved using the JavaScript array push method to add new elements to an inner sub-array, which was exactly what I needed to achieve! The code successfully demons ...

Divide the array of words into segments based on the maximum character limit

I am looking for a way to divide an array of words into chunks based on a maximum number of characters: const maxChar = 50 const arrOfWords =['Emma','Woodhouse,','handsome,','clever,','and','rich,&apo ...

Webpack is ejected from watch mode

Currently, I am in the process of learning React and have decided to use webpack alongside it. However, I seem to be facing an issue with webpack when it comes to the watch mode. It builds the files once but then halts. The console output reflects the foll ...

Remove all Visual Composer Shortcodes while preserving the content

I'm in the process of transferring 200 posts from a previous WordPress website, which contain numerous visual composer shortcodes within the content. Is there a method to remove all the shortcodes and retain the content? ...

Embed the Nest API into your HTML5 code

My mobile HTML5 application includes a script in the index.html file. Nest.js (code below) Whenever I run my application, I encounter an error stating that Firebase is not defined. This is odd because the function seems simple: --> var dataRef = new ...

Implementing the decrement functionality within an onclick event handler for a variable

Can someone assist me with this issue? I am trying to use a variable ID in HTML to call a function on a JavaScript page. For example: (Minus button not functioning) <button class="minus-button quantity-button button" type="button" name="subtract" onc ...

Alter the component and then refresh it

I am encountering an issue with a component that has an event handler for a "like" icon. The goal is to allow users to click the like icon, update the database to indicate their liking of the item, and then re-render the component to visually reflect this ...

issue with react prop causing my function to function in one scenario but fail in another

I'm a bit confused with these two functions. Although they seem identical to me, only the first one is able to generate images from this.state.images. Any guidance on this seemingly small mistake would be much appreciated. The following code snippet ...

The transition from material-ui v3 to v4 results in a redux form Field component error stating 'invalid prop component.'

Since upgrading from material-ui v3 to v4, I am encountering an error with all my <Field> components that have the component prop. Error: Warning: Failed prop type: Invalid prop component supplied to Field. The Field component is imported from im ...

Why doesn't the 'javascript' named directory have access to my localhost?

My Ubuntu 16.04 system is running Apache 2.4.18. Recently, I created a directory called "javascript" within /var/www/html and added an HTML file to it. However, when attempting to access the file via localhost/javascript/, I received the following error me ...