ImageUtils.js 779 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var ImageUtils = {
  2. loadTexture: function ( path, mapping, callback ) {
  3. var image = new Image(),
  4. texture = new THREE.Texture( image, mapping );
  5. image.onload = function () { texture.needsUpdate = true; if( callback ) callback( this ); };
  6. image.src = path;
  7. return texture;
  8. },
  9. loadTextureCube: function ( array, mapping, callback ) {
  10. var i, l,
  11. images = [],
  12. texture = new THREE.Texture( images, mapping );
  13. images.loadCount = 0;
  14. for ( i = 0, l = array.length; i < l; ++i ) {
  15. images[ i ] = new Image();
  16. images[ i ].onload = function () {
  17. images.loadCount += 1;
  18. if( images.loadCount == 6 ) texture.needsUpdate = true;
  19. if( callback ) callback( this );
  20. };
  21. images[ i ].src = array[ i ];
  22. }
  23. return texture;
  24. }
  25. };