From 66e98e3be5d6d5b243cdc7dee7b593f99de7e5fa Mon Sep 17 00:00:00 2001 From: devtejasx Date: Wed, 16 Sep 2026 16:34:54 +0530 Subject: [PATCH] Document the loadModel(path, normalize) overload loadModel() accepts a boolean normalize flag as its second argument, and the reference examples use it, but no documented overload listed it. The parameter validator reads the same overloads, so loadModel('model.obj', true) logged a false "Expected string at the second parameter" error. Add the overload to the JSDoc and parameterData.json (matching what npm run docs generates for loadModel). Fixes #9176 --- docs/parameterData.json | 6 ++++++ src/webgl/loading.js | 8 ++++++++ test/unit/core/param_errors.js | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/docs/parameterData.json b/docs/parameterData.json index 81a8b6b4d0..2594301de4 100644 --- a/docs/parameterData.json +++ b/docs/parameterData.json @@ -962,6 +962,12 @@ "function(p5.Geometry)?", "function(Event)?" ], + [ + "String|Request", + "Boolean?", + "function(p5.Geometry)?", + "function(Event)?" + ], [ "String|Request", "String?", diff --git a/src/webgl/loading.js b/src/webgl/loading.js index 51bb504cc4..6b3207ef88 100755 --- a/src/webgl/loading.js +++ b/src/webgl/loading.js @@ -530,6 +530,14 @@ function loading(p5, fn) { * console.error('Oops!', error); * } */ + /** + * @method loadModel + * @param {String|Request} path + * @param {Boolean} [normalize] + * @param {function(p5.Geometry)} [successCallback] + * @param {function(Event)} [failureCallback] + * @return {Promise} new p5.Geometry object. + */ /** * @method loadModel * @param {String|Request} path diff --git a/test/unit/core/param_errors.js b/test/unit/core/param_errors.js index 7a01c3a165..4f26f5b923 100644 --- a/test/unit/core/param_errors.js +++ b/test/unit/core/param_errors.js @@ -380,6 +380,26 @@ suite('Validate Params', function () { }); }); + suite('validateParams: loadModel normalize overload', function () { + const onLoad = () => {}; + test('loadModel(): accepts normalize as the second argument', function () { + const result = mockP5Prototype._validate('p5.loadModel', ['model.obj', true]); + assert.isTrue(result.success); + }); + test('loadModel(): accepts normalize followed by a callback', function () { + const result = mockP5Prototype._validate('p5.loadModel', ['model.obj', true, onLoad]); + assert.isTrue(result.success); + }); + test('loadModel(): still accepts a file type and normalize', function () { + const result = mockP5Prototype._validate('p5.loadModel', ['model', '.obj', true]); + assert.isTrue(result.success); + }); + test('loadModel(): still rejects a number as the second argument', function () { + const result = mockP5Prototype._validate('p5.loadModel', ['model.obj', 5]); + assert.isFalse(result.success); + }); + }); + suite('validateParams: variadic min/max', function () { ['min', 'max'].forEach(fn => { test(`${fn}(): works with two numbers`, function () {