Geometry2Loader.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.Geometry2Loader = function ( manager ) {
  5. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  6. };
  7. THREE.Geometry2Loader.prototype = {
  8. constructor: THREE.Geometry2Loader,
  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.Geometry2( json.vertices.length / 3 );
  22. var attributes = [ 'vertices', 'normals', 'uvs' ];
  23. var boundingSphere = json.boundingSphere;
  24. for ( var key in attributes ) {
  25. var attribute = attributes[ key ];
  26. geometry[ attribute ].set( json[ attribute ] );
  27. }
  28. if ( boundingSphere !== undefined ) {
  29. geometry.boundingSphere = new THREE.Sphere(
  30. new THREE.Vector3().fromArray( boundingSphere.center !== undefined ? boundingSphere.center : [ 0, 0, 0 ] ),
  31. boundingSphere.radius
  32. );
  33. }
  34. return geometry;
  35. }
  36. };