Skip to content

Commit

Permalink
USDZLoader: Added normals handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Sep 6, 2022
1 parent 7358181 commit f82bbc9
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions examples/jsm/loaders/USDZLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,29 +291,44 @@ class USDZLoader extends Loader {

function buildGeometry( data ) {

const geometry = new BufferGeometry();

const positions = JSON.parse( data[ 'point3f[] points' ].replace( /[()]*/g, '' ) );
const attribute = new BufferAttribute( new Float32Array( positions ), 3 );
let geometry = new BufferGeometry();

if ( 'int[] faceVertexIndices' in data ) {

const indices = JSON.parse( data[ 'int[] faceVertexIndices' ] );
geometry.setAttribute( 'position', toFlatBufferAttribute( attribute, indices ) );
geometry.setIndex( new BufferAttribute( new Uint16Array( indices ), 1 ) );

} else {
}

if ( 'point3f[] points' in data ) {

const positions = JSON.parse( data[ 'point3f[] points' ].replace( /[()]*/g, '' ) );
const attribute = new BufferAttribute( new Float32Array( positions ), 3 );
geometry.setAttribute( 'position', attribute );

}

if ( 'normal3f[] normals' in data ) {

const normals = JSON.parse( data[ 'normal3f[] normals' ].replace( /[()]*/g, '' ) );
const attribute = new BufferAttribute( new Float32Array( normals ), 3 );
geometry.setAttribute( 'normal', attribute );

} else {

geometry.computeVertexNormals();

}

if ( 'texCoord2f[] primvars:st' in data ) {

const uvs = JSON.parse( data[ 'texCoord2f[] primvars:st' ].replace( /[()]*/g, '' ) );
const attribute = new BufferAttribute( new Float32Array( uvs ), 2 );

if ( 'int[] primvars:st:indices' in data ) {

geometry = geometry.toNonIndexed();

const indices = JSON.parse( data[ 'int[] primvars:st:indices' ] );
geometry.setAttribute( 'uv', toFlatBufferAttribute( attribute, indices ) );

Expand All @@ -324,8 +339,6 @@ class USDZLoader extends Loader {
}

}

geometry.computeVertexNormals();

return geometry;

Expand Down

0 comments on commit f82bbc9

Please sign in to comment.