diff --git a/src/HTMLMesh.js b/src/HTMLMesh.js
index 4b736bc..7533525 100644
--- a/src/HTMLMesh.js
+++ b/src/HTMLMesh.js
@@ -59,6 +59,7 @@ class HTMLTexture extends CanvasTexture {
constructor( dom ) {
super( html2canvas( dom ) );
+ this.prevCanvasSize = { width: this.image.width, height: this.image.height };
this.dom = dom;
@@ -103,6 +104,12 @@ class HTMLTexture extends CanvasTexture {
this.scheduleUpdate = null;
+ if ( this.image.width !== this.prevCanvasSize.width || this.image.height !== this.prevCanvasSize.height ) {
+ this.prevCanvasSize.width = this.image.width;
+ this.prevCanvasSize.height = this.image.height;
+ this.dom.dispatchEvent(new CustomEvent('size-changed'))
+ }
+
}
dispose() {
@@ -480,12 +487,13 @@ function html2canvas( element ) {
if ( canvas === undefined ) {
canvas = document.createElement( 'canvas' );
- canvas.width = offset.width;
- canvas.height = offset.height;
canvases.set( element, canvas );
}
+ canvas.width = offset.width;
+ canvas.height = offset.height;
+
const context = canvas.getContext( '2d'/*, { alpha: false }*/ );
const clipper = new Clipper( context );
diff --git a/src/aframe-html.js b/src/aframe-html.js
index ac4cf3d..9fc31ef 100644
--- a/src/aframe-html.js
+++ b/src/aframe-html.js
@@ -38,6 +38,10 @@ AFRAME.registerComponent('html', {
intersection: null
}
};
+ this.sizeChanged = this.sizeChanged.bind(this);
+ },
+ sizeChanged() {
+ this.update();
},
play() {
this.el.addEventListener('click', this.onClick);
@@ -45,6 +49,7 @@ AFRAME.registerComponent('html', {
this.el.addEventListener('mouseenter', this.onMouseEnter);
this.el.addEventListener('mouseup', this.onMouseUp);
this.el.addEventListener('mousedown', this.onMouseDown);
+ this.data.html.addEventListener('size-changed', this.sizeChanged)
},
pause() {
this.el.removeEventListener('click', this.onClick);
@@ -52,6 +57,7 @@ AFRAME.registerComponent('html', {
this.el.removeEventListener('mouseenter', this.onMouseEnter);
this.el.removeEventListener('mouseup', this.onMouseUp);
this.el.removeEventListener('mousedown', this.onMouseDown);
+ this.data.html.removeEventListener('size-changed', this.sizeChanged)
},
update() {
this.remove();