BufferGeometryExporter.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.BufferGeometryExporter = function () {};
  5. THREE.BufferGeometryExporter.prototype = {
  6. constructor: THREE.BufferGeometryExporter,
  7. parse: function ( geometry ) {
  8. var output = {
  9. metadata: {
  10. version: 4.0,
  11. type: 'BufferGeometry',
  12. generator: 'BufferGeometryExporter'
  13. },
  14. attributes: {
  15. }
  16. };
  17. var attributes = geometry.attributes;
  18. var offsets = geometry.offsets;
  19. var boundingSphere = geometry.boundingSphere;
  20. for ( var key in attributes ) {
  21. var attribute = attributes[ key ];
  22. var array = [], typeArray = attribute.array;
  23. for ( var i = 0, l = typeArray.length; i < l; i ++ ) {
  24. array[ i ] = typeArray[ i ];
  25. }
  26. output.attributes[ key ] = {
  27. itemSize: attribute.itemSize,
  28. type: attribute.array.constructor.name,
  29. array: array
  30. }
  31. }
  32. if ( offsets.length > 0 ) {
  33. output.offsets = JSON.parse( JSON.stringify( offsets ) );
  34. }
  35. if ( boundingSphere !== null ) {
  36. output.boundingSphere = {
  37. center: boundingSphere.center.toArray(),
  38. radius: boundingSphere.radius
  39. }
  40. }
  41. return output;
  42. }
  43. };