/src/away3d/materials/ColorMaterial.as

http://github.com/away3d/away3d-core-fp11 · ActionScript · 68 lines · 42 code · 9 blank · 17 comment · 6 complexity · 7d52f4c6ee07197d1d77c2d4dbfde907 MD5 · raw file

  1. package away3d.materials
  2. {
  3. import away3d.arcane;
  4. import flash.display.BlendMode;
  5. use namespace arcane;
  6. /**
  7. * ColorMaterial is a single-pass material that uses a flat color as the surface's diffuse reflection value.
  8. */
  9. public class ColorMaterial extends SinglePassMaterialBase
  10. {
  11. private var _diffuseAlpha:Number = 1;
  12. /**
  13. * Creates a new ColorMaterial object.
  14. * @param color The material's diffuse surface color.
  15. * @param alpha The material's surface alpha.
  16. */
  17. public function ColorMaterial(color:uint = 0xcccccc, alpha:Number = 1)
  18. {
  19. super();
  20. this.color = color;
  21. this.alpha = alpha;
  22. }
  23. /**
  24. * The alpha of the surface.
  25. */
  26. public function get alpha():Number
  27. {
  28. return _screenPass.diffuseMethod.diffuseAlpha;
  29. }
  30. public function set alpha(value:Number):void
  31. {
  32. if (value > 1)
  33. value = 1;
  34. else if (value < 0)
  35. value = 0;
  36. _screenPass.diffuseMethod.diffuseAlpha = _diffuseAlpha = value;
  37. _screenPass.preserveAlpha = requiresBlending;
  38. _screenPass.setBlendMode(blendMode == BlendMode.NORMAL && requiresBlending? BlendMode.LAYER : blendMode);
  39. }
  40. /**
  41. * The diffuse reflectivity color of the surface.
  42. */
  43. public function get color():uint
  44. {
  45. return _screenPass.diffuseMethod.diffuseColor;
  46. }
  47. public function set color(value:uint):void
  48. {
  49. _screenPass.diffuseMethod.diffuseColor = value;
  50. }
  51. /**
  52. * @inheritDoc
  53. */
  54. override public function get requiresBlending():Boolean
  55. {
  56. return super.requiresBlending || _diffuseAlpha < 1;
  57. }
  58. }
  59. }