Are you expecting an icosahedron particle system in three.js but only seeing squares instead?

I am new to three.js and I'm working on a project to create a solar system. I need a particle system where the particles are icosahedrons. Following a tutorial, I used the following function to create a particle system:

function createParticleSystem() {

    var particleCount = 2000;

    var particles = new THREE.IcosahedronGeometry(1, 0);

    for (var p = 0; p < particleCount; p++) {
        var x = Math.random() * 400 - 200;
        var y = Math.random() * 400 - 200;
        var z = Math.random() * 400 - 200;
        
        var particle = new THREE.Vector3(x, y, z);
        
        particles.vertices.push(particle);
    }

    var particleMaterial = new THREE.PointsMaterial(
            {color: 0xffffff, 
             size: 4,
             shading: THREE.FlatShading,
             blending: THREE.AdditiveBlending,
             transparent: true,
            });

    var partMaterial2 = new THREE.MeshPhongMaterial({ color: 0xffffff, shading: THREE.FlatShading, vertexColors: THREE.VertexColors, shininess: 0   } );

    particleSystem = new THREE.Points(particles, particleMaterial);

    return particleSystem;  
}

After implementing this code, my particles are appearing as flat white squares instead of icosahedrons. Changing the material to MeshPhongMaterial causes rendering issues. How can I resolve this and achieve Icosahedron particles?

Answer №1

(Apologies for the delay.) The IcosahedronGeometry has vertices, which are typically not set individually. Instead, vertices of Points and Lines are commonly set. It appears that most other elements are created as meshes. (I am hopeful for a clearer explanation from someone else.)

For creating points:

geometry = new THREE.Geometry(); 
material = new THREE.PointsMaterial( { color:0xffffff, size:1 } );
geometry.vertices.push( // insert your points here
var object3d = new THREE.Points(geometry, material);
scene.add(object3d);

To create line segments:

geometry = new THREE.Geometry();
geometry.vertices.push( // add your line end points
material = new THREE.LineBasicMaterial( { color:0xffffff } );
object3d = new THREE.Line(geometry, material);
scene.add(object3d);

For generating Icosahedrons or any mesh:

for (var i1=0; i1<N; i1+=1) { 
  geometry = new THREE.IcosahedronGeometry(1); 
  material = new THREE.MeshPhongMaterial( { color:0xffffff, shading:THREE.FlatShading } );
  material.side = THREE.DoubleSide;
  mesh= new THREE.Mesh(geometry, material);
  mesh.position.set(x, y, z);
  scene.add(mesh);
}

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

React JS currently throws an error stating that the variable 'state' is not recognized and is therefore undefined (no-undef

As I dive into learning ReactJS, I encountered an error message stating that 'state' is not defined (no-undef). I am currently using React version "react": "^16.8.6". When attempting to address this by adding this.state, I was met with the follow ...

What are some methods to prevent cookies from being overridden?

Just beginning my journey in web development. Currently utilizing asp.net Web API and Angular with token authentication. Every time a user logs in, I set the token in a cookie and send it with each request. Everything has been running smoothly so far, bu ...

Transfer the html div element to the ajax request

My server-side code runs multiple bigquery queries and organizes the results in a table. The client calls this code via an ajax request. I want to send the table/div generated by the server-side code to the client so that it can be rendered there. Is this ...

Is there a way to customize the width of a Twitter Bootstrap modal box?

I attempted the following: <div class="modal hide fade modal-admin" id="testModal" style="display: none;"> <div class="modal-header"> <a data-dismiss="modal" class="close">×</a> <h3 id='dialo ...

Saving a collection of unique identifiers in Firebase

Struggling to find a solution for organizing Firebase data: Each user has posts with generated IDs, but how do I store these IDs in a user node efficiently? Currently using string concatenation and treating them like a CSV file in my JS app, but that feel ...

The art of spinning objects in Three.js

Currently experimenting with creating a basic multi-resolution panorama in Three.js. Successfully implemented the cubic projection using the following code: mesh = new THREE.Mesh(new THREE.BoxGeometry(512, 512, 512, 20, 20, 10, 10), new THREE.MeshFaceMat ...

How to round whole numbers to whole numbers using JavaScript?

Looking to manipulate some numbers in JavaScript. Let's say we have x = 320232, y = 2301, and z = 12020305. The goal is to round these numbers to the nearest tens, hundreds, or thousands place. Thus, we want them to become x = 320000, y = 2300, and z ...

Creating a method in Angular that combines async/await functionality with Observables

After transitioning from using async/await to Observables in Angular, I am trying to refactor the following code snippet to make it work with Observables: async refreshToken() { const headers = this.authStorage.getRequestHeader(); const body = { ...

The context is undefined through which the state was passed

I am currently facing an issue with my context setup. When I pass a string as a property to the state, everything works perfectly. However, I intend to use a prop as the state. Here is what works: export class DataProvider extends Component { construct ...

How can I iterate through each element of MySelector in the callback function of jquery-ui's draggable function?

When using: jQuery(MySelector).dragabble( start: function( e, ui ) { } ) In the start function: The start event provides $(this) with the current dragged element from MySelector. How can I loop through each element in MySelector to apply additional code ...

Steps for closing a modal popup in Asp.NET WebForms after saving data

I have implemented javascript code on my main page that triggers a popup when a link is clicked: <script language="javascript"> function OpenResidentialAddressWin(subscriberContactRelationGid, routeId, btn) { window.showModalDialog("Subscribe ...

What is causing the [object%20Object] to appear in my URL during the API call?

I feel stuck with my coding assignment. Can anyone lend a hand? class Settings extends Component { render(){ return( <div className='App container'> <h3>Pick Your Preferred Currency</h3> <select class ...

The (auth) cookie set on a Cross Site server is not utilized in jQuery/Ajax requests made to that server

We are encountering issues with a web page that retrieves data from an external server. The page is being loaded "locally" (specifically, from the file system as part of a phonegap application in Firefox/Chrome) and utilizes jQuery and AJAX for fetching da ...

NPM is currently malfunctioning and displaying the following error message: npm ERR! 404

When running npm update -g, the following error occurs: npm ERR! code E404 npm ERR! 404 Not found : default-html-example npm ERR! 404 npm ERR! 404 'default-html-example' is not in the npm registry. npm ERR! 404 You should bug the author to publi ...

Error: Unsuitable texture dimensions for the source - WebGL video not supported in Chrome

Recently I encountered a strange issue with Chrome where a video that has been working perfectly fine for a long time suddenly started showing as black. The rendering process also generated the following error: The video resolution is 1920x1080 [.Offsc ...

What is the best way to utilize AJAX to access a URL, not receive a response, and solely manipulate HTML content on the

Should I use AJAX for this issue? Let me know! Here's the problem: Let's say I'm utilizing Zend Framework. I have a table filled with various entries from a database, each row having a delete button. The structure looks like this: [...] ...

Possible scope problem causing AngularJS image preview not showing up in ng-repeat loop

I came across this question and made some modifications. It works well when used outside of the ng-repeat. However, I'm facing issues when trying to use it within my repeat loop; the image.src does not update. I believe this is more related to the sc ...

Angular - the utilization of expressions in view templates

Exploring Angular for the first time and attempting to create a Single Page Application (SPA). I have included the route module, which seems to be functioning properly. However, the templates are not interpreting Angular expressions as expected - for examp ...

What is the method for setting the current time as the default in a time picker?

Below is a snippet of code where I attempt to implement a date picker and set the current time as the default value. .HTML <input type="time" [(ngModel)]="time"> .TS time; constructor() { this.time= new Date(); } ...

Mastering the art of bi-directional data binding with nested arrays in Angular

Imagine you have a to-do list with various tasks, each containing multiple subtasks. You want the ability to change the subtask data, but why is Angular not properly two-way binding the data for the subtasks? HTML <div *ngFor="let task of tasks"> ...