[prev in list] [next in list] [prev in thread] [next in thread]
List: osflash-sandy
Subject: [Sandy] [sandy commit] r209 - in trunk/sandy/as3/branches/3.0: .
From: codesite-noreply () google ! com (codesite-noreply () google ! com)
Date: 2007-04-30 8:23:35
Message-ID: 163600d8e4042f50338b218866626 () google ! com
[Download RAW message or body]
Author: kiroukou
Date: Mon Apr 30 01:23:18 2007
New Revision: 209
Added:
trunk/sandy/as3/branches/3.0/test/
trunk/sandy/as3/branches/3.0/test/SimpleTest1.as
trunk/sandy/as3/branches/3.0/test/primitiveTest/
trunk/sandy/as3/branches/3.0/test/primitiveTest/src/
trunk/sandy/as3/branches/3.0/test/primitiveTest/src/PrimitiveTest.as
Removed:
trunk/sandy/as3/branches/3.0/SimpleTest1.as
Modified:
trunk/sandy/as3/branches/3.0/sandy/core/data/Polygon.as
trunk/sandy/as3/branches/3.0/sandy/materials/BitmapMaterial.as
trunk/sandy/as3/branches/3.0/sandy/materials/ColorMaterial.as
trunk/sandy/as3/branches/3.0/sandy/materials/LineAttributes.as
trunk/sandy/as3/branches/3.0/sandy/math/FastMath.as
trunk/sandy/as3/branches/3.0/sandy/primitive/Hedra.as
trunk/sandy/as3/branches/3.0/sandy/primitive/Line3D.as
trunk/sandy/as3/branches/3.0/sandy/primitive/Primitive3D.as
Log:
Addition of a test with primitives and BitmapMaterial.as
The performance is ok, but FPS seems to fall down after 3 seconds to half of what it \
used to be... Quite strange, and I think we should focus of that problem (maybe it is \
a mac player problem... please confirm that)
Modified: trunk/sandy/as3/branches/3.0/sandy/core/data/Polygon.as
==============================================================================
--- trunk/sandy/as3/branches/3.0/sandy/core/data/Polygon.as (original)
+++ trunk/sandy/as3/branches/3.0/sandy/core/data/Polygon.as Mon Apr 30 01:23:18 2007
@@ -65,6 +65,7 @@
private var m_aUVCoords:Array;
/** Unique face id */
private var id:Number;
+ private var m_bVisible:Boolean;
public function Polygon( p_oOwner:Shape3D, p_geometry:Geometry3D, \
p_aVertexID:Array, p_aUVCoordsID:Array=null, p_nFaceNormalID:Number=0 ) {
@@ -94,7 +95,8 @@
// all normals are refreshed every loop. Face is visible is normal face to the \
camera var a:Vertex = vertices[0];
var l_nDot:Number = ( a.wx * normal.wx + a.wy * normal.wy + a.wz * normal.wz );
- return (( backfaceCulling ) * (l_nDot) < 0);
+ m_bVisible = (( backfaceCulling ) * (l_nDot) < 0);
+ return m_bVisible;
}
public function clip( p_oFrustum:Frustum ):void
@@ -113,7 +115,7 @@
public function render():void
{
- if( visible ) m_oAppearance.frontMaterial.renderPolygon( this );
+ if( m_bVisible )m_oAppearance.frontMaterial.renderPolygon( this );
else m_oAppearance.backMaterial.renderPolygon( this );
}
@@ -125,7 +127,6 @@
{
var i:Number, l:Number;
// --
- if( p_aUVCoordsID == null ) return;
vertices = new Array( l = p_aVertexID.length );
for( i=0; i<l; i++ )
{
@@ -133,14 +134,15 @@
}
// --
cvertices = vertices;
- // --
- aUVCoord = new Array( l = p_aUVCoordsID.length );
- for( i=0; i<l; i++ )
+ // -- every polygon does not have some texture coordinates
+ if( p_aUVCoordsID )
{
- aUVCoord[i] = UVCoord( m_oGeometry.aUVCoords[ p_aUVCoordsID[i] ] );
+ aUVCoord = new Array( l = p_aUVCoordsID.length );
+ for( i=0; i<l; i++ )
+ {
+ aUVCoord[i] = UVCoord( m_oGeometry.aUVCoords[ p_aUVCoordsID[i] ] );
+ }
}
- // TODO update the texture matrix? or just when the appearance is applied.
- // Second choice because we need the picture dimensions
// --
normal = Vertex( m_oGeometry.aFacesNormals[ p_nFaceNormalID ] );
// If no normal has been given, we create it ourself.
@@ -151,8 +153,6 @@
normal = Vertex( m_oGeometry.aFacesNormals[ l_nID ] );
}
}
-
-
/**
* Return the depth average of the face.
Modified: trunk/sandy/as3/branches/3.0/sandy/materials/BitmapMaterial.as
==============================================================================
--- trunk/sandy/as3/branches/3.0/sandy/materials/BitmapMaterial.as (original)
+++ trunk/sandy/as3/branches/3.0/sandy/materials/BitmapMaterial.as Mon Apr 30 \
01:23:18 2007 @@ -16,7 +16,7 @@
package sandy.materials
{
import flash.display.BitmapData;
- import flash.display.Sprite;
+ import flash.display.Shape;
import flash.filters.ColorMatrixFilter;
import flash.geom.Matrix;
import flash.geom.Point;
@@ -49,7 +49,7 @@
* Create a new BitmapMaterial.
* @param t : The bitmapdata
*/
- public function BitmapMaterial( t:BitmapData, p_oLineAttr:LineAttributes )
+ public function BitmapMaterial( t:BitmapData, p_oLineAttr:LineAttributes = null )
{
super();
// --
@@ -66,7 +66,7 @@
public override function renderPolygon( p_oPolygon:Polygon ):void
{
- var sprite:Sprite = p_oPolygon.container;
+ var sprite:Shape = p_oPolygon.container;
var l_points:Array = p_oPolygon.cvertices;
// --
if( l_points.length == 1 )
@@ -167,7 +167,7 @@
if( f.vertices.length == 1 )
{
// Small hack, which is enought for the moment
- f.container.addChild( new Bitmap(m_oTexture) );
+ //f.container.addChild( new Bitmap(m_oTexture) );
//f.container.cacheAsBitmap = true;
}
else if( f.vertices.length >= 3 )
Modified: trunk/sandy/as3/branches/3.0/sandy/materials/ColorMaterial.as
==============================================================================
--- trunk/sandy/as3/branches/3.0/sandy/materials/ColorMaterial.as (original)
+++ trunk/sandy/as3/branches/3.0/sandy/materials/ColorMaterial.as Mon Apr 30 01:23:18 \
2007 @@ -13,7 +13,7 @@
private var m_nColor:Number;
private var m_nAlpha:Number;
// --
- public function ColorMaterial( p_nColor:Number = 0, p_nAlpha:Number = 1.0, \
p_oLineAttr:LineAttributes = null ) + public function ColorMaterial( p_nColor:uint = \
0, p_nAlpha:uint = 100, p_oLineAttr:LineAttributes = null ) {
super();
m_nColor = p_nColor;
Modified: trunk/sandy/as3/branches/3.0/sandy/materials/LineAttributes.as
==============================================================================
--- trunk/sandy/as3/branches/3.0/sandy/materials/LineAttributes.as (original)
+++ trunk/sandy/as3/branches/3.0/sandy/materials/LineAttributes.as Mon Apr 30 \
01:23:18 2007 @@ -11,7 +11,7 @@
// --
public var modified:Boolean;
- public function LineAttributes( p_nThickness:Number, p_nColor:Number, \
p_nAlpha:Number ) + public function LineAttributes( p_nThickness:uint = 1, \
p_nColor:uint = 0, p_nAlpha:Number = 100 ) {
m_nThickness = p_nThickness;
m_nAlpha = p_nAlpha/100;
Modified: trunk/sandy/as3/branches/3.0/sandy/math/FastMath.as
==============================================================================
--- trunk/sandy/as3/branches/3.0/sandy/math/FastMath.as (original)
+++ trunk/sandy/as3/branches/3.0/sandy/math/FastMath.as Mon Apr 30 01:23:18 2007
@@ -1,4 +1,5 @@
-package sandy.math {
+package sandy.math
+{
/**
* Fast trigonometry functions using cache table and precalculated data.
* Based on Michael Kraus implementation.
@@ -6,75 +7,85 @@
* @author Mirek Mencel // miras at polychrome.pl
* @date 01.02.2007
*/
+ public const FastMath:_FastMath_ = _FastMath_.initialize();
- public class FastMath
- {
-
- /** Precission. The bigger, the more entries in lookup table so the more accurate \
results. */
- public static var PRECISION:Number = 0x10000;
- public static var TWO_PI:Number = 2*Math.PI;
- public static var HALF_PI:Number = Math.PI/2;
-
- /** Precalculated values with given precision */
- private static var sinTable:Array = new Array(PRECISION);
- private static var tanTable:Array = new Array(PRECISION);
-
- private static var RAD_SLICE:Number = TWO_PI / PRECISION;
-
- // Shall be done at the end of the static properties declaration.
- private static var _isInitialize:Boolean = FastMath.initialize();
-
- private static function initialize():Boolean
- {
- var rad:Number = 0;
-
- for (var i:Number = 0; i < FastMath.PRECISION; i++)
- {
- rad = Number(i * FastMath.RAD_SLICE);
- sinTable[i] = Math.sin(rad);
- tanTable[i] = Math.tan(rad);
- }
-
- return true;
- }
+}
+
+import flash.utils.getTimer;
+
+class _FastMath_
+{
+ private static var instance:_FastMath_;
- private static function radToIndex(radians:Number):Number
- {
- return int( ((radians / TWO_PI) * PRECISION) & (PRECISION - 1) );
- }
+ /** Precission. The bigger, the more entries in lookup table so the more accurate \
results. */ + public static var PRECISION:int = 0x100000;
+ public static var TWO_PI:Number = 2*Math.PI;
+ public static var HALF_PI:Number = Math.PI/2;
- /**
- * Returns the sine of a given value, by looking up it's approximation in a
- * precomputed table.
- * @param radians The value to sine.
- * @return The approximation of the value's sine.
- */
- public static function sin(radians:Number):Number
- {
- return sinTable[ radToIndex(radians) ];
- }
+ /** Precalculated values with given precision */
+ private static var sinTable:Array = new Array(PRECISION);
+ private static var tanTable:Array = new Array(PRECISION);
- /**
- * Returns the cosine of a given value, by looking up it's approximation in a
- * precomputed table.
- * @param radians The value to cosine.
- * @return The approximation of the value's cosine.
- */
- public static function cos(radians:Number ):Number
- {
- return sinTable[radToIndex(HALF_PI-radians)];
- }
+ private static var RAD_SLICE:Number = TWO_PI / PRECISION;
+
+
+ public static function initialize():_FastMath_
+ {
+ if (!instance) instance = new _FastMath_();
+
+ return instance;
+ }
- /**
- * Returns the tangent of a given value, by looking up it's approximation in a
- * precomputed table.
- * @param radians The value to tan.
- * @return The approximation of the value's tangent.
- */
- public static function tan(radians:Number):Number
- {
- return tanTable[radToIndex(radians)];
+ public function _FastMath_()
+ {
+ var timer:int = getTimer();
+ var rad:Number = 0;
+
+ for (var i:int = 0; i < PRECISION; i++) {
+ rad = Number(i * RAD_SLICE);
+ sinTable[i] = Number(Math.sin(rad));
+ tanTable[i] = Number(Math.tan(rad));
}
+ trace("FastMath initialization time: " + (getTimer() - timer));
+
+ }
+
+ private function radToIndex(radians:Number):int
+ {
+ return int( ((radians / TWO_PI) * PRECISION) & (PRECISION - 1) );
+ }
+
+ /**
+ * Returns the sine of a given value, by looking up it's approximation in a
+ * precomputed table.
+ * @param radians The value to sine.
+ * @return The approximation of the value's sine.
+ */
+ public function sin(radians:Number):Number
+ {
+ return sinTable[ radToIndex(radians) ];
+ }
+
+ /**
+ * Returns the cosine of a given value, by looking up it's approximation in a
+ * precomputed table.
+ * @param radians The value to cosine.
+ * @return The approximation of the value's cosine.
+ */
+ public function cos(radians:Number ):Number
+ {
+ return sinTable[radToIndex(HALF_PI-radians)];
+ }
+
+ /**
+ * Returns the tangent of a given value, by looking up it's approximation in a
+ * precomputed table.
+ * @param radians The value to tan.
+ * @return The approximation of the value's tangent.
+ */
+ public function tan(radians:Number):Number
+ {
+ return tanTable[radToIndex(radians)];
}
}
Modified: trunk/sandy/as3/branches/3.0/sandy/primitive/Hedra.as
==============================================================================
--- trunk/sandy/as3/branches/3.0/sandy/primitive/Hedra.as (original)
+++ trunk/sandy/as3/branches/3.0/sandy/primitive/Hedra.as Mon Apr 30 01:23:18 2007
@@ -14,11 +14,11 @@
# ***** END LICENSE BLOCK *****
*/
-package sandy.primitive {
+package sandy.primitive
+{
import sandy.core.scenegraph.Geometry3D;
import sandy.core.scenegraph.Shape3D;
import sandy.primitive.Primitive3D;
-
/**
* Hedra
Modified: trunk/sandy/as3/branches/3.0/sandy/primitive/Line3D.as
==============================================================================
--- trunk/sandy/as3/branches/3.0/sandy/primitive/Line3D.as (original)
+++ trunk/sandy/as3/branches/3.0/sandy/primitive/Line3D.as Mon Apr 30 01:23:18 2007
@@ -13,7 +13,8 @@
# ***** END LICENSE BLOCK *****
*/
-package sandy.primitive {
+package sandy.primitive
+{
import sandy.core.data.Vector;
import sandy.core.data.Vertex;
import sandy.primitive.Primitive3D;
@@ -41,16 +42,16 @@
*
* @param As many parameters as needed points can be passed. However a minimum of 2 \
vector instance must be given.
*/
- public function Line3D ( p_sName:String, deb:Vector, fin:Vector )
+ public function Line3D ( p_sName:String, ...rest )
{
super ( p_sName );
- if( arguments.length < 2 )
+ if( rest.length < 2 )
{
trace('Line3D::Number of arguments to low');
}
else
{
- geometry = generate ( arguments.splice(1) );
+ geometry = generate( rest );
enableBackFaceCulling = false;
}
}
@@ -60,7 +61,7 @@
*
* <p>Generate all is needed to construct the Line3D : </p>
*/
- public function generate (... arguments) : Geometry3D
+ public function generate ( ... arguments ) : Geometry3D
{
var l_oGeometry:Geometry3D = new Geometry3D();
var l_aPoints:Array = arguments[0];
Modified: trunk/sandy/as3/branches/3.0/sandy/primitive/Primitive3D.as
==============================================================================
--- trunk/sandy/as3/branches/3.0/sandy/primitive/Primitive3D.as (original)
+++ trunk/sandy/as3/branches/3.0/sandy/primitive/Primitive3D.as Mon Apr 30 01:23:18 \
2007 @@ -13,7 +13,8 @@
# ***** END LICENSE BLOCK *****
*/
-package sandy.primitive {
+package sandy.primitive
+{
/**
* Primitive3D
*
Added: trunk/sandy/as3/branches/3.0/test/SimpleTest1.as
==============================================================================
--- (empty file)
+++ trunk/sandy/as3/branches/3.0/test/SimpleTest1.as Mon Apr 30 01:23:18 2007
@@ -0,0 +1,114 @@
+package
+{
+ import flash.display.BitmapData;
+ import flash.display.MovieClip;
+ import flash.display.Sprite;
+ import flash.display.Stage;
+ import flash.display.StageScaleMode;
+ import flash.events.*;
+ import flash.text.TextField;
+ import flash.ui.Keyboard;
+
+ import com.mir3.display.FPSMetter;
+ //import com.mir3.display.SceneStats;
+ import com.mir3.utils.KeyManager;
+
+ import sandy.core.World3D;
+ import sandy.core.scenegraph.Camera3D;
+ import sandy.core.scenegraph.Group;
+ import sandy.core.scenegraph.Shape3D;
+ import sandy.events.SandyEvent;
+ import sandy.materials.Appearance;
+ import sandy.materials.ColorMaterial;
+ import sandy.materials.LineAttributes;
+ import sandy.primitive.Box;
+
+ [SWF(width="500", height="500", backgroundColor="#FFFFFF", frameRate=120)]
+
+ public class SimpleTest1 extends Sprite
+ {
+ internal static const SCREEN_WIDTH:int = 500;
+ internal static const SCREEN_HEIGHT:int = 500;
+
+ private var world : World3D;
+ private var camera : Camera3D;
+ private var keyPressed:Array;
+
+ public function SimpleTest1()
+ {
+ super();
+ // --
+ stage.scaleMode = StageScaleMode.NO_SCALE ;
+ // -- FPS
+ addChild(new FPSMetter(false, 110, stage));
+ // -- INIT
+ keyPressed = [];
+ // -- User interface
+ stage.addEventListener(KeyboardEvent.KEY_DOWN, __onKeyDown);
+ stage.addEventListener(KeyboardEvent.KEY_UP, __onKeyUp);
+ // --
+ _init();
+ // --
+ addEventListener( Event.ENTER_FRAME, enterFrameHandler );
+ }
+
+ private function _init():void
+ {
+ // --
+ var l_mcWorld:MovieClip = new MovieClip();
+ l_mcWorld.x = (stage.stageWidth - SCREEN_WIDTH) / 2;
+ l_mcWorld.y = (stage.stageHeight - SCREEN_HEIGHT) / 2;
+ addChild(l_mcWorld);
+ world = World3D.getInstance();
+ world.container = l_mcWorld;
+ // --
+ world.camera = new Camera3D( SCREEN_WIDTH, SCREEN_HEIGHT );
+ world.camera.z = -300;
+ // -- create scene
+ var g:Group = new Group();
+ var box:Shape3D = new Box( "box", 100, 100, 100, "tri", 2 );
+ box.appearance = new Appearance(new ColorMaterial( 0xff00, 20, new \
LineAttributes( 2, 0xFF0000, 100 ) ), + new ColorMaterial( 0xFF, 50, new \
LineAttributes( 2, 0xFF00, 100 ) ) ); + box.enableBackFaceCulling = false;
+ // --
+ g.addChild( box );
+ world.root = g;
+ world.root.addChild( world.camera );
+ // --
+ return;
+ }
+
+ public function __onKeyDown(e:KeyboardEvent):void
+ {
+ keyPressed[e.keyCode]=true;
+ }
+
+ public function __onKeyUp(e:KeyboardEvent):void
+ {
+ keyPressed[e.keyCode]=false;
+ }
+
+ private function enterFrameHandler( event : Event ) : void
+ {
+ var cam:Camera3D = world.camera;
+ // --
+ if( keyPressed[Keyboard.RIGHT] )
+ {
+ cam.rotateY -= 1;
+ }
+ if( keyPressed[Keyboard.LEFT] )
+ {
+ cam.rotateY += 1;
+ }
+ if( keyPressed[Keyboard.UP] )
+ {
+ cam.moveForward( 2 );
+ }
+ if( keyPressed[Keyboard.DOWN] )
+ {
+ cam.moveForward( -2 );
+ }
+ world.render();
+ }
+ }
+}
Added: trunk/sandy/as3/branches/3.0/test/primitiveTest/src/PrimitiveTest.as
==============================================================================
--- (empty file)
+++ trunk/sandy/as3/branches/3.0/test/primitiveTest/src/PrimitiveTest.as Mon Apr 30 \
01:23:18 2007 @@ -0,0 +1,133 @@
+package
+{
+ import com.mir3.display.FPSMetter;
+ import com.mir3.utils.KeyManager;
+
+ import flash.display.Bitmap;
+ import flash.display.BitmapData;
+ import flash.display.MovieClip;
+ import flash.display.Sprite;
+ import flash.display.Stage;
+ import flash.display.StageScaleMode;
+ import flash.events.*;
+ import flash.text.TextField;
+ import flash.ui.Keyboard;
+
+ import sandy.core.World3D;
+ import sandy.core.data.*;
+ import sandy.math.*;
+ import sandy.core.scenegraph.*;
+ import sandy.materials.*;
+ import sandy.primitive.*;
+
+ [SWF(width="500", height="500", backgroundColor="#FFFFFF", frameRate=120)]
+ /**
+ * @author thomaspfeiffer
+ */
+ public class PrimitiveTest extends Sprite
+ {
+ internal static const SCREEN_WIDTH:int = 500;
+ internal static const SCREEN_HEIGHT:int = 500;
+
+ [Embed(source="assets/texture.jpg")]
+ private var Texture:Class;
+
+ private var _mc:Sprite;
+ private var _world:World3D;
+ private var box:Box;
+ private var hedra:Hedra;
+ private var tgRotation:TransformGroup;
+
+ public function PrimitiveTest()
+ {
+ Matrix4Math.USE_FAST_MATH = true;
+ _mc = this;
+ // --
+ stage.scaleMode = StageScaleMode.NO_SCALE ;
+ // -- FPS
+ addChild(new FPSMetter(false, 110, stage));
+ // --
+ addEventListener( Event.ENTER_FRAME, enterFrameHandler );
+ //
+ _world = World3D.getInstance();
+ // FIRST THING TO INITIALIZE
+ _world.container = this;
+ _init();
+ }
+
+ private function _init():void
+ {
+ _world.root = _createScene();
+ _world.camera = new Camera3D( SCREEN_WIDTH, SCREEN_HEIGHT );
+ _world.root.addChild( _world.camera );
+ }
+
+ private function _createScene():Group
+ {
+ // -- variables declaration
+ var g:Group = new Group();
+ var tgTranslation:TransformGroup = new TransformGroup("translation");
+ tgRotation = new TransformGroup("rotation");
+ // -- transformations
+ tgTranslation.z = 500;
+ // -- creation of the materials and apperance
+ var pic:Bitmap = new Texture();
+ var l_oTextureAppearance:Appearance = new Appearance( new BitmapMaterial( \
pic.bitmapData ) ); + // -- creation of objects
+ box = new Box( "myBox", 50, 50, 50, "quad", 3 );
+ box.appearance = l_oTextureAppearance;
+ box.rotateZ = 45;
+
+ hedra = new Hedra( "myHedra", 50, 50, 100 );
+ hedra.appearance = l_oTextureAppearance;
+ hedra.y = 50;
+ hedra.x = 20;
+
+ var l_oCylinder:Cylinder = new Cylinder("myCylinder", 50, 50, 6, 1, 50 );
+ //l_oCylinder.enableBackFaceCulling = false;
+ l_oCylinder.rotateX = 45;
+ l_oCylinder.z = -150;
+ l_oCylinder.appearance = l_oTextureAppearance;
+
+ var l_oTorus:Torus = new Torus("myTorus", 70, 40, 6, 6 );
+ //l_oCylinder.enableBackFaceCulling = false;
+ l_oTorus.x = -150;
+ l_oTorus.rotateX = 90;
+ l_oTorus.appearance = l_oTextureAppearance;
+
+ var l_oSphere:Sphere = new Sphere("mySphere", 60, 6, 4 );
+ //l_oCylinder.enableBackFaceCulling = false;
+ l_oSphere.z = 150;
+ l_oSphere.appearance = l_oTextureAppearance;
+
+ var l_oCone:Cone = new Cone("myCone", 60, 40, 8, 1 );
+ //l_oCylinder.enableBackFaceCulling = false;
+ l_oCone.y = -50;
+ l_oCone.x = -30;
+ l_oCone.appearance = l_oTextureAppearance;
+
+ // --
+ var line:Line3D = new Line3D( "myLine", new Vector( 50, 50), new Vector( 100, 50 \
), new Vector( 100, 100 ), new Vector( 75, 50 ), new Vector( 50, 100 ), new Vector( \
50, 50 ) ); + line.appearance = new Appearance( new ColorMaterial( 0, 0, new \
LineAttributes( 1, 0xFF ) ) ); + // -- Tree creation
+ tgTranslation.addChild( box );
+ tgRotation.addChild( hedra );
+ tgRotation.addChild( line );
+ tgRotation.addChild( l_oCylinder );
+ tgRotation.addChild( l_oTorus );
+ tgRotation.addChild( l_oSphere );
+ tgRotation.addChild( l_oCone );
+ tgTranslation.addChild( tgRotation );
+ g.addChild( tgTranslation );
+ // --
+ return g;
+ }
+
+ private function enterFrameHandler( event : Event ) : void
+ {
+ tgRotation.rotateY ++;
+ box.rotateX += 0.5;
+ _world.render();
+ }
+ }
+}
\ No newline at end of file
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic