4
votes

Exporting some obj models from Blender to json with three.js plugin result in javascript errors in my web page. The error is always like

TypeError: vertices is undefined

In Three.js at line

zLength = vertices.length;

The json file do not seems to be correctly formatted, what to change ? How to create a correct obj file ?

The json files are really different in format, and the node "vertices" does not appear as a root node but inside of embeds nodes:

"embeds" :
{
"emb___9903__30_1 __9903__30_1_8.002": {    "scale" : 1.000000,

"materials" : [],

"vertices" : [...]}

This format does not seems to be correct but I don't know what to during the export in json or the creationg of the obj file.

The html/js web page seems to works correctly because some file is correctly open in the browser

Basically I do:

function init()
{
...
var jsonLoader = new THREE.JSONLoader();
jsonLoader.load( "models/model.js", addModelToScene );
...
}

function addModelToScene( geometry, materials ) 
{
    var material = new THREE.MeshFaceMaterial( materials );
    modeltd = new THREE.Mesh( geometry, material );
    modeltd.scale.set(1,1,1);
    scene.add( modeltd );
}
1
Partially solved: the problem comes by the "embed meshes" flag during the exporting, I've deselected and the format is now back correct. Anyway I've seen people using this kind of format with the "embeds" node, where to get information about it ?Gulp

1 Answers

0
votes

I had the same problem exactly as you described. Here's what worked for me (although I may have different goal for my output) I got the latest dev branch of the exporter and three.js code, I loaded the exporter through a zip file instead of just copying the files over. (I mention all of this as it may be related but, I suspect that the resolution is the following) I set the export options as follows

  • Scene: Scene checked;
  • Geometry: Vertices checked and Faces checked;
  • Material: Face Materials checked;
  • All other items were unchecked or left at the original values.

The importer code:

var loader = new THREE.JSONLoader();
loader.load(path /*<--not file system but url*/, doLoad );
console.log("success");
doLoad = function(g) {
    mesh = new THREE.Mesh(g, new THREEMeshBasicMaterial(someVal));
    mesh.scale.set(3,3,3); //perhaps the mesh is loaded but off the screen?
    scene.add(mesh);
}

Also it maybe helpful in debugging to know that I was able to get the same errors removing the loader completely. Where g = ({/*json blob here*/}).