[−][src]Static p5_sys::global::loadModel
pub static loadModel: LoadModelInternalType
Load a 3d model from an OBJ or STL file.
loadModel() should be placed inside of preload(). This allows the model to load fully before the rest of your code is run.
One of the limitations of the OBJ and STL format is that it doesn't have a built-in sense of scale. This means that models exported from different programs might be very different sizes. If your model isn't displaying, try calling loadModel() with the normalized parameter set to true. This will resize the model to a scale appropriate for p5. You can also make additional changes to the final size of your model with the scale() function.
Also, the support for colored STL files is not present. STL files with color will be rendered without color properties.
Examples
//draw a spinning octahedron
let octahedron;
function preload() {
octahedron = loadModel('assets/octahedron.obj');
}
function setup() {
createCanvas(100, 100, WEBGL);
}
function draw() {
background(200);
rotateX(frameCount * 0.01);
rotateY(frameCount * 0.01);
model(octahedron);
}
//draw a spinning teapot
let teapot;
function preload() {
// Load model with normalise parameter set to true
teapot = loadModel('assets/teapot.obj', true);
}
function setup() {
createCanvas(100, 100, WEBGL);
}
function draw() {
background(200);
scale(0.4); // Scaled to make model fit into canvas
rotateX(frameCount * 0.01);
rotateY(frameCount * 0.01);
normalMaterial(); // For effect
model(teapot);
}
Overloads
path
Path of the model to be loaded
normalize
If true, scale the model to a
standardized size when loading
successCallback?
Function to be called
once the model is loaded. Will be passed
the 3D model object.
failureCallback?
called with event error if
the model fails to load.
fileType?
The file extension of the model
(.stl, .obj).
path
Path of the model to be loaded
successCallback?
Function to be called
once the model is loaded. Will be passed
the 3D model object.
failureCallback?
called with event error if
the model fails to load.
fileType?
The file extension of the model
(.stl, .obj).