Skip to content

Commit

Permalink
Merge pull request #5 from rodrigocam/performance
Browse files Browse the repository at this point in the history
Improve performance
  • Loading branch information
rodrigocam authored Mar 7, 2019
2 parents a80ca74 + 35631b1 commit efc332a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build/ar-gif.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/ar-gif.min.js

Large diffs are not rendered by default.

23 changes: 10 additions & 13 deletions src/ARMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,45 @@ class ARMarker extends HTMLElement {
init(markerId, arScene, arController) {
this.markerId = markerId
this.textureCanvas.setAttribute('id', markerId)

let texture = new THREE.CanvasTexture(this.textureCanvas)
this.material = new THREE.MeshBasicMaterial({map: texture, transparent: true});

let threeMarker = this.create3DMarker(markerId, arController)
arScene.scene.add(threeMarker)
const self = this

arController.addEventListener('getMarker', (ev) => {
// supress wanings
console.warn = function(){}
if(ev.data.marker.id == markerId) {
if(!self.gifLoaded) {
self.gif = gifler(self.content).animate(self.textureCanvas)
self.gifLoaded = true;
}
self.gifPlaying = true
self.updateMarkerTexture(self.get3DMarker(markerId, arScene))
texture.needsUpdate = true
}
})
console.log("Initialized marker ", markerId, this.textureCanvas)
}

updateMarkerTexture(threeMarker) {
let texture = new THREE.CanvasTexture(this.textureCanvas);
let material = new THREE.MeshBasicMaterial({map: texture, transparent: true});
threeMarker.children[0].material = material;
}

get3DMarker(markerId, arScene) {
let arController = arScene.arController;
return arController.threePatternMarkers[markerId];
}

create3DMarker(markerId, arController) {
let threeMarker = arController.createThreeMarker(markerId)
let plane = this.create3DPlane(this.textureCanvas)
let plane = this.create3DPlane()

threeMarker.add(plane)
return threeMarker
}

create3DPlane(textureCanvas) {
create3DPlane() {
let geometry = new THREE.PlaneGeometry()
let texture = new THREE.CanvasTexture(textureCanvas)
let material = new THREE.MeshBasicMaterial({map: texture, transparent: true})

return new THREE.Mesh(geometry, material)
return new THREE.Mesh(geometry, this.material)
}

static get observedAttributes() {
Expand Down
4 changes: 2 additions & 2 deletions src/ARScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class ARScene extends HTMLElement {
config.width = {ideal: document.body.clientWidth},
config.height = {ideal: document.body.clientHeight}
}

window.ARThreeOnLoad = () => {
ARController.getUserMediaThreeScene({
maxARVideoSize: config.maxARVideoSize,
maxARVideoSize: 640,
cameraParam: CameraParam,
facingMode: 'environment',
width: config.width,
Expand Down

0 comments on commit efc332a

Please sign in to comment.