Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/modelviewer.dev/examples/scenegraph/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -759,14 +759,16 @@ <h2 class="demo-title">Materials API</h2>

modelViewer.addEventListener("load", () => {
const changeColor = (event) => {
const material = modelViewer.materialFromPoint(event.clientX, event.clientY);
if (material != null) {
material.pbrMetallicRoughness.
setBaseColorFactor([Math.random(), Math.random(), Math.random()]);
if(modelViewer.modelIsVisible){
const material = modelViewer.materialFromPoint(event.clientX, event.clientY);
if (material != null) {
material.pbrMetallicRoughness.
setBaseColorFactor([Math.random(), Math.random(), Math.random()]);
}
}
};

modelViewer.addEventListener("click", changeColor);
document.addEventListener("click", changeColor);
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tested this whole page? I'm guessing since there are multiple examples, this might have odd behavior. Maybe add a check in changeColor to ensure the event came through the right element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add a check in changeColor to ensure the event came through the right element?

You are right. i think my new commit fixes this

});
</script>
<script>
Expand Down