Cannot specify sphereDetail when using createShape SPHERE

When creating a sphere() you are able to specify the number of vertices it has if you previously call sphereDetail(). However seems that there is no way to specify the detail when using createShape(SPHERE, size).

Does anyone knows a way to set it? I want to create a bunch of spheres and storing them in PShapes seems more performant than doing a lot of sphere() calls

I checked the source code but couldn’t find anything. Niether trying createShape(SPHERE with more params (brute force)

1 Like

Hi @danieltorrer,

The way of specifying sphere detail is the same as with sphere.

PShape shp;

void setup() {
  size(256, 256, P3D);
  sphereDetail(4, 3);
  shp = createShape(SPHERE, 100.0);
}

void draw() {
  background(#ffffff);
  camera(0, 0, height * 0.86602, 0, 0, 0, 0, 1, 0);
  rotate(frameCount * 0.01, 0, 1, 0);
  shape(shp);
}

The sphere shape uses the latitude and longitude from the renderer.

Best,
Jeremy

4 Likes

Solved! Thanks @behreajj
I can’t believe how I never tried that :expressionless:

Conceptually, all these parameter-setting methods (strokeWeight, textAlign, sphereDetail, etc.) are then used by the appropriate drawing functions without needing to pass all the parameters explicitly. This fits with Processing’s general “learners-should-have-to-pass-6-arguments” API design.

Keep in mind that these are canvas-level settings. sphereDetail() controls the main canvas, but if you are creating a PGraphics pg and drawing to it with pg.shape(), then you need to call a setting pg.sphereDetail().

PGraphics pg;
void setup() {
  size(400, 200, P3D);
  pg = createGraphics(200, 200, P3D);
}
void draw() {
  background(128);

  pg.beginDraw();
  pg.background(128);
  pg.sphereDetail(20);
  pg.translate(100, 100);
  pg.sphere(80);
  pg.endDraw();
  image(pg, 0, 0);

  sphereDetail(10);
  translate(300, 100);
  sphere(80);

}

1 Like