Skip to content

Do not apply environment maps to unlit models. Fixes #374#377

Merged
jsantell merged 1 commit intomasterfrom
374
Mar 4, 2019
Merged

Do not apply environment maps to unlit models. Fixes #374#377
jsantell merged 1 commit intomasterfrom
374

Conversation

@jsantell
Copy link
Contributor

Currently with a default env map, image env map, and PMREM'd env map currently:

localhost_5000_examples_fullscreen2 html 11

With this patch:

localhost_5000_examples_fullscreen2 html 10

Note that UnlitTest.glb is included (4kb) -- can reference the Khronos models if/when they land. The Astronaut is not unlit AFAICT (or, does not use the unlit extension), maybe should change the background-image demo describing it as such.

cdata
cdata previously approved these changes Feb 21, 2019
Copy link
Contributor

@cdata cdata left a comment

Choose a reason for hiding this comment

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

LGTM 👍

await onLoad;
});
test('applies no environment map on unlit model', async function() {
expect(!modelHasEnvMap(scene)).to.be.ok;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: for the case of checking a boolean, prefer expect(...).to.be.true (expect(...).to.be.false also works) or expect(...).to.be.equal(true)

// Unlit models (using MeshBasicMaterial) should not apply
// an environment map, even though `map` is the currently configured
// environment map.
if (obj && obj.isMesh && obj.material && !obj.material.isMeshBasicMaterial) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For some edge cases, obj.material could be an array of materials. We should probably avoid creating those in GLTFLoader at some point, but for now it's worth handling.

@cdata
Copy link
Contributor

cdata commented Feb 22, 2019

@jsantell since we have merged #375 , would you be willing to update this change to use the unlit sample from the Khronos samples so that we don't have to check the model into our repo?

@jsantell
Copy link
Contributor Author

@cdata

since we have merged #375 , would you be willing to update this change to use the unlit sample from the Khronos samples so that we don't have to check the model into our repo?

wouldn't that require needing to fetch all the models before being able to run tests? UnlitTest.glb is 4kb as well.

@donmccurdy

For some edge cases, obj.material could be an array of materials. We should probably avoid creating those in GLTFLoader at some point, but for now it's worth handling.

Any models that you know that do this to test?

@cdata
Copy link
Contributor

cdata commented Feb 25, 2019

since we have merged #375 , would you be willing to update this change to use the unlit sample from the Khronos samples so that we don't have to check the model into our repo?

wouldn't that require needing to fetch all the models before being able to run tests? UnlitTest.glb is 4kb as well.

Yes, and we do this (models are fetched as part of npm prepare, so it happens after npm install and npm ci).

In practice this is probably fine. We have set up Travis to cache the directory they are checked out to, and it doesn't seem to take much time. We also update in place if we detect that the models are already fetched.

@cdata
Copy link
Contributor

cdata commented Feb 25, 2019

FYI looks like UnlitTest.glb is still checked in

@jsantell
Copy link
Contributor Author

Using the Khronos sample models now, and handle when material is an array

materialStack.push(obj.material);
}

for (let material of materialStack) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to do iteration of the material stack on every invocation of the traverse callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mm, yes, but missing clearing it out. I don't like any way that attempts to not duplicate the logic for the (untested) edge case as well. Will change

@donmccurdy
Copy link
Contributor

It's a bit contrived, but here's an example that will result in mesh.material being an array. The model contains a single mesh with two primitives, and the primitives are identical except for using different materials.

Triangle.gltf.zip

instances where meshes may have multiple materials defined.
@jsantell
Copy link
Contributor Author

jsantell commented Mar 4, 2019

  • Fixed the material array logic
  • Added Triangle.gltf for test case (added PBR values to see envmap), shook out some issues in our GLTFLoader wrapper
  • Remove UnlitTest.glb

@jsantell jsantell requested a review from cdata March 4, 2019 22:42
});
});

suite('on a model with multi-material meshes', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

Copy link
Contributor

@cdata cdata left a comment

Choose a reason for hiding this comment

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

Great fix, LGTM 👍

@jsantell jsantell merged commit c4dac10 into master Mar 4, 2019
@jsantell jsantell deleted the 374 branch March 4, 2019 23:35
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.

3 participants