MultiColor.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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.constructor = THREE.MultiColor;
  8. THREE.MultiColor.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 color
  14. // Setters set the same value for all linked colors
  15. Object.defineProperties( THREE.MultiColor.prototype, {
  16. 'r': {
  17. get: function () { return (this.links[0] ? this.links[0].r : 0); },
  18. set: function ( v ) { this.setAll('r', v); }
  19. },
  20. 'g': {
  21. get: function () { return (this.links[0] ? this.links[0].g : 0); },
  22. set: function ( v ) { this.setAll('g', v); }
  23. },
  24. 'b': {
  25. get: function () { return (this.links[0] ? this.links[0].b : 0); },
  26. set: function ( v ) { this.setAll('b', v); }
  27. }
  28. } );