-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit events when a marker is found and lost, when using aframe's <a-marker> #303
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2e61cdc
Add 'emitevents' property to the arjs-anchor component, which emits e…
aeb14b7
Add an example for using 'markerFound' and 'markerLost' events.
0cc7498
Update aframe README to include information about a-marker's 'emiteve…
673ff5f
Update version to 1.5.2 and update the relevant files after re-build.
31e1b7d
Update CHANGELOG to reflect the changes in build 1.5.2.
3a31667
Merge remote-tracking branch 'upstream/dev' into dev
50e6aa6
Sync three AR.js build file with upstream/dev.
a3b90b5
Move markerFound and markerLost event changelog notes to the newest v…
7f54945
Merge remote-tracking branch 'upstream/dev' into 20180619-update-dev
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<script src="vendor/aframe/build/aframe.min.js"></script> | ||
<!-- include aframe-ar.js --> | ||
<script src="../build/aframe-ar.js"></script> | ||
<!-- Register an aframe component that allows reacting to marker events --> | ||
<script> | ||
AFRAME.registerComponent('registerevents', { | ||
init: function () { | ||
var marker = this.el; | ||
|
||
// Make the element emit events when found and when lost. | ||
marker.setAttribute('emitevents', 'true'); | ||
|
||
marker.addEventListener('markerFound', function() { | ||
var markerId = marker.id; | ||
console.log('markerFound', markerId); | ||
// TODO: Add your own code here to react to the marker being found. | ||
}); | ||
|
||
marker.addEventListener('markerLost', function() { | ||
var markerId = marker.id; | ||
console.log('markerLost', markerId); | ||
// TODO: Add your own code here to react to the marker being lost. | ||
}); | ||
} | ||
}); | ||
</script> | ||
|
||
<body style='margin : 0px; overflow: hidden; font-family: Monospace;'><div style='position: fixed; top: 10px; width:100%; text-align: center; z-index: 1;'> | ||
<a href="https://github.com/jeromeetienne/AR.js/" target="_blank">AR.js</a> - marker events example for a-frame | ||
<br/> | ||
Contact me any time at <a href='https://twitter.com/jerome_etienne' target='_blank'>@jerome_etienne</a> | ||
</div> | ||
<a-scene embedded arjs='sourceType: webcam; detectionMode: mono_and_matrix; matrixCodeType: 3x3;'> | ||
<!-- handle hiro marker --> | ||
<!-- 'registerevents' will register event listeners for the marker when it is found and lost, | ||
as defined in the inline script above --> | ||
<a-marker preset='hiro' id='marker-hiro' registerevents> | ||
</a-marker> | ||
|
||
<!-- handle matrix marker --> | ||
<!-- 'emitevents' will make the marker emit events when it is found and lost | ||
but, since there are no registered listeners for these events, you will not see any effect. | ||
You can register event listeners in your own custom component, defined similarly to | ||
the 'registerevents' in the inline script above --> | ||
<a-marker type='barcode' value='5' id='marker-barcode-5' emitevents='true'> | ||
</a-marker> | ||
|
||
<!-- add a simple camera --> | ||
<a-entity camera></a-entity> | ||
</a-scene> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,12 @@ AFRAME.registerComponent('arjs-anchor', { | |
type: 'number', | ||
default: 0.6, | ||
}, | ||
|
||
// Whether to emit events when the element is found or lost. | ||
emitevents: { | ||
type: 'boolean', | ||
default: false, | ||
} | ||
}, | ||
init: function () { | ||
var _this = this | ||
|
@@ -155,7 +161,16 @@ AFRAME.registerComponent('arjs-anchor', { | |
// honor visibility | ||
////////////////////////////////////////////////////////////////////////////// | ||
if( _this._arAnchor.parameters.changeMatrixMode === 'modelViewMatrix' ){ | ||
var wasVisible = _this.el.object3D.visible | ||
_this.el.object3D.visible = this._arAnchor.object3d.visible | ||
|
||
if( _this.data.emitevents ){ | ||
if( _this.el.object3D.visible && !wasVisible ){ | ||
_this.el.emit('markerFound') | ||
}else if( !_this.el.object3D.visible && wasVisible ){ | ||
_this.el.emit('markerLost') | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice standalone trick! what about the 'cameraTransformMatrix' case tho ? |
||
}else if( _this._arAnchor.parameters.changeMatrixMode === 'cameraTransformMatrix' ){ | ||
_this.el.sceneEl.object3D.visible = this._arAnchor.object3d.visible | ||
}else console.assert(false) | ||
|
@@ -212,6 +227,7 @@ AFRAME.registerPrimitive('a-marker', AFRAME.utils.extendDeep({}, AFRAME.primitiv | |
'preset': 'arjs-anchor.preset', | ||
'minConfidence': 'arjs-anchor.minConfidence', | ||
'markerhelpers': 'arjs-anchor.markerhelpers', | ||
'emitevents': 'arjs-anchor.emitevents', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be removed, as seen above |
||
|
||
'hit-testing-renderDebug': 'arjs-hit-testing.renderDebug', | ||
'hit-testing-enabled': 'arjs-hit-testing.enabled', | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(thanks a lot for your contributions @NikolayMihaylov, im making comments here but you dont have to do it. i can do the modification myself after the merge)
this seems harmless to emit the event. it is a rare event so no performance impact. we can remove this options for the sake of simplicity