mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.25k stars 35.35k forks source link

Error loading the json generated by Maya exporter using THREE.JSONloader() #5252

Closed cjishnu closed 9 years ago

cjishnu commented 10 years ago

Hi,

I am using Autodesk Maya 2014 SP2 to create the 3d models for a threejs based browser-game. Models have skeletal animation and textures. Maya exporter plugin that I am using is downloaded from here: https://github.com/mrdoob/three.js/tree/master/utils/exporters/maya (python version is 2.7 and pymel version I think is 1.0.0). Maya exporter plugin successfully generates the three.js json file. Now there are two problems:

ERROR 1: json.colors array is not present (even when I check the colors checkbox while exporting) - this gives javascript errors while loading using THREE.JSONloader() with the latest version of three.js (r68)

js error:

Uncaught TypeError: Cannot read property '16265' of undefined 

The errors can be traced to the following lines in three.js:

                if ( hasFaceColor ) {
                    colorIndex = faces[ offset ++ ];
                                       /*hasFaceColor is true, but colors array doesn't exist*/
                    hex = colors[ colorIndex ]; 
                    faceA.color.setHex( hex );
                    faceB.color.setHex( hex );
                }

ERROR 2: After creating a workaround for the non-existent colors array, one more js error comes inside computeFaceNormals.

js error:

Uncaught TypeError: Cannot read property 'x' of undefined three.js:1636THREE.Vector3.subVectors three.js:1636THREE.Geometry.computeFaceNormals three.js:9895THREE.JSONLoader.parse three.js:12010xhr.onreadystatechange

This is because inside computeFaceNormals definition, vertices.length is only 17795 in my case, but face.a is going above 17795 resulting in undefined 'vA'.

I realize that this could be due to some peculiarities in my model. But since the latest version of Maya exporter is successfully creating an output json file without any errors, I think my model is correct and expect it to be readable by JSONloader. Also when I tried with Inka3d (http://www.inka3d.com/) , the models render properly on the browser. So I am reporting this as bug.

Please look into it. Let me know if I have to share my model.

mrdoob commented 10 years ago

Please look into it. Let me know if I have to share my model.

Yes please, share your model.

cjishnu commented 10 years ago

Hi, Sorry for the late reply. You can find the Maya model here in the original format (.mb) and the generated json. https://drive.google.com/folderview?id=0B_bh5AxtV5KMUVJ4blJXRFNOTmM&usp=sharing

Thanks!

mrdoob commented 10 years ago

/ping @sgrif

cjishnu commented 10 years ago

I am redoing my animations in Blender where everything seems to be working. I would like to contribute to fixing this issue in Maya (since my 3D artist is more comfortable with Maya) if I could get some insights on what could be wrong? Is the problem in three.js or the exporter? Does the pymel version matter?

mrdoob commented 10 years ago

Did you tried with the last version of the exporter in the dev branch?

cjishnu commented 10 years ago

Yes. three.js r69dev version + dev branch exporters (both .py & .mel). Were the files updated properly?

mrdoob commented 10 years ago

/ping @sgrif

sgrif commented 10 years ago

Can't contribute much more here, since we moved off of Three.js a few months back due to a number of issues. I tried running this file through our legacy format importer though. I couldn't successfully get it to render, since the zip file doesn't include all of the textures referenced by the mesh, but no errors were emitted relating to attribute reference or indexing issues, so that implies that the bug is in Three not the exporter.

mrdoob commented 10 years ago

Can't contribute much more here, since we moved off of Three.js a few months back due to a number of issues.

Off topic, but I would love to know what those issues were ^^

JHanley85 commented 9 years ago

I am still receiving this exact error. Maya 2015, export using the threejs exporter, fails in the hasFaceColor block

mrdoob commented 9 years ago

Can you share the faulty exported file?

Jojocaster commented 8 years ago

Same error on my side, any updates ?

mattdesl commented 8 years ago

Same here with Maya 2016, unfortunately I can't share the model due to NDA. Will poke around further.

Only happens on a model with bones/skeletal animations.

me97esn commented 8 years ago

I have the same problem.

Using this converter: convert_obj_three

I then try to import it into three.js v69 scene using the following code:

const jsonLoader = new window.THREE.JSONLoader();
jsonLoader.load('3dmodels/lowpoly_character/gamecharacter.js', function(geometry, materials) {
    const character = new window.THREE.Mesh(geometry, new window.THREE.MeshFaceMaterial(materials));
    scene.add(character);
  });

But I get this error: three.js:1677 Uncaught TypeError: Cannot read property 'x' of undefined

Archive.zip

arnicas commented 8 years ago

FWIW, my student also ran into this. Is there any solution? :(

mrdoob commented 8 years ago

Make sure you're using the latest version of the library and the exporter.

Jojocaster commented 8 years ago

I don't really know what the issue really was, but I managed to fix it by creating g another scene in Maya and importing my object in it. Give it a go, try to load parts of your object within a new scene, might work too.

theopenwindow commented 8 years ago

I rebuilt a scene in Maya and import the object, and then export the three.js file with the latest plugins versions. But the error is still the same. When I load it in html, the object insist no show...

js error: Uncaught TypeError: Cannot read property '111' of undefined : (

mattdesl commented 8 years ago

I think this issue may be related to the way meshes are selected from the Python script. Here's what I used in my own plugin to get around this issue:

https://github.com/Jam3/maya-json-export/blob/a77debbc24be36e510cf1c385173da5755fea2a7/exporter/plug-ins/SimpleJSON.py#L64-L92

mrdoob commented 8 years ago

@mattdesl I don't know what features does the Maya exporter in this repo currently supports, but maybe we could replace it with yours?

mattdesl commented 8 years ago

Hmm mine is a bit purpose-built for our own needs (instancing) and unfortunately my trial for Maya has run out, so I'm temporarily unable to test/develop. :smile: Hopefully next month I will have a machine set up with Maya and I can get back to improving the plugin.

But if somebody is able, they could test by simply changing the _allMeshes function in the current ThreeJS repo to see if it indeed fixes the situation.

arnicas commented 8 years ago

Hoping this will help... My students have 2 models of a laptop. The one with the keyboard results in the error, the one without the keyboard imports to three.js just fine with no error.

The dropbox file is here: https://www.dropbox.com/sh/jnm4gw2zlh2qjdx/AAD-s56nqI0U9NKE69DPP4gya?dl=0

They say:

"the tag folder is the maya files that we want to use in our website (it's a shark skeleton, I believe)" - also produces the error.