How could I migrate Md2.parse(Cast.bytearray(md2Model)) to using v4 loader?

Software: Away3D 4.x

Ludovic, Jr. Member
Posted: 09 May 2014 11:12 PM   Total Posts: 31

Hi, I have some v3.6 code I am trying to migrate to v4 and I am having a hard time figuring out how to use the new loaders.* classes to replace the code below:

mesh = Md2.parse(Cast.bytearray(md2Model), { scale: 1, y: 0, z: 0, rotationX: 0, rotationY: rotationY, rotationZ: 0 } );

Looking for help or an example to point me in the right direction?

   

Avatar
Fabrice Closier, Administrator
Posted: 10 May 2014 01:23 PM   Total Posts: 1265   [ # 1 ]

Check the tutorials section on this site, download the examples classes on github. There are plenty examples using loaders, including md2’s.

Note that using Prefab, you could load your md2 and export it as as3.
then its just in your code: import ClassOutput and addChid(new ClassOutput() )
You also can edit the md2 right into Prefab if required (adding/removing frames, creating anims etc)

   

Ludovic, Jr. Member
Posted: 10 May 2014 05:03 PM   Total Posts: 31   [ # 2 ]

Thanks Fabrice, it’s funny how things work, I figured what I was doing wrong a couple of hours after my post. I’d like to use prefab especially for my textures. Because of the Right VS Left handed axis when I export my mesh + texture from blender into Away3d I have to negate an axis to turn the mesh inside out but as a result my texture are mirrored. Up until now I have done some re-edit of the texture to mirror back so that everything looks ok but I am pretty sure there is a better way of correcting that using PreFab, any tips or trick on that? Merci et @+ Ludo

   

Avatar
Fabrice Closier, Administrator
Posted: 10 May 2014 07:07 PM   Total Posts: 1265   [ # 3 ]

in Prefab 2.x, simply set scale (unlink the 3 scale factors) -1 to the axis you want to mirror, right-mouse click, and press invertface (and uv’s u if you want the map to not be mirrored). Prefab one will do same, tho, you will have to invert uvs probably using the uveditor.

   

Ludovic, Jr. Member
Posted: 15 May 2014 10:23 PM   Total Posts: 31   [ # 4 ]

Thanks, I installed version 2.x.

When loading MD2 models how can I differentiate which mesh data I am getting in the callback

private function onAssetComplete(event:AssetEvent):void
{
  if (event.asset.assetType == AssetType.MESH) {
      //mesh1 = event.asset as Mesh; ??
      //mesh2 = event.asset as Mesh; ??
  }
}

What is the best approach if there is no way of doing that?
a) should I daisy chain the loading of MD2 assets making sure one has completed before starting the next inside my ObjectContainer3D?
b) should I subclass Mesh class to load each MD2 Asset individually on instantiation and then add the Mesh to my ObjectContainer3D?

   

Avatar
Fabrice Closier, Administrator
Posted: 16 May 2014 07:24 AM   Total Posts: 1265   [ # 5 ]

if you load multiple md2’ files, make a queue and onComplete load the next one, or give a namespace so you can id the specific model, handy if you load different models holding similar names. You might need to specify the library strategy to handle the name doubles.

when you receive an asset event, you check the type as you do and you simply extract the name of the asset to identify them. You also can use the library on complete en do myMesh = lib.getAsset(nameOfMyMesh);
Prefab does not allow null or empty names, so the names you see in Prefab would be exactly same once loaded in Away, unless you load all at once and haven’t set the library strategy or defined a nameSpace.

If you use as3, you can access each mesh using the class.meshes array, containers are accessed via the class.containers array. You simply loop over them and do what you want. For md2 like as3’s, all the work is done for you, so a import class, addchild(new class) and class.play(animId) is already functional.

Standard the loaded model comes with an objectContainer, so addChilding on load complete is easy. You still can use the assetLoaded method to specify your instances, animators etc…

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X