Is it possible to set specific points within a Points object in THREE.js to be transparent or invisible?

I am working with a Three.js Points object that holds information for displaying multiple points in 3D space. I am looking for a way to dynamically hide certain points, but I am uncertain of the process.

The PointsMaterial used has xyz data stored in

pointsObj.geometry.attributes.position.array
and color data stored in
pointsObj.geometry.attributes.color.array
. However, I am unsure if it is feasible to adjust properties such as alpha value or visibility on an individual point basis (I can only make all points invisible at once).

Can anyone provide insight on whether this is possible?

Answer №1

Ensure that every point includes the color.array attribute, which can be directly modified.

var colors = pointsObj.geometry.attributes.color.array;

for (var i = 0; i < colors.length; i += 4) {
  if (shouldPointBeInvisible(i)) { //<-- implementation pending
    colors[i + 3] = 0; // Setting alpha value to 0 makes the point invisible
  }
}

pointsObj.geometry.attributes.color.needsUpdate = true;

-- Potentially with a shader material:

var material = new THREE.ShaderMaterial({
  uniforms: {
    visibility: { value: 1.0 }
  },
  vertexShader: `
    uniform float visibility;
    varying vec3 vColor;
    
    void main() {
      vColor = color;
      vColor.a *= visibility;
      gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
    }
  `,
  fragmentShader: `
    varying vec3 vColor;
    
    void main() {
      gl_FragColor = vec4(vColor, 1.0);
    }
  `
});

pointsObj.material = material;

...

if (shouldPointBeInvisible(i)) {
  pointsObj.material.uniforms.visibility.value = 0.0;
} else {
  pointsObj.material.uniforms.visibility.value = 1.0;
}

-- Another approach using PointsMaterial:

var material = new THREE.PointsMaterial({
size: 1,
transparent: true,
opacity: 1.0,
uniforms: {
visibility: { value: 1.0 }
},
vertexShader: `
uniform float visibility;
varying vec3 vColor;
void main() {
  vColor = color;
  vColor.a *= visibility;
  gl_PointSize = size;
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}

, fragmentShader: varying vec3 vColor;
`
});

pointsObj.material = material;

...

if (shouldPointBeInvisible(i)) {
pointsObj.material.uniforms.visibility.value = 0.0;
} else {
pointsObj.material.uniforms.visibility.value = 1.0;
}

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

Transfer an object to $state.go

I'm having trouble solving this issue. Here's the state I am working with: var myState:ng.ui.IState = <ng.ui.IState> { url: '/new/{order.orderNumber}', controller: 'OrderController', controll ...

Encountered an issue while trying to use Figma's spellchecker extension

Despite following the instructions in the readme carefully, I am facing difficulties running the Figma spellchecker extension. Executing npm run build goes smoothly. But when I try to run npm run spellcheck, I encounter an error message in the console: co ...

Error with Expression Engine: PHP function cannot be executed

I have been attempting to execute a PHP Script with ExpressionEngine tags using Ajax on my webpage. I followed the documentation and set up the PHP script accordingly, but it appears that I am unable to call the function in the PHP script. There must be so ...

The database did not respond, causing the API to resolve without sending a response for the specified endpoint (/api/dates). This could potentially lead to requests becoming stalled in Next

I have been attempting to retrieve a list of dates from my database in a straightforward manner, but unfortunately, I am not receiving any response (even after trying to log the response data to the console). The only feedback I seem to be getting when sel ...

Combining Express and React for seamless email sending functionality

Attempting to merge a React.js form with a backend setup using Express to send emails. Uncertain of the proper way to format the form body or which HTTP request method to utilize. React.js and Express.js are located in separate directories. express-mailer ...

Combining PHP, Javascript, and Ajax all in one powerful code snippet

Would it be considered poor coding practice to combine PHP, JavaScript, and AJAX in the same block of code? For example: <?php $randNum = rand(1,10) if ($randNum <= 5) { echo "Enemy got the jump on you! <script> enemyTurn() </script& ...

Press the button obscured by an image

Recently on my HTML website, I encountered an issue where I tried adding a transparent image over a button but found that I was unable to click on the button afterwards. The problem seems to be related to the following code snippet: #container { heigh ...

Tips for transforming code with the use of the then block in javascript, react, and cypress

In my code snippet below, I have several nested 'then' clauses. This code is used to test my JavaScript and React code with Cypress. { export const waitForItems = (retries, nrItems) => { cy.apiGetItems().then(items => { if(items ...

Styling Javascript Objects

[ [ {"path":"path2","value":"kkk"}, {"path":"path0","value":"uuu"}, {"path":"path1","value":"ppp"} ] ] The result obtained from my manipulation is shown above. However, I require the format to be as depicted below: ["path":"pat ...

"Encountering an error: invalid CSRF token in Node.js csurf

I have been utilizing the npm module csurf to generate a token. Initially, I retrieve the token from the server and then utilize it for the /register request. When I replicate these steps in Postman, everything seems to function correctly, but unfortunatel ...

I need to verify that the input type for time is valid, starting from today's date and extending beyond the current

<input type="date" onChange={(e)=>setDate(e.target.value)}/> <input type="time" onChange={(e)=>setTime(e.target.value)} /> If the selected date is after today and the time is after the current time, display a valida ...

Ajax requests that are delayed to the same URL with identical data

While waiting for the back end developers to add a "cancel all" function, which would cancel all tasks tracked by the system, I am trying to create a workaround by cancelling each task individually. The cancellation REST service requires an ID in the form ...

Webpack bundling, however, encountering issues with resolving TypeScript from the node_modules package

Hey everyone, I've been exploring various approaches to tackle this issue. We are working with two folders within a makeshift mono-repo structure (without using yarn workspace). One folder is named Mgt-Shared and the other is Server. We have set up a ...

Dealing with errors in AngularJS factory servicesTips for managing errors that occur

Factory code app.factory('abcFactory', function ($http, Config, $log) { var serviceURL = Config.baseURL + '/results'; return{ results:function() { var promise = $http({ method: 'GET&apos ...

What exactly sets one string apart from another? (JavaScript)

Is it possible to use JavaScript to detect the specific part of strings that makes them different from each other? For example, consider the following three strings: String1 = "Java1String" String2 = "Java2String" String3 = "Java3String" If String1 is t ...

Error in Sequelize and Express JS: Cannot access undefined properties while attempting to read 'findAll'

I am currently facing an issue while working with Express JS and Sequelize in connection to a MSSQL database. The error message "Cannot read properties of undefined (reading 'findAll')" is blocking me from making any requests. Can anyone provide ...

Tips for transferring a list via ajax to a controller

Having a controller as follows.. public ActionResult Report(List<string> invoiceIds) and utilizing an ajax call like this... function generateAccountsPayableReports() { var ms = $("#msInvoicesAPV").data("kendoMultiSelect"); var invoices = ...

Using AngularJS to create a form and showcase JSON information

My code is below: PizzaStore.html: <!DOCTYPE html> <html ng-app="PizzaApp"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Delicious pizza for all!</title> ...

When implementing a TypeScript interface, there is no method parameter checking performed

interface IConverter { convert(value: number): string } class Converter implements IConverter { convert(): string { // no error? return ''; } } const v1: IConverter = new Converter(); const v2: Converter = new Converter(); ...

Efficiently managing repeated records in NodeJS using loops

I am trying to retrieve sales records for specific products from a table in my database based on client ID. This is how I attempted to achieve it: public async getData(clientID: any): Promise<any> { try { return await client .scan( ...