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

📄 pv3dcolladascene.as

📁 Flex3实现的掼蛋游戏
💻 AS
📖 第 1 页 / 共 2 页
字号:
		{
			_rotationList = p_rotation;
		}
		/**
		 * @private
		 */	
		public function get rotationList():Object
		{
			return _rotationList;
		}
		
		public function PV3DColladaScene()
		{
			//BitmapMaterial.AUTO_MIP_MAPPING = true;
			super();
		}
		
		/**
		 * @private
		 */	
		override protected function init3D():void
		{
			super.init3D();
			
			initScene();
		}
		
		/**
		 * @private
		 */	
		protected function initScene():void
		{

		}
		
		/**
		 * @private
		 * Creates the 3 main types of materials and loads external materials.
		 * 
		 * Note that smooth has been pulled. It was causing rte's about smooth not being a property of the materials.  Will have to fix later.
		 */	
		protected function createMaterials():void
		{
			if(debug) log.debug("extMaterials", extMaterials.dataProvider.length);
			var loadCollada:Boolean = false;
			
			if(extMaterials.dataProvider.length > 0)
			{
				// reset the materials que
				materialsQue = new Dictionary();
				
				var clrMat:ColorMaterial = new ColorMaterial(0x00ff00, .75);
				
				for(var i:Number=0;i<extMaterials.dataProvider.length;i++)
				{
					// materials are in library with linkage
					var materialsListItem:MaterialsListItem = MaterialsListItem(extMaterials.dataProvider[i]);
					
					switch(materialsListItem.materialType.toLowerCase())
					{
						case "bitmap":
							if(isLivePreview)
							{								
								clrMat.oneSide = materialsListItem.singleSided;
								materialsList.addMaterial(clrMat, materialsListItem.materialName);
							}else
							{
								var bam:BitmapAssetMaterial = materialsListItem.interactive ? new InteractiveBitmapAssetMaterial(materialsListItem.materialLinkageID) : new BitmapAssetMaterial(materialsListItem.materialLinkageID);;
								loadCollada = true;
								bam.oneSide = materialsListItem.singleSided;
								//bam.smooth = materialsListItem.smooth;
								materialsList.addMaterial(bam, materialsListItem.materialName);
							}
							if(!checkForFileLoads(extMaterials)) loadCollada = true;
						break;
						
						case "file":
							var fileLocation:String = isLivePreview ? _localPath + materialsListItem.materialFileLocation : materialsListItem.materialFileLocation;
							fileLocation = fileLocation.split("\\").join("/");
							if(debug) log.debug("File to load", fileLocation);
							var bm:BitmapFileMaterial = materialsListItem.interactive ? new InteractiveBitmapFileMaterial("") : new BitmapFileMaterial("");
							bm.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleBitmapFileLoadComplete);
							materialsQue[bm] = false;
							// setting the texture property actually causes the load of the file
							bm.texture = fileLocation;
							//bm.smooth = materialsListItem.smooth;
							// because we didn't set the URL through the constructor, we have to set it manually if we want it back in the event thats disatched
							bm.url = fileLocation;
							bm.oneSide = materialsListItem.singleSided;
							materialsList.addMaterial(bm, materialsListItem.materialName);
						break;
						
						case "movieclip":
							if(isLivePreview)
							{
								clrMat.oneSide = materialsListItem.singleSided;
								materialsList.addMaterial(clrMat, materialsListItem.materialName);
							}else
							{
								var mov:MovieAssetMaterial = materialsListItem.interactive ? new InteractiveMovieAssetMaterial(materialsListItem.materialLinkageID, materialsListItem.transparent) : new MovieAssetMaterial(materialsListItem.materialLinkageID, materialsListItem.transparent);
								if(materialsListItem.animated) mov.animated = true;
								mov.oneSide = materialsListItem.singleSided;
								//mov.smooth = materialsListItem.smooth;
								materialsList.addMaterial(mov, materialsListItem.materialName);
							}
							if(!checkForFileLoads(extMaterials)) loadCollada = true;
						break;
					}
				}
			}else
			{
				if(debug) log.debug("*************************** NO MATERIALS TO LOAD***************");
				loadCollada = true;
			}
			
			if(loadCollada)	createColladaScene();
		}
		
		/**
		 * @private
		 * Checks the load que to make sure all files are loaded before loading the collada scene
		 */	
		private function checkForFileLoads(obj:SimpleDataProvider):Boolean
		{			
			for(var i:Number=0;i<obj.dataProvider.length;i++)
			{
				var materialsListItem:MaterialsListItem = MaterialsListItem(extMaterials.dataProvider[i]);
				if(debug) log.debug("@@@@@@@@@@@@@@@@ checkForFileLoads", materialsListItem.materialType.toLowerCase())
				if(materialsListItem.materialType.toLowerCase() == "file") return true;
			}
			
			return false;
		}
		
		/**
		 * @private
		 * When an external file is completely loaded, we receive this event and check to see if all the files have been loaded before loading the collada scene
		 */	
		protected function handleBitmapFileLoadComplete(e:FileLoadEvent):void
		{
			if(debug) log.debug("%%%%%% handleBitmapFileLoadComplete", e.file);
			materialsQue[e.target] = true;
			var bm:BitmapFileMaterial = BitmapFileMaterial(e.target);
			bm.removeEventListener(FileLoadEvent.LOAD_COMPLETE, handleBitmapFileLoadComplete);
			if(collada != null && materialsList.numMaterials > 0) collada.materials = materialsList;
			if(colladaFile.length > 0 && checkLoadedQue()) 
			{
				if(debug) log.debug("should load collada after getting all bitmaps");
				createColladaScene();
			}
		}
		
		/**
		 * @private
		 */	
		protected function checkLoadedQue():Boolean
		{
			for each(var items:Object in materialsQue)
			{
				if(!items) return false;
			}
			return true;
		}
		
		/**
		 * @private
		 */	
		override protected function stageResizeHandler(e:Event):void
		{			
			if(!resizeWithStage) return;
			if(debug) log.debug("stageResize");
			resizeStage();
		}
		
		/**
		 * @private
		 * Creates the Collada object and loads the file
		 */	
		protected function createColladaScene():void
		{
			if(colladaFile.length == 0) return;
			
			if(debug) log.debug("createColladaScene", colladaFile, scene == null);
			
			if(collada != null) scene.removeChild(collada);
			
			var fileLocation:String = isLivePreview ? _localPath + colladaFile : colladaFile;
			if(debug) log.debug("fileLocation for collada", fileLocation);
			
			if(collada) collada.container.graphics.clear();
			collada = new Collada(fileLocation, materialsList, sceneScale,{localPath:localPath});
			scene.addChild(collada);
			collada.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleLoadComplete);
			//collada.addEventListener(FileLoadEvent.COLLADA_MATERIALS_DONE, handleLoadComplete);
			collada.addEventListener(FileLoadEvent.LOAD_PROGRESS, handleLoadProgress);
			collada.addEventListener(FileLoadEvent.LOAD_ERROR, handleLoadError);
			collada.addEventListener(FileLoadEvent.SECURITY_LOAD_ERROR, handleLoadError);
		}
		
		/**
		 * @private
		 * Called when Collada file is completely rendered
		 */	
		protected function handleLoadComplete(e:FileLoadEvent):void
		{
			if(debug) log.debug("handleLoadComplete - Collada", e.file);
			// remove listeners
			collada.removeEventListener(FileLoadEvent.LOAD_COMPLETE, handleLoadComplete);
			collada.removeEventListener(FileLoadEvent.LOAD_PROGRESS, handleLoadProgress);
			collada.removeEventListener(FileLoadEvent.LOAD_ERROR, handleLoadError);
			collada.removeEventListener(FileLoadEvent.SECURITY_LOAD_ERROR, handleLoadError);
			
			finalizeColladaLoad();
		}
		
		/**
		 * @private
		 * Called when Collada progress event is dispatched
		 */	
		protected function handleLoadProgress(e:FileLoadEvent):void
		{
			dispatchEvent(new FileLoadEvent(SCENE_LOAD_PROGRESS, e.file, e.bytesLoaded, e.bytesTotal));
		}
		
		/**
		 * @private
		 * Called when Collada has an error with loading the DAE file specified
		 */	
		protected function handleLoadError(e:FileLoadEvent):void
		{
			dispatchEvent(new FileLoadEvent(SCENE_LOAD_ERROR, e.file, 0, 0, e.message));
		}
		
		/**
		 * @private
		 * Called after Collada file is loaded completely.  sets the rotation, and updates the scene.
		 */	
		protected function finalizeColladaLoad():void
		{			
			collada.rotationX = rotationList.pitch;
			collada.rotationY = rotationList.yaw;
			collada.rotationZ = rotationList.roll;			
			
			updateScene();
			
			dispatchEvent(new FileLoadEvent(SCENE_COMPLETE));
			
			// set to false so no unnecessary redraws occur
			rebuildCollada = false;
			
			if(sceneRotation && !isLivePreview)
			{
				ObjectController.getInstance().registerStage(this.stage);
				ObjectController.getInstance().registerControlObject(collada);
			}
			
			// for debugging
			if(debug) showChildren();
		}
		
		/**
		 * @private
		 * Just for testing to see the children of the collada object
		 */	
		private function showChildren():void
		{
			for each(var item:Object in collada.children) if(debug) trace("collada children: ", item.name);
		}
		
		/**
		 * @private
		 */	
		override protected function handleTimerUpdate(e:TimerEvent):void
		{
			updateScene();
		}
		
		/**
		 * @private
		 * Used for matching the materials list that comes in when an update occurs on the component at Designtime.  A brand new version is sent with every change to the 
		 * component at design time, so we have to crawl through and verify if it's been changed to really know if we need to re-render the collada scene.
		 */	
		private function checkMaterialListsMatch(obj_0:SimpleDataProvider, obj_1:SimpleDataProvider):Boolean
		{
			if(obj_0.dataProvider.length != obj_1.dataProvider.length) return false;
			
			for(var i:Number=0;i<obj_0.dataProvider.length;i++)
			{
				// materials are in library with linkage
				var m0:MaterialsListItem = MaterialsListItem(obj_0.dataProvider[i]);
				var m1:MaterialsListItem = MaterialsListItem(obj_1.dataProvider[i]);
								
				var props:Array = PropertyTools.getProperties(m0);
				
				for (var ii:Number=0;i<props.length;i++)
				{
					if(debug) log.debug("compare", m0[props[i].name] + ", " + m1[props[i].name]);
					if(m0[props[i].name] != m1[props[i].name]) return false;
				}
				
			}
			
			return true;
		}
	}
}

⌨️ 快捷键说明

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