BufferGeometryLoader.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. } );
  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. var offsets = json.offsets;
  24. var boundingSphere = json.boundingSphere;
  25. for ( var key in attributes ) {
  26. var attribute = attributes[ key ];
  27. geometry.attributes[ key ] = {
  28. itemSize: attribute.itemSize,
  29. array: new self[ attribute.type ]( attribute.array )
  30. }
  31. }
  32. if ( offsets !== undefined ) {
  33. geometry.offsets = JSON.parse( JSON.stringify( offsets ) );
  34. }
  35. if ( boundingSphere !== undefined ) {
  36. geometry.boundingSphere = new THREE.Sphere( undefined, boundingSphere.radius );
  37. }
  38. return geometry;
  39. }
  40. };