SoundRenderer.js 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @author mikael emtinger / http://gomo.se/
  3. */
  4. THREE.SoundRenderer = function() {
  5. this.volume = 1;
  6. this.domElement = document.createElement( "div" );
  7. this.domElement.id = "THREESound";
  8. this.cameraPosition = new THREE.Vector3();
  9. this.soundPosition = new THREE.Vector3();
  10. /*
  11. * Render
  12. */
  13. this.render = function( scene, camera, callSceneUpdate ) {
  14. if( callSceneUpdate )
  15. scene.update( undefined, false, camera );
  16. // loop through all sounds
  17. var sound;
  18. var sounds = scene.sounds;
  19. var s, l = sounds.length;
  20. //camera.globalMatrix.extractPositionVector( this.cameraPosition );
  21. for( s = 0; s < l; s++ ) {
  22. sound = sounds[ s ];
  23. sound.globalMatrix.extractPositionVector( this.soundPosition );
  24. this.soundPosition.subSelf( camera.position );
  25. if( sound.isPlaying && sound.isLoaded ) {
  26. if( !sound.isAddedToDOM )
  27. sound.addToDOM( this.domElement );
  28. sound.calculateVolumeAndPan( this.soundPosition );
  29. }
  30. }
  31. }
  32. }