提交 0f7a1f90 编写于 作者: J Jerome Etienne

more work

上级 815f52f0
......@@ -49,7 +49,7 @@
- maybe cached in a ARtoolkit specific function
- projectionAxisTransformMatrix renamed as artoolkitprojectionAxisTransformMatrix
- simple, no risk and make it clear it is artoolkit -
- DONE in arbackend-switch put the backend in hash. and offer to switch
- DONE in trackingbackend-switch put the backend in hash. and offer to switch
- good for testing
- DONE all this testing about aruco or jsartoolkit it crappy
- in artoolkitContext.backend === 'aruco' || 'artoolkit'
......
......@@ -48,9 +48,9 @@
- [parameters-tunning](https://jeromeetienne.github.io/AR.js/three.js/examples/parameters-tunning.html) :
three.js example for parameters-tunning
([source](https://github.com/jeromeetienne/AR.js/blob/master/three.js/examples/parameters-tunning.html))
- [backend switcher](https://jeromeetienne.github.io/AR.js/three.js/examples/arbackend-switch.html) :
- [backend switcher](https://jeromeetienne.github.io/AR.js/three.js/examples/trackingbackend-switch.html) :
Show to easily switch between arBackend 'aruco' or 'jsartoolkit'
([source](https://github.com/jeromeetienne/AR.js/blob/master/three.js/examples/arbackend-switch.html))
([source](https://github.com/jeromeetienne/AR.js/blob/master/three.js/examples/trackingbackend-switch.html))
- [multi-markers](https://jeromeetienne.github.io/AR.js/three.js/examples/multi-markers/examples/player.html) :
multi markers examples - it shows how to dynamically learn a multi markers and then how to use it.
learner.html is a example of dynamic learning of a multi markers configuration. It has been designed
......
......@@ -21,7 +21,6 @@
<script src='../threex-arsmoothedcontrols.js'></script>
<script>THREEx.ArToolkitContext.baseURL = '../'</script>
<body style='margin : 0px; overflow: hidden; font-family: Monospace;'><div style='position: absolute; top: 10px; width:100%; text-align: center; z-index: 1;'>
<a href="https://github.com/jeromeetienne/AR.js/" target="_blank">AR.js</a> - switching between backend
by <a href='https://twitter.com/jerome_etienne' target='_blank'>@jerome_etienne</a>
......@@ -31,7 +30,7 @@
/
<a href='../../../three.js/threex/threex-aruco/examples/images/1001.png' target='_blank'>1001 for aruco</a>
<br/>
<strong>Backend:</strong>
<strong>Tracking Backend:</strong>
switch to :
<a href='#artoolkit' onclick='location.reload()'>artoolkit</a>
/
......@@ -41,8 +40,8 @@
-
current : <span id='currentArBackend'>unknown</a>
</div><script>
var arBackend = location.hash.substring(1) ? location.hash.substring(1) : 'artoolkit'
document.querySelector('#currentArBackend').innerHTML = arBackend
var trackingBackend = location.hash.substring(1) ? location.hash.substring(1) : 'artoolkit'
document.querySelector('#currentArBackend').innerHTML = trackingBackend
var changeMatrixMode = 'cameraTransformMatrix'
// var changeMatrixMode = 'modelViewMatrix'
......@@ -74,13 +73,13 @@
//////////////////////////////////////////////////////////////////////////////////
// Create a camera
if( arBackend === 'artoolkit' ){
if( trackingBackend === 'artoolkit' ){
var camera = new THREE.Camera();
}else if( arBackend === 'aruco' ){
}else if( trackingBackend === 'aruco' ){
var camera = new THREE.PerspectiveCamera(42, renderer.domElement.width / renderer.domElement.height, 0.01, 100);
}else if( arBackend === 'tango' ){
}else if( trackingBackend === 'tango' ){
var camera = new THREE.PerspectiveCamera(42, renderer.domElement.width / renderer.domElement.height, 0.01, 1000);
console.log('TODO here init tango arBackend')
console.log('TODO here init tango trackingBackend')
}else console.assert(false)
scene.add(camera);
......@@ -88,13 +87,13 @@
// handle arToolkitSource
////////////////////////////////////////////////////////////////////////////////
if( arBackend === 'artoolkit' ){
if( trackingBackend === 'artoolkit' ){
var sourceParameters = {
// to read from an image
sourceType : 'image',
sourceUrl : THREEx.ArToolkitContext.baseURL + '../data/images/img.jpg',
}
}else if( arBackend === 'aruco' ){
}else if( trackingBackend === 'aruco' ){
var sourceParameters = {
// to read from an image
sourceType : 'image',
......@@ -114,16 +113,16 @@
function onResize(){
arToolkitSource.onResize()
arToolkitSource.copySizeTo(renderer.domElement)
if( arBackend === 'artoolkit' ){
if( trackingBackend === 'artoolkit' ){
if( arToolkitContext.arController !== null ){
arToolkitSource.copySizeTo(arToolkitContext.arController.canvas)
}
}else if( arBackend === 'aruco' ){
}else if( trackingBackend === 'aruco' ){
arToolkitSource.copySizeTo(arToolkitContext.arucoContext.canvas)
camera.aspect = renderer.domElement.width / renderer.domElement.height;
camera.updateProjectionMatrix();
}else if( arBackend === 'tango' ){
}else if( trackingBackend === 'tango' ){
// console.log('here resize for tango')
camera.aspect = renderer.domElement.width / renderer.domElement.height;
camera.updateProjectionMatrix();
......@@ -139,13 +138,13 @@
var arToolkitContext = new THREEx.ArToolkitContext({
cameraParametersUrl: THREEx.ArToolkitContext.baseURL + '../data/data/camera_para.dat',
detectionMode: 'mono',
arBackend: arBackend,
trackingBackend: trackingBackend,
})
// initialize it
arToolkitContext.init(function onCompleted(){
// if artoolkit, copy projection matrix to camera
if( arToolkitContext.parameters.arBackend === 'artoolkit' ){
if( arToolkitContext.parameters.trackingBackend === 'artoolkit' ){
camera.projectionMatrix.copy( arToolkitContext.getProjectionMatrix() );
}
})
......@@ -166,13 +165,13 @@
// as we controls the camera, set changeMatrixMode: 'cameraTransformMatrix'
changeMatrixMode: changeMatrixMode
}
if( arToolkitContext.parameters.arBackend === 'artoolkit' ){
if( arToolkitContext.parameters.trackingBackend === 'artoolkit' ){
controlsParameters.type = 'pattern'
controlsParameters.patternUrl = THREEx.ArToolkitContext.baseURL + '../data/data/patt.hiro'
}else if( arToolkitContext.parameters.arBackend === 'aruco' ){
}else if( arToolkitContext.parameters.trackingBackend === 'aruco' ){
controlsParameters.type = 'barcode'
controlsParameters.barcodeValue = 1001
}else if( arToolkitContext.parameters.arBackend === 'tango' ){
}else if( arToolkitContext.parameters.trackingBackend === 'tango' ){
controlsParameters.type = 'barcode'
controlsParameters.barcodeValue = 1001
}else console.assert(false)
......
var THREEx = THREEx || {}
/**
* - lerp position/quaternino/scale
* - minDelayDetected
* - minDelayUndetected
* @param {[type]} object3d [description]
* @param {[type]} parameters [description]
*/
THREEx.ArSmoothedControls = function(object3d, parameters){
var _this = this
THREEx.ArBaseControls.call(this, object3d)
// copy parameters
this.object3d.visible = false
this._lastLerpStepAt = null
this._visibleStartedAt = null
this._unvisibleStartedAt = null
// handle default parameters
parameters = parameters || {}
this.parameters = {
// lerp coeficient for the position - between [0,1] - default to 1
lerpPosition: parameters.lerpPosition !== undefined ? parameters.lerpPosition : 0.8,
// lerp coeficient for the quaternion - between [0,1] - default to 1
lerpQuaternion: parameters.lerpQuaternion !== undefined ? parameters.lerpQuaternion : 0.2,
// lerp coeficient for the scale - between [0,1] - default to 1
lerpScale: parameters.lerpScale !== undefined ? parameters.lerpScale : 0.7,
// delay for lerp fixed steps - in seconds - default to 1/120
lerpStepDelay: parameters.fixStepDelay !== undefined ? parameters.fixStepDelay : 1/60,
// minimum delay the sub-control must be visible before this controls become visible - default to 0 seconds
minVisibleDelay: parameters.minVisibleDelay !== undefined ? parameters.minVisibleDelay : 0.0,
// minimum delay the sub-control must be unvisible before this controls become unvisible - default to 0 seconds
minUnvisibleDelay: parameters.minUnvisibleDelay !== undefined ? parameters.minUnvisibleDelay : 0.2,
}
}
THREEx.ArSmoothedControls.prototype = Object.create( THREEx.ArBaseControls.prototype );
THREEx.ArSmoothedControls.prototype.constructor = THREEx.ArSmoothedControls;
//////////////////////////////////////////////////////////////////////////////
// update function
//////////////////////////////////////////////////////////////////////////////
THREEx.ArSmoothedControls.prototype.update = function(targetObject3d){
var object3d = this.object3d
var parameters = this.parameters
var wasVisible = object3d.visible
var present = performance.now()/1000
//////////////////////////////////////////////////////////////////////////////
// handle object3d.visible with minVisibleDelay/minUnvisibleDelay
//////////////////////////////////////////////////////////////////////////////
if( targetObject3d.visible === false ) this._visibleStartedAt = null
if( targetObject3d.visible === true ) this._unvisibleStartedAt = null
if( wasVisible === false && targetObject3d.visible === true ){
if( this._visibleStartedAt === null ) this._visibleStartedAt = present
var visibleFor = present - this._visibleStartedAt
if( visibleFor >= this.parameters.minVisibleDelay ){
object3d.visible = true
this._visibleStartedAt = null
}
console.log('visibleFor', visibleFor)
}
if( wasVisible === true && targetObject3d.visible === false ){
if( this._unvisibleStartedAt === null ) this._unvisibleStartedAt = present
var unvisibleFor = present - this._unvisibleStartedAt
if( unvisibleFor >= this.parameters.minUnvisibleDelay ){
object3d.visible = false
}
// console.log('unvisibleFor', unvisibleFor)
}
// disabled minVisibleDelay+minUnvisibleDelay
// if( true ){
// object3d.visible = targetObject3d.visible
// }
//////////////////////////////////////////////////////////////////////////////
// apply lerp on positon/quaternion/scale
//////////////////////////////////////////////////////////////////////////////
// apply lerp steps - require fix time steps to behave the same no matter the fps
if( this._lastLerpStepAt === null ){
applyOneSlepStep()
this._lastLerpStepAt = present
}else{
var nStepsToDo = Math.floor( (present - this._lastLerpStepAt)/this.parameters.lerpStepDelay )
for(var i = 0; i < nStepsToDo; i++){
applyOneSlepStep()
this._lastLerpStepAt += this.parameters.lerpStepDelay
}
}
// update the matrix
this.object3d.updateMatrix()
// disable the lerp by directly copying targetObject3d position/quaternion/scale
if( false ){
this.object3d.position.copy( targetObject3d.position )
this.object3d.quaternion.copy( targetObject3d.quaternion )
this.object3d.scale.copy( targetObject3d.scale )
this.object3d.updateMatrix()
}
//////////////////////////////////////////////////////////////////////////////
// honor becameVisible/becameUnVisible event
//////////////////////////////////////////////////////////////////////////////
// honor becameVisible event
if( wasVisible === false && object3d.visible === true ){
this.dispatchEvent({ type: 'becameVisible' })
}
// honor becameUnVisible event
if( wasVisible === true && object3d.visible === false ){
this.dispatchEvent({ type: 'becameUnVisible' })
}
return
function applyOneSlepStep(){
object3d.position.lerp(targetObject3d.position, parameters.lerpPosition)
object3d.quaternion.slerp(targetObject3d.quaternion, parameters.lerpQuaternion)
object3d.scale.lerp(targetObject3d.scale, parameters.lerpScale)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册