Skip to content
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

Update HTMLMesh to observe DOM mutation and support Canvas elements #23386

Merged
merged 2 commits into from
Jan 31, 2022

Conversation

zz85
Copy link
Contributor

@zz85 zz85 commented Jan 30, 2022

Description

  • enable html2canvas updates to be made automatically based on dom updates (previously, updates was made when events were dispatched to HTMLMesh)
  • also optimizes update calls a little
  • also add Stats.js to VR Sandbox example

image

video: https://twitter.com/BlurSpline/status/1487453742488190983
demo: https://raw.githack.com/zz85/three.js/html_mesh/examples/webxr_vr_sandbox.html

- enable html2canvas updates to be made automatically based on dom updates
- also add Stats.js to VR Sandbox
@zz85
Copy link
Contributor Author

zz85 commented Jan 30, 2022

hmm, it seems window.requestAnimationFrame() doesn't really play nice in webxr mode, let me find a fix for that

@amitlzkpa
Copy link
Contributor

This might do the job.
https://threejs.org/docs/#api/en/renderers/WebGLRenderer.setAnimationLoop

Looks cool!

@mrdoob mrdoob added this to the r138 milestone Jan 31, 2022
@mrdoob mrdoob merged commit 91658c9 into mrdoob:dev Jan 31, 2022
@mrdoob
Copy link
Owner

mrdoob commented Jan 31, 2022

Thanks!

Comment on lines +201 to +202
stats.dom.style.width = '80px';
stats.dom.style.height = '48px';
Copy link
Owner

Choose a reason for hiding this comment

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

How come this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll have to check, but I think the floating parent div doesn't have an explicit width and height (computed size - offsetWidth and offsetHeight should reflect the true dimensions tho)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, looks like these 2 lines aren't needed at all to work...

Comment on lines +240 to +241
// Canvas elements doesn't trigger DOM updates, so we have to update the texture
statsMesh.material.map.update();
Copy link
Owner

Choose a reason for hiding this comment

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

The canvas element resizes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, could be clearer in the description, canvas can trigger dom changes, this line is needed because render updates on the 2d canvas context needs a manual update call.

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, is this for stats.js or in general?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we will need to call .update() only if the input dom element is an actively updating canvas.

for all other dom types, MutationObserver calls the .update() automatically. (I was thinking maybe add a html marquee element as another HTMLMesh example)

@0b5vr 0b5vr mentioned this pull request Mar 1, 2022
16 tasks
donmccurdy pushed a commit to donmccurdy/three.js that referenced this pull request Mar 10, 2022
…rdoob#23386)

* Update HTMLMesh to observe DOM mutation and support Canvas elements

- enable html2canvas updates to be made automatically based on dom updates
- also add Stats.js to VR Sandbox

* Switch raf to setTimeout in HTMLMesh, also fix repeat notes in haptics
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