Skip to content

Commit

Permalink
Fix usage of model() in buildGeometry()
Browse files Browse the repository at this point in the history
  • Loading branch information
davepagurek committed Jan 18, 2025
1 parent d1f33db commit dcd91b6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
14 changes: 1 addition & 13 deletions src/webgl/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -1087,19 +1087,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 dcd91b6

Please sign in to comment.