BufferGeometryLoader.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.BufferGeometryLoader = function ( manager ) {
  5. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  6. };
  7. THREE.BufferGeometryLoader.prototype = {
  8. constructor: THREE.BufferGeometryLoader,
  9. load: function ( url, onLoad, onProgress, onError ) {
  10. var scope = this;
  11. var loader = new THREE.XHRLoader();
  12. loader.setCrossOrigin( this.crossOrigin );
  13. loader.load( url, function ( text ) {
  14. onLoad( scope.parse( JSON.parse( text ) ) );
  15. }, onProgress, onError );
  16. },
  17. setCrossOrigin: function ( value ) {
  18. this.crossOrigin = value;
  19. },
  20. parse: function ( json ) {
  21. var geometry = new THREE.BufferGeometry();
  22. var attributes = json.attributes;
  23. for ( var key in attributes ) {
  24. var attribute = attributes[ key ];
  25. geometry.attributes[ key ] = {
  26. itemSize: attribute.itemSize,
  27. array: new self[ attribute.type ]( attribute.array )
  28. }
  29. }
  30. var offsets = json.offsets;
  31. if ( offsets !== undefined ) {
  32. geometry.offsets = JSON.parse( JSON.stringify( offsets ) );
  33. }
  34. var boundingSphere = json.boundingSphere;
  35. if ( boundingSphere !== undefined ) {
  36. geometry.boundingSphere = new THREE.Sphere(
  37. new THREE.Vector3().fromArray( boundingSphere.center !== undefined ? boundingSphere.center : [ 0, 0, 0 ] ),
  38. boundingSphere.radius
  39. );
  40. }
  41. return geometry;
  42. }
  43. };