Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <a-entity position="0 0 0" rotation="0 0 0" >
- <a-video Mysmoothingfunction src="#video" width="3.5" height="2"></a-video>
- </a-entity>
- <script type="text/javascript">
- AFRAME.registerComponent("listener", {
- schema :
- {
- stepFactor : {
- type : "number",
- default : 0.05
- }
- },
- tick: function() {
- this.getProperty("position"); // something like this?
- }
- </script>
- AFRAME.registerComponent("listener", {
- init: function() {
- this.target = document.querySelector('#target'); // your video
- this.prevPosition = null; // initially there is no position or rotation
- this.prevRotation = null;
- },
- tick: function() {
- if (this.el.object3D.visible) {
- this.target.setAttribute('visible', 'true')
- if(!this.prevPosition) {
- // there are no values to lerp from - set the initial values
- this.target.setAttribute('position', this.el.getAttribute('position'))
- this.target.setAttribute('rotation', this.el.getAttribute('rotation'))
- } else {
- // use the previous values to get an approximation
- this.target.object3D.position.lerp(this.prevPosition, 0.1)
- let rot = this.target.object3D.rotation.toVector3().lerp(this.prevRotation, 0.1)
- this.target.object3D.rotation.setFromVector3(rot)
- }
- // update the values
- this.prevPosition = this.el.object3D.position
- this.prevRotation = this.el.object3D.rotation
- } else {
- // the marker dissapeared - reset the values
- this.target.setAttribute('visible', 'false')
- this.prevPosition = null;
- this.prevRotation = null;
- }
- }
- })
Add Comment
Please, Sign In to add comment