MultiVector3.js 1009 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Allows updating of multiple THREE.Vector3 objects with the same value
  2. // Used for face.normal -> face.vertexNormal[] compatibility layer for FlatShading
  3. THREE.MultiVector3 = function(links) {
  4. this.links = links;
  5. }
  6. THREE.MultiVector3.prototype = Object.create( THREE.Vector3.prototype );
  7. THREE.MultiVector3.prototype.setAll = function(axis, value) {
  8. for (var i = 0, l = this.links.length; i < l; i++) {
  9. this.links[i][axis] = value;
  10. }
  11. }
  12. // Getters return value from the first linked vector
  13. // Setters set the same value for all linked vectors
  14. Object.defineProperties( THREE.MultiVector3.prototype, {
  15. 'x': {
  16. get: function () { return (this.links[0] ? this.links[0].x : 0); },
  17. set: function ( v ) { this.setAll('x', v); }
  18. },
  19. 'y': {
  20. get: function () { return (this.links[0] ? this.links[0].y : 0); },
  21. set: function ( v ) { this.setAll('y', v); }
  22. },
  23. 'z': {
  24. get: function () { return (this.links[0] ? this.links[0].z : 0); },
  25. set: function ( v ) { this.setAll('z', v); }
  26. }
  27. } );