[prev in list] [next in list] [prev in thread] [next in thread] 

List:       osflash-sandy
Subject:    [Sandy] [sandy commit] r213 - in
From:       codesite-noreply () google ! com (codesite-noreply () google ! com)
Date:       2007-04-30 18:14:37
Message-ID: 163600cc53042f58753bc6756e57b () google ! com
[Download RAW message or body]

Author: kiroukou
Date: Mon Apr 30 11:14:21 2007
New Revision: 213

Added:
   trunk/sandy/as3/branches/3.0/sandy/parser/AParser.as
   trunk/sandy/as3/branches/3.0/sandy/parser/ASEParser.as
   trunk/sandy/as3/branches/3.0/sandy/parser/IParser.as
   trunk/sandy/as3/branches/3.0/sandy/parser/Parser.as
   trunk/sandy/as3/branches/3.0/sandy/parser/ParserEvent.as
Modified:
   trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Camera3D.as
   trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Node.as
   trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Shape3D.as

Log:
Introduction of the parser package.
First parser is the ASE Parser.as

For the demo, I'm using the rhino that PV3D was using too.
HAve fun_

Modified: trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Camera3D.as
==============================================================================
--- trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Camera3D.as	(original)
+++ trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Camera3D.as	Mon Apr 30 \
11:14:21 2007 @@ -47,7 +47,7 @@
 		 * @param nFoc The focal of the Camera3D
 		 * @param s the screen associated to the camera
 		 */
-		public function Camera3D( p_nWidth:Number, p_nHeight:Number, p_nFov:Number = 45, \
p_nNear:Number = 10, p_nFar:Number = 3000 ) +		public function Camera3D( \
p_nWidth:Number, p_nHeight:Number, p_nFov:Number = 45, p_nNear:Number = 50, \
p_nFar:Number = 10000 )  {
 			super( null );
 			_viewport = new ViewPort( p_nWidth, p_nHeight );

Modified: trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Node.as
==============================================================================
--- trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Node.as	(original)
+++ trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Node.as	Mon Apr 30 11:14:21 \
2007 @@ -124,7 +124,7 @@
 		* @param	index Number The ID of the child you want to get
 		* @return 	Node The desired Node or null is no child with this ID has been found
 		*/
-		public function getChildFromId( id:Number, p_recurs:Boolean ):Node 
+		public function getChildFromId( id:Number, p_recurs:Boolean=false ):Node 
 		{
 			var l:Number = _aChilds.length;
 			while( -- l > -1 )
@@ -152,7 +152,7 @@
 		* @param	index Number The name of the child you want to get
 		* @return 	Node The desired Node or null is no child with this name has been found
 		*/
-		public function getChildByName( pName:String, p_recurs:Boolean ):Node 
+		public function getChildByName( pName:String, p_recurs:Boolean=false ):Node 
 		{
 			var l:Number = _aChilds.length;
 			while( -- l > -1 )
@@ -389,7 +389,7 @@
 		////////////////////
 		
 		// TODO: private function in original implementation
-		public function Node( p_sName:String ) 
+		public function Node( p_sName:String = "" ) 
 		{
 			parent = null;
 			_aChilds = [];

Modified: trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Shape3D.as
==============================================================================
--- trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Shape3D.as	(original)
+++ trunk/sandy/as3/branches/3.0/sandy/core/scenegraph/Shape3D.as	Mon Apr 30 11:14:21 \
2007 @@ -28,7 +28,7 @@
 			m_nForcedDepth = 0;
 			m_bEv = false;
 			// --
-			appearance = p_oAppearance;
+			if( p_oAppearance ) appearance = p_oAppearance;
 			// -- 
 			updateBoundingVolumes();
 	    }

Added: trunk/sandy/as3/branches/3.0/sandy/parser/AParser.as
==============================================================================
--- (empty file)
+++ trunk/sandy/as3/branches/3.0/sandy/parser/AParser.as	Mon Apr 30 11:14:21 2007
@@ -0,0 +1,61 @@
+package sandy.parser
+{
+	import flash.events.EventDispatcher;
+	import flash.events.IOErrorEvent;
+	import flash.events.Event;
+	import flash.net.URLLoader;
+	import flash.net.URLRequest;
+	import flash.net.URLLoaderDataFormat;
+	
+	import sandy.core.scenegraph.Group;
+	import sandy.parser.ParserEvent;
+	
+	internal class AParser extends EventDispatcher implements IParser
+	{
+		protected static var m_eProgress:ParserEvent = new ParserEvent( \
ParserEvent.onProgressEVENT ); +		protected const m_oLoader:URLLoader = new \
URLLoader(); +		protected var m_oGroup:Group;
+		protected var m_oFileLoader:URLLoader
+		private var m_sUrl:String;
+		
+		public function AParser( p_sUrl:String )
+		{ 
+			m_sUrl = p_sUrl;
+			m_oFileLoader = new URLLoader();
+			m_oGroup = new Group('parser');
+		}
+		
+		/**
+		* Function is call in case of IO error
+		* @param	e IOErrorEvent 	IO_ERROR
+		*/
+		private function _io_error( e:IOErrorEvent ):void
+		{
+			dispatchEvent( new ParserEvent( ParserEvent.onFailEVENT ) );
+		}
+		
+		protected function parseData( e:Event ):void
+		{
+			m_oFileLoader = URLLoader( e.target );
+		}
+		
+	    /**
+	     * Initialize the object passed in parameter (which should be new) with the \
datas +	     * stored in the ASE file given in second parameter
+	     * 
+	     * @param o    Object3D 	The Object3D we want to initialize
+	     * @param url    String	The url of the .ASE file used to initialized the \
Object3D +	     */
+	    public function parse():void
+		{
+			// Construction d'un objet URLRequest qui encapsule le chemin d'acc ???s
+			var urlRequest:URLRequest = new URLRequest( m_sUrl );
+			// Ecoute de l'evennement COMPLETE
+			m_oFileLoader.addEventListener( Event.COMPLETE, parseData );
+			m_oFileLoader.addEventListener( IOErrorEvent.IO_ERROR , _io_error );
+			// Lancer le chargement
+			m_oFileLoader.dataFormat = URLLoaderDataFormat.TEXT;
+			m_oFileLoader.load(urlRequest);
+		}
+	}
+}
\ No newline at end of file

Added: trunk/sandy/as3/branches/3.0/sandy/parser/ASEParser.as
==============================================================================
--- (empty file)
+++ trunk/sandy/as3/branches/3.0/sandy/parser/ASEParser.as	Mon Apr 30 11:14:21 2007
@@ -0,0 +1,139 @@
+package sandy.parser
+{
+	import flash.events.Event;
+	import flash.events.EventDispatcher;
+	import flash.events.IOErrorEvent;
+	import flash.net.URLLoader;
+	import flash.net.URLLoaderDataFormat;
+	import flash.net.URLRequest;
+	import flash.utils.unescapeMultiByte;
+
+	import sandy.parser.Parser;
+	import sandy.parser.AParser;
+	import sandy.parser.IParser;
+	import sandy.parser.ParserEvent;
+	import sandy.core.scenegraph.Geometry3D;
+	import sandy.core.scenegraph.Shape3D;
+	import sandy.core.scenegraph.Group;
+	import sandy.materials.ColorMaterial;
+	import sandy.materials.Appearance;
+	/**
+	 */
+	internal final class ASEParser extends AParser implements IParser
+	{
+		public function ASEParser( p_sUrl:String )
+		{
+			super( p_sUrl );
+		}
+		
+		/////////////////////
+		///  PROPERTIES   ///
+		/////////////////////		
+		protected override function parseData( e:Event ):void
+		{
+			super.parseData( e );
+			// --
+			var lines:Array = unescapeMultiByte( (m_oFileLoader.data as String ) ).split( \
'\r\n' ); +			var lineLength:uint = lines.length;
+			var id:uint;
+			// -- local vars
+			var line:String;
+			var content:String;
+			var chunk:String;
+			var l_oGeometry:Geometry3D = null;
+			var l_oShape:Shape3D = null;
+			// -- 
+			while( lines.length )
+			{
+				m_eProgress.percent = ( 100 - ( lines.length * 100 / lineLength ) );
+				dispatchEvent( m_eProgress );
+				//-- parsing
+				line = String(lines.shift());		
+				//-- clear white space from begin
+				line = line.substr( line.indexOf( '*' ) + 1 );
+				//-- clear closing brackets
+				if( line.indexOf( '}' ) >= 0 ) line = '';
+				//-- get chunk description
+				chunk = line.substr( 0, line.indexOf( ' ' ) );
+				//-- 
+				switch( chunk )
+				{
+					case 'MESH_NUMFACES':
+					{		
+						//var num: Number =  Number(line.split( ' ' )[1]);
+						l_oGeometry = new Geometry3D();
+						break;
+					}	
+					case 'MESH_VERTEX_LIST':
+					{
+						while( ( content = (lines.shift() as String )).indexOf( '}' ) < 0 )
+						{
+							content = content.substr( content.indexOf( '*' ) + 1 );
+							var vertexReg:RegExp = \
/MESH_VERTEX\s*(\d+)\s*([\d-.]+)\s*([\d-.]+)\s*([\d-.]+)/ +							id = \
uint(content.replace(vertexReg, "$1")); +							var v1:Number = \
Number(content.replace(vertexReg, "$2")); +							var v2:Number = \
Number(content.replace(vertexReg, "$4")); +							var v3:Number = \
Number(content.replace(vertexReg, "$3")); +
+							l_oGeometry.setVertex(id, v1, -v2, v3 );
+						}
+						break;
+					}	
+					case 'MESH_FACE_LIST':
+					{
+						while( ( content = (lines.shift() as String )).indexOf( '}'  ) < 0 )
+						{
+							content = content.substr( content.indexOf( '*' ) + 1 );		
+							var mfl:String = content.split(  '*' )[0]; // ignore: \
[MESH_SMOOTHING,MESH_MTLID] +							//"MESH_FACE    0:    A:    777 B:    221 C:    \
122 AB:    1 BC:    1 CA:    1" +							var faceReg:RegExp = \
/MESH_FACE\s*(\d+):\s*A:\s*(\d+)\s*B:\s*(\d+)\s*C:\s*(\d+)\s*AB:\s*(\d+)\s*BC:\s*(\d+)\s*CA:\s*(\d+)\s*/
 +							id = uint(mfl.replace(faceReg, "$1"));
+							var p1:uint = uint(mfl.replace(faceReg, "$2"));
+							var p2:uint = uint(mfl.replace(faceReg, "$4"));
+							var p3:uint = uint(mfl.replace(faceReg, "$3"));
+							
+							l_oGeometry.setFaceVertexIds(id, p1, p2, p3 );
+						}
+						break;
+					}		
+					case 'MESH_TVERTLIST':
+					{		
+						while( ( content = (lines.shift() as String )).indexOf( '}' ) < 0 )
+						{
+							content = content.substr( content.indexOf( '*' ) + 1 );
+							vertexReg = /MESH_TVERT\s*(\d+)\s*([\d-.]+)\s*([\d-.]+)\s*([\d-.]+)/
+							id = uint(content.replace(vertexReg, "$1"));
+							v1 = Number(content.replace(vertexReg, "$2"));
+							v2 = Number(content.replace(vertexReg, "$3"));
+							//var v3 = (content.replace(vertexReg, "$2"));
+							l_oGeometry.setUVCoords(id, v1, 1-v2 );
+						}
+						break;
+					}	
+					//TODO: there are ASE file without MESH_TFACELIST, what then							
+					case 'MESH_TFACELIST':
+					{
+						while( ( content = (lines.shift() as String)).indexOf( '}' ) < 0 )
+						{
+							content = content.substr( content.indexOf( '*' ) + 1 );
+							faceReg = /MESH_TFACE\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/
+							id = uint(content.replace(faceReg, "$1"));
+							var f1:uint = uint(content.replace(faceReg, "$2"));
+							var f2:uint = uint(content.replace(faceReg, "$4"));
+							var f3:uint = uint(content.replace(faceReg, "$3"));
+							l_oGeometry.setFaceUVCoordsIds( id, f1, f2, f3 );
+						}
+						break;
+					}
+				}
+			}
+			// -- 
+			l_oShape = new Shape3D( null, l_oGeometry );
+			m_oGroup.addChild( l_oShape );
+			// -- Parsing is finished
+			var l_eOnInit:ParserEvent = new ParserEvent( ParserEvent.onInitEVENT );
+			l_eOnInit.group = m_oGroup;
+			dispatchEvent( l_eOnInit );
+		} 
+	}// -- end AseParser
+}
\ No newline at end of file

Added: trunk/sandy/as3/branches/3.0/sandy/parser/IParser.as
==============================================================================
--- (empty file)
+++ trunk/sandy/as3/branches/3.0/sandy/parser/IParser.as	Mon Apr 30 11:14:21 2007
@@ -0,0 +1,9 @@
+package sandy.parser
+{
+	import flash.events.IEventDispatcher;
+	
+	public interface IParser extends IEventDispatcher
+	{
+		function parse():void;
+	}
+}
\ No newline at end of file

Added: trunk/sandy/as3/branches/3.0/sandy/parser/Parser.as
==============================================================================
--- (empty file)
+++ trunk/sandy/as3/branches/3.0/sandy/parser/Parser.as	Mon Apr 30 11:14:21 2007
@@ -0,0 +1,31 @@
+package sandy.parser
+{
+	import sandy.parser.AParser;
+	import sandy.parser.ASEParser;
+	
+	public final class Parser
+	{
+		public static function parse( p_sFileName:String ):IParser
+		{
+			var l_sExt:String = (p_sFileName.split('.')).reverse()[0];
+			var l_iParser:IParser = null;
+			// --
+			switch( l_sExt.toUpperCase() )
+			{
+				case "ASE":
+					l_iParser = new ASEParser( p_sFileName );
+					break;
+				case "OBJ":
+					break;
+				case "DAE":
+					break;
+				case "3DS":
+					break;
+				default:
+					break;
+			}
+			// --
+			return l_iParser;
+		}
+	}
+}
\ No newline at end of file

Added: trunk/sandy/as3/branches/3.0/sandy/parser/ParserEvent.as
==============================================================================
--- (empty file)
+++ trunk/sandy/as3/branches/3.0/sandy/parser/ParserEvent.as	Mon Apr 30 11:14:21 2007
@@ -0,0 +1,34 @@
+package sandy.parser
+{
+	import flash.events.Event;
+	import sandy.core.scenegraph.Group;
+
+	public final class ParserEvent extends Event
+	{
+		/**
+	     * The load has failed
+	     */
+	    static public const onFailEVENT:String = 'onFailEVENT';
+	    /**
+	     * The OBject3D object is initialized
+	     */
+	    static public const onInitEVENT:String = 'onInitEVENT';
+	    /**
+	     * The load has started
+	     */
+	    static public const onLoadEVENT:String = 'onLoadEVENT';
+		/**
+		 *  The load is in progress
+		 */
+		public static const onProgressEVENT:String = 'onProgressEVENT';
+		
+		
+		public var percent:Number;
+		public var group:Group;
+
+		public function ParserEvent( p_sType:String )
+		{
+			super( p_sType );
+		}
+	}
+}
\ 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