-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Closed
Labels
Description
using r68. In case of lightmap, if two sets of uvs are defined in json, uvs = [ [primary uv set], [ secondary uv set] ]. The engine either renders weird geometry or generates webgl errors.
The cause is found by faulty increase of face index.
for ( i = 0; i < nUvLayers; i ++ ) { //loop over uv sets
uvLayer = json.uvs[ i ]; //assign the json uv set data from json parser
geometry.faceVertexUvs[ i ][ fi ] = []; //make array for indices lookup
for ( j = 0; j < 3; j ++ ) { //loop over the 3 vertices (or 4 for quad case)
uvIndex = faces[ offset ++ ]; //get faces index.in a one face case, the last line becomes on first iteration, offset = 0,1,2, on second iteration offset becomes 3,4,5, while the secondary set should still point at 0,1,2.
fix:
add on top "parseModel" method:
var collectedIndices = [0,0,0,0];the quad loop becomes:
if ( hasFaceVertexUv ) {
for ( i = 0; i < nUvLayers; i ++ ) {
uvLayer = json.uvs[ i ];
geometry.faceVertexUvs[ i ][ fi ] = [];
geometry.faceVertexUvs[ i ][ fi + 1 ] = []
for ( j = 0; j < 4; j ++ ) {
if(i == 0) collectedIndices[j] = offset++;
uvIndex = faces[ collectedIndices[j] ];
u = uvLayer[ uvIndex * 2 ];
v = uvLayer[ uvIndex * 2 + 1 ];
uv = new THREE.Vector2( u, v );
if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
}
}
}the 3 vertices case becomes:
for ( i = 0; i < nUvLayers; i ++ ) {
uvLayer = json.uvs[ i ];
geometry.faceVertexUvs[i][ fi ] = [];
for ( j = 0; j < 3; j ++ ) {
if(i == 0) collectedIndices[j] = offset++;
uvIndex = faces[ collectedIndices[j] ];
u = uvLayer[ uvIndex * 2 ];
v = uvLayer[ uvIndex * 2 + 1 ];
uv = new THREE.Vector2( u, v );
geometry.faceVertexUvs[ i ][ fi ].push( uv );
}
}Now the engine renders models using 2 sets of uv's with lightmap as expected.