GeometryLoader.js 1.2 KB

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