0

I created a Mesh in blender, exported it and loaded it via the JSON loader. Everything is rendered perfectly in the scene, but when I try to access it from outside the loader's callback function, I always get an "undefined".

This is my code:

var mesh, material;
var loader = new THREE.JSONLoader();
loader.load("./models/Baccanti/Bac.js", addModelToScene);

function addModelToScene(geometry,materials){
 material = new THREE.MeshFaceMaterial(materials);
 mesh = new THREE.Mesh(geometry,material);
 mesh.position.set(0,0,0);
 scene.add(mesh);

}

What do I miss or how do I access the mesh after loading?

Thank you!

Larisa
  • 56
  • 7

1 Answers1

0

You are probably calling it before the mesh is loaded. You can put another callback into your addModelToScene function to alert you when its done loading

Similar question:

using three.js JSONLoader

Community
  • 1
  • 1
pailhead
  • 5,162
  • 2
  • 25
  • 46
  • Could anyone contribute the code example for specifically how to add another callback to the addModelToScene function. I'm very new to javascript and three.js, and I have exactly the same problem... Seeing this as an example would really help me out... – Tom Oct 13 '19 at 06:32