The normal rendering in a THREE.Points Geometry is not functioning properly in three.js

Recently delving into the world of threejs, I find myself faced with a project that demands rendering a point cloud using three.js through the Qt5 Canvas3D. Following the examples on threejs.org, I opt for a BufferGeometry where I set the attributes (position and normal) and then encapsulate it with THREE.Points and THREE.PointsMaterial. While this successfully allows me to display the points in the scene, I'm encountering an issue where the normals set on each vertex appear to be disregarded. Here's a snippet of the code I'm dealing with:

var vertexPositions = [
[10, 10, 0, 1, 0, 0],
[10, -10, 0, 1, 0, 0],
[-10, -10, 0, 1, 0, 0]
];
geometry = new THREE.BufferGeometry();
var vertices = new Float32Array(vertexPositions.length * 3);
for (var i = 0; i < vertexPositions.length; i++) {
    vertices[i * 3 + 0] = vertexPositions[i][0];
    vertices[i * 3 + 1] = vertexPositions[i][1];
    vertices[i * 3 + 2] = vertexPositions[i][2];
}
var normals = new Float32Array(vertexPositions.length * 3);
for (i = 0; i < vertexPositions.length; i++) {
    normals[i * 3 + 0] = vertexPositions[i][3];
    normals[i * 3 + 1] = vertexPositions[i][4];
    normals[i * 3 + 2] = vertexPositions[i][5];
}
var colors = new Float32Array(vertexPositions.length * 3);
for (i = 0; i < vertexPositions.length; i++) {
    colors[i * 3 + 0] = 1;
    colors[i * 3 + 1] = 0;
    colors[i * 3 + 2] = 0;
}
geometry.addAttribute('position', new THREE.BufferAttribute(vertices, 3));
geometry.addAttribute('normal', new THREE.BufferAttribute(normals, 3));
geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3));
material = new THREE.PointsMaterial({size: 50, vertexColors: THREE.VertexColors});

mesh = new THREE.Points(geometry, material);
scene.add(mesh);

My quest now is to figure out how to successfully render the point cloud with normals set on the vertices. What might I be overlooking or missing in my approach? Any guidance or suggestions on this conundrum would be deeply appreciated. Many thanks in advance!

Answer №1

If you're looking to display a point cloud that interacts with lighting, you'll need to create a specialized ShaderMaterial.

Check out this answer for an example of a custom ShaderMaterial designed for use with THREE.Points.

Version: three.js r.75

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

<dt> and <dd> have not been added after the previous element

I can't seem to figure out why the dt and dd elements are not being added to the dl I created. Here's my initial attempt: // Dictionary list var words = [ { term: "Procrastination", definition: "Pathological tendency to s ...

Guide on passing variables along the promise chain within a Node Express router

Upon reflection, I realized the difficulty of injecting or utilizing a variable inside the Promise scope without a surrounding object or a "this" reference to attach it to. ...

Achieving optimal performance with scoped CSS in Vue.js

As I work on creating a new app using VueJs, I have noticed the implementation of "css scoped" as shown below: <style scoped> .example { color: red; } </style> <template> <div class="example">hi</div> </template> ...

The passport local strategy functions properly when tested with Postman, but encounters a "missing credentials" error when used with axios

I am currently working on creating a login system using passport and a local strategy. Strangely, when I attempt to send the request through axios it doesn't seem to work, although it functions properly with Postman. When using axios, I receive an er ...

Utilize MaterialUI Grid to define custom styles for the ::after pseudo-element

I came across a helpful article on Stack Overflow about Flex-box and how to align the last row to the grid. I'm interested in implementing it in my project: .grid::after { content: ""; flex: auto; } However, I'm not sure how to inc ...

Difficulties encountered when trying to create a basic timeline using Moment JS

I'm in the process of developing a straightforward report that retrieves entries through an ajax request and I aim to organize my entries by the day of the week. My desired output would look something like this: ---------------------------------- Mon ...

JavaScript: set values to elements in an array

Below is the code snippet I am working with: function gotData(data){ result = data.val() const urls_kws = Object.keys(result) .filter(key => result[key].last_res > 10) var keywords = urls_kws; c ...

Utilize AngularJS to modify the appearance of text

Just starting out with AngularJS and I need to achieve the following task. I have a text that says "bob" and two buttons, one for bold and one for italic. When the bold button is clicked, I want to make the text BOB bold and when the italic button is click ...

Guide to converting a specific tag into div using Javascript

I am working with some HTML code that includes a div: <div class="myDiv"> <a href="" title="">My link</a> <p>This is a paragraph</p> <script>//This is a script</script> </div> Additionally, I ha ...

Setting the z-index for Bootstrap dropdown menus on containers that are generated dynamically

When using the Bootstrap 3 dropdown-menu within a dynamically generated container, I am encountering an issue where the dropdown-menu appears behind the newly created elements. Please refer to the image for visual clarification. The container item has pos ...

Contrasting methods of adding a value to an array state in React

Can you advise me on the most effective method for inserting a value into an array, as well as explain the distinctions between these two code examples? setOtoValue((current) => [ ...current, Buffer.from(arraybuf, 'binary').toString(' ...

Installing Yarn causes the download of an unconventional directory

Currently, I am facing an issue while trying to install yarn on my Macbook Pro (2017). The installation process seems to be downloading a folder called /react-praktis/ instead of completing successfully. Below is a screenshot for reference: https://i.stac ...

Switch the view to a grid layout upon clicking

Using bootstrap 5, I've successfully created a list view: <div class="col"> Click to switch to grid/list </div> Below is the content list: <div class="row mt-3 list"> list view ... ..... ....... </div ...

The jQuery functions are unable to function properly when retrieving AJAX data

I am currently working on a script that inserts a record into my database using AJAX. After inserting the data, it is posted back in the following format... Print "<li>"; Print "<span class='cost'>" . $bill. "</span> "; Print ...

How to display (fade in a portion of an image) using .SVG

I have the following code in my DOM: <div class="icon-animated"><img src="icon_non_active.svg" id="icon_non_active"></div> There are two icons (.svg) available: icon_non_active & icon_active Can I animate the transformation from i ...

How to remove a loop-rendered component from the DOM in Vue

My website has an image upload form where users can select multiple images. Once the images are selected, they are previewed and users can provide meta info such as Category and Type for each image. This functionality is implemented in the upload.vue file ...

Exploring the world of Restify: Mastering the art of sending POST

Having trouble reading the body of a request while trying to create an API with Restify. Snippet from main.js: 'use strict'; const perfy = require('perfy'); perfy.start('startup'); const restify = require('rest ...

The type 'Event' argument cannot be assigned to the 'InfiniteScrollCustomEvent' parameter

I'm facing an issue with Ionic Angular. Here is my movies.page.html: <ion-header> <ion-toolbar color="primary"> <ion-title>Trending Movies</ion-title> </ion-toolbar> </ion-header> <ion-content ...

Is there a way to replicate a DIV and its contents in ASP.NET using C#?

I am looking to create a form that can duplicate or clone itself when the CPF/CNPJ (Brazilian personal identification) onchange. Below is the current code I have: <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" r ...

Question about using React, NPM, Vite, Babel, and Node.js together

I want to confirm my understanding. So, if I decide to create a react 'app' and incorporate babel for jsx support. Then, I opt for vite for enhanced development runtime and packaging. Lastly, I utilize node.js to execute my code. To sum it up, ...