From a952ca5906c9d78c4aff70bbcc6ec08fb0677ae9 Mon Sep 17 00:00:00 2001 From: Jerome Etienne Date: Sat, 25 Feb 2017 14:47:02 +0000 Subject: [PATCH] first version of profile --- README.md | 3 + three.js/examples/dev.html | 8 +- three.js/examples/profile.html | 164 +++++++++++++++++++++++++++ three.js/threex-artoolkitcontext.js | 2 +- three.js/threex-artoolkitprofile.js | 168 +++++++++++++++------------- 5 files changed, 266 insertions(+), 79 deletions(-) create mode 100644 three.js/examples/profile.html diff --git a/README.md b/README.md index ce66e37..7d32718 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,9 @@ Three.js Examples: - [mobile-performance](https://jeromeetienne.github.io/AR.js/three.js/examples/mobile-performance.html) : three.js example for mobile-performance ([source](https://github.com/jeromeetienne/AR.js/blob/master/three.js/examples/mobile-performance.html)) +- [profile](https://jeromeetienne.github.io/AR.js/three.js/examples/profile.html) : + three.js example for artoolkit-profile + ([source](https://github.com/jeromeetienne/AR.js/blob/master/three.js/examples/profile.html)) a-frame Examples: diff --git a/three.js/examples/dev.html b/three.js/examples/dev.html index 80dc8a9..4cfa655 100644 --- a/three.js/examples/dev.html +++ b/three.js/examples/dev.html @@ -60,7 +60,13 @@ //////////////////////////////////////////////////////////////////////////////// - var artoolkitProfile = new THREEx.ArToolkitProfile('guess') + var artoolkitProfile = new THREEx.ArToolkitProfile() + // artoolkitProfile.sourceWebcam().hiroMarker(); + artoolkitProfile.sourceVideo('../../data/videos/headtracking.mp4').kanjiMarker(); + // artoolkitProfile.sourceImage('../../data/images/img.jpg').hiroMarker(); + + artoolkitProfile.performance('slow'); + var arToolkitSource = new THREEx.ArToolkitSource(artoolkitProfile.sourceParameters) diff --git a/three.js/examples/profile.html b/three.js/examples/profile.html new file mode 100644 index 0000000..d637450 --- /dev/null +++ b/three.js/examples/profile.html @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + +
+ AR.js - developement playground +
+ Contact me any time at @jerome_etienne +
diff --git a/three.js/threex-artoolkitcontext.js b/three.js/threex-artoolkitcontext.js index 560aad7..f56e27a 100644 --- a/three.js/threex-artoolkitcontext.js +++ b/three.js/threex-artoolkitcontext.js @@ -44,7 +44,7 @@ THREEx.ArToolkitContext.prototype.init = function(onCompleted){ var sourceWidth = this.parameters.sourceWidth var sourceHeight = this.parameters.sourceHeight - console.log('ArToolkitContext: _onSourceReady width', sourceWidth, 'height', sourceHeight) + // console.log('ArToolkitContext: _onSourceReady width', sourceWidth, 'height', sourceHeight) _this._cameraParameters = new ARCameraParam(_this.parameters.cameraParametersUrl, function() { // init controller var arController = new ARController(sourceWidth, sourceHeight, _this._cameraParameters); diff --git a/three.js/threex-artoolkitprofile.js b/three.js/threex-artoolkitprofile.js index d57b436..02f9b87 100644 --- a/three.js/threex-artoolkitprofile.js +++ b/three.js/threex-artoolkitprofile.js @@ -1,99 +1,113 @@ var THREEx = THREEx || {} -/** - * TODO - * - .setMarkerHiro() - * - .setMarkerKanji() - * - .setSourceWebcam() - * - .setSourceVideo(url) - * - .setSourceImage(url) - * - .setPerformance() - */ - -THREEx.ArToolkitProfile = function(label){ - if( label === 'guess' ) label = this._guessLabel() - - this.reset() - this.setProfile(label) -} -THREEx.ArToolkitProfile.prototype.reset = function () { - this.sourceParameters = {} - this.contextParameters = {} - this.defaultMarkerParameters = {} -}; - -THREEx.ArToolkitProfile.prototype._guessLabel = function () { - // TODO implement this - return 'desktop' -}; +THREEx.ArToolkitProfile = function(){ + this.reset().discoverPerformance() +} -THREEx.ArToolkitProfile.prototype.setProfile = function (label) { - if( 'desktop' ){ - this.desktopProfile() - }else if( 'mobile' ){ - this.mobileProfile() - }else console.assert('false') -}; -THREEx.ArToolkitProfile.prototype.desktopProfile = function () { +THREEx.ArToolkitProfile.prototype.reset = function () { this.sourceParameters = { // to read from the webcam sourceType : 'webcam', - - // to read from an image - // sourceType : 'image', - // sourceUrl : '../../data/images/img.jpg', - - // to read from a video - // sourceType : 'video', - // sourceUrl : '../../data/videos/headtracking.mp4', - - // sourceWidth: 80*3, - // sourceHeight: 60*3, - // } this.contextParameters = { cameraParametersUrl: THREEx.ArToolkitContext.baseURL + '../data/data/camera_para.dat', detectionMode: 'mono', - maxDetectionRate: 30, } this.defaultMarkerParameters = { type : 'pattern', - // patternUrl : THREEx.ArToolkitContext.baseURL + '../data/data/patt.hiro' - patternUrl : THREEx.ArToolkitContext.baseURL + '../data/data/patt.kanji' + patternUrl : THREEx.ArToolkitContext.baseURL + '../data/data/patt.hiro' } -} + return this +}; -THREEx.ArToolkitProfile.prototype.mobileProfile = function () { - this.sourceParameters = { - // to read from the webcam - sourceType : 'webcam', - - // to read from an image - // sourceType : 'image', - // sourceUrl : '../../data/images/img.jpg', - - // to read from a video - // sourceType : 'video', - // sourceUrl : '../../data/videos/headtracking.mp4', - - sourceWidth: 80*3, - sourceHeight: 60*3, - // - } +////////////////////////////////////////////////////////////////////////////// +// Performance +////////////////////////////////////////////////////////////////////////////// - this.contextParameters = { - cameraParametersUrl: THREEx.ArToolkitContext.baseURL + '../data/data/camera_para.dat', - detectionMode: 'mono', - maxDetectionRate: 30, - sourceWidth: this.sourceParameters.sourceWidth, - sourceHeight: this.sourceParameters.sourceHeight, +THREEx.ArToolkitProfile.prototype.discoverPerformance = function() { + var isMobile = navigator.userAgent.match(/Android/i) + || navigator.userAgent.match(/webOS/i) + || navigator.userAgent.match(/iPhone/i) + || navigator.userAgent.match(/iPad/i) + || navigator.userAgent.match(/iPod/i) + || navigator.userAgent.match(/BlackBerry/i) + || navigator.userAgent.match(/Windows Phone/i) + ? true : false + if( isMobile === true ){ + this.performance('phone-normal') + }else{ + this.performance('desktop-normal') } - this.defaultMarkerParameters = { - type : 'pattern', - // patternUrl : THREEx.ArToolkitContext.baseURL + '../data/data/patt.hiro' - patternUrl : THREEx.ArToolkitContext.baseURL + '../data/data/patt.kanji' +} + +THREEx.ArToolkitProfile.prototype.performance = function(label) { + if( label === 'desktop-fast' ){ + this.sourceParameters.sourceWidth = 640*2 + this.sourceParameters.sourceWidth = 480*2 + + this.contextParameters.maxDetectionRate = 60 + }else if( label === 'desktop-normal' ){ + this.sourceParameters.sourceWidth = 640 + this.sourceParameters.sourceWidth = 480 + + this.contextParameters.maxDetectionRate = 60 + }else if( label === 'phone-normal' ){ + this.sourceParameters.sourceWidth = 240 + this.sourceParameters.sourceWidth = 180 + + this.contextParameters.maxDetectionRate = 30 + }else if( label === 'phone-slow' ){ + this.sourceParameters.sourceWidth = 240 + this.sourceParameters.sourceWidth = 180 + + this.contextParameters.maxDetectionRate = 15 + }else { + console.assert(false, 'unknonwn label '+label) } + this.contextParameters.sourceWidth = this.sourceParameters.sourceWidth + this.contextParameters.sourceHeight = this.sourceParameters.sourceHeight +} + +////////////////////////////////////////////////////////////////////////////// +// Marker +////////////////////////////////////////////////////////////////////////////// +THREEx.ArToolkitProfile.prototype.kanjiMarker = function () { + this.contextParameters.detectionMode = 'mono' + + this.defaultMarkerParameters.type = 'pattern' + this.defaultMarkerParameters.patternUrl = THREEx.ArToolkitContext.baseURL + '../data/data/patt.kanji' + return this +} + +THREEx.ArToolkitProfile.prototype.hiroMarker = function () { + this.contextParameters.detectionMode = 'mono' + + this.defaultMarkerParameters.type = 'pattern' + this.defaultMarkerParameters.patternUrl = THREEx.ArToolkitContext.baseURL + '../data/data/patt.hiro' + return this +} + +////////////////////////////////////////////////////////////////////////////// +// Source +////////////////////////////////////////////////////////////////////////////// +THREEx.ArToolkitProfile.prototype.sourceWebcam = function () { + this.sourceParameters.sourceType = 'webcam' + delete this.sourceParameters.sourceUrl + return this +} + + +THREEx.ArToolkitProfile.prototype.sourceVideo = function (url) { + this.sourceParameters.sourceType = 'video' + this.sourceParameters.sourceUrl = url + return this +} + +THREEx.ArToolkitProfile.prototype.sourceImage = function (url) { + this.sourceParameters.sourceType = 'image' + this.sourceParameters.sourceUrl = url + return this } -- GitLab