Material.js 2.5 KB

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