/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

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