GeometryLoader.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.GeometryLoader = function ( manager ) {
  5. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  6. };
  7. THREE.GeometryLoader.prototype = {
  8. constructor: THREE.GeometryLoader,
  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.Geometry();
  22. geometry.indices = json.indices;
  23. geometry.vertices = json.vertices;
  24. geometry.normals = json.normals;
  25. geometry.uvs = json.uvs;
  26. var boundingSphere = json.boundingSphere;
  27. if ( boundingSphere !== undefined ) {
  28. geometry.boundingSphere = new THREE.Sphere(
  29. new THREE.Vector3().fromArray( boundingSphere.center !== undefined ? boundingSphere.center : [ 0, 0, 0 ] ),
  30. boundingSphere.radius
  31. );
  32. }
  33. return geometry;
  34. }
  35. };
粤ICP备19079148号