/src/away3d/materials/BitmapMaterial.as

http://github.com/away3d/away3d-core-fp11 · ActionScript · 117 lines · 70 code · 17 blank · 30 comment · 5 complexity · dfbe7788abbff77c879cf06d68ae785c MD5 · raw file

  1. package away3d.materials
  2. {
  3. import away3d.arcane;
  4. import away3d.cameras.Camera3D;
  5. import flash.display.BitmapData;
  6. import flash.display3D.Context3D;
  7. import flash.geom.ColorTransform;
  8. use namespace arcane;
  9. /**
  10. * BitmapMaterial is a material that uses a BitmapData texture as the surface's diffuse colour.
  11. */
  12. public class BitmapMaterial extends DefaultMaterialBase
  13. {
  14. private var _alphaBlending : Boolean;
  15. /**
  16. * Creates a new BitmapMaterial.
  17. * @param bitmapData The BitmapData object to use as the texture.
  18. * @param smooth Indicates whether or not the texture should use smoothing.
  19. * @param repeat Indicates whether or not the texture should be tiled.
  20. * @param mipmap Indicates whether or not the texture should use mipmapping.
  21. */
  22. public function BitmapMaterial(bitmapData : BitmapData = null, smooth : Boolean = true, repeat : Boolean = false, mipmap : Boolean = true)
  23. {
  24. super();
  25. this.bitmapData = bitmapData;
  26. this.smooth = smooth;
  27. this.repeat = repeat;
  28. this.mipmap = mipmap;
  29. }
  30. public function get animateUVs() : Boolean
  31. {
  32. return _screenPass.animateUVs;
  33. }
  34. public function set animateUVs(value : Boolean) : void
  35. {
  36. _screenPass.animateUVs = value;
  37. }
  38. /**
  39. * The alpha of the surface.
  40. */
  41. public function get alpha() : Number
  42. {
  43. return _screenPass.colorTransform? _screenPass.colorTransform.alphaMultiplier : 1;
  44. }
  45. public function set alpha(value : Number) : void
  46. {
  47. if (value > 1) value = 1;
  48. else if (value < 0) value = 0;
  49. colorTransform ||= new ColorTransform();
  50. colorTransform.alphaMultiplier = value;
  51. }
  52. // arcane override function activatePass(index : uint, context : Context3D, contextIndex : uint, camera : Camera3D) : void
  53. // {
  54. // super.arcane::activatePass(index, context, contextIndex, camera);
  55. // }
  56. /**
  57. * The BitmapData object to use as the texture.
  58. */
  59. public function get bitmapData() : BitmapData
  60. {
  61. return _screenPass.diffuseMethod.bitmapData;
  62. }
  63. public function set bitmapData(value : BitmapData) : void
  64. {
  65. _screenPass.diffuseMethod.bitmapData = value;
  66. }
  67. /**
  68. * Triggers an update of the texture, to be used when the contents of the BitmapData has changed.
  69. */
  70. public function updateTexture() : void
  71. {
  72. _screenPass.diffuseMethod.invalidateBitmapData();
  73. }
  74. override public function get requiresBlending() : Boolean
  75. {
  76. return super.requiresBlending || _alphaBlending;
  77. }
  78. /**
  79. * Indicate whether or not the BitmapData contains semi-transparency. If binary transparency is sufficient, for
  80. * example when using textures of foliage, consider using alphaThreshold instead.
  81. */
  82. public function get alphaBlending() : Boolean
  83. {
  84. return _alphaBlending;
  85. }
  86. public function set alphaBlending(value : Boolean) : void
  87. {
  88. _alphaBlending = value;
  89. }
  90. /**
  91. * @inheritDoc
  92. */
  93. override public function dispose(deep : Boolean) : void
  94. {
  95. if (deep)
  96. _screenPass.dispose(deep);
  97. super.dispose(deep);
  98. }
  99. }
  100. }