Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
Optimize rendering large of objects in p5js

I am trying to create a scene using p5.js that creates many different objects in 3d space. It works fine for a small number of objects but slows down really badly for thousands of objects. The objects and their relative positions will remain the same so I was wondering if it's possible to render once and then only rotate the view angle or control with the mouse without having to draw every single object again for every single draw iteration. I have tired noloop and creating the objects outside the draw loop and the perspective change within the draw loop but the scene remains static. Many thanks in advance!

var Sz = 300;
var N = 1000;
var x = [];
var y = [];
var z = [];
// noprotect

function setup() {
  createCanvas(windowWidth, windowHeight, WEBGL);
  background(0);

  for (var i = 0; i < N; i++) {
    x[i] = random(-Sz, Sz);
    y[i] = random(-Sz, Sz);
    z[i] = random(-Sz, Sz);
  }
}

function draw() {
  background(0, 0, 0);
  //translate(0,0,-100);
  rotateY(frameCount * 0.01);
  rotateX(frameCount * 0.01);
  rotateZ(frameCount * 0.01);
  orbitControl();

  for (var i = 0; i < N; i++) {
    push();
    translate(x[i], y[i], z[i]);
    R = 255 * abs(x[i] / max(x));
    G = 255 * abs(y[i] / max(y));
    B = 255 * abs(z[i] / max(z));
    stroke(R, G, B);
    sphere(Sz / 50, 8);
    pop();
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can start looking into Three.js or other WebGL libraries if you need this kind of control or optimization.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!