Reputation: 11
I followed the example from p5.js Reference It contains an example of how to load an OBJ file in JavaScript with p5.js:
//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);
describe('Vertically rotating 3-d teapot with red, green and blue gradient.');
}
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);
}
Is there a way to load an MTL file which contains the material and texture information to replace the normalMaterial() function?
The texture() function doesn't work right for 3D objects.
Upvotes: 1
Views: 429