Geometry2Loader.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. var center = new THREE.Vector3();
  30. if ( boundingSphere.center !== undefined ) {
  31. center.fromArray( boundingSphere.center );
  32. }
  33. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  34. }
  35. return geometry;
  36. }
  37. };