Ice101781
Ice101781

Reputation: 105

How can I model thousands of stars in THREE.js without resorting to a particle system?

Ideally, I'd like to be able to model about 10,000 stars on screen at once. I also want to be able to specify individual characteristics such as size and color. I've tried using SphereGeometry() and creating a separate mesh for each star, but I can't even get the scene to render with that approach. A particle system works, but then color/size is uniform, and the result is a scene that doesn't look realistic enough. Any ideas? Thanks in advance.

Upvotes: 1

Views: 363

Answers (1)

Samuel Goodell
Samuel Goodell

Reputation: 630

A particle system is ideal for this kind of situation because of the performance benefits.

It may be possible to achieve the effect you want using multiple particle systems, and some logic that creates them with different attributes such as size and color, for example:

var systems = {};

function findOrGenerate(size, color) {
    return systems[size + "x" + color] || (function() {
        var system = new ParticleSystem(size, color);

        systems[system] = system;

        return system;
    })();
}

function ParticleSystem(size, color) {
    this.size = size;
    this.color = color;

    return this;
}

ParticleSystem.prototype.toString = function() {
    return this.size + "x" + this.color;
};

Upvotes: 3

Related Questions