Skip to content

Commit

Permalink
Merge pull request #7479 from processing/fix/model-buildgeometry
Browse files Browse the repository at this point in the history
Fix usage of model() in buildGeometry()
  • Loading branch information
davepagurek authored Jan 18, 2025
2 parents ad777f2 + 0d5e383 commit 1db55f6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/webgl/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ function loading(p5, fn){
if (flipV) {
model.flipV();
}
model._makeTriangleEdges();

if (successCallback) {
return successCallback(model);
Expand All @@ -464,6 +465,7 @@ function loading(p5, fn){
if (flipV) {
model.flipV();
}
model._makeTriangleEdges();

if (successCallback) {
return successCallback(model);
Expand Down Expand Up @@ -1087,19 +1089,7 @@ function loading(p5, fn){
fn.model = function (model, count = 1) {
this._assert3d('model');
// p5._validateParameters('model', arguments);
if (model.vertices.length > 0) {
if (!this._renderer.geometryInHash(model.gid)) {

if (model.edges.length === 0) {
model._makeTriangleEdges();
}

model._edgesToVertices();
this._renderer._getOrMakeCachedBuffers(model);
}

this._renderer._drawGeometry(model, { count });
}
this._renderer.model(model, count);
};
}

Expand Down
15 changes: 15 additions & 0 deletions src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,21 @@ class RendererGL extends Renderer {
this.updateShapeVertexProperties();
}

model(model, count = 1) {
if (model.vertices.length > 0) {
if (this.geometryBuilder) {
this.geometryBuilder.addRetained(model);
} else {
if (!this.geometryInHash(model.gid)) {
model._edgesToVertices();
this._getOrMakeCachedBuffers(model);
}

this._drawGeometry(model, { count });
}
}
}

//////////////////////////////////////////////
// Rendering
//////////////////////////////////////////////
Expand Down
20 changes: 20 additions & 0 deletions test/unit/visual/cases/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,24 @@ visualSuite('WebGL', function() {
screenshot();
});
});

visualSuite('buildGeometry()', () => {
visualTest('can draw models', (p5, screenshot) => {
p5.createCanvas(50, 50, p5.WEBGL);

const sphere = p5.buildGeometry(() => {
p5.scale(0.25);
p5.sphere();
});

const geom = p5.buildGeometry(() => {
p5.model(sphere);
});

p5.background(255);
p5.lights();
p5.model(geom);
screenshot();
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}

0 comments on commit 1db55f6

Please sign in to comment.