BufferGeometryLoader.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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( scope.manager );
  12. loader.load( url, function ( text ) {
  13. onLoad( scope.parse( JSON.parse( text ) ) );
  14. }, onProgress, onError );
  15. },
  16. parse: function ( json ) {
  17. var geometry = new THREE.BufferGeometry();
  18. var index = json.data.index;
  19. if ( index !== undefined ) {
  20. var typedArray = new self[ index.type ]( index.array );
  21. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  22. }
  23. var attributes = json.data.attributes;
  24. for ( var key in attributes ) {
  25. var attribute = attributes[ key ];
  26. var typedArray = new self[ attribute.type ]( attribute.array );
  27. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  28. }
  29. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  30. if ( groups !== undefined ) {
  31. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  32. var group = groups[ i ];
  33. geometry.addGroup( group.start, group.count, group.materialIndex );
  34. }
  35. }
  36. var boundingSphere = json.data.boundingSphere;
  37. if ( boundingSphere !== undefined ) {
  38. var center = new THREE.Vector3();
  39. if ( boundingSphere.center !== undefined ) {
  40. center.fromArray( boundingSphere.center );
  41. }
  42. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  43. }
  44. return geometry;
  45. }
  46. };
粤ICP备19079148号