My .obj failing to work with loadModel() - " Cannot read property 'vertices' of undefined"

Hi all,

Apologies if this makes no sense as I’m fairly new to p5.

I’m having trouble trying to get my .obj to work with loadModel() in my code.

What I’m hoping is to allow the user to select an .obj of their choice and have it appear on the canvas.

I am using “createGraphics()” instead of another canvas as that initially didn’t work and I’ve read more than one canvas can cause unintended issues.

Please see below:

let objCreation;

let loadModelOn;

let lamp;

function preload()

{

  lamp = loadModel("/lamp.obj");

}

function setup() {

  objCreation = createGraphics(1500, 1500, WEBGL);

}

function draw() {

  // BEGGINNING OF loadModel 

  loadModelObj = createButton("Δ");

  loadModelObj.position(1261.5, 953);

  loadModelObj.mousePressed(loadModelOn);

  loadModelOn = () => {

    objCreation.model(lamp);

    objCreation.frameRate(60);

    objCreation.background(150);

    objCreation.ambientLight(100);

    objCreation.directionalLight(255, 255, 255, 0, 0, 1);

    objCreation.rotateX(frameCount * 0.05);

    objCreation.rotateY(frameCount * 0.05);

  }

  image(objCreation, 0, 0);

}

There is more code but is redundant for this issue so I’ve isolated it to what the issue is.

I appreciate any and all input! :slight_smile:

Many thanks