home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / org / papervision3d / materials / BitmapMaterial.as next >
Encoding:
Text File  |  2010-06-23  |  27.1 KB  |  772 lines

  1. package org.papervision3d.materials
  2. {
  3.    import flash.display.BitmapData;
  4.    import flash.display.Graphics;
  5.    import flash.geom.Matrix;
  6.    import flash.geom.Point;
  7.    import flash.geom.Rectangle;
  8.    import flash.utils.Dictionary;
  9.    import org.papervision3d.Papervision3D;
  10.    import org.papervision3d.core.geom.renderables.Triangle3D;
  11.    import org.papervision3d.core.geom.renderables.Vertex3DInstance;
  12.    import org.papervision3d.core.log.PaperLogger;
  13.    import org.papervision3d.core.material.TriangleMaterial;
  14.    import org.papervision3d.core.proto.MaterialObject3D;
  15.    import org.papervision3d.core.render.command.RenderTriangle;
  16.    import org.papervision3d.core.render.data.RenderSessionData;
  17.    import org.papervision3d.core.render.draw.ITriangleDrawer;
  18.    import org.papervision3d.materials.utils.PrecisionMode;
  19.    import org.papervision3d.materials.utils.RenderRecStorage;
  20.    
  21.    public class BitmapMaterial extends TriangleMaterial implements ITriangleDrawer
  22.    {
  23.       protected static var _triMap:Matrix;
  24.       
  25.       protected static const DEFAULT_FOCUS:Number = 200;
  26.       
  27.       protected static var hitRect:Rectangle = new Rectangle();
  28.       
  29.       public static var AUTO_MIP_MAPPING:Boolean = false;
  30.       
  31.       public static var MIP_MAP_DEPTH:Number = 8;
  32.       
  33.       protected static var _triMatrix:Matrix = new Matrix();
  34.       
  35.       protected static var _localMatrix:Matrix = new Matrix();
  36.       
  37.       protected var renderRecStorage:Array;
  38.       
  39.       protected var dsbc:Number;
  40.       
  41.       private var d2bc:Number;
  42.       
  43.       private var b2:Number;
  44.       
  45.       public var uvMatrices:Dictionary = new Dictionary();
  46.       
  47.       protected var _precise:Boolean;
  48.       
  49.       protected var faz:Number;
  50.       
  51.       protected var dsca:Number;
  52.       
  53.       protected var ax:Number;
  54.       
  55.       protected var ay:Number;
  56.       
  57.       protected var az:Number;
  58.       
  59.       private var d2ca:Number;
  60.       
  61.       protected var tempPreGrp:Graphics;
  62.       
  63.       public var precisionMode:int = PrecisionMode.ORIGINAL;
  64.       
  65.       protected var fbz:Number;
  66.       
  67.       private var c2:Number;
  68.       
  69.       protected var mcax:Number;
  70.       
  71.       protected var mcay:Number;
  72.       
  73.       protected var mcaz:Number;
  74.       
  75.       private var d2:Number;
  76.       
  77.       protected var bx:Number;
  78.       
  79.       protected var by:Number;
  80.       
  81.       protected var bz:Number;
  82.       
  83.       protected var fcz:Number;
  84.       
  85.       public var minimumRenderSize:Number = 4;
  86.       
  87.       protected var dbcx:Number;
  88.       
  89.       protected var dbcy:Number;
  90.       
  91.       protected var cx:Number;
  92.       
  93.       protected var cullRect:Rectangle;
  94.       
  95.       protected var cz:Number;
  96.       
  97.       protected var cy:Number;
  98.       
  99.       protected var dmax:Number;
  100.       
  101.       protected var dabx:Number;
  102.       
  103.       private var dy:Number;
  104.       
  105.       protected var _perPixelPrecision:int = 8;
  106.       
  107.       protected var daby:Number;
  108.       
  109.       protected var tempPreRSD:RenderSessionData;
  110.       
  111.       private var dx:Number;
  112.       
  113.       private var x0:Number;
  114.       
  115.       private var x1:Number;
  116.       
  117.       private var x2:Number;
  118.       
  119.       protected var mbcy:Number;
  120.       
  121.       protected var mbcz:Number;
  122.       
  123.       protected var mbcx:Number;
  124.       
  125.       private var y0:Number;
  126.       
  127.       protected var focus:Number = 200;
  128.       
  129.       private var y2:Number;
  130.       
  131.       protected var _texture:Object;
  132.       
  133.       protected var tempPreBmp:BitmapData;
  134.       
  135.       private var y1:Number;
  136.       
  137.       protected var tempTriangleMatrix:Matrix = new Matrix();
  138.       
  139.       protected var maby:Number;
  140.       
  141.       protected var mabz:Number;
  142.       
  143.       private var d2ab:Number;
  144.       
  145.       protected var dsab:Number;
  146.       
  147.       protected var mabx:Number;
  148.       
  149.       protected var dcax:Number;
  150.       
  151.       protected var dcay:Number;
  152.       
  153.       private var a2:Number;
  154.       
  155.       protected var _precision:int = 8;
  156.       
  157.       public function BitmapMaterial(param1:BitmapData = null, param2:Boolean = false)
  158.       {
  159.          super();
  160.          if(param1)
  161.          {
  162.             this.texture = param1;
  163.          }
  164.          this.precise = param2;
  165.          this.createRenderRecStorage();
  166.       }
  167.       
  168.       public function transformUV(param1:Triangle3D) : Matrix
  169.       {
  170.          var _loc2_:Array = null;
  171.          var _loc3_:Number = NaN;
  172.          var _loc4_:Number = NaN;
  173.          var _loc5_:Number = NaN;
  174.          var _loc6_:Number = NaN;
  175.          var _loc7_:Number = NaN;
  176.          var _loc8_:Number = NaN;
  177.          var _loc9_:Number = NaN;
  178.          var _loc10_:Number = NaN;
  179.          var _loc11_:Number = NaN;
  180.          var _loc12_:Number = NaN;
  181.          var _loc13_:Number = NaN;
  182.          var _loc14_:Number = NaN;
  183.          var _loc15_:Matrix = null;
  184.          var _loc16_:Matrix = null;
  185.          if(!param1.uv)
  186.          {
  187.             PaperLogger.error("MaterialObject3D: transformUV() uv not found!");
  188.          }
  189.          else if(bitmap)
  190.          {
  191.             _loc2_ = param1.uv;
  192.             _loc3_ = bitmap.width * maxU;
  193.             _loc4_ = bitmap.height * maxV;
  194.             _loc5_ = _loc3_ * param1.uv0.u;
  195.             _loc6_ = _loc4_ * (1 - param1.uv0.v);
  196.             _loc7_ = _loc3_ * param1.uv1.u;
  197.             _loc8_ = _loc4_ * (1 - param1.uv1.v);
  198.             _loc9_ = _loc3_ * param1.uv2.u;
  199.             _loc10_ = _loc4_ * (1 - param1.uv2.v);
  200.             if(_loc5_ == _loc7_ && _loc6_ == _loc8_ || _loc5_ == _loc9_ && _loc6_ == _loc10_)
  201.             {
  202.                _loc5_ -= _loc5_ > 0.05 ? 0.05 : -0.05;
  203.                _loc6_ -= _loc6_ > 0.07 ? 0.07 : -0.07;
  204.             }
  205.             if(_loc9_ == _loc7_ && _loc10_ == _loc8_)
  206.             {
  207.                _loc9_ -= _loc9_ > 0.05 ? 0.04 : -0.04;
  208.                _loc10_ -= _loc10_ > 0.06 ? 0.06 : -0.06;
  209.             }
  210.             _loc11_ = _loc7_ - _loc5_;
  211.             _loc12_ = _loc8_ - _loc6_;
  212.             _loc13_ = _loc9_ - _loc5_;
  213.             _loc14_ = _loc10_ - _loc6_;
  214.             _loc15_ = new Matrix(_loc11_,_loc12_,_loc13_,_loc14_,_loc5_,_loc6_);
  215.             if(Papervision3D.useRIGHTHANDED)
  216.             {
  217.                _loc15_.scale(-1,1);
  218.                _loc15_.translate(_loc3_,0);
  219.             }
  220.             _loc15_.invert();
  221.             _loc16_ = this.uvMatrices[param1] = _loc15_.clone();
  222.             _loc16_.a = _loc15_.a;
  223.             _loc16_.b = _loc15_.b;
  224.             _loc16_.c = _loc15_.c;
  225.             _loc16_.d = _loc15_.d;
  226.             _loc16_.tx = _loc15_.tx;
  227.             _loc16_.ty = _loc15_.ty;
  228.          }
  229.          else
  230.          {
  231.             PaperLogger.error("MaterialObject3D: transformUV() material.bitmap not found!");
  232.          }
  233.          return _loc16_;
  234.       }
  235.       
  236.       public function transformUVRT(param1:RenderTriangle) : Matrix
  237.       {
  238.          var _loc2_:Number = NaN;
  239.          var _loc3_:Number = NaN;
  240.          var _loc4_:Number = NaN;
  241.          var _loc5_:Number = NaN;
  242.          var _loc6_:Number = NaN;
  243.          var _loc7_:Number = NaN;
  244.          var _loc8_:Number = NaN;
  245.          var _loc9_:Number = NaN;
  246.          var _loc10_:Number = NaN;
  247.          var _loc11_:Number = NaN;
  248.          var _loc12_:Number = NaN;
  249.          var _loc13_:Number = NaN;
  250.          var _loc14_:Matrix = null;
  251.          var _loc15_:Matrix = null;
  252.          if(bitmap)
  253.          {
  254.             _loc2_ = bitmap.width * maxU;
  255.             _loc3_ = bitmap.height * maxV;
  256.             _loc4_ = _loc2_ * param1.uv0.u;
  257.             _loc5_ = _loc3_ * (1 - param1.uv0.v);
  258.             _loc6_ = _loc2_ * param1.uv1.u;
  259.             _loc7_ = _loc3_ * (1 - param1.uv1.v);
  260.             _loc8_ = _loc2_ * param1.uv2.u;
  261.             _loc9_ = _loc3_ * (1 - param1.uv2.v);
  262.             if(_loc4_ == _loc6_ && _loc5_ == _loc7_ || _loc4_ == _loc8_ && _loc5_ == _loc9_)
  263.             {
  264.                _loc4_ -= _loc4_ > 0.05 ? 0.05 : -0.05;
  265.                _loc5_ -= _loc5_ > 0.07 ? 0.07 : -0.07;
  266.             }
  267.             if(_loc8_ == _loc6_ && _loc9_ == _loc7_)
  268.             {
  269.                _loc8_ -= _loc8_ > 0.05 ? 0.04 : -0.04;
  270.                _loc9_ -= _loc9_ > 0.06 ? 0.06 : -0.06;
  271.             }
  272.             _loc10_ = _loc6_ - _loc4_;
  273.             _loc11_ = _loc7_ - _loc5_;
  274.             _loc12_ = _loc8_ - _loc4_;
  275.             _loc13_ = _loc9_ - _loc5_;
  276.             _loc14_ = new Matrix(_loc10_,_loc11_,_loc12_,_loc13_,_loc4_,_loc5_);
  277.             if(Papervision3D.useRIGHTHANDED)
  278.             {
  279.                _loc14_.scale(-1,1);
  280.                _loc14_.translate(_loc2_,0);
  281.             }
  282.             _loc14_.invert();
  283.             _loc15_ = this.uvMatrices[param1] = _loc14_.clone();
  284.             _loc15_.a = _loc14_.a;
  285.             _loc15_.b = _loc14_.b;
  286.             _loc15_.c = _loc14_.c;
  287.             _loc15_.d = _loc14_.d;
  288.             _loc15_.tx = _loc14_.tx;
  289.             _loc15_.ty = _loc14_.ty;
  290.          }
  291.          else
  292.          {
  293.             PaperLogger.error("MaterialObject3D: transformUV() material.bitmap not found!");
  294.          }
  295.          return _loc15_;
  296.       }
  297.       
  298.       protected function renderRec(param1:Matrix, param2:Vertex3DInstance, param3:Vertex3DInstance, param4:Vertex3DInstance, param5:Number) : void
  299.       {
  300.          this.az = param2.z;
  301.          this.bz = param3.z;
  302.          this.cz = param4.z;
  303.          if(this.az <= 0 && this.bz <= 0 && this.cz <= 0)
  304.          {
  305.             return;
  306.          }
  307.          this.cx = param4.x;
  308.          this.cy = param4.y;
  309.          this.bx = param3.x;
  310.          this.by = param3.y;
  311.          this.ax = param2.x;
  312.          this.ay = param2.y;
  313.          if(this.cullRect)
  314.          {
  315.             hitRect.x = this.bx < this.ax ? (this.bx < this.cx ? this.bx : this.cx) : (this.ax < this.cx ? this.ax : this.cx);
  316.             hitRect.width = (this.bx > this.ax ? (this.bx > this.cx ? this.bx : this.cx) : (this.ax > this.cx ? this.ax : this.cx)) + (hitRect.x < 0 ? -hitRect.x : hitRect.x);
  317.             hitRect.y = this.by < this.ay ? (this.by < this.cy ? this.by : this.cy) : (this.ay < this.cy ? this.ay : this.cy);
  318.             hitRect.height = (this.by > this.ay ? (this.by > this.cy ? this.by : this.cy) : (this.ay > this.cy ? this.ay : this.cy)) + (hitRect.y < 0 ? -hitRect.y : hitRect.y);
  319.             if(hitRect.right < this.cullRect.left || hitRect.left > this.cullRect.right)
  320.             {
  321.                return;
  322.             }
  323.             if(hitRect.bottom < this.cullRect.top || hitRect.top > this.cullRect.bottom)
  324.             {
  325.                return;
  326.             }
  327.          }
  328.          if(param5 >= 100 || hitRect.width < this.minimumRenderSize || hitRect.height < this.minimumRenderSize || this.focus == Infinity)
  329.          {
  330.             this.a2 = param3.x - param2.x;
  331.             this.b2 = param3.y - param2.y;
  332.             this.c2 = param4.x - param2.x;
  333.             this.d2 = param4.y - param2.y;
  334.             this.tempTriangleMatrix.a = param1.a * this.a2 + param1.b * this.c2;
  335.             this.tempTriangleMatrix.b = param1.a * this.b2 + param1.b * this.d2;
  336.             this.tempTriangleMatrix.c = param1.c * this.a2 + param1.d * this.c2;
  337.             this.tempTriangleMatrix.d = param1.c * this.b2 + param1.d * this.d2;
  338.             this.tempTriangleMatrix.tx = param1.tx * this.a2 + param1.ty * this.c2 + param2.x;
  339.             this.tempTriangleMatrix.ty = param1.tx * this.b2 + param1.ty * this.d2 + param2.y;
  340.             if(lineAlpha)
  341.             {
  342.                this.tempPreGrp.lineStyle(lineThickness,lineColor,lineAlpha);
  343.             }
  344.             this.tempPreGrp.beginBitmapFill(this.tempPreBmp,this.tempTriangleMatrix,tiled,smooth);
  345.             this.tempPreGrp.moveTo(param2.x,param2.y);
  346.             this.tempPreGrp.lineTo(param3.x,param3.y);
  347.             this.tempPreGrp.lineTo(param4.x,param4.y);
  348.             this.tempPreGrp.endFill();
  349.             if(lineAlpha)
  350.             {
  351.                this.tempPreGrp.lineStyle();
  352.             }
  353.             ++this.tempPreRSD.renderStatistics.triangles;
  354.             return;
  355.          }
  356.          this.faz = this.focus + this.az;
  357.          this.fbz = this.focus + this.bz;
  358.          this.fcz = this.focus + this.cz;
  359.          this.mabz = 2 / (this.faz + this.fbz);
  360.          this.mbcz = 2 / (this.fbz + this.fcz);
  361.          this.mcaz = 2 / (this.fcz + this.faz);
  362.          this.mabx = (this.ax * this.faz + this.bx * this.fbz) * this.mabz;
  363.          this.maby = (this.ay * this.faz + this.by * this.fbz) * this.mabz;
  364.          this.mbcx = (this.bx * this.fbz + this.cx * this.fcz) * this.mbcz;
  365.          this.mbcy = (this.by * this.fbz + this.cy * this.fcz) * this.mbcz;
  366.          this.mcax = (this.cx * this.fcz + this.ax * this.faz) * this.mcaz;
  367.          this.mcay = (this.cy * this.fcz + this.ay * this.faz) * this.mcaz;
  368.          this.dabx = this.ax + this.bx - this.mabx;
  369.          this.daby = this.ay + this.by - this.maby;
  370.          this.dbcx = this.bx + this.cx - this.mbcx;
  371.          this.dbcy = this.by + this.cy - this.mbcy;
  372.          this.dcax = this.cx + this.ax - this.mcax;
  373.          this.dcay = this.cy + this.ay - this.mcay;
  374.          this.dsab = this.dabx * this.dabx + this.daby * this.daby;
  375.          this.dsbc = this.dbcx * this.dbcx + this.dbcy * this.dbcy;
  376.          this.dsca = this.dcax * this.dcax + this.dcay * this.dcay;
  377.          var _loc6_:int = param5 + 1;
  378.          var _loc7_:RenderRecStorage = RenderRecStorage(this.renderRecStorage[int(param5)]);
  379.          var _loc8_:Matrix = _loc7_.mat;
  380.          if(this.dsab <= this._precision && this.dsca <= this._precision && this.dsbc <= this._precision)
  381.          {
  382.             this.a2 = param3.x - param2.x;
  383.             this.b2 = param3.y - param2.y;
  384.             this.c2 = param4.x - param2.x;
  385.             this.d2 = param4.y - param2.y;
  386.             this.tempTriangleMatrix.a = param1.a * this.a2 + param1.b * this.c2;
  387.             this.tempTriangleMatrix.b = param1.a * this.b2 + param1.b * this.d2;
  388.             this.tempTriangleMatrix.c = param1.c * this.a2 + param1.d * this.c2;
  389.             this.tempTriangleMatrix.d = param1.c * this.b2 + param1.d * this.d2;
  390.             this.tempTriangleMatrix.tx = param1.tx * this.a2 + param1.ty * this.c2 + param2.x;
  391.             this.tempTriangleMatrix.ty = param1.tx * this.b2 + param1.ty * this.d2 + param2.y;
  392.             if(lineAlpha)
  393.             {
  394.                this.tempPreGrp.lineStyle(lineThickness,lineColor,lineAlpha);
  395.             }
  396.             this.tempPreGrp.beginBitmapFill(this.tempPreBmp,this.tempTriangleMatrix,tiled,smooth);
  397.             this.tempPreGrp.moveTo(param2.x,param2.y);
  398.             this.tempPreGrp.lineTo(param3.x,param3.y);
  399.             this.tempPreGrp.lineTo(param4.x,param4.y);
  400.             this.tempPreGrp.endFill();
  401.             if(lineAlpha)
  402.             {
  403.                this.tempPreGrp.lineStyle();
  404.             }
  405.             ++this.tempPreRSD.renderStatistics.triangles;
  406.             return;
  407.          }
  408.          if(this.dsab > this._precision && this.dsca > this._precision && this.dsbc > this._precision)
  409.          {
  410.             _loc8_.a = param1.a * 2;
  411.             _loc8_.b = param1.b * 2;
  412.             _loc8_.c = param1.c * 2;
  413.             _loc8_.d = param1.d * 2;
  414.             _loc8_.tx = param1.tx * 2;
  415.             _loc8_.ty = param1.ty * 2;
  416.             _loc7_.v0.x = this.mabx * 0.5;
  417.             _loc7_.v0.y = this.maby * 0.5;
  418.             _loc7_.v0.z = (this.az + this.bz) * 0.5;
  419.             _loc7_.v1.x = this.mbcx * 0.5;
  420.             _loc7_.v1.y = this.mbcy * 0.5;
  421.             _loc7_.v1.z = (this.bz + this.cz) * 0.5;
  422.             _loc7_.v2.x = this.mcax * 0.5;
  423.             _loc7_.v2.y = this.mcay * 0.5;
  424.             _loc7_.v2.z = (this.cz + this.az) * 0.5;
  425.             this.renderRec(_loc8_,param2,_loc7_.v0,_loc7_.v2,_loc6_);
  426.             --_loc8_.tx;
  427.             this.renderRec(_loc8_,_loc7_.v0,param3,_loc7_.v1,_loc6_);
  428.             --_loc8_.ty;
  429.             _loc8_.tx = param1.tx * 2;
  430.             this.renderRec(_loc8_,_loc7_.v2,_loc7_.v1,param4,_loc6_);
  431.             _loc8_.a = -param1.a * 2;
  432.             _loc8_.b = -param1.b * 2;
  433.             _loc8_.c = -param1.c * 2;
  434.             _loc8_.d = -param1.d * 2;
  435.             _loc8_.tx = -param1.tx * 2 + 1;
  436.             _loc8_.ty = -param1.ty * 2 + 1;
  437.             this.renderRec(_loc8_,_loc7_.v1,_loc7_.v2,_loc7_.v0,_loc6_);
  438.             return;
  439.          }
  440.          if(this.precisionMode == PrecisionMode.ORIGINAL)
  441.          {
  442.             this.d2ab = this.dsab;
  443.             this.d2bc = this.dsbc;
  444.             this.d2ca = this.dsca;
  445.             this.dmax = this.dsca > this.dsbc ? (this.dsca > this.dsab ? this.dsca : this.dsab) : (this.dsbc > this.dsab ? this.dsbc : this.dsab);
  446.          }
  447.          else
  448.          {
  449.             this.dx = param2.x - param3.x;
  450.             this.dy = param2.y - param3.y;
  451.             this.d2ab = this.dx * this.dx + this.dy * this.dy;
  452.             this.dx = param3.x - param4.x;
  453.             this.dy = param3.y - param4.y;
  454.             this.d2bc = this.dx * this.dx + this.dy * this.dy;
  455.             this.dx = param4.x - param2.x;
  456.             this.dy = param4.y - param2.y;
  457.             this.d2ca = this.dx * this.dx + this.dy * this.dy;
  458.             this.dmax = this.d2ca > this.d2bc ? (this.d2ca > this.d2ab ? this.d2ca : this.d2ab) : (this.d2bc > this.d2ab ? this.d2bc : this.d2ab);
  459.          }
  460.          if(this.d2ab == this.dmax)
  461.          {
  462.             _loc8_.a = param1.a * 2;
  463.             _loc8_.b = param1.b;
  464.             _loc8_.c = param1.c * 2;
  465.             _loc8_.d = param1.d;
  466.             _loc8_.tx = param1.tx * 2;
  467.             _loc8_.ty = param1.ty;
  468.             _loc7_.v0.x = this.mabx * 0.5;
  469.             _loc7_.v0.y = this.maby * 0.5;
  470.             _loc7_.v0.z = (this.az + this.bz) * 0.5;
  471.             this.renderRec(_loc8_,param2,_loc7_.v0,param4,_loc6_);
  472.             _loc8_.a = param1.a * 2 + param1.b;
  473.             _loc8_.c = 2 * param1.c + param1.d;
  474.             _loc8_.tx = param1.tx * 2 + param1.ty - 1;
  475.             this.renderRec(_loc8_,_loc7_.v0,param3,param4,_loc6_);
  476.             return;
  477.          }
  478.          if(this.d2ca == this.dmax)
  479.          {
  480.             _loc8_.a = param1.a;
  481.             _loc8_.b = param1.b * 2;
  482.             _loc8_.c = param1.c;
  483.             _loc8_.d = param1.d * 2;
  484.             _loc8_.tx = param1.tx;
  485.             _loc8_.ty = param1.ty * 2;
  486.             _loc7_.v2.x = this.mcax * 0.5;
  487.             _loc7_.v2.y = this.mcay * 0.5;
  488.             _loc7_.v2.z = (this.cz + this.az) * 0.5;
  489.             this.renderRec(_loc8_,param2,param3,_loc7_.v2,_loc6_);
  490.             _loc8_.b += param1.a;
  491.             _loc8_.d += param1.c;
  492.             _loc8_.ty += param1.tx - 1;
  493.             this.renderRec(_loc8_,_loc7_.v2,param3,param4,_loc6_);
  494.             return;
  495.          }
  496.          _loc8_.a = param1.a - param1.b;
  497.          _loc8_.b = param1.b * 2;
  498.          _loc8_.c = param1.c - param1.d;
  499.          _loc8_.d = param1.d * 2;
  500.          _loc8_.tx = param1.tx - param1.ty;
  501.          _loc8_.ty = param1.ty * 2;
  502.          _loc7_.v1.x = this.mbcx * 0.5;
  503.          _loc7_.v1.y = this.mbcy * 0.5;
  504.          _loc7_.v1.z = (this.bz + this.cz) * 0.5;
  505.          this.renderRec(_loc8_,param2,param3,_loc7_.v1,_loc6_);
  506.          _loc8_.a = param1.a * 2;
  507.          _loc8_.b = param1.b - param1.a;
  508.          _loc8_.c = param1.c * 2;
  509.          _loc8_.d = param1.d - param1.c;
  510.          _loc8_.tx = param1.tx * 2;
  511.          _loc8_.ty = param1.ty - param1.tx;
  512.          this.renderRec(_loc8_,param2,_loc7_.v1,param4,_loc6_);
  513.       }
  514.       
  515.       protected function createRenderRecStorage() : void
  516.       {
  517.          this.renderRecStorage = new Array();
  518.          var _loc1_:int = 0;
  519.          while(_loc1_ <= 100)
  520.          {
  521.             this.renderRecStorage[_loc1_] = new RenderRecStorage();
  522.             _loc1_++;
  523.          }
  524.       }
  525.       
  526.       public function get texture() : Object
  527.       {
  528.          return this._texture;
  529.       }
  530.       
  531.       public function resetUVS() : void
  532.       {
  533.          this.uvMatrices = new Dictionary(false);
  534.       }
  535.       
  536.       public function set pixelPrecision(param1:int) : void
  537.       {
  538.          this._precision = param1 * param1 * 1.4;
  539.          this._perPixelPrecision = param1;
  540.       }
  541.       
  542.       protected function correctBitmap(param1:BitmapData) : BitmapData
  543.       {
  544.          var _loc2_:BitmapData = null;
  545.          var _loc3_:Number = 1 << MIP_MAP_DEPTH;
  546.          var _loc4_:Number = param1.width / _loc3_;
  547.          _loc4_ = _loc4_ == uint(_loc4_) ? _loc4_ : uint(_loc4_) + 1;
  548.          var _loc5_:Number = param1.height / _loc3_;
  549.          _loc5_ = _loc5_ == uint(_loc5_) ? _loc5_ : uint(_loc5_) + 1;
  550.          var _loc6_:Number = _loc3_ * _loc4_;
  551.          var _loc7_:Number = _loc3_ * _loc5_;
  552.          var _loc8_:Boolean = true;
  553.          if(_loc6_ > 2880)
  554.          {
  555.             _loc6_ = param1.width;
  556.             _loc8_ = false;
  557.          }
  558.          if(_loc7_ > 2880)
  559.          {
  560.             _loc7_ = param1.height;
  561.             _loc8_ = false;
  562.          }
  563.          if(!_loc8_)
  564.          {
  565.             PaperLogger.warning("Material " + this.name + ": Texture too big for mip mapping. Resizing recommended for better performance and quality.");
  566.          }
  567.          if(Boolean(param1) && (param1.width % _loc3_ != 0 || param1.height % _loc3_ != 0))
  568.          {
  569.             _loc2_ = new BitmapData(_loc6_,_loc7_,param1.transparent,0);
  570.             widthOffset = param1.width;
  571.             heightOffset = param1.height;
  572.             this.maxU = param1.width / _loc6_;
  573.             this.maxV = param1.height / _loc7_;
  574.             _loc2_.draw(param1);
  575.             this.extendBitmapEdges(_loc2_,param1.width,param1.height);
  576.          }
  577.          else
  578.          {
  579.             this.maxU = this.maxV = 1;
  580.             _loc2_ = param1;
  581.          }
  582.          return _loc2_;
  583.       }
  584.       
  585.       protected function createBitmap(param1:BitmapData) : BitmapData
  586.       {
  587.          var _loc2_:BitmapData = null;
  588.          this.resetMapping();
  589.          if(AUTO_MIP_MAPPING)
  590.          {
  591.             _loc2_ = this.correctBitmap(param1);
  592.          }
  593.          else
  594.          {
  595.             this.maxU = this.maxV = 1;
  596.             _loc2_ = param1;
  597.          }
  598.          return _loc2_;
  599.       }
  600.       
  601.       public function get precise() : Boolean
  602.       {
  603.          return this._precise;
  604.       }
  605.       
  606.       public function set texture(param1:Object) : void
  607.       {
  608.          if(param1 is BitmapData == false)
  609.          {
  610.             PaperLogger.error("BitmapMaterial.texture requires a BitmapData object for the texture");
  611.             return;
  612.          }
  613.          bitmap = this.createBitmap(BitmapData(param1));
  614.          this._texture = param1;
  615.       }
  616.       
  617.       override public function clone() : MaterialObject3D
  618.       {
  619.          var _loc1_:MaterialObject3D = super.clone();
  620.          _loc1_.maxU = this.maxU;
  621.          _loc1_.maxV = this.maxV;
  622.          return _loc1_;
  623.       }
  624.       
  625.       override public function drawTriangle(param1:RenderTriangle, param2:Graphics, param3:RenderSessionData, param4:BitmapData = null, param5:Matrix = null) : void
  626.       {
  627.          _triMap = !!param5 ? param5 : this.uvMatrices[param1] || this.transformUVRT(param1);
  628.          if(!this._precise || !_triMap)
  629.          {
  630.             if(lineAlpha)
  631.             {
  632.                param2.lineStyle(lineThickness,lineColor,lineAlpha);
  633.             }
  634.             if(bitmap)
  635.             {
  636.                this.x0 = param1.v0.x;
  637.                this.y0 = param1.v0.y;
  638.                this.x1 = param1.v1.x;
  639.                this.y1 = param1.v1.y;
  640.                this.x2 = param1.v2.x;
  641.                this.y2 = param1.v2.y;
  642.                _triMatrix.a = this.x1 - this.x0;
  643.                _triMatrix.b = this.y1 - this.y0;
  644.                _triMatrix.c = this.x2 - this.x0;
  645.                _triMatrix.d = this.y2 - this.y0;
  646.                _triMatrix.tx = this.x0;
  647.                _triMatrix.ty = this.y0;
  648.                _localMatrix.a = _triMap.a;
  649.                _localMatrix.b = _triMap.b;
  650.                _localMatrix.c = _triMap.c;
  651.                _localMatrix.d = _triMap.d;
  652.                _localMatrix.tx = _triMap.tx;
  653.                _localMatrix.ty = _triMap.ty;
  654.                _localMatrix.concat(_triMatrix);
  655.                param2.beginBitmapFill(!!param4 ? param4 : bitmap,_localMatrix,tiled,smooth);
  656.             }
  657.             param2.moveTo(this.x0,this.y0);
  658.             param2.lineTo(this.x1,this.y1);
  659.             param2.lineTo(this.x2,this.y2);
  660.             param2.lineTo(this.x0,this.y0);
  661.             if(bitmap)
  662.             {
  663.                param2.endFill();
  664.             }
  665.             if(lineAlpha)
  666.             {
  667.                param2.lineStyle();
  668.             }
  669.             ++param3.renderStatistics.triangles;
  670.          }
  671.          else if(bitmap)
  672.          {
  673.             this.focus = param3.camera.focus;
  674.             this.tempPreBmp = !!param4 ? param4 : bitmap;
  675.             this.tempPreRSD = param3;
  676.             this.tempPreGrp = param2;
  677.             this.cullRect = param3.viewPort.cullingRectangle;
  678.             this.renderRec(_triMap,param1.v0,param1.v1,param1.v2,0);
  679.          }
  680.       }
  681.       
  682.       public function get precision() : int
  683.       {
  684.          return this._precision;
  685.       }
  686.       
  687.       public function resetMapping() : void
  688.       {
  689.          this.uvMatrices = new Dictionary();
  690.       }
  691.       
  692.       override public function copy(param1:MaterialObject3D) : void
  693.       {
  694.          super.copy(param1);
  695.          this.maxU = param1.maxU;
  696.          this.maxV = param1.maxV;
  697.       }
  698.       
  699.       override public function toString() : String
  700.       {
  701.          return "Texture:" + this.texture + " lineColor:" + this.lineColor + " lineAlpha:" + this.lineAlpha;
  702.       }
  703.       
  704.       public function get pixelPrecision() : int
  705.       {
  706.          return this._perPixelPrecision;
  707.       }
  708.       
  709.       public function set precise(param1:Boolean) : void
  710.       {
  711.          this._precise = param1;
  712.       }
  713.       
  714.       protected function extendBitmapEdges(param1:BitmapData, param2:Number, param3:Number) : void
  715.       {
  716.          var _loc6_:int = 0;
  717.          var _loc4_:Rectangle = new Rectangle();
  718.          var _loc5_:Point = new Point();
  719.          if(param1.width > param2)
  720.          {
  721.             _loc4_.x = param2 - 1;
  722.             _loc4_.y = 0;
  723.             _loc4_.width = 1;
  724.             _loc4_.height = param3;
  725.             _loc5_.y = 0;
  726.             _loc6_ = param2;
  727.             while(_loc6_ < param1.width)
  728.             {
  729.                _loc5_.x = _loc6_;
  730.                param1.copyPixels(param1,_loc4_,_loc5_);
  731.                _loc6_++;
  732.             }
  733.          }
  734.          if(param1.height > param3)
  735.          {
  736.             _loc4_.x = 0;
  737.             _loc4_.y = param3 - 1;
  738.             _loc4_.width = param1.width;
  739.             _loc4_.height = 1;
  740.             _loc5_.x = 0;
  741.             _loc6_ = param3;
  742.             while(_loc6_ < param1.height)
  743.             {
  744.                _loc5_.y = _loc6_;
  745.                param1.copyPixels(param1,_loc4_,_loc5_);
  746.                _loc6_++;
  747.             }
  748.          }
  749.       }
  750.       
  751.       override public function destroy() : void
  752.       {
  753.          super.destroy();
  754.          if(this.uvMatrices)
  755.          {
  756.             this.uvMatrices = null;
  757.          }
  758.          if(bitmap)
  759.          {
  760.             bitmap.dispose();
  761.          }
  762.          this.renderRecStorage = null;
  763.       }
  764.       
  765.       public function set precision(param1:int) : void
  766.       {
  767.          this._precision = param1;
  768.       }
  769.    }
  770. }
  771.  
  772.