2
0

Geometry5.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.TypedVector2 = function ( array, offset ) {
  23. this.array = array;
  24. this.offset = offset;
  25. };
  26. THREE.TypedVector2.prototype = Object.create( THREE.Vector2.prototype );
  27. Object.defineProperties( THREE.TypedVector2.prototype, {
  28. 'x': {
  29. get: function () { return this.array[ this.offset ]; },
  30. set: function ( v ) { this.array[ this.offset ] = v; }
  31. },
  32. 'y': {
  33. get: function () { return this.array[ this.offset + 1 ]; },
  34. set: function ( v ) { this.array[ this.offset + 1 ] = v; }
  35. }
  36. } );
  37. THREE.TypedVector3 = function ( array, offset ) {
  38. this.array = array;
  39. this.offset = offset;
  40. };
  41. THREE.TypedVector3.prototype = Object.create( THREE.Vector3.prototype );
  42. Object.defineProperties( THREE.TypedVector3.prototype, {
  43. 'x': {
  44. get: function () { return this.array[ this.offset ]; },
  45. set: function ( v ) { this.array[ this.offset ] = v; }
  46. },
  47. 'y': {
  48. get: function () { return this.array[ this.offset + 1 ]; },
  49. set: function ( v ) { this.array[ this.offset + 1 ] = v; }
  50. },
  51. 'z': {
  52. get: function () { return this.array[ this.offset + 2 ]; },
  53. set: function ( v ) { this.array[ this.offset + 2 ] = v; }
  54. }
  55. } );