Listen for as3 class asset load complete

Software: Away3D 4.x

drbii, Member
Posted: 02 July 2014 03:13 AM   Total Posts: 72

I am use to loading AWD via Loader3D() as follows:

AssetLibrary.enableParser(AWD2Parser);
   
   
//kickoff asset loading
   
q1loader = new Loader3D();
   
q1loader.load(new URLRequest("q1_anim.awd"));
   
q1loader.addEventListener(AssetEvent.ASSET_COMPLETEL1L2_Q1_onAssetComplete);
   
away3dView.scene.addChild(q1loader); 

I am trying to learn how to load an object as an AS3 Class.  I have used the code straight out of the Prefab default AS file:

import MyDISC;
...
private var 
_prefabOutput:MyDISC;
...
   
_prefabOutput = new MyDISC();
   
_prefabOutput.addEventListener(AssetEvent.ASSET_COMPLETEL1L2_Q1_onAssetComplete);
   
_view.scene.addChild(_prefabOutput); 

 

I can get the object loaded but how do I listen to see if the mesh (or any entity) is finished loading?  If I use the above EventListener it is never triggered.  How would you listen for completion and then call a function to find meshes, or animations?
I’m sure I have overcomplicated this.  I really want to use AS3 as the loading overhead seems a lot faster. 
Thanks!

 

   

Avatar
Fabrice Closier, Administrator
Posted: 02 July 2014 10:29 AM   Total Posts: 1265   [ # 1 ]

That’s the beauty of the AS3. You addChild and It’s there right away.
Depending on settings you selected (not embedded), dependencies may be defaulted till they are loaded.

You can access every meshes by simply doing var mesh:Mesh = myClass.meshes[index]; same for ObjectContainers.

This means the class itself doesn’t perse have to be addChilded. You can use it as storage, for instance a game level.

Into the default project file (assuming you have the option on), you can see an example on how you could implement into your code. You can use the project class as well, but its purely there to show you how you could implement the class that you have exported. In case of animation, it will also generate an example for you.

   

drbii, Member
Posted: 03 July 2014 01:32 PM   Total Posts: 72   [ # 2 ]

Thanks Fabrice!  Is index the only way you can reference the mesh?  Can you get the mesh by the name of the mesh???  Not working for me.


Thanks for all of your help!
Dan

   

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

its a class , not an API smile
just loop over the meshes and do your magic!

if(meshes.name == theMeshNameIneed) doSomeCoolNess();
else doSomeCoolnessAnyway();

you can also register the meshes to the lib, and simply use lib.getAsset(“myID”);

your choice.

   

drbii, Member
Posted: 03 July 2014 07:13 PM   Total Posts: 72   [ # 4 ]

I’ll give a shot in a bit.  I am in modeling mode right now.  Thanks for your help!

   

drbii, Member
Posted: 03 July 2014 07:32 PM   Total Posts: 72   [ # 5 ]

I’ll give a shot in a bit.  I am in modeling mode right now.

While I have your attention though.  I am in Prefab right now and can’t find how to turn shadows on for a light.  I have the light, attached to a light picker and that attached to my material…everything is working…just can’t find where you add the shadow methods.  Thanks for your help!

   

Avatar
Fabrice Closier, Administrator
Posted: 03 July 2014 08:20 PM   Total Posts: 1265   [ # 6 ]

There is no builded-in shadows in the current public Prefab.
Tho its really easy to set up, just declare a shadowMethod and pass it to the material.

like this _someMaterial.shadowMethod = new SoftShadowMapMethod(myDirectionLight, 4, 1);
or HardShadow method…
The directional light must have the param castShadow on.
For good results ensure that the camera far and near are as small as possible.

If you loop over your meshes just add the flag to the mesh you want by accessing their material. All in all, you’ll get your shadows in a few minutes if not seconds.

Tip for light setups: Prefab allows you to rotate the light direction vector by using the interface gismo for the direction (the ball with trident). It reacts from the current camera orientation. When satisfied, press then the away picto in the lights panel, and you’ll have your settings in as3 ready to be pasted if you would need to change the exported one.

   

drbii, Member
Posted: 04 July 2014 06:12 PM   Total Posts: 72   [ # 7 ]

Thanks Fabrice.  I got the above to work.  I was able to assign the light picker, shadow method etc to all materials.  Now I am trying to figure out how to control my vertex animations that I have in my as3 class.  I am sure I exported them in prefab (clicked the include animation button).  They imported…they are playing, looping over and over.  I knew how to do this with loader obj, but with it being as3 now I am confused. 

If you are anyone can point me in the right direction (again) I appreciate it.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X