BufferGeometryExporter.js 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. output.attributes[ key ] = {
  23. itemSize: attribute.itemSize,
  24. type: attribute.array.constructor.name,
  25. array: Array.apply( [], attribute.array )
  26. }
  27. }
  28. if ( offsets.length > 0 ) {
  29. output.offsets = JSON.parse( JSON.stringify( offsets ) );
  30. }
  31. if ( boundingSphere !== null ) {
  32. output.boundingSphere = {
  33. center: boundingSphere.center.toArray(),
  34. radius: boundingSphere.radius
  35. }
  36. }
  37. return output;
  38. }
  39. };