4
votes

I did a simple 3d model in blender and exported it to .obj file. Now I am loading it using three.js and I want objects that have string 'clickable' in its name to move on Y axis on click.

You can look at it here: http://three.parkz.cz/shop.html

The problem is that the informations parsed from names of objects (which I set in blender) are not corresponding to the right objects.

Loading and parsing:

var loader = new THREE.OBJMTLLoader();
loader.addEventListener('load', function(event) {
  object = event.content;
  object.name = 'CustomObjects';
  for(var i = 0; i < object.children.length; i++) {      

    //console.log(object.children[i]);
    var properties = object.children[i].name.split('_');
    if(properties[1] == 'clickable') {
      object.children[i].clickable = true; 
    } else object.children[i].clickable = false;

  }
  object.rotation.x = 0.5;
  object.rotation.y = 0.5;                                  
  scene.add(object);
});
loader.load('shop.obj', 'shop.mtl');

For example that two cubes in the center (called '005_kiosek' and '010_kiosek2') are not supposed to be clickable but they are! You can open console and after click on it you can see that they are named wrongly '004_clickable' and '009_clickable'!

Here is my blender file: http://three.parkz.cz/shop.blend

Is it problem on javascript side or blender exports it wrong?

Thank you in advance!

Martin

P.S: Does anybody know why aren't that simple meshes (green and blue) rendered well?

1

1 Answers

4
votes

The green and blue mesh are not rendered correctly because, under the current implementation, the obj loader only accepts triangles as faces. As those meshes use polygons, they are not rendered correctly.

As for the names I would try to verify that what I put in the blender file, comes out correct. So when you load the model, just print the name and its clickable attribute, to see if all is correct instead for taking it for granted.