Geometry5.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.Geometry5 = function ( size ) {
  5. THREE.BufferGeometry.call( this );
  6. var verticesBuffer = new Float32Array( size * 3 );
  7. var normalsBuffer = new Float32Array( size * 3 );
  8. var uvsBuffer = new Float32Array( size * 2 );
  9. this.vertices = [];
  10. this.normals = [];
  11. this.uvs = [];
  12. for ( var i = 0; i < size; i ++ ) {
  13. this.vertices.push( new THREE.TypedVector3( verticesBuffer, i * 3 ) );
  14. this.normals.push( new THREE.TypedVector3( normalsBuffer, i * 3 ) );
  15. this.uvs.push( new THREE.TypedVector2( uvsBuffer, i * 2 ) );
  16. }
  17. this.attributes[ 'position' ] = { array: verticesBuffer, itemSize: 3 };
  18. this.attributes[ 'normal' ] = { array: normalsBuffer, itemSize: 3 };
  19. this.attributes[ 'uv' ] = { array: uvsBuffer, itemSize: 2 };
  20. };
  21. THREE.Geometry5.prototype = Object.create( THREE.BufferGeometry.prototype );
  22. THREE.Geometry5.prototype.constructor = THREE.Geometry5;
  23. THREE.TypedVector2 = function ( array, offset ) {
  24. this.array = array;
  25. this.offset = offset;
  26. };
  27. THREE.TypedVector2.prototype = Object.create( THREE.Vector2.prototype );
  28. THREE.TypedVector2.prototype.constructor = THREE.TypedVector2;
  29. Object.defineProperties( THREE.TypedVector2.prototype, {
  30. 'x': {
  31. get: function () { return this.array[ this.offset ]; },
  32. set: function ( v ) { this.array[ this.offset ] = v; }
  33. },
  34. 'y': {
  35. get: function () { return this.array[ this.offset + 1 ]; },
  36. set: function ( v ) { this.array[ this.offset + 1 ] = v; }
  37. }
  38. } );
  39. THREE.TypedVector3 = function ( array, offset ) {
  40. this.array = array;
  41. this.offset = offset;
  42. };
  43. THREE.TypedVector3.prototype = Object.create( THREE.Vector3.prototype );
  44. THREE.TypedVector3.prototype.constructor = THREE.TypedVector3;
  45. Object.defineProperties( THREE.TypedVector3.prototype, {
  46. 'x': {
  47. get: function () { return this.array[ this.offset ]; },
  48. set: function ( v ) { this.array[ this.offset ] = v; }
  49. },
  50. 'y': {
  51. get: function () { return this.array[ this.offset + 1 ]; },
  52. set: function ( v ) { this.array[ this.offset + 1 ] = v; }
  53. },
  54. 'z': {
  55. get: function () { return this.array[ this.offset + 2 ]; },
  56. set: function ( v ) { this.array[ this.offset + 2 ] = v; }
  57. }
  58. } );