Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USDZExporter does not work with MeshoptDecoder #22609

Closed
wallabyway opened this issue Sep 30, 2021 · 2 comments
Closed

USDZExporter does not work with MeshoptDecoder #22609

wallabyway opened this issue Sep 30, 2021 · 2 comments

Comments

@wallabyway
Copy link

wallabyway commented Sep 30, 2021

There's an error when USDZExporter encodes a USDZ file based on a GLTF compressed with MeshOpt compression.

For example,
if I compress cube.glb with MeshOpt (gltfpack -I cube.glb -o cube.zeux.glb), then will preview correctly inside three.js.
When I click the AR button, it causes the following error.

usdz-error

and the error refers to

line 291:

array.push( `(${ data[ i + 0 ].toPrecision( PRECISION ) }, ${ data[ i + 1 ].toPrecision( PRECISION ) }, ${ data[ i + 2 ].toPrecision( PRECISION ) })` );

To Reproduce

Steps to reproduce the behavior:

  1. Compress cube.glb or damaged-helmet.glb with gltfpack -I cube.glb -o cube.zeux.glb
  2. Load the glb using
			import { MeshoptDecoder } from 'https://wallabyway.github.io/gltf-imaginate-test/jsm/meshopt_decoder.module.js';

...
				const loader = new GLTFLoader().setPath( 'glb/' );
				loader.setMeshoptDecoder(MeshoptDecoder);
				loader.load( 'output.glb', async function ( gltf ) {
  1. Host and Open index.html on iPhone, and click on 'AR' button
  2. Host and Open index.html on desktop browser, and click on 'AR' button, and refer to error in debug console.

Live example

Expected behavior

Expect the compressed .glb to appear in Quicklook

Screenshots

meshOpt-no-usdz-threejs

Platform:

  • Browser: [Chrome]
  • Three.js version: [latest]
@donmccurdy
Copy link
Collaborator

donmccurdy commented Sep 30, 2021

The issue here is that USDZExporter accesses attribute.array on vertex attributes, which won't work for geometry with interleaved attributes:

const data = attribute.array;
for ( let i = 0; i < data.length; i += 3 ) {
array.push( `(${ data[ i + 0 ].toPrecision( PRECISION ) }, ${ data[ i + 1 ].toPrecision( PRECISION ) }, ${ data[ i + 2 ].toPrecision( PRECISION ) })` );
}

Using attribute.getXYZ( ... ) instead should work fine. Also note that the vertex attributes will likely be normalized, I'm not sure whether USDZExporter accounts for this. You can recreate the same error with these models and the three.js editor:

Archive.zip

^One model is interleaved, the other is not. Neither uses compression, and only the interleaved copy will have errors. Normalization and compression will be lost when converting to USDZ, so file size will probably increase.

@wallabyway
Copy link
Author

That fixed it - thanks !
Loads very quickly.
https://github.com/wallabyway/quicklook-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants