MultiColor.js 1001 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Allows updating of multiple THREE.Color objects with the same value
  2. // Used for face.color -> face.vertexColor[] compatibility layer for non-indexed geometry
  3. THREE.MultiColor = function(links) {
  4. this.links = links;
  5. }
  6. THREE.MultiColor.prototype = Object.create( THREE.Color.prototype );
  7. THREE.MultiColor.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 color
  13. // Setters set the same value for all linked colors
  14. Object.defineProperties( THREE.MultiColor.prototype, {
  15. 'r': {
  16. get: function () { return (this.links[0] ? this.links[0].r : 0); },
  17. set: function ( v ) { this.setAll('r', v); }
  18. },
  19. 'g': {
  20. get: function () { return (this.links[0] ? this.links[0].g : 0); },
  21. set: function ( v ) { this.setAll('g', v); }
  22. },
  23. 'b': {
  24. get: function () { return (this.links[0] ? this.links[0].b : 0); },
  25. set: function ( v ) { this.setAll('b', v); }
  26. }
  27. } );