ParticleSystemUtil.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @author Mark Kellogg - http://www.github.com/mkkellogg
  3. */
  4. var ParticleSystemUtil = {
  5. loadingManager: undefined,
  6. objLoader: undefined,
  7. imageLoader: undefined,
  8. initializeLoadingManager: function() {
  9. this.loadingManager = new THREE.LoadingManager();
  10. this.loadingManager.onProgress = function( item, loaded, total ) {
  11. console.log( "Loaded " + loaded + " items out of " + total + ": " + item);
  12. };
  13. },
  14. loadObj: function( objFile, textureFile, material, onMesh, onLoadComplete ) {
  15. var onProgress = function( xhr ) {
  16. if ( xhr.lengthComputable ) {
  17. var percentComplete = xhr.loaded / xhr.total * 100;
  18. //console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
  19. }
  20. };
  21. var onError = function( xhr ) {
  22. console.log( "ERROR: loadObj() - " + xhr );
  23. };
  24. if ( ! this.objLoader ) {
  25. this.objLoader = new THREE.OBJLoader( loadingManager );
  26. }
  27. if ( ! this.imageLoader ) {
  28. this.imageLoader = new THREE.ImageLoader( this.loadingManager );
  29. }
  30. var texture = new THREE.Texture();
  31. var _this = this;
  32. this.imageLoader.load( textureFile, function( image ) {
  33. texture.image = image;
  34. texture.needsUpdate = true;
  35. _this.objLoader.load( objFile, function( object ) {
  36. object.traverse( function( child ) {
  37. if ( child instanceof THREE.Mesh ) {
  38. child.material = material;
  39. child.material.map = texture;
  40. if ( onMesh ) {
  41. onMesh ( child );
  42. }
  43. }
  44. } );
  45. console.log( "Finished loading model: " + objFile );
  46. if ( onLoadComplete ) {
  47. onLoadComplete( object );
  48. }
  49. }, onProgress, onError );
  50. } );
  51. }
  52. }