Skip to content

Commit

Permalink
Merge pull request #21 from rodrigocam/video_support
Browse files Browse the repository at this point in the history
Add support for static images
  • Loading branch information
rodrigocam authored Feb 22, 2020
2 parents 13b5d63 + 86a4ad4 commit dffbcf8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build/ar-gif.min.js

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions src/ARMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ class ARMarker extends HTMLElement {
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)
let threeMarker = this.create3DMarker(markerId, arController);
arScene.scene.add(threeMarker);

if(this.contentProps.src.split(".")[1] == "gif"){
let content_ext = this.contentProps.src.split(".")[1];

if(content_ext == "gif"){
this.contentIsGif = true;
}else if(content_ext == "png" || content_ext == "jpg" || content_ext == "jpeg"){
this.contentIsImage = true;
this.image = document.createElement("img");
this.image.src = this.contentProps.src;
}else{
this.video = document.createElement("video");
this.video.src = this.contentProps.src;
Expand All @@ -60,6 +66,11 @@ class ARMarker extends HTMLElement {
}
self.gifPlaying = true
texture.needsUpdate = true
} else if (self.contentIsImage){
let ctx = self.textureCanvas.getContext('2d');
ctx.clearRect(0, 0, self.textureCanvas.width, self.textureCanvas.height);
ctx.drawImage(self.image, 0, 0, self.textureCanvas.width, self.textureCanvas.height);

} else if(ev.data.marker.id == markerId) {
self.video.play();
(function loop() {
Expand Down
4 changes: 2 additions & 2 deletions src/ARScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ARScene extends HTMLElement {
}

init() {
console.log('AR-GIF version 0.0.4')
console.log('AR-GIF version 0.0.5')

window.ARThreeOnLoad = () => {
ARController.getUserMediaThreeScene({
Expand Down Expand Up @@ -190,4 +190,4 @@ var crop = {
h: 480
}

customElements.define("ar-scene", ARScene)
customElements.define("ar-scene", ARScene)

0 comments on commit dffbcf8

Please sign in to comment.