@Alessandro:
First of all: Loading in Flash is by nature asynchronous, and the only
reason you could load a mesh and add that mesh instantly to the scene
with the ResourceManager was because what you were adding was not a
mesh -- it was a container. The parser was in charge of creating a
container and handing that back to you, and then add things to that
container as they were loading. This works ok (even though it forces
you to have a useless container) when the file that you're loading can
only contain scene objects (which is the case for many file formats.)
It doesn't work at all if the parser has no way of knowing what the
file it's about to receive will contain (which is the case for AWD and
COLLADA.)
So what we have done now is not make something synchronous
asynchronous, we have just stopped faking something asynchronous as
being synchronous, for the sake of flexibility, transparency and
stability. So now, iff you want to use misc assets that you load using
any of the loading methods you will need to wait for it to finish.
That being said however, if you just want to load things into a scene
to display it quickly, you can use the Loader3D class which has
returned from Away3D 3.x:
Loader3D.enableParsers(Parsers.ALL_BUNDLED);
var loader : Loader3D = new Loader3D();
loader.load(new URLRequest('mysimplescene.obj'));
myScene.addChild(loader);
This way you can add the loader directly to the scene without having
to wait for the load to complete. Note however that this will only
work with assets that make sense to add to a scene (i.e. models and
similar.)
The asset library is really meant for more complex apps, where you
load e.g. an entire game level from a single file, and one file
containing all the characters for example. You will then be able to,
like you're guessing, to retrieve a single "asset" (mesh, material,
texture, animation et c) using the getAsset() method and the name of
that asset.
All loader classes dispatch LoaderEvent.RESOURCE_COMPLETE when they
finish loading an entire resource (a file and all it's dependencies)
which you can listen for. That event contains a "url" property that
you can use to distinguish loads from each other. The AssetLibrary
also returns a token (currently an AssetLoader, but this is likely to
change) on which you can listen for load events if you want to
distinguish loads from each other in another way than using the URL:
var token : EventDispatcher;
token = AssetLibrary.load(new URLRequest('mymodel.awd'));
token.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onComplete);
Alternatively, you can listen for the AssetEvent.ASSET_COMPLETE on any
loader class, and it will be dispatched for every single
"asset" (mesh, material, animation et c) in a resource (file) as they
are encountered by the parser. If the asset (which is in the event's
"asset" property) is of assetType AssetType.MESH for instance, you
know that you should likely add it to the scene. This is actually what
Loader3D does internally.
Make sure you have a look at the document in my original post in this
thread, as it may contain more useful information!
I hope this helps!
Cheers
/R
On May 6, 10:01 am, Alessandro Bianco <[email protected]> wrote:
> the autodetection and plugin system it's really awesome. it really
> could be the best loading and asset-management implementation i've
> ever seen ^_^
>
> as for the questions ...
> the new async nature means that we will needto wait for the model to
> completely load before adding it to the scene or use it, right?
> we're goind to receive a general "complete" event from the
> AssetLibrary for everything we load or we will get some kind of
> reference from the AssetLibrary.load method, to add specific listeners
> to it? in the former case, how can we distinguish between multiple
> assets that could be loaded at the same time?
>
> in the end i don't really understand the getAsset("meshName") method:
> if we load a big model with a lot of meshes inside, we can retrieve a
> singular mesh contained there, without the need of adding the whole
> "world" to our scene?
> we can also reference directly textures or other kind of assets?
>
> Bianco Alessandro
>
> 2011/5/6 richardolsson <[email protected]>:
>
>
>
>
>
>
>
> > Cheers guys!
>
> > The document mainly outlines the changes between Away 3.x and this new
> > solution, so not so much the transition from ResourceManager (the
> > previous alpha solution that this one replaces) to AssetLibrary.
>
> > However, the ResourceManager really didn't do much before, so I don't
> > think that modifying your code for the AssetLibrary will require much
> > work once the general understanding is there (and that's what I'm
> > trying to provide through the document.) I know this from having
> > changed all the examples very quickly from ResourceManager to Loader3D
> > (which in essence is very similar to the AssetLibrary.)
>
> > Since it's not in the document, let me quickly outline the reason for
> > ditching the ResourceManager. With the ResourceManager we tried to do
> > some pretty magical things with returning proxy objects for
> > everything, and using the same method to load and retrieve an already
> > loaded resource. As we were implementing more complex file formats
> > (especially AWD and COLLADA) it became clear that this will not work
> > throughout, so we decided to ditch it in favor of a single approach
> > which would always work (first load, and retrieve from library only
> > once loaded.)
>
> > To clearly mark that we were moving away from the ResourceManager (and
> > the fact that we now have a library-like functionality) we decided to
> > rename the new manager class AssetLibrary, which is what you'll be
> > working with from now on.
>
> > Another important change is something that is indeed mentioned in the
> > document, but deserves another mention, because IT'S VERY IMPORTANT!
> > Away4 right now adds about 40kb to your SWF file, which is really
> > neat. However, with the ResourceManager, all the parsers were
> > forcefully included in the app adding almost 100kb. That's 200% extra
> > weight for parsers that you may or may not use! We decided to remove
> > the hard-coded parsers in favor of a plug-in approach, which is really
> > nice for file size (and to some extent file format detection
> > performance) but it does require you to do the following at an early
> > point in your app, e.g. if you want to use AWD and OBJ files:
>
> > AssetLibrary.enableParser(AWDParser);
> > AssetLibrary.enableParser(OBJParser);
>
> > If you don't care about file size, and just don't want to think about
> > what file formats you'll be using, you can use a short-hand to add all
> > the bundled parsers, which is essentially what happened automatically
> > in the ResourceManager:
>
> > AssetLibrary.enableParsers(Parsers.ALL_BUNDLED);
>
> > One of the above needs to happen before the first load in your app is
> > started.
>
> > You can use the enableParser() set of methods on AssetLibrary,
> > AssetLoader, Loader3D or SingleFileLoader (internal class) and they
> > will all end up in the same place, so if you add the above line of
> > code once in your app, you can then use automatic file detection in
> > any or all of the AssetLibrary, AssetLoader and Loader3D.
>
> > I was expecting more questions to be honest, so please don't be shy if
> > you are wondering anything. :)
>
> > Cheers
> > /R
>
> > On May 6, 8:59 am, Apprentice <[email protected]> wrote:
> >> Thanks for letting us know :)
> >> And for putting a document online which describes the changes in depth
> >> (which I have yet to read carefully).
>
> >> On 5 mei, 20:01, Richard Olsson <[email protected]> wrote:
>
> >> > Hello Away3D community!
>
> >> > This is a heads up that in a moment, I will be pushing changes to the
> >> > GitHub repository (SVN will follow in the next couple of days) that will
> >> > likely break any code that you have that uses Broomstick (Away3D 4.0
> >> > alpha). This is because of some major incompatible changes that we're
> >> > making to the way that assets are loaded and managed in Away3D 4.0. (In
> >> > the unlikely event that your code doesn't load assets at all, it might
> >> > be unaffected.)
>
> >> > We wanted to make these changes right now, while Away3D is still in
> >> > alpha, and we believe strongly that this is the best loading framework
> >> > that we have ever had in Away3D (and probably better than most if not
> >> > all competing engines out there.)
>
> >> > The short version is that we have removed the ResourceManager (which you
> >> > are probably currently using to load assets) and replaced it with three
> >> > different classes that can be used for loading: The AssetLibrary (with
> >> > asset management features), the AssetLoader (for simple loading of files
> >> > including dependencies) and the Loader3D (for easily loading assets into
> >> > a scene.)
>
> >> > For those interested in a slightly longer description of the new loading
> >> > framework, I have attached a five page PDF outlining the design
> >> > principles, features and basic usage of the new loading classes. We hope
> >> > this will ease your transition while waiting for proper documentation.
>
> >> > Remember that Away3D 4 is still alpha, and things might still change,
> >> > but we feel a lot more comfortable with the new solution, and I think
> >> > that we will be able to keep it more or less stable through to the final
> >> > release of Away3D 4.0.
>
> >> > The examples have been updated as well (all apart from the ones that use
> >> > MD5, so those are still broken. Please bear with us while we fix them.)
> >> > Example code for the AssetLibrary, AssetLoader and Loader3D will be
> >> > coming shortly as well.
>
> >> > Thanks for your understanding, and if you have any questions, comments,
> >> > feature requests or bug reports: Fire away! ;)
>
> >> > /Richard, Away3D
>
> >> > LoadingInAway4.pdf
> >> > 147KWeergevenDownloaden