mrdoob/three.js — Issue #1130: ColladaLoader fails when mesh exported with tangents/normals
Author: canassa
Created: 2012-01-18 19:26:03+00:00
State: open

I found this problem on the latest dev build while I was trying to export a mesh from 3D Max using the OpenCollada plugin.

I noticed that when the mesh is exported using the 'include tangents/normals' option the ColladaLoader fails to load the mesh.

The importer fails on the Geometry.js computeCentroids method.

computeCentroids: function () {

var f, fl, face;

for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {

face = this.faces[ f ];
face.centroid.set( 0, 0, 0 );

if ( face instanceof THREE.Face3 ) {

face.centroid.addSelf( this.vertices[ face.a ].position );
face.centroid.addSelf( this.vertices[ face.b ].position );
face.centroid.addSelf( this.vertices[ face.c ].position ); // Fails here
face.centroid.divideScalar( 3 );

I ran these tests on the Chrome console, as you can see the face.c is pointing to a index outside the this.vertices array:

>> this.vertices.length
8
>> face.c
10

If the mesh is exported without the tangents/normals option it loads fine.

The mesh is a simple cube, here is the collada with that failed the import:

http://pastebin.com/q97CYBaL

And for reference, this is same mesh without the extra options (loads ok)

http://pastebin.com/06AJTn7k