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.
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
elalish
left a comment
There was a problem hiding this comment.
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.
Were you still planning to rename $correlatedObjects?
There was a problem hiding this comment.
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++; |
There was a problem hiding this comment.
Should this be the name as well, as before?
| "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.
I'm a little sad to loose this warning, but I think it's okay because three.js throws its own anyway.
| return (this[$sourceObject] as DefaultedMaterial).emissiveFactor; | ||
| return ( | ||
| this[$backingThreeMaterial] | ||
| .emissive.toArray() as [number, number, number]); |
There was a problem hiding this comment.
Does it not work with as RGB?
| } | ||
|
|
||
| [$getAlphaMode](): string { | ||
| // Follows implementation of GLTFExporter from three.js |
| 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.
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.
💯 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.
ahh good copy-paste catch
| })(); | ||
|
|
||
| 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.
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.
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.
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.
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.
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.
Can we leave this now that name is fixed?
|
|
||
| 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.
Likewise, is this necessary anymore?
textureInfo, material, and threeDomElement still require them for Lazyloading (assigning the correlated amterial after the constructor)
elalish
left a comment
There was a problem hiding this comment.
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