-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,11 @@ | |
import { XRControllerModelFactory } from './jsm/webxr/XRControllerModelFactory.js'; | ||
|
||
import { GUI } from './jsm/libs/lil-gui.module.min.js'; | ||
import Stats from './jsm/libs/stats.module.js'; | ||
|
||
let camera, scene, renderer; | ||
let reflector; | ||
let stats, statsMesh; | ||
|
||
const parameters = { | ||
radius: 0.6, | ||
|
@@ -193,6 +195,21 @@ | |
mesh.scale.setScalar( 2 ); | ||
group.add( mesh ); | ||
|
||
|
||
// Add stats.js | ||
stats = new Stats(); | ||
stats.dom.style.width = '80px'; | ||
stats.dom.style.height = '48px'; | ||
document.body.appendChild( stats.dom ); | ||
|
||
statsMesh = new HTMLMesh( stats.dom ); | ||
statsMesh.position.x = - 0.75; | ||
statsMesh.position.y = 2; | ||
statsMesh.position.z = - 0.6; | ||
statsMesh.rotation.y = Math.PI / 4; | ||
statsMesh.scale.setScalar( 2.5 ); | ||
group.add( statsMesh ); | ||
|
||
} | ||
|
||
function onWindowResize() { | ||
|
@@ -218,6 +235,10 @@ | |
torus.rotation.y = time * 5; | ||
|
||
renderer.render( scene, camera ); | ||
stats.update(); | ||
|
||
// Canvas elements doesn't trigger DOM updates, so we have to update the texture | ||
statsMesh.material.map.update(); | ||
Comment on lines
+240
to
+241
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The canvas element resizes? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, is this for stats.js or in general? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
} | ||
|
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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...