-
Notifications
You must be signed in to change notification settings - Fork 816
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
Conversation
Change from MeshStandardMaterial to MeshPhysicalMaterial
Looking for feedback on the correct way to set up the API before completing other PBR next properties + unit tests. |
this[$ensureMaterialIsLoaded](); | ||
for (const material of this[$correlatedObjects] as | ||
Set<MeshPhysicalMaterial>) { | ||
material.emissiveIntensity = emissiveStrength; |
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.
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.
Single source of truth is now the three.js scene graph
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.
Looking good, just a few things.
}; | ||
super(onUpdate, gltfImage, new Set<ThreeTexture>(texture ? [texture] : [])); | ||
get[$threeTextures](): Set<ThreeTexture> { | ||
return this[$correlatedObjects] as Set<ThreeTexture>; |
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.
Were you still planning to rename $correlatedObjects
?
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 think the "correlated" name comes from the default correlation through the gltfMap from ThreeJS Loader:
if (correlatedMaterial != null) { |
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++; |
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 the name
as well, as before?
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.
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/.`); |
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'm a little sad to loose this warning, but I think it's okay because three.js throws its own anyway.
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.
RIP
return (this[$sourceObject] as DefaultedMaterial).emissiveFactor; | ||
return ( | ||
this[$backingThreeMaterial] | ||
.emissive.toArray() as [number, number, number]); |
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.
Does it not work with as RGB
?
this[$onUpdate](); | ||
} | ||
|
||
[$getAlphaMode](): string { | ||
// Follows implementation of GLTFExporter from three.js |
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[$onUpdate](); | ||
} | ||
|
||
getDoubleSided(): boolean { | ||
this[$ensureMaterialIsLoaded](); | ||
return (this[$sourceObject] as DefaultedMaterial).doubleSided; | ||
// 0 for FrontSide, 2 for DoubleSide. | ||
return this[$backingThreeMaterial].side == 2; |
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.
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); |
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.
💯 Always nice to remove code!
private get[$threeMaterial]() { | ||
console.assert( | ||
this[$correlatedObjects] != null && this[$correlatedObjects]!.size > 0, | ||
'Sampler correlated object is undefined'); |
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.
Is this a Sampler?
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.
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] => { |
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 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 =>
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.
It says DefaultedSampler is not generic. Probably no support for
?
return this[$correlatedObjects] as Set<ThreeTexture>; | ||
} | ||
|
||
constructor(onUpdate: () => void, texture: ThreeTexture|null) { |
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 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.
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.
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.
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.
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; | ||
}); |
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.
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(); |
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.
Likewise, is this necessary anymore?
textureInfo, material, and threeDomElement still require them for Lazyloading (assigning the correlated amterial after the constructor)
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 great, thanks for helping to clean up our code base!
…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)
Change from MeshStandardMaterial to MeshPhysicalMaterial
Feature: #4273