[Sandy] [sandy commit] r194 - in trunk/sandy/as2/branches/2_0: sandy/materials tests/cubeTest/src tests/spriteTest tests...

codesite-noreply@google.com codesite-noreply at google.com
Tue Apr 24 17:05:43 EDT 2007


Author: kiroukou
Date: Tue Apr 24 14:05:28 2007
New Revision: 194

Added:
   trunk/sandy/as2/branches/2_0/tests/spriteTest/
   trunk/sandy/as2/branches/2_0/tests/spriteTest/deploy/
   trunk/sandy/as2/branches/2_0/tests/spriteTest/src/
   trunk/sandy/as2/branches/2_0/tests/spriteTest/src/SpriteTest.as   (contents, props changed)
Modified:
   trunk/sandy/as2/branches/2_0/sandy/materials/BitmapMaterial.as
   trunk/sandy/as2/branches/2_0/tests/cubeTest/src/TestCube.as

Log:
Addition of a SpriteTest class, and small modifications on the sprites and materials.

For the moment, the performance of a single sprite rendering is quite disapointing. But more tests shall be done to have a better idea.

Modified: trunk/sandy/as2/branches/2_0/sandy/materials/BitmapMaterial.as
==============================================================================
--- trunk/sandy/as2/branches/2_0/sandy/materials/BitmapMaterial.as	(original)
+++ trunk/sandy/as2/branches/2_0/sandy/materials/BitmapMaterial.as	Tue Apr 24 14:05:28 2007
@@ -59,56 +59,58 @@
 
 	function renderPolygon( p_oPolygon:Polygon ):Void 
 	{
-		// -- we prepare the texture
-		prepare( p_oPolygon );
-		// --
 		var mc:MovieClip = p_oPolygon.container;
 		var l_points:Array = p_oPolygon.cvertices;
 		// --
-		mc.beginBitmapFill( m_oTexture, matrix, false, smooth );
-		// --
-		if( lineAttributes )
-			mc.lineStyle( lineAttributes.thickness, lineAttributes.color, lineAttributes.alpha );
-		// --
-		mc.moveTo( l_points[0].sx, l_points[0].sy );
-		// --
-		switch( l_points.length )
+		if( l_points.length == 1 )
 		{
-			case 1 :
-				mc.attachBitmap( m_oTexture, 0 );
-				mc._xscale = mc._yscale = (10000 / l_points[0].wz);
-				mc._x = l_points[0].sx - mc._width  / 2;
-				mc._y = l_points[0].sy - mc._height / 2;
-				break;
-			case 2 :
-				mc.lineTo( l_points[1].sx, l_points[1].sy );
-				break;
-			case 3 :
-				mc.lineTo( l_points[1].sx, l_points[1].sy );
-				mc.lineTo( l_points[2].sx, l_points[2].sy );
-				break;
-			case 4 :
-				mc.lineTo( l_points[1].sx, l_points[1].sy );
-				mc.lineTo( l_points[2].sx, l_points[2].sy );
-				mc.lineTo( l_points[3].sx, l_points[3].sy );
-				break;
-			default :
-				var l:Number = l_points.length;
-				while( --l > 0 )
-				{
-					mc.lineTo( l_points[(l)].sx, l_points[(l)].sy);
-				}
-				break;
+			//FIXME I don't like the way the perspective is applied here...
+			mc._xscale = mc._yscale = (10000 / l_points[0].wz);
+			mc._x = l_points[0].sx - mc._width  / 2;
+			mc._y = l_points[0].sy - mc._height / 2;;
 		}
-		
-		// -- we draw the last edge
-		if( lineAttributes )
+		else
 		{
-			mc.lineTo( l_points[0].sx, l_points[0].sy );
+			// -- we prepare the texture
+			prepare( p_oPolygon );
+			// --
+			mc.beginBitmapFill( m_oTexture, matrix, false, smooth );
+			// --
+			if( lineAttributes )
+				mc.lineStyle( lineAttributes.thickness, lineAttributes.color, lineAttributes.alpha );
+			// --
+			mc.moveTo( l_points[0].sx, l_points[0].sy );
+			// --
+			switch( l_points.length )
+			{
+				case 2 :
+					mc.lineTo( l_points[1].sx, l_points[1].sy );
+					break;
+				case 3 :
+					mc.lineTo( l_points[1].sx, l_points[1].sy );
+					mc.lineTo( l_points[2].sx, l_points[2].sy );
+					break;
+				case 4 :
+					mc.lineTo( l_points[1].sx, l_points[1].sy );
+					mc.lineTo( l_points[2].sx, l_points[2].sy );
+					mc.lineTo( l_points[3].sx, l_points[3].sy );
+					break;
+				default :
+					var l:Number = l_points.length;
+					while( --l > 0 )
+					{
+						mc.lineTo( l_points[(l)].sx, l_points[(l)].sy);
+					}
+					break;
+			}
+			// -- we draw the last edge
+			if( lineAttributes )
+			{
+				mc.lineTo( l_points[0].sx, l_points[0].sy );
+			}
+			// --
+			mc.endFill();
 		}
-		
-		// --
-		mc.endFill();
 	}
 		
 	public function get texture():BitmapData
@@ -154,36 +156,45 @@
 	
 	public function init( f:Polygon ):Void
 	{
-		var m:Matrix = null;
-		// --
-		//Logger.LOG("BitmapMaterial::init "+m_nHeight+" "+m_nWidth);
-		if( m_nWidth > 0 && m_nHeight > 0 )
-		{		
-			var l_aUV:Array = f.aUVCoord;
-			var u0: Number = l_aUV[0].u;
-			var v0: Number = l_aUV[0].v;
-			var u1: Number = l_aUV[1].u;
-			var v1: Number = l_aUV[1].v;
-			var u2: Number = l_aUV[2].u;
-			var v2: Number = l_aUV[2].v;
-			// -- Fix perpendicular projections. Not sure it is really useful here since there's no texture prjection. This will certainly solve the freeze problem tho
-			if( (u0 == u1 && v0 == v1) || (u0 == u2 && v0 == v2) )
-			{
-				u0 -= (u0 > 0.05)? 0.05 : -0.05;
-				v0 -= (v0 > 0.07)? 0.07 : -0.07;
-			}	
-			if( u2 == u1 && v2 == v1 )
-			{
-				u2 -= (u2 > 0.05)? 0.04 : -0.04;
-				v2 -= (v2 > 0.06)? 0.06 : -0.06;
+		// The Sprite case
+		if( f.vertices.length == 1 )
+		{
+			// Small hack, which is enought for the moment
+			f.container.attachBitmap( m_oTexture, 0 );
+			//f.container.cacheAsBitmap = true;
+		}
+		else if( f.vertices.length > 3 )
+		{
+			var m:Matrix = null;
+			// --
+			if( m_nWidth > 0 && m_nHeight > 0 )
+			{		
+				var l_aUV:Array = f.aUVCoord;
+				var u0: Number = l_aUV[0].u;
+				var v0: Number = l_aUV[0].v;
+				var u1: Number = l_aUV[1].u;
+				var v1: Number = l_aUV[1].v;
+				var u2: Number = l_aUV[2].u;
+				var v2: Number = l_aUV[2].v;
+				// -- Fix perpendicular projections. Not sure it is really useful here since there's no texture prjection. This will certainly solve the freeze problem tho
+				if( (u0 == u1 && v0 == v1) || (u0 == u2 && v0 == v2) )
+				{
+					u0 -= (u0 > 0.05)? 0.05 : -0.05;
+					v0 -= (v0 > 0.07)? 0.07 : -0.07;
+				}	
+				if( u2 == u1 && v2 == v1 )
+				{
+					u2 -= (u2 > 0.05)? 0.04 : -0.04;
+					v2 -= (v2 > 0.06)? 0.06 : -0.06;
+				}
+				// --
+				m = new Matrix( (u1 - u0), m_nHeight*(v1 - v0)/m_nWidth, m_nWidth*(u2 - u0)/m_nHeight, (v2 - v0), u0*m_nWidth, v0*m_nHeight );
+				m.invert();
+				//Logger.LOG("Polygon matrix : "+f+" "+m);
 			}
 			// --
-			m = new Matrix( (u1 - u0), m_nHeight*(v1 - v0)/m_nWidth, m_nWidth*(u2 - u0)/m_nHeight, (v2 - v0), u0*m_nWidth, v0*m_nHeight );
-			m.invert();
-			//Logger.LOG("Polygon matrix : "+f+" "+m);
+			m_oPolygonMatrixMap.put( f, m );
 		}
-		// --
-		m_oPolygonMatrixMap.put( f, m );
 	}
 	
 	/**

Modified: trunk/sandy/as2/branches/2_0/tests/cubeTest/src/TestCube.as
==============================================================================
--- trunk/sandy/as2/branches/2_0/tests/cubeTest/src/TestCube.as	(original)
+++ trunk/sandy/as2/branches/2_0/tests/cubeTest/src/TestCube.as	Tue Apr 24 14:05:28 2007
@@ -1,8 +1,8 @@
 import com.bourre.data.libs.GraphicLib;
 import com.bourre.data.libs.GraphicLibLocator;
 import com.bourre.log.Logger;
+import com.bourre.transitions.FPSBeacon;
 import com.bourre.transitions.IFrameListener;
-import com.bourre.transitions.MSBeacon;
 import com.bourre.utils.LuminicTracer;
 import com.bourre.visual.FPSLoggerUI;
 
@@ -71,8 +71,8 @@
 		gl.execute();
 		// -- we register to a pulsing event that simple
 		//MSBeacon.getInstance().setFPS( 120 );
-		MSBeacon.getInstance().addFrameListener( this );
-		//FPSBeacon.getInstance().addFrameListener( this );
+		//MSBeacon.getInstance().addFrameListener( this );
+		FPSBeacon.getInstance().addFrameListener( this );
 	}
 	
 	private function _onReady( Void ):Void

Added: trunk/sandy/as2/branches/2_0/tests/spriteTest/src/SpriteTest.as
==============================================================================
--- (empty file)
+++ trunk/sandy/as2/branches/2_0/tests/spriteTest/src/SpriteTest.as	Tue Apr 24 14:05:28 2007
@@ -0,0 +1,116 @@
+import com.bourre.data.libs.GraphicLib;
+import com.bourre.data.libs.GraphicLibLocator;
+import com.bourre.log.Logger;
+import com.bourre.transitions.FPSBeacon;
+import com.bourre.transitions.IFrameListener;
+import com.bourre.utils.LuminicTracer;
+import com.bourre.visual.FPSLoggerUI;
+
+import flash.display.BitmapData;
+
+import sandy.core.scenegraph.Camera3D;
+import sandy.core.scenegraph.Group;
+import sandy.core.scenegraph.Sprite2D;
+import sandy.core.scenegraph.TransformGroup;
+import sandy.core.World3D;
+import sandy.materials.Appearance;
+import sandy.materials.BitmapMaterial;
+import sandy.materials.ColorMaterial;
+import sandy.materials.LineAttributes;
+import sandy.materials.Material;
+import sandy.math.Matrix4Math;
+import sandy.util.BitmapUtil;
+
+/**
+ * @author thomaspfeiffer
+ */
+class tests.spriteTest.src.SpriteTest implements IFrameListener 
+{
+	private var _mc:MovieClip;
+	private var _world:World3D;
+	
+	public static function main( mc:MovieClip ):Void
+	{
+		Logger.getInstance().addLogListener( LuminicTracer.getInstance() );
+		// --
+		var t:SpriteTest = new SpriteTest(mc);
+		// -- Does not make things a lot faster in AS2 but does in AS3...
+		Matrix4Math.USE_FAST_MATH = true;
+	}
+	
+	public function SpriteTest( p_oMc:MovieClip )
+	{
+		_mc = p_oMc;
+		
+		var fpsUI:FPSLoggerUI = new FPSLoggerUI( _mc, -3 );
+		//
+		_world = World3D.getInstance();
+		// FIRST THING TO INITIALIZE
+		_world.container = p_oMc;
+		_init();
+	}
+	
+	private function _init( Void ):Void
+	{
+		var gl:GraphicLib = new GraphicLib( _mc.createEmptyMovieClip("texture",0), 0, false );
+		gl.setName( "TEXTURE" );
+		gl.addEventListener( GraphicLib.onLoadInitEVENT, this, _onReady);
+		gl.load( "texture.jpg" );
+		gl.execute();
+		FPSBeacon.getInstance().addFrameListener( this );
+	}	
+
+	
+	private function _onReady( Void ):Void
+	{
+		_world.root = _createScene();
+		_world.camera = new Camera3D( 500, 500 );
+		_world.root.addChild( _world.camera );
+		_world.container = _mc;
+	}
+	
+	private function _createScene( Void ):Group
+	{
+		// -- variables declaration
+		var g:Group = new Group();
+		var tgTranslation:TransformGroup = new TransformGroup("translation");
+		// -- transformations
+		tgTranslation.z = 500;
+		// -- creation of the materials and apperance
+		var b:BitmapData = BitmapUtil.movieToBitmap( GraphicLibLocator.getInstance().getGraphicLib("TEXTURE").getContent(), false );
+		var l_oTextureAppearance:Appearance = new Appearance( new BitmapMaterial( b ) ); 
+		// --
+		var l_oMaterial:Material = new ColorMaterial( 0xFF0000, 100 );
+		l_oMaterial.lineAttributes = new LineAttributes( 10, 0xFF, 100 );
+		var l_oAppearance:Appearance = new Appearance( l_oMaterial ); 
+		// --
+		var l_oSprite:Sprite2D = new Sprite2D();
+		l_oSprite.appearance = l_oTextureAppearance;
+		
+		var l_oSprite2:Sprite2D = new Sprite2D();
+		l_oSprite2.x = -100;
+		l_oSprite2.appearance = l_oAppearance;
+		// --
+		tgTranslation.addChild( l_oSprite );
+		tgTranslation.addChild( l_oSprite2 );
+		g.addChild( tgTranslation );
+		// --
+		return g;
+	}
+	
+
+	public function onEnterFrame() : Void 
+	{
+		var cam:Camera3D = _world.camera;
+		// --
+		//if(Key.isDown(Key.HOME))   cam.moveForward(1); 
+		//if(Key.isDown(Key.END))    cam.moveForward(-5); 
+		if ( Key.isDown(Key.UP))   cam.moveForward(3);
+		if ( Key.isDown(Key.DOWN)) cam.moveForward(-3);
+		if(Key.isDown(Key.LEFT))   cam.rotateY += 1; 
+		if(Key.isDown(Key.RIGHT))  cam.rotateY -= 1; 		
+		// --
+		_world.render();
+	}
+
+}
\ No newline at end of file



More information about the Sandy mailing list