The loadModel() function is used to load a 3d model from file, and return it as a p5.Geometry Object. This model can be loaded with the the formats
The OBJ and STL loaded files do not have any sense of scale, hence it may be required to use the normalized parameter so that the model is automatically scaled to the correct size. The scale() function can be used once the model is loaded to make further changes to the size of the model.
This method is asynchronous in nature and therefore it may not finish before the model can be used. It is hence advised to load the model in the preload() function.
loadModel( path, normalize, [successCallback], [failureCallback] )
loadModel(path, [successCallback], [failureCallback])
Parameters: This function accept four parameters as mentioned above and described below:
- path: It is a string which denotes the path from where the model has to be loaded.
- normalize: It is a boolean value which determines if the loaded model would be scaled to standardized size when loading. It is an optional parameter.
- successCallback: This is a function which is called if the model is loaded successfully. The loaded model is passed as a parameter. It is an optional parameter.
- failureCallback: This is a function which is called if the model does not load due to any error. The error event is passed as a parameter. It is an optional parameter.
Return Value: It returns a p5.Geometry object with the given model.
Below programs illustrate the loadModel() function in p5.js:
Example 1: This example shows how the model is loaded in the preload() function.
Example 2: This example shows how the callbacks can be used to load and use the model.
- How to get the function name inside a function in PHP ?
- PHP | ord() Function
- PHP | Ds\Set add() Function
- D3.js | d3.max() function
- PHP | cos( ) Function
- p5.js | sin() function
- p5.js | tan() function
- p5.js | log() function
- PHP | Ds\Set xor() Function
- PHP | each() Function
- p5.js | cos() function
- p5.js | mag() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.