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

EmissiveStrength and Clearcoat extensions #4319

Merged
merged 7 commits into from
Jun 28, 2023
Merged

EmissiveStrength and Clearcoat extensions #4319

merged 7 commits into from
Jun 28, 2023

Conversation

diegoteran
Copy link
Collaborator

Change from MeshStandardMaterial to MeshPhysicalMaterial

Feature: #4273

Change from MeshStandardMaterial to MeshPhysicalMaterial
@diegoteran
Copy link
Collaborator Author

Looking for feedback on the correct way to set up the API before completing other PBR next properties + unit tests.

@diegoteran diegoteran requested a review from elalish June 13, 2023 21:59
this[$ensureMaterialIsLoaded]();
for (const material of this[$correlatedObjects] as
Set<MeshPhysicalMaterial>) {
material.emissiveIntensity = emissiveStrength;
Copy link
Collaborator

Choose a reason for hiding this comment

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

LGTM, but I believe these are simplified compared to the existing setters right (recall our duplicated state)? We should change the others to match this style and check to ensure that doesn't break anything before we adopt it for these. Let's add that in before we get too deep into testing these new ones.

@diegoteran diegoteran requested a review from elalish June 27, 2023 22:24
Copy link
Collaborator

@elalish elalish left a comment

Choose a reason for hiding this comment

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

Looking good, just a few things.

};
super(onUpdate, gltfImage, new Set<ThreeTexture>(texture ? [texture] : []));
get[$threeTextures](): Set<ThreeTexture> {
return this[$correlatedObjects] as Set<ThreeTexture>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Were you still planning to rename $correlatedObjects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the "correlated" name comes from the default correlation through the gltfMap from ThreeJS Loader:

I'm not sure if the name should change.

super(onUpdate, new Set<ThreeTexture>(texture ? [texture] : []));

if (!this[$threeTexture].image.src) {
this[$threeTexture].image.src = 'adhoc_image' + adhocNum++;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be the name as well, as before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

"KHR_materials_pbrSpecularGlossiness", please use
"pbrMetallicRoughness" instead. Specular Glossiness materials are
no longer supported; to convert to metal-rough, see
https://www.donmccurdy.com/2022/11/28/converting-gltf-pbr-materials-from-specgloss-to-metalrough/.`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a little sad to loose this warning, but I think it's okay because three.js throws its own anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

RIP

return (this[$sourceObject] as DefaultedMaterial).emissiveFactor;
return (
this[$backingThreeMaterial]
.emissive.toArray() as [number, number, number]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it not work with as RGB?

this[$onUpdate]();
}

[$getAlphaMode](): string {
// Follows implementation of GLTFExporter from three.js
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

this[$onUpdate]();
}

getDoubleSided(): boolean {
this[$ensureMaterialIsLoaded]();
return (this[$sourceObject] as DefaultedMaterial).doubleSided;
// 0 for FrontSide, 2 for DoubleSide.
return this[$backingThreeMaterial].side == 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use the DoubleSided enum from three, or whatever it's called.

gltfSourceMaterial.name = newMaterialName;
// Adds the source material clone to the gltf def.
const gltf = this[$correlatedSceneGraph].gltf;
gltf.materials!.push(gltfSourceMaterial);
Copy link
Collaborator

Choose a reason for hiding this comment

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

💯 Always nice to remove code!

private get[$threeMaterial]() {
console.assert(
this[$correlatedObjects] != null && this[$correlatedObjects]!.size > 0,
'Sampler correlated object is undefined');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a Sampler?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ahh good copy-paste catch

@@ -49,29 +49,29 @@ const isWrapMode = (() => {
wrapModes.indexOf(value as WrapMode) > -1;
})();

const isValidSamplerValue = <P extends 'minFilter'|'magFilter'|'wrapS'|'wrapT'|'rotation'|'repeat'|'offset'>(
property: P, value: unknown): value is DefaultedSampler[P] => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed this value is thing before - I've never seen that syntax. I know it's not yours, but if there's a simpler way, that would be great. Seems like it should just be P, value: DefaultedSampler<P>): boolean =>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It says DefaultedSampler is not generic. Probably no support for

?

@diegoteran diegoteran requested a review from elalish June 27, 2023 23:16
elalish
elalish previously approved these changes Jun 28, 2023
return this[$correlatedObjects] as Set<ThreeTexture>;
}

constructor(onUpdate: () => void, texture: ThreeTexture|null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this predates you, but do we know when |null happens? There's an assert above that seems to imply null would be an error. Doesn't have to happen in this PR, but it would be great to clean this up if we can.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, or at least it should work the same way as https://github.com/google/model-viewer/blob/8546f41450af57ee37fe7c00e3ef210138f6e3a0/packages/model-viewer/src/features/scene-graph/sampler.ts#L80C2-L100C56

Maybe another refactor where we remove |null from all ThreeDOMElements (Sampler, Image, Texture, etc...) is something worth looking into.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I think that would be ideal.

test('Accessing the name getter does not cause throw error.', async () => {
expect(model.materials[2].name).to.equal('red');
expect(model.materials[2][$lazyLoadGLTFInfo]).to.be.ok;
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we leave this now that name is fixed?

@@ -150,6 +150,7 @@ suite('scene-graph/model', () => {

test('getMaterialByName returns material when name exists', async () => {
await loadModel(CUBES_GLTF_PATH);
await model.materials[2].ensureLoaded();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Likewise, is this necessary anymore?

textureInfo, material, and threeDomElement still require them for Lazyloading (assigning the correlated amterial after the constructor)
Copy link
Collaborator

@elalish elalish left a comment

Choose a reason for hiding this comment

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

This looks great, thanks for helping to clean up our code base!

@diegoteran diegoteran merged commit ddef677 into master Jun 28, 2023
3 checks passed
@diegoteran diegoteran deleted the pbr branch June 28, 2023 21:11
JL-Vidinoti pushed a commit to vidinoti/model-viewer that referenced this pull request Apr 22, 2024
…sions (google#4319)

* EmissiveStrength and Clearcoat extensions

Change from MeshStandardMaterial to MeshPhysicalMaterial

* Add Clearcoat Normal Texture Scale

* Remove canonical GLTF element from ThreeDOMElement

Single source of truth is now the three.js scene graph

* Cleanup for space-opera tests

* Address review comments.

* Reverted tests after adding name functionality

* Remove unused `|null` in some ThreeDOMElements

textureInfo, material, and threeDomElement still require them for Lazyloading (assigning the correlated amterial after the constructor)
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