Guest User

Untitled

a guest
Nov 19th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. <a-entity position="0 0 0" rotation="0 0 0" >
  2. <a-video Mysmoothingfunction src="#video" width="3.5" height="2"></a-video>
  3. </a-entity>
  4.  
  5. <script type="text/javascript">
  6. AFRAME.registerComponent("listener", {
  7. schema :
  8. {
  9. stepFactor : {
  10. type : "number",
  11. default : 0.05
  12. }
  13. },
  14. tick: function() {
  15. this.getProperty("position"); // something like this?
  16. }
  17. </script>
  18.  
  19. AFRAME.registerComponent("listener", {
  20. init: function() {
  21. this.target = document.querySelector('#target'); // your video
  22. this.prevPosition = null; // initially there is no position or rotation
  23. this.prevRotation = null;
  24. },
  25. tick: function() {
  26. if (this.el.object3D.visible) {
  27. this.target.setAttribute('visible', 'true')
  28. if(!this.prevPosition) {
  29. // there are no values to lerp from - set the initial values
  30. this.target.setAttribute('position', this.el.getAttribute('position'))
  31. this.target.setAttribute('rotation', this.el.getAttribute('rotation'))
  32. } else {
  33. // use the previous values to get an approximation
  34. this.target.object3D.position.lerp(this.prevPosition, 0.1)
  35. let rot = this.target.object3D.rotation.toVector3().lerp(this.prevRotation, 0.1)
  36. this.target.object3D.rotation.setFromVector3(rot)
  37. }
  38. // update the values
  39. this.prevPosition = this.el.object3D.position
  40. this.prevRotation = this.el.object3D.rotation
  41. } else {
  42. // the marker dissapeared - reset the values
  43. this.target.setAttribute('visible', 'false')
  44. this.prevPosition = null;
  45. this.prevRotation = null;
  46. }
  47. }
  48. })
Add Comment
Please, Sign In to add comment