⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pv3dcolladascene.as

📁 Flex3实现的掼蛋游戏
💻 AS
📖 第 1 页 / 共 2 页
字号:
/**
* @author John Grden
*/
package org.papervision3d.components.as3.flash9
{
	import com.blitzagency.xray.logger.util.PropertyTools;
	
	import fl.data.SimpleDataProvider;
	
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Dictionary;
	import flash.utils.Timer;
	
	import org.papervision3d.components.as3.collections.MaterialsListItem;
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.events.FileLoadEvent;
	import org.papervision3d.materials.BitmapAssetMaterial;
	import org.papervision3d.materials.BitmapFileMaterial;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.MaterialsList;
	import org.papervision3d.materials.MovieAssetMaterial;
	import org.papervision3d.objects.Collada;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.materials.InteractiveBitmapFileMaterial;
	import org.papervision3d.materials.InteractiveMovieAssetMaterial;
	import org.papervision3d.materials.InteractiveBitmapAssetMaterial;
	import org.papervision3d.components.as3.utils.ObjectController;
	
	/**
	* Dispatched when the collada file and materials have been completely parsed and loaded.
	* 
	* @eventType org.papervision3d.components.as3.flash9.PV3DColladaScene.SCENE_COMPLETE
	*/
	[Event(name="sceneComplete", type="flash.events.Event")]
	
	/**
	* Dispatched while the collada file is loading.  
	 * <p>Event carries 2 properties:
	 * <ul>
	 * <li>1.  bytesLoaded
	 * <li>2.  bytesTotal
	* </ul>
	 * </p>
	* @eventType org.papervision3d.components.as3.flash9.PV3DColladaScene.SCENE_LOAD_PROGRESS
	*/
	[Event(name="sceneLoadProgress", type="flash.events.Event")]
	
	/**
	* Dispatched when the collada object cannot load the file specified either because of security or non-existance
	* <p>
	 * provides a property called "message" which is the actual load error initially received.
	 * </p>
	* @eventType org.papervision3d.components.as3.flash9.PV3DColladaScene.SCENE_LOAD_ERROR
	*/
	[Event(name="sceneLoadError", type="flash.events.Event")]
	
	/**
	 * PV3DColladaScene is the main class for the Flash CS3 COLLADA component.
	 * </p>
	 * <p>It's main purpose is to provide the developer/designer with drag and drop functionality to render a COLLADA scene with a camera and Scene3D.  Full access to a materials list and objects
	 * is given through the api:
	 * <ul>
	 * <li>scene</li>
	 * <li>camera</li>
	 * <li>collada</li>
	 * </ul>
	 * </p>
	 * <p>The component includes a Custom Panel via Windows>other panels>PV3DPanel</P>
	 * <p>To use the component, drag it from the components list on to the stage in the Flash IDE.  First, set the local directory by clicking on the folder icon in the Panel.
	 * Then, select the DAE (COLLADA) file to use.  At this point, you *should* see your 3D scene being rendered.
	 * </p>
	 * <p>You might have to play with the scale if you're not seeing the scene or camera Z (move it out more).
	 * </p>
	 * <p>If you textured your models with bitmaps in your 3D application, COLLADA retains those file paths and Papervision3D will attempt to dynamically load them for you IF you don't 
	 * provide a materials list.  So, there is a good chance you'll see your scene fully textured once you've provided the local directory and file paths.
	 * </p>
	 * <p>If you provide a MaterialsList via the property inspector, there are 3 types supported:
	 * <ul>
	 * <li>Bitmap: BitmapAssetMaterial - a bitmap defined in the library</li>
	 * <li>MovieClip: MovieAssetMaterial - a MovieClip defined in the library</li>
	 * <li>File: BitmapFileMaterial - an external bitmap file</li>
	 * </ul>
	 * 
	 * </p>
	 * @see org.papervision3d.components.as3.collections.MaterialsListItem
	 */	
	public class PV3DColladaScene extends PV3DScene3D
	{
		
		/**
		* @eventType sceneComplete
		*/		
		public static const SCENE_COMPLETE	:String = "sceneComplete";
		
		/**
		* @eventType sceneLoadProgress
		*/		
		public static const SCENE_LOAD_PROGRESS	:String = "sceneLoadProgress";
		
		/**
		* @eventType sceneLoadError
		*/		
		public static const SCENE_LOAD_ERROR	:String = "sceneLoadError";
		
		/**
		* A boolean flag letting the component know whether or not to show trace output
		*/		
		public var debug						:Boolean = false;
		
				
		private var _materialsList						:MaterialsList = new MaterialsList();
		/**
		* The MaterialsList object that is used by the component if one is provided.  This is set at design-time and is read-only at runtime
		*/
		public function get materialsList():MaterialsList { return _materialsList; }
		
		private var _col						:Collada;		
		private var _colladaFile				:String = "";
		private var _localPath					:String = "";
		private var _sceneScale					:Number = 0;
		private var rebuildCollada				:Boolean = false;
		private var _rotationList				:Object = {pitch:0, yaw:0, roll:0};
		private var _extMaterials				:SimpleDataProvider = new SimpleDataProvider();
		
		private var materialsQue				:Dictionary = new Dictionary();
		
		private var previewTimer				:Timer = new Timer(25,0);
		
		/**
		 * @private
		 * @note Called when the component is actually running in a compiled SWF at runtime, rather than LivePreview
		 * @param p_piSetting
		 * 
		 */	
		override public function set componentInspectorSetting(p_piSetting:Boolean):void
		{
			_componentInspectorSetting = p_piSetting;
			if(debug) log.debug("componentInspectorSetting", p_piSetting);
			if(!_componentInspectorSetting) 
			{
				initApp();
				if(debug) log.debug("colladaFile?", colladaFile);
				if(debug) log.debug("isLivePreview?", isLivePreview);
				
				// just start by building materials and it'll light up from there.
				createMaterials();
			}
		}
		
		/**
		 * @private
		 */	
		override public function get componentInspectorSetting():Boolean
		{
			return _componentInspectorSetting;
		}
		
		/**
		 * The Papervision3D Collada object created for the component's use.
		 * @return Collada object
		 * 
		 */		
		public function get collada():Collada
		{
			return _col;
		}
		
		public function set collada(col:Collada):void
		{
			_col = col;
		}
		
		/**
		 * this fires after all of the properties have been updated.  The Property Inspector (pi) sets all properties for a component even if only 1 is updated.
		 * So, the modified LivePreviewParent I created makes this call to propertyInspectorSetting and passes a flag to let the component know that's its
		 * ok to proceed with dealing with the changes.
		 * 
		 * Changes have to be dealt with in a specific order.  Materials, then collada WITH scale passed in the constructor, then rotation after collada is completely loaded.
		 * @private
		 */	
		override public function set propertyInspectorSetting(p_piSetting:Boolean):void
		{
			_propertyInspectorSetting = p_piSetting;
			if(!p_piSetting)
			{
				// if we haven't initialized yet, do so
				if(!isAppInitialized) initApp();
				
				if(debug) log.debug("********** isLivePreview?", isLivePreview);
				
				if(rebuildCollada || collada == null) 
				{
					if(debug) log.debug("GO CREATE MATERIALS");
					createMaterials();
				}else
				{
					if(debug) log.debug("GO update collada");
					finalizeColladaLoad();
				}
			}
			if(debug) log.debug("propertyInspectorSetting", p_piSetting);
		}
		
		/**
		 * @private
		 */	
		override public function get propertyInspectorSetting():Boolean
		{
			return _propertyInspectorSetting;
		}
		
		[Inspectable (name="Scene Rotation", defaultValue=false, type="Boolean")]
		/**
		* Boolean flag indicating whether or not to add mouse drag/rotation abilities to the collada container.  Clicking 
		 * yes will allow you to use simple dragging to rotate the scene.
		*/		
		public var sceneRotation					:Boolean = true;
			
		[Inspectable (type="String", defaultValue="", name="Local Directory") ]
		/**
		 * @private
		 */	
		public function set localPath(p_localPath:String):void
		{
			if(p_localPath != _localPath && p_localPath.length > 0) 
			{
				p_localPath = p_localPath.split("\\").join("/");
				_localPath = p_localPath.substring(p_localPath.length-1) == "/" ?  p_localPath : p_localPath + "/";
			}
		}
		/**
		 * @private
		 */	
		public function get localPath():String
		{
			return _localPath;
		}
				
		[Inspectable (type="String", defaultValue="", name="Collada File") ]
		/**
		 * A relative reference to the external collada file to be used
		 * @return String 
		 * 
		 */	
		public function set colladaFile(p_colladaFile:String):void
		{
			if(_colladaFile != p_colladaFile && p_colladaFile.length > 0) 
			{
				if(debug) log.debug("set colladaFile", p_colladaFile);
				rebuildCollada = true;
				_colladaFile = p_colladaFile;
			}
		}
	
		public function get colladaFile():String
		{
			return _colladaFile;
		}
		
		[Collection(name="Materials List", collectionClass="fl.data.SimpleDataProvider", collectionItem="org.papervision3d.components.as3.collections.MaterialsListItem", identifier="item")]
		/**
		 * @private
		 */	
		public function set extMaterials(p_extMaterials:SimpleDataProvider):void
		{
			if(p_extMaterials.dataProvider.length > 0 && !checkMaterialListsMatch(extMaterials, p_extMaterials)) 
			{
				if(debug) log.debug("****** COMPARE", checkMaterialListsMatch(extMaterials, p_extMaterials));
				_extMaterials = p_extMaterials;
				rebuildCollada = true;
			}
		}
		/**
		 * @private
		 */	
		public function get extMaterials():SimpleDataProvider { return _extMaterials; }
		
		[Inspectable (type="Number", defaultValue=.01, name="Scale") ]
		/**
		 * @private
		 */	
		public function set sceneScale(p_scale:Number):void
		{
			if(p_scale == _sceneScale) return;
			_sceneScale = p_scale;
			if(isLivePreview && (collada != null && colladaFile.length > 0)) 
			{
				// force an object redraw
				rebuildCollada = true;
			}
		}
		/**
		 * @private
		 */	
		public function get sceneScale():Number
		{
			return _sceneScale;
		}
		
		[Inspectable (type="Object", defaultValue="pitch:0, yaw:0, roll:0", name="Initial Rotation") ]
		/**
		 * @private
		 */	
		public function set rotationList(p_rotation:Object):void

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -