-
Notifications
You must be signed in to change notification settings - Fork 311
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
Conversation
0a4f4f1
to
1f0278a
Compare
There was a problem hiding this 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.
lib/createGltf.js
Outdated
@@ -194,6 +198,31 @@ function getTexture(gltf, texture) { | |||
}; | |||
} | |||
|
|||
function cloneMaterial(material, removeTextures) { | |||
if (material === null || typeof material !== 'object') { |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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.
lib/createGltf.js
Outdated
} | ||
} | ||
} | ||
|
||
function getMaterial(gltf, materials, materialName) { |
There was a problem hiding this comment.
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.
lib/createGltf.js
Outdated
break; | ||
} | ||
materialName = originalMaterialName + '-' + suffix++; | ||
} |
There was a problem hiding this comment.
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.
lib/createGltf.js
Outdated
primitive.material = materialName; | ||
primitiveInfoByMaterial[materialName] = primitiveInfo; | ||
|
||
var material = getMaterialByName(splitMaterials, materialName); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
6ed450c
to
a79a953
Compare
@likangning93 should be ready now. |
a79a953
to
eaca567
Compare
👍 Just waiting on #161 now |
@likangning93 - ready now. |
👍 |
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:
1.0
branch.