Skip to content

Add minimum viable debug mode - #856

Merged
cdata merged 4 commits into
masterfrom
introduce-debugger
Oct 28, 2019
Merged

cdata merged 4 commits into
masterfrom
introduce-debugger

Conversation

@cdata

@cdata cdata commented Oct 28, 2019 •

Copy link
Copy Markdown
Contributor

This change introduces a very light "debug" mode to <model-viewer>. Debug mode can be activated in two ways:

  1. By adding a query parameter to the URL:
    • http://example.com/foo.html?model-viewer-debug-mode
  2. By including a global signal on the page with script:
<script>
ModelViewerElement = ModelViewerElement || {};
ModelViewerElement.debugMode = true;
</script>

Activating debug mode currently does two things:

  1. Enables verbose shader error messages on the GL context
  2. Exposes renderer internal details with a globally dispatched model-viewer-renderer-debug event

An example of using this event looks like:

<!-- Before model-viewer.js is loaded: -->
<script>
self.addEventListener('model-viewer-renderer-debug', (event) => {
  const {
    THREE, // Limited subset of Three.js constructors
    renderer // The singleton instance of Renderer
  } = event.detail;

  // Do debugging stuff...
});
</script>

The Debugger will also advertise scenes as they are registered and unregistered. You can listen for global model-viewer-scene-added-debug and model-viewer-scene-removed-debug events, which contain a reference to the related scene as event.detail.scene. The scenes in this case will be instances of ModelScene.

If you wanted to turn on debugging for most tests, you could manually run them with a URL like: http://localhost:8000/test/?model-viewer-debug-mode.

Note that this will currently only enable debug mode for tests that create a Renderer via ModelViewerElementBase. Tests that instantiate a Renderer directly would need to pass a debug flag e.g., new Renderer({ debug: true });.

@cdata
cdata requested a review from elalish October 28, 2019 16:52
detail: {
renderer,
THREE: {
ShaderMaterial,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We should probably include Scene here, I think. Any others, @elalish ? My hope is to limit it to things that we already import for rendering, and are necessary to do essential debug rendering outside of the element.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed on Scene. Renderer already includes TextureUtils, so that's good. We might want to reevaluate what is private, for instance TextureUtils has a private member PMREMGenerator that it might be nice to access. Likewise perhaps with Renderer's private member arRenderer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added Scene, and I added a read-only accessor for the PMREMGenerator in TextureUtils. Let's add arRenderer later if and when we need it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When you said Scene, I was actually thinking [$scene], since that owns things like the model and the shadow. The renderer has the set of all scenes, but it might be hard to tell which one relates to this element.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yah, currently there is no offered mechanism to distinguish the scenes. Originally, I added a special event to advertise each scene as it is registered with the Renderer, but I don't have a use case for it yet so I took it out.

I'm happy to add it back in if you think we should land it now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't have a strong opinion, but I like the idea of being able to access all of the textures. Many of those are in the Model's materials and the shadow lives in the ModelScene, so having hooks to that seems important.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added advertisement of scenes as they are registered/unregistered. Details in the PR description.

Comment thread src/three-components/Renderer.ts Outdated
this.renderer.setPixelRatio(resolveDpr());

if (options == null || options.debug === false) {
this.debugger = new Debugger(this);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this condition backwards? Seems like you make a debugger if debug is false.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes, good catch. Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Mesh,
PlaneBufferGeometry,
OrthographicCamera,
WebGLRenderTarget

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the rationale behind these particular things to include?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are intended to be the minimum viable set of things needed to do debug rendering outside of the element. The actual set we should use may be different, have any suggestions?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So basically what's needed to display a texture? Yeah that sounds good. I'm not sure what other kinds of debugging we'd do here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can add more as we need it

elalish
elalish previously approved these changes Oct 28, 2019
detail: {
renderer,
THREE: {
ShaderMaterial,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When you said Scene, I was actually thinking [$scene], since that owns things like the model and the shadow. The renderer has the set of all scenes, but it might be hard to tell which one relates to this element.

Comment thread src/three-components/Renderer.ts Outdated
if (options != null && options.debug) {
this.debugger = new Debugger(this);
} else {
this.renderer.debug = {checkShaderErrors: false};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if this condition is going to live here, maybe turning it on should live here too instead of buried in the Debugger.ts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's funky because it's technically on by default, I just wanted the Debugger to assert that it be on when it is used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I changed the logic here to make it more explicit. LMKWYT.

@elalish elalish left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

@cdata
cdata merged commit f5b5408 into master Oct 28, 2019
@cdata
cdata deleted the introduce-debugger branch October 28, 2019 19:00
@cdata cdata self-assigned this Dec 19, 2019
@cdata cdata added this to the v0.8.0 milestone Dec 19, 2019
elalish pushed a commit to elalish/model-viewer that referenced this pull request Feb 4, 2020
Christopher Joel
 
Add minimum viable debug mode (google#856)

* Add minimum viable debug mode

* Make debugger protected

* Fix debug logic, expose more things

* Announce adding/removing scenes
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