Material.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * @author alteredq / http://alteredqualia.com/
  4. */
  5. THREE.Material = function () {
  6. this.id = THREE.Math.generateUUID();
  7. this.name = '';
  8. this.side = THREE.FrontSide;
  9. this.opacity = 1;
  10. this.transparent = false;
  11. this.blending = THREE.NormalBlending;
  12. this.blendSrc = THREE.SrcAlphaFactor;
  13. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  14. this.blendEquation = THREE.AddEquation;
  15. this.depthTest = true;
  16. this.depthWrite = true;
  17. this.polygonOffset = false;
  18. this.polygonOffsetFactor = 0;
  19. this.polygonOffsetUnits = 0;
  20. this.alphaTest = 0;
  21. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  22. this.visible = true;
  23. this.needsUpdate = true;
  24. };
  25. THREE.Material.prototype = {
  26. constructor: THREE.Material,
  27. addEventListener: THREE.EventDispatcher.prototype.addEventListener,
  28. hasEventListener: THREE.EventDispatcher.prototype.hasEventListener,
  29. removeEventListener: THREE.EventDispatcher.prototype.removeEventListener,
  30. dispatchEvent: THREE.EventDispatcher.prototype.dispatchEvent,
  31. setValues: function ( values ) {
  32. if ( values === undefined ) return;
  33. for ( var key in values ) {
  34. var newValue = values[ key ];
  35. if ( newValue === undefined ) {
  36. console.warn( 'THREE.Material: \'' + key + '\' parameter is undefined.' );
  37. continue;
  38. }
  39. if ( key in this ) {
  40. var currentValue = this[ key ];
  41. if ( currentValue instanceof THREE.Color ) {
  42. currentValue.set( newValue );
  43. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  44. currentValue.copy( newValue );
  45. } else if ( key == 'overdraw') {
  46. // ensure overdraw is backwards-compatable with legacy boolean type
  47. this[ key ] = Number(newValue);
  48. } else {
  49. this[ key ] = newValue;
  50. }
  51. }
  52. }
  53. },
  54. clone: function ( material ) {
  55. if ( material === undefined ) material = new THREE.Material();
  56. material.name = this.name;
  57. material.side = this.side;
  58. material.opacity = this.opacity;
  59. material.transparent = this.transparent;
  60. material.blending = this.blending;
  61. material.blendSrc = this.blendSrc;
  62. material.blendDst = this.blendDst;
  63. material.blendEquation = this.blendEquation;
  64. material.depthTest = this.depthTest;
  65. material.depthWrite = this.depthWrite;
  66. material.polygonOffset = this.polygonOffset;
  67. material.polygonOffsetFactor = this.polygonOffsetFactor;
  68. material.polygonOffsetUnits = this.polygonOffsetUnits;
  69. material.alphaTest = this.alphaTest;
  70. material.overdraw = this.overdraw;
  71. material.visible = this.visible;
  72. return material;
  73. },
  74. dispose: function () {
  75. this.dispatchEvent( { type: 'dispose' } );
  76. }
  77. };