Geometry2.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.Geometry = function ( size ) {
  5. this.id = THREE.GeometryIdCount ++;
  6. this.uuid = THREE.Math.generateUUID();
  7. this.name = '';
  8. this.vertices = size !== undefined ? new Float32Array( size * 3 ) : [];
  9. this.normals = size !== undefined ? new Float32Array( size * 3 ) : [];
  10. this.uvs = size !== undefined ? new Float32Array( size * 2 ) : [];
  11. this.boundingBox = null;
  12. this.boundingSphere = null;
  13. };
  14. THREE.Geometry.prototype = {
  15. constructor: THREE.Geometry,
  16. applyMatrix: function ( matrix ) {
  17. matrix.multiplyVector3Array( this.vertices );
  18. },
  19. computeBoundingSphere: function () {
  20. var box = new THREE.Box3();
  21. var vector = new THREE.Vector3();
  22. return function () {
  23. if ( this.boundingSphere === null ) {
  24. this.boundingSphere = new THREE.Sphere();
  25. }
  26. box.makeEmpty();
  27. var vertices = this.vertices;
  28. var center = this.boundingSphere.center;
  29. for ( var i = 0, il = vertices.length; i < il; i += 3 ) {
  30. vector.set( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] );
  31. box.addPoint( vector );
  32. }
  33. box.center( center );
  34. var maxRadiusSq = 0;
  35. for ( var i = 0, il = vertices.length; i < il; i += 3 ) {
  36. vector.set( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] );
  37. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  38. }
  39. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  40. }
  41. }(),
  42. dispose: function () {
  43. this.dispatchEvent( { type: 'dispose' } );
  44. }
  45. };
  46. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );