GeometryEditor.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.GeometryEditor = function ( geometry ) {
  5. this.geometry = geometry;
  6. };
  7. Object.defineProperties( THREE.GeometryEditor.prototype, {
  8. vertices: {
  9. enumerable: true,
  10. get: function() { return this.createVertexProxies(); }
  11. },
  12. normals: {
  13. enumerable: true,
  14. get: function() { return this.createNormalProxies(); }
  15. },
  16. uvs: {
  17. enumerable: true,
  18. get: function() { return this.createUVProxies(); }
  19. }
  20. } );
  21. THREE.GeometryEditor.prototype.createVertexProxies = function () {
  22. Object.defineProperty( this, 'vertices', { value: [], writable: true } );
  23. var attributes = this.geometry.attributes;
  24. var length = attributes.position.array.length / 3;
  25. for ( var i = 0; i < length; i ++ ) {
  26. this.vertices.push( new THREE.ProxyVector3( attributes.position.array, i * 3 ) );
  27. }
  28. return this.vertices;
  29. };
  30. THREE.GeometryEditor.prototype.createNormalProxies = function () {
  31. Object.defineProperty( this, 'normals', { value: [], writable: true } );
  32. var attributes = this.geometry.attributes;
  33. var length = attributes.position.array.length / 3;
  34. for ( var i = 0; i < length; i ++ ) {
  35. this.normals.push( new THREE.ProxyVector3( attributes.normal.array, i * 3 ) );
  36. }
  37. return this.normals;
  38. };
  39. THREE.GeometryEditor.prototype.createUVProxies = function () {
  40. Object.defineProperty( this, 'uvs', { value: [], writable: true } );
  41. var attributes = this.geometry.attributes;
  42. var length = attributes.position.array.length / 3;
  43. for ( var i = 0; i < length; i ++ ) {
  44. this.uvs.push( new THREE.ProxyVector2( attributes.uv.array, i * 2 ) );
  45. }
  46. return this.uvs;
  47. };