Skip to content
Draft
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions src/HTMLMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions src/aframe-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,26 @@ AFRAME.registerComponent('html', {
intersection: null
}
};
this.sizeChanged = this.sizeChanged.bind(this);
},
sizeChanged() {
this.update();
},
play() {
this.el.addEventListener('click', this.onClick);
this.el.addEventListener('mouseleave', this.onMouseLeave);
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);
this.el.removeEventListener('mouseleave', this.onMouseLeave);
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();
Expand Down