PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 0ms

/src/away3d/loaders/misc/AssetLoaderContext.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 174 lines | 89 code | 19 blank | 66 comment | 1 complexity | 594ea75d04135453f27f4650c85ac30d MD5 | raw file
  1package away3d.loaders.misc
  2{
  3	import away3d.arcane;
  4	
  5	public class AssetLoaderContext
  6	{
  7		public static const UNDEFINED:uint = 0;
  8		public static const SINGLEPASS_MATERIALS:uint = 1;
  9		public static const MULTIPASS_MATERIALS:uint = 2;
 10		private var _includeDependencies:Boolean;
 11		private var _dependencyBaseUrl:String;
 12		private var _embeddedDataByUrl:Object;
 13		private var _remappedUrls:Object;
 14		private var _materialMode:uint;
 15		
 16		private var _overrideAbsPath:Boolean;
 17		private var _overrideFullUrls:Boolean;
 18		
 19		/**
 20		 * AssetLoaderContext provides configuration for the AssetLoader load() and parse() operations.
 21		 * Use it to configure how (and if) dependencies are loaded, or to map dependency URLs to
 22		 * embedded data.
 23		 *
 24		 * @see away3d.loading.AssetLoader
 25		 */
 26		public function AssetLoaderContext(includeDependencies:Boolean = true, dependencyBaseUrl:String = null)
 27		{
 28			_includeDependencies = includeDependencies;
 29			_dependencyBaseUrl = dependencyBaseUrl || '';
 30			_embeddedDataByUrl = {};
 31			_remappedUrls = {};
 32			_materialMode = UNDEFINED;
 33		}
 34		
 35		/**
 36		 * Defines whether dependencies (all files except the one at the URL given to the load() or
 37		 * parseData() operations) should be automatically loaded. Defaults to true.
 38		 */
 39		public function get includeDependencies():Boolean
 40		{
 41			return _includeDependencies;
 42		}
 43		
 44		public function set includeDependencies(val:Boolean):void
 45		{
 46			_includeDependencies = val;
 47		}
 48		
 49		/**
 50		 * MaterialMode defines, if the Parser should create SinglePass or MultiPass Materials
 51		 * Options:
 52		 * 0 (Default / undefined) - All Parsers will create SinglePassMaterials, but the AWD2.1parser will create Materials as they are defined in the file
 53		 * 1 (Force SinglePass) - All Parsers create SinglePassMaterials
 54		 * 2 (Force MultiPass) - All Parsers will create MultiPassMaterials
 55		 * 
 56		 */
 57		public function get materialMode():uint
 58		{
 59			return _materialMode;
 60		}
 61		
 62		public function set materialMode(materialMode:uint):void
 63		{
 64			_materialMode = materialMode;
 65		}
 66		
 67		/**
 68		 * A base URL that will be prepended to all relative dependency URLs found in a loaded resource.
 69		 * Absolute paths will not be affected by the value of this property.
 70		 */
 71		public function get dependencyBaseUrl():String
 72		{
 73			return _dependencyBaseUrl;
 74		}
 75		
 76		public function set dependencyBaseUrl(val:String):void
 77		{
 78			_dependencyBaseUrl = val;
 79		}
 80		
 81		/**
 82		 * Defines whether absolute paths (defined as paths that begin with a "/") should be overridden
 83		 * with the dependencyBaseUrl defined in this context. If this is true, and the base path is
 84		 * "base", /path/to/asset.jpg will be resolved as base/path/to/asset.jpg.
 85		 */
 86		public function get overrideAbsolutePaths():Boolean
 87		{
 88			return _overrideAbsPath;
 89		}
 90		
 91		public function set overrideAbsolutePaths(val:Boolean):void
 92		{
 93			_overrideAbsPath = val;
 94		}
 95		
 96		/**
 97		 * Defines whether "full" URLs (defined as a URL that includes a scheme, e.g. http://) should be
 98		 * overridden with the dependencyBaseUrl defined in this context. If this is true, and the base
 99		 * path is "base", http://example.com/path/to/asset.jpg will be resolved as base/path/to/asset.jpg.
100		 */
101		public function get overrideFullURLs():Boolean
102		{
103			return _overrideFullUrls;
104		}
105		
106		public function set overrideFullURLs(val:Boolean):void
107		{
108			_overrideFullUrls = val;
109		}
110		
111		/**
112		 * Map a URL to another URL, so that files that are referred to by the original URL will instead
113		 * be loaded from the new URL. Use this when your file structure does not match the one that is
114		 * expected by the loaded file.
115		 *
116		 * @param originalUrl The original URL which is referenced in the loaded resource.
117		 * @param newUrl The URL from which Away3D should load the resource instead.
118		 *
119		 * @see mapUrlToData()
120		 */
121		public function mapUrl(originalUrl:String, newUrl:String):void
122		{
123			_remappedUrls[originalUrl] = newUrl;
124		}
125		
126		/**
127		 * Map a URL to embedded data, so that instead of trying to load a dependency from the URL at
128		 * which it's referenced, the dependency data will be retrieved straight from the memory instead.
129		 *
130		 * @param originalUrl The original URL which is referenced in the loaded resource.
131		 * @param data The embedded data. Can be ByteArray or a class which can be used to create a bytearray.
132		 */
133		public function mapUrlToData(originalUrl:String, data:*):void
134		{
135			_embeddedDataByUrl[originalUrl] = data;
136		}
137		
138		/**
139		 * @private
140		 * Defines whether embedded data has been mapped to a particular URL.
141		 */
142		arcane function hasDataForUrl(url:String):Boolean
143		{
144			return _embeddedDataByUrl.hasOwnProperty(url);
145		}
146		
147		/**
148		 * @private
149		 * Returns embedded data for a particular URL.
150		 */
151		arcane function getDataForUrl(url:String):*
152		{
153			return _embeddedDataByUrl[url];
154		}
155		
156		/**
157		 * @private
158		 * Defines whether a replacement URL has been mapped to a particular URL.
159		 */
160		arcane function hasMappingForUrl(url:String):Boolean
161		{
162			return _remappedUrls.hasOwnProperty(url);
163		}
164		
165		/**
166		 * @private
167		 * Returns new (replacement) URL for a particular original URL.
168		 */
169		arcane function getRemappedUrl(originalUrl:String):String
170		{
171			return _remappedUrls[originalUrl];
172		}
173	}
174}