📄 bitmapmaterial.as.svn-base
字号:
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled,bitmap);
renderSessionData.renderStatistics.triangles++;
return;
}
if ((dsab > precision) && (dsca > precision) && (dsbc > precision))
{
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1, renderSessionData, bitmap);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2-1, ty*2,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1, renderSessionData, bitmap);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1, renderSessionData, bitmap);
renderRec(graphics, -ta*2, -tb*2, -tc*2, -td*2, -tx*2+1, -ty*2+1,
mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, index+1, renderSessionData, bitmap);
return;
}
var dmax:Number = Math.max(dsab, Math.max(dsca, dsbc));
if (dsab == dmax)
{
renderRec(graphics, ta*2, tb*1, tc*2, td*1, tx*2, ty*1,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, cx, cy, cz, index+1, renderSessionData, bitmap);
renderRec(graphics, ta*2+tb, tb*1, 2*tc+td, td*1, tx*2+ty-1, ty*1,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, cx, cy, cz, index+1, renderSessionData, bitmap);
return;
}
if (dsca == dmax)
{
renderRec(graphics, ta*1, tb*2, tc*1, td*2, tx*1, ty*2,
ax, ay, az, bx, by, bz, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1, renderSessionData, bitmap);
renderRec(graphics, ta*1, tb*2 + ta, tc*1, td*2 + tc, tx, ty*2+tx-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, bx, by, bz, cx, cy, cz, index+1, renderSessionData, bitmap);
return;
}
renderRec(graphics, ta-tb, tb*2, tc-td, td*2, tx-ty, ty*2,
ax, ay, az, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1, renderSessionData, bitmap);
renderRec(graphics, 2*ta, tb-ta, tc*2, td-tc, 2*tx, ty-tx,
ax, ay, az, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1, renderSessionData, bitmap);
}
public function renderTriangleBitmap(graphics:Graphics,a:Number, b:Number, c:Number, d:Number, tx:Number, ty:Number,
v0x:Number, v0y:Number, v1x:Number, v1y:Number, v2x:Number, v2y:Number, smooth:Boolean, repeat:Boolean, bitmapData:BitmapData):void
{
var a2:Number = v1x - v0x;
var b2:Number = v1y - v0y;
var c2:Number = v2x - v0x;
var d2:Number = v2y - v0y;
var matrix:Matrix = new Matrix(a*a2 + b*c2,
a*b2 + b*d2,
c*a2 + d*c2,
c*b2 + d*d2,
tx*a2 + ty*c2 + v0x,
tx*b2 + ty*d2 + v0y);
graphics.beginBitmapFill(bitmapData, matrix, repeat, smooth);
graphics.moveTo(v0x, v0y);
graphics.lineTo(v1x, v1y);
graphics.lineTo(v2x, v2y);
graphics.endFill();
}
// ______________________________________________________________________ TO STRING
/**
* Returns a string value representing the material properties in the specified BitmapMaterial object.
*
* @return A string.
*/
public override function toString(): String
{
return 'Texture:' + this.texture + ' lineColor:' + this.lineColor + ' lineAlpha:' + this.lineAlpha;
}
// ______________________________________________________________________ CREATE BITMAP
protected function createBitmap( asset:BitmapData ):BitmapData
{
resetMapping();
if( AUTO_MIP_MAPPING )
{
return correctBitmap( asset );
}
else
{
this.maxU = this.maxV = 1;
return ( asset );
}
}
// ______________________________________________________________________ CORRECT BITMAP FOR MIP MAPPING
protected function correctBitmap( bitmap :BitmapData ):BitmapData
{
var okBitmap :BitmapData;
var levels :Number = 1 << MIP_MAP_DEPTH;
// this is faster than Math.ceil
var bWidth :Number = bitmap.width / levels;
bWidth = bWidth == uint(bWidth) ? bWidth : uint(bWidth)+1;
var bHeight :Number = bitmap.height / levels;
bHeight = bHeight == uint(bHeight) ? bHeight : uint(bHeight)+1;
var width :Number = levels * bWidth;
var height :Number = levels * bHeight;
// Check for BitmapData maximum size
var ok:Boolean = true;
if( width > 2880 )
{
width = bitmap.width;
ok = false;
}
if( height > 2880 )
{
height = bitmap.height;
ok = false;
}
if( ! ok ) Papervision3D.log( "Material " + this.name + ": Texture too big for mip mapping. Resizing recommended for better performance and quality." );
// Create new bitmap?
if( bitmap && ( bitmap.width % levels !=0 || bitmap.height % levels != 0 ) )
{
okBitmap = new BitmapData( width, height, bitmap.transparent, 0x00000000 );
// this is for ISM and offsetting bitmaps that have been resized
widthOffset = bitmap.width;
heightOffset = bitmap.height;
this.maxU = bitmap.width / width;
this.maxV = bitmap.height / height;
okBitmap.draw( bitmap );
// PLEASE DO NOT REMOVE
extendBitmapEdges( okBitmap, bitmap.width, bitmap.height );
}
else
{
this.maxU = this.maxV = 1;
okBitmap = bitmap;
}
return okBitmap;
}
protected function extendBitmapEdges( bmp:BitmapData, originalWidth:Number, originalHeight:Number ):void
{
var srcRect :Rectangle = new Rectangle();
var dstPoint :Point = new Point();
//trace(dstPoint + "BitmapMaterialPOINT?");
var i :int;
// Check width
if( bmp.width > originalWidth )
{
// Extend width
srcRect.x = originalWidth-1;
srcRect.y = 0;
srcRect.width = 1;
srcRect.height = originalHeight;
dstPoint.y = 0;
for( i = originalWidth; i < bmp.width; i++ )
{
dstPoint.x = i;
bmp.copyPixels( bmp, srcRect, dstPoint );
}
}
// Check height
if( bmp.height > originalHeight )
{
// Extend height
srcRect.x = 0;
srcRect.y = originalHeight-1;
srcRect.width = bmp.width;
srcRect.height = 1;
dstPoint.x = 0;
for( i = originalHeight; i < bmp.height; i++ )
{
dstPoint.y = i;
bmp.copyPixels( bmp, srcRect, dstPoint );
}
}
}
// ______________________________________________________________________
/**
* Copies the properties of a material.
*
* @param material Material to copy from.
*/
override public function copy( material :MaterialObject3D ):void
{
super.copy( material );
this.maxU = material.maxU;
this.maxV = material.maxV;
}
/**
* Creates a copy of the material.
*
* @return A newly created material that contains the same properties.
*/
override public function clone():MaterialObject3D
{
var cloned:MaterialObject3D = super.clone();
cloned.maxU = this.maxU;
cloned.maxV = this.maxV;
return cloned;
}
public function set precise(boolean:Boolean):void
{
_precise = boolean;
}
public function get precise():Boolean
{
return _precise;
}
/**
* A texture object.
*/
public function get texture():Object
{
return this._texture;
}
/**
* @private
*/
public function set texture( asset:Object ):void
{
if( asset is BitmapData == false )
{
Papervision3D.log("Error: BitmapMaterial.texture requires a BitmapData object for the texture");
return;
}
bitmap = createBitmap( BitmapData(asset) );
_texture = asset;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -