parsing embedded 3ds

Software: Away3D 4.x

PabloCr, Newbie
Posted: 07 April 2012 05:58 PM   Total Posts: 9

hi all, are there a way to get parsed mesh from [embed ...] tag? as I understand using this construction will not provide mesh as result but byte array, so next step is use parser to retreive 3d objects:

[Embed(source="obj.3ds"mimeType="application/octet-stream")]
private var objclass:Class;

var 
data:* = new objclass(); 

what to do next with variable ‘data’?
I saw examples with Loader3D, the data can be loaded and then parsed from callback, but I want not to use callback and return mesh from function that get class name as argument, is this possible?

 

   

Vice, Member
Posted: 07 April 2012 06:21 PM   Total Posts: 58   [ # 1 ]

e.g.:

Loader3D.enableParser(Max3DSParser);
var loader = new Loader3D();
loader.parseData(objclass, null, new AssetLoaderContext(false));

var obj:Mesh = Mesh(loader.getChildAt(0));

   

PabloCr, Newbie
Posted: 07 April 2012 06:39 PM   Total Posts: 9   [ # 2 ]

what is loader.parseData() method? I use away3d 4, and there are only loadData

   

Richard Olsson, Administrator
Posted: 07 April 2012 06:54 PM   Total Posts: 1192   [ # 3 ]

You want loadData(). It used to be called parseData() but was renamed to loadData() before Away3D 4 went beta.

   

Avatar
Fabrice Closier, Administrator
Posted: 07 April 2012 08:29 PM   Total Posts: 1265   [ # 4 ]

var obj:Mesh = Mesh(loader.getChildAt(0));

Try set asset events instead of this above example. As not every parser returns a mesh as child 0. But on assetEvent you can check the type of the asset returned and surely access the element of the file that you want to edit. On complete you can addchild safely the event.currentTarget as ObjectContainer3D

   

PabloCr, Newbie
Posted: 08 April 2012 08:29 AM   Total Posts: 9   [ # 5 ]

thank you for the answer. yes, if add event listeners the mesh can be get from (ev.target as Loader3D).getChildAt(...), but can I do this without using event handling? the idea is to use single function that take class name of the embedded .3ds file as argument and return mesh from that file, so all parsing actions are done within this function. with approach you mentioned mesh can be get only in event listener function onResourceComplete…

   

Richard Olsson, Administrator
Posted: 08 April 2012 08:35 AM   Total Posts: 1192   [ # 6 ]

First of all, what Fabrice is referring to is not the RESOURCE_COMPLETE event, but the ASSET_COMPLETE (or even MESH_COMPLETE) events that are fired by the parser for each asset (i.e. each mesh, geometry, material et c respectively.) These events will contain a reference to the asset in the AssetEvent.asset property, allowing you to access it by simple type casting:

myMesh = ev.asset as Mesh;

The short answer to your question however is no. All parsers in Away3D 4.0 are asynchronous, meaning that you cannot rely on it to happen from one line of code to the next. Actually, it should never do that. It works much like the Loader class in Flash, which even if you load embedded files (using Loader.loadBytes()) will be asynchronous. So you need to listen for the RESOURCE_COMPLETE event to know that the resource has finished loading and that all the assets contained within have been parsed.

   

PabloCr, Newbie
Posted: 08 April 2012 10:30 AM   Total Posts: 9   [ # 7 ]

ok got it, but why? smile are the parsing procedures too complex? another idea… what about to write extension to use something like:

[Embed(source="library.3ds"symbol="Loader3D")]
public var res:Class; 

I mean res will be Loader3D object with contained resources already when new class instanciated

   

Richard Olsson, Administrator
Posted: 08 April 2012 10:41 AM   Total Posts: 1192   [ # 8 ]

Yes, the parsing procedure is (often) too complex to happen within the 16ms window of a single 60fps frame. Even more so when external dependencies like textures need to be loaded, which inevitably must happen asynchronously.

What you are suggesting is interesting, but again hard to achieve because of the asynchronous nature of parsing a big resource and loading any dependencies.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X