MultiVector3.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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.constructor = THREE.MultiVector3;
  8. THREE.MultiVector3.prototype.setAll = function(axis, value) {
  9. for (var i = 0, l = this.links.length; i < l; i ++) {
  10. this.links[i][axis] = value;
  11. }
  12. }
  13. // Getters return value from the first linked vector
  14. // Setters set the same value for all linked vectors
  15. Object.defineProperties( THREE.MultiVector3.prototype, {
  16. 'x': {
  17. get: function () { return (this.links[0] ? this.links[0].x : 0); },
  18. set: function ( v ) { this.setAll('x', v); }
  19. },
  20. 'y': {
  21. get: function () { return (this.links[0] ? this.links[0].y : 0); },
  22. set: function ( v ) { this.setAll('y', v); }
  23. },
  24. 'z': {
  25. get: function () { return (this.links[0] ? this.links[0].z : 0); },
  26. set: function ( v ) { this.setAll('z', v); }
  27. }
  28. } );