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

Duplicate materials with mismatching attributes #162

Merged
merged 6 commits into from
Nov 2, 2018

Conversation

lilleyse
Copy link
Contributor

@lilleyse lilleyse commented Oct 29, 2018

Fixes #160

Duplicates materials whose referring primitives don't have the same attribute types. E.g. if a textured material is referenced by a primitive with both positions and uvs and a primitive with just positions, the material will be duplicated such that the first copy is unchanged and the second copy has textures removed.

#161 needs to be merged first in order for the tests to pass.

To do:

  • After this is merged open a PR into the 1.0 branch.

@lilleyse lilleyse force-pushed the material-duplication branch from 0a4f4f1 to 1f0278a Compare October 30, 2018 03:15
lilleyse added a commit that referenced this pull request Oct 30, 2018
Copy link
Contributor

@likangning93 likangning93 left a comment

Choose a reason for hiding this comment

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

Works as advertised, just a couple small notes and maybe a bigger note on performance when there are lots and lots of materials.

@@ -194,6 +198,31 @@ function getTexture(gltf, texture) {
};
}

function cloneMaterial(material, removeTextures) {
if (material === null || typeof material !== 'object') {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be !defined(material)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to handle typeof null being "object".

I might remove it though since a material will never have a null property, and this function is already somewhat specialized for cloning materials.

}
}
}

function getMaterial(gltf, materials, materialName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a huge deal, but maybe this is named too similarly now to getMaterialIndex considering that's supposed to do something kind of different. Maybe something like getOrCreateGltfMaterial would be more descriptive.

break;
}
materialName = originalMaterialName + '-' + suffix++;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it's basically doing a getUniqueId, but I think having it as an inlined loop here kind of hurts readability. Consider a getUniqueId helper.

primitive.material = materialName;
primitiveInfoByMaterial[materialName] = primitiveInfo;

var material = getMaterialByName(splitMaterials, materialName);
Copy link
Contributor

Choose a reason for hiding this comment

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

In general it seems like there's a lot of looping in here, which was also true for master. I wonder if this poses a performance risk for objs that have a large number of materials like the San Miguel model at https://casual-effects.com/data/. We can address that in a followup PR if it becomes a problem, it might also be cleaner to pass around material dictionaries instead within the conversion pipeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I timed this just in case. It doesn't look like it's much of a performance concern. Obj parsing just completely trumps it.

Split materials: 5.306ms
Total: 42602.737ms

@lilleyse lilleyse force-pushed the material-duplication branch from 6ed450c to a79a953 Compare November 1, 2018 01:10
@lilleyse
Copy link
Contributor Author

lilleyse commented Nov 1, 2018

@likangning93 should be ready now.

@lilleyse lilleyse force-pushed the material-duplication branch from a79a953 to eaca567 Compare November 1, 2018 01:12
@likangning93
Copy link
Contributor

👍

Just waiting on #161 now

@lilleyse
Copy link
Contributor Author

lilleyse commented Nov 1, 2018

@likangning93 - ready now.

@likangning93
Copy link
Contributor

👍

@likangning93 likangning93 merged commit ac03e9f into master Nov 2, 2018
@likangning93 likangning93 deleted the material-duplication branch November 2, 2018 13:56
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.

2 participants