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

Fix GLTFExporter bug #16267

Merged
merged 10 commits into from
Apr 18, 2019
Merged

Fix GLTFExporter bug #16267

merged 10 commits into from
Apr 18, 2019

Conversation

takahirox
Copy link
Collaborator

@takahirox takahirox commented Apr 16, 2019

This PR fixes a regression added to GLTFExporter by #16265 (comment). Simpler solution idea is welcome.

@donmccurdy
Copy link
Collaborator

What is the bug you're trying to fix? From your earlier comments:

So even if another geometry.index refers to the same BufferAttribute instance, it's distinguished.

Agreed, if geometry1.index === geometry2.index then it would be nice to not duplicate the attribute.

So, I know it's very rare case but, if geometry.attributes/morphAttributes and geometry.index refer to the same BufferAttribute instance, they're distinguished.

I don't agree here – reusing an index as a vertex attribute is too much of an edge case. If we can reduce the +50 lines of code in this change by omitting this case, we should do so.

@takahirox
Copy link
Collaborator Author

takahirox commented Apr 17, 2019

What is the bug you're trying to fix? From your earlier comments:

So even if another geometry.index refers to the same BufferAttribute instance, it's distinguished.

Agreed, if geometry1.index === geometry2.index then it would be nice to not duplicate the attribute.

Yes, that one. We didn't duplicate before (in case no multi materials). #16265 has regression.

So, I know it's very rare case but, if geometry.attributes/morphAttributes and geometry.index refer to the same BufferAttribute instance, they're distinguished.

I don't agree here – reusing an index as a vertex attribute is too much of an edge case. If we can reduce >the +50 lines of code in this change by omitting this case, we should do so.

I think I'm ok +50 lines for that. But no strong opinion. If we distinguish index attributes from vertex attributes, maybe adding cacheData.indices or something may be clear.

BTW, if we don't like this +50 lines functions and distinguish index from attributes, how simply we can write index cache? BufferAttribute doesn't have uuid. And we need to take account of group.start/count for cache key.

@takahirox
Copy link
Collaborator Author

takahirox commented Apr 17, 2019

BTW, if we don't like this +50 lines functions and distinguish index from attributes, how simply we can write index cache? BufferAttribute doesn't have uuid. And we need to take account of group.start/count for cache key.

A cheap idea is temporal uid.

var uids = new Map();
var uid = 0;

function getUID( object ) {

    if ( ! uids.has( object ) ) {

        uids.set( object, uid ++ );

    }

    return uids.get( object );

}

var key = getUID( geometry.index ) + ':' + start + ':' + count;

if ( cachedData.indices.has( key ) ) {
...

Copy link
Collaborator

@donmccurdy donmccurdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new version (with a Map and incrementing counter) looks good to me 👍

@mrdoob mrdoob merged commit a904498 into mrdoob:dev Apr 18, 2019
@mrdoob mrdoob added this to the r104 milestone Apr 18, 2019
@mrdoob
Copy link
Owner

mrdoob commented Apr 18, 2019

Thanks!

@takahirox takahirox deleted the FixGLTFExporter branch April 18, 2019 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants