donmccurdy/glTF-Transform

Sparse accessor with many non-zero elements (78.0%) may increase file size

Closed this issue · 3 comments

Describe the bug
I'm getting this warning around 30 times in a row when passing this model through gltf transform NodeIO

To Reproduce
My code is roughly like this (i uncommented all processing so this should be enough to reproduce the warnings)

const io = new NodeIO()
		registerExtensions(io);
		io.registerDependencies({
			'meshopt.decoder': MeshoptDecoder,
		})
const document = await io.read(file).catch((err) => {...});
io.write(filename, document);

Versions:

  • Version: 4.0.0-alpha.10
  • Environment: Node 20, win10

Additional context

image

File that produces this warning
Min.zip

@marwie do you feel that the message is inaccurate or shouldn't be a warning? Or just that the logging is too noisy? Note that sparse() will detect these and remove them.

It feels noisy
I'm also not sure how/why the percentage rate increases - is this expected?
Regarding sparse: would you recommend that I add a call to sparse() by default?

Current behavior is that for each accessor marked as sparse, I/O will log a warning if the % of non-zero values in the accessor is above the threshold at which use of sparse accessors increases final file size:

if (count > accessor.getCount() / 3) {
// Too late to write non-sparse values in the proper buffer views here.
const pct = ((100 * indices.length) / accessor.getCount()).toFixed(1);
logger.warn(`Sparse accessor with many non-zero elements (${pct}%) may increase file size.`);
}

Perhaps I've got the threshold slightly wrong though, there's a (small) file size increase if we make these accessors non-sparse. In general there's no harm including sparse() by default, it should only change accessors if they benefit. It's included in the CLI 'optimize' command for example:

transforms.push(sparse());

This does require a pass over ever element of every accessor, so if you're really tight on the processing time budget, maybe better to do something targeted only to morph target accessors.

In any case, I'm open to making this logging less noisy.