Give each point a distinctive color in Three.js

For each point, I have both position coordinates and color values represented as (r, g, b). My goal is to assign a unique color to each individual point. Here is the approach I took:

    const vertices = new Float32Array(data.points);
    const colors = new Float32Array(data.colors)
    geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
    geometry.setAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
    const material = new THREE.PointsMaterial({color: colors});
    const pointCloud = new THREE.Points( geometry, material)
    this.scene.clear();
    this.scene.add( pointCloud );
    this.renderer.render(this.scene, this.camera);

However, when using this method, all my points appear white. So, I attempted an alternative solution:

const material = new THREE.PointsMaterial( { vertexColors: true } );

But, unfortunately, it resulted in the following error message:

[.WebGL-0x2e2bb1a84c00]GL ERROR :GL_INVALID_OPERATION : glDrawArrays: attempt to access out of range vertices in attribute 1

Answer №1

Thanks so much! Initially, I had to work with color values ranging from 0 to 1 instead of the usual 0 to 255. Additionally, it was crucial for me to have arrays of equal length and incorporate the { vertexColors: true } parameter.

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

Error in MongooseJS Route Error: Strange Casting Issue

I'm currently working on the backend and facing an issue with a specific route intended to return an array of IDs from the database for lazy loading purposes. The route is set up as follows: router.get('/list', (req, res) => { Inside ...

JQuery and Fancybox causing issues when triggered on Internet Explorer 8

I am experiencing an issue with my jQuery code on my webpage. It works perfectly fine in Chrome, but I encounter an error in Internet Explorer 8 specifically in the trigger('click') line. $('#btnd16').click(function(e){ var iiid = ...

What is the most effective way to redirect users accessing from Android devices?

Attempting to send all Android users to a designated page. I attempted this method using php, but uncertain of its reliability. Need assurance that it will work for all possible Android devices. Thoughts on the safety of this approach? <?php $user_ag ...

Create a circle-shaped floor in THREE.JS that mimics the appearance of a shadow

I am working on creating a circle mesh with a gradient material that resembles a shadow effect. Specifically, I want the circle to have a black center and fade to almost white at the edges. Currently, I have been able to create a circle and position it co ...

Is your toggleclass button suffering from technical difficulties?

Why am I having trouble toggling the box with the button? I want it to maintain its current functionality and also toggle the box as well. Check out my JS fiddle for reference. Here's my code snippet: $(function timelinetiles() { $('.timeline ...

The process of transforming XML data into JSON format

Currently, I am utilizing the xml2json library to convert an XML payload into JSON format. However, I have encountered the following issue: When my code looks like this: var xml = <Stat />; var obj = xml2json.toJson(xml, {}); The value of obj["St ...

Setting the initial state value in Gatsby according to the static query result: a step-by-step guide

I am currently working on developing a video filtering user interface. The UI will consist of a grid displaying videos and some filter options in the sidebar. The videos are stored as items/objects in an array that I retrieve from a Gatsby static query. O ...

Issue with the compatibility of the datepicker and autocomplete features in jQuery

Separately, the code below works on different PHP pages. However, when combining them on one page, nothing seems to work. In Firebug, the error message reads: TypeError: $(...).datepicker is not a function $("#test1").datepicker({ DATEPICKER CODE & ...

The server encountered an issue: 415 Unsupported Media Type. JSON data was not loaded as the Content-Type in the request was not 'application/json'

I'm currently working on a React-Python(Flask) project and encountering an error in the backend: '415 Unsupported Media Type: Did not attempt to load JSON data because the request Content-Type was not 'application/json'. the frontend ...

The function for the Protractor promise is not defined

UPDATE: After some troubleshooting, I believe I have identified the issue causing it not to work. It seems that I am unable to pass arguments along when calling flow.execute(getSpendermeldung). Does anyone have a better solution than wrapping the ApiCall i ...

Something strange happening with the HTML received after making a jQuery AJAX request

My PHP form handler script echoes out some HTML, which is called by my AJAX call. Below is the jQuery code for this AJAX call: $(function() { $('#file').bind("change", function() { var formData = new FormData(); //loop to add ...

Wrap the content with a div at the beginning and at the end

Hello, I am currently working on implementing the following structure: <div class="content"> <img src="/"> <img src="/"> <div class="slideshow"> <img src="/"><img src="/"><img src="/"></div> ...

The unexpected disappearance of data in a d3 v4 map leaves users puzzled

My current task involves reading data from a csv file and creating a map where the key is the state abbreviation and the value is the frequency of that state in the data. The code I have successfully creates the map, reads in the data, and when I use cons ...

Looking to find the length of a word within a txt file using jQuery?

I'm facing an issue with parsing text from a file. The file in question can be accessed via the following link: File: google-books-common-words.txt [1] Word => 'THE' USED => 53097401461 [2] Word => 'OF' USED => 3096 ...

creating a function within an object that allows for chaining

My goal is to create a chainable object, but I am struggling to implement this in a function. This is the functionality I desire: $donate.ga('testing').go(value); The code for my object currently appears as follows: var $donate = { ga: fu ...

Tips for developing a directive that supplies values for ng-options

I have select elements with the same options throughout the entire app, but they may vary in appearance. For example, selects for a user's birthday (day, month, year). Is it possible to create a directive that can provide values or expressions for ng ...

executing a hook within _app.tsx in Next.js

The issue I'm facing involves the rendering of a hook that helps determine if my components are within the screen's view to trigger animations. This hook is executed in _app.tsx, however, it doesn't run when switching to another page. Oddly ...

Disabling functionality is not working properly when multiple expressions are added

One specific scenario involves using a radio button for selecting options and requiring users to confirm their selection using the JavaScript confirm method before enabling the next button. Take a look at the following code: HTML <body ng-controller ...

When you click on the text, it vanishes, but when you enter new text,

As I create my very first landing page, I aim for a simple and not too professional design to familiarize myself with building web pages independently. However, I am facing an issue where the text disappears when a user clicks on the textbox. The problem ...

Utilize a WCF Service with HTML and JavaScript

FILE WebService.svc.vb Public Class WebService Implements IWebService Public Function Greetings(ByVal name As String) As String Implements IWebService.Greetings Return "Greetings, dear " & name End Function End Class FILE IWebServ ...