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
22 changes: 19 additions & 3 deletions examples/jsm/interactive/HTMLMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ class HTMLTexture extends CanvasTexture {
this.magFilter = LinearFilter;
this.generateMipmaps = false;

// Create an observer on the DOM, and run html2canvas update in the next loop
const observer = new MutationObserver( () => {
this.scheduleUpdate = null;

const scheduleUpdate = () => {

if ( ! this.scheduleUpdate ) {

Expand All @@ -100,13 +101,25 @@ class HTMLTexture extends CanvasTexture {

}

} );
};

// Create an observer on the DOM, and run html2canvas update in the next loop

const observer = new MutationObserver( scheduleUpdate );

// The state of form controls lives in properties (checked, value) which
// are not reported by MutationObserver, so listen to their events as well.

dom.addEventListener( 'input', scheduleUpdate );
dom.addEventListener( 'change', scheduleUpdate );

const config = { attributes: true, childList: true, subtree: true, characterData: true };
observer.observe( dom, config );

this.observer = observer;

this._scheduleUpdate = scheduleUpdate;

}

dispatchDOMEvent( event ) {
Expand Down Expand Up @@ -136,6 +149,9 @@ class HTMLTexture extends CanvasTexture {

}

this.dom.removeEventListener( 'input', this._scheduleUpdate );
this.dom.removeEventListener( 'change', this._scheduleUpdate );

this.scheduleUpdate = clearTimeout( this.scheduleUpdate );

super.dispose();
Expand Down