AssetLibrary with different meshes and materialss?

Software: Away3D 4.x

edgar, Member
Posted: 25 December 2011 06:29 PM   Total Posts: 52

Hi there,

how do I use the AssetLibrary for different meshes with different materials, e.g

object1 : AssetLibrary.enableParser(3dsParser);
 
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
AssetLibrary.load(new URLRequest(“assets/object1.3ds”));

object2: AssetLibrary2.enableParser(3dsParser);
AssetLibrary2.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
AssetLibrary.load(new URLRequest(“assets/object2.3ds”));

Does anybody knows , what the code should look like?

Many thanks
Edgar

   

Alex Bogartz, Sr. Member
Posted: 25 December 2011 06:44 PM   Total Posts: 216   [ # 1 ]

Use namespace and the check for event.asset.assetNamespace.

if(event.asset.assetNamespace==“bear”){
  do bear stuff
}
if(event.asset.assetNamespace==“tiger”){
  do tiger stuff
}

 

   

edgar, Member
Posted: 26 December 2011 07:52 AM   Total Posts: 52   [ # 2 ]

And how do I assign a namespace here?

I have this code:

AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
AssetLibrary.load(new URLRequest(“assets/smartroadster.3ds”));

.....

private function onAssetComplete(event:AssetEvent):void
  {
  if(event.asset.assetType == AssetType.MESH)
  {
  //create material object and assign it to our mesh
  smartMaterial = new BitmapMaterial(new smartColor().bitmapData);
  smartMaterial.bothSides = true;
  smartMaterial.shadowMethod = filteredShadowMapMethod;
  smartMaterial.lights = [sunLight, skyLight];
  //smartMaterial.gloss = 50;
  smartMaterial.specular = 0.8;
  smartMaterial.ambientColor = 0xFFFFFF;
  smartMaterial.ambient = 0.5;
 
  //create mesh object and assign our animation object and material object
  casingMesh = event.asset as Mesh;
  casingMesh.material = smartMaterial;
  casingMesh.castsShadows = true;
  casingMesh.scale(100);
  casingMesh.z = 1000;
  casingMesh.y = 200;
  casingMesh.rotationY = -45;
  scene.addChild(casingMesh);
 
  //register our mesh as the lookAt target
  cameraController.lookAtObject = casingMesh;
 
  //default to breathe sequence
  }


How do I change this, so that it works as you said?

Many, many thanks
Edgar

 

   

Albert, Newbie
Posted: 26 December 2011 09:31 AM   Total Posts: 16   [ # 3 ]
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
AssetLibrary.load(new URLRequest(“assets/smartroadster.3ds”), null"a");
AssetLibrary.load(new URLRequest(“assets/smartroadster.3ds”), null"b");

.....

private function 
onAssetComplete(event:AssetEvent):void
  {
  
if(event.asset.assetType == AssetType.MESH && event.asset.assetNamespace == "a")
  
{
     
...
  
}
  
if(event.asset.assetType == AssetType.MESH && event.asset.assetNamespace == "b")
  
{
    
...
  

Good luck

 

   

edgar, Member
Posted: 26 December 2011 09:38 AM   Total Posts: 52   [ # 4 ]

Thanks a lot. I will try it and give you feedback.

Edgar

 

   

edgar, Member
Posted: 26 December 2011 10:41 AM   Total Posts: 52   [ # 5 ]

I have tried your code and with some changes it works.

The parts of the car have all different meshes seat.3ds, interior.3ds, smartroadster.3ds.

And the changed code

private function initObjects():void
{
AssetLibrary.enableParser(Max3DSParser);
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
AssetLibrary.load(new URLRequest(“assets/smartroadster.3ds”), null, “car”);
AssetLibrary.load(new URLRequest(“assets/seat.3ds”), null, “seat”);
  AssetLibrary.load(new URLRequest(“assets/interior.3ds”), null, “interior”);
 
smartRoadster = new ObjectContainer3D();
scene.addChild(smartRoadster);
smartRoadster.z = -1000;
cameraController.lookAtObject = smartRoadster;
 
  //create a ground plane
  groundMaterial = new BitmapMaterial((new groundColor()).bitmapData, true, true, true);
  groundMaterial.lights = [sunLight, skyLight];
  groundMaterial.shadowMethod = filteredShadowMapMethod;
  ground = new Plane(groundMaterial, 5000, 5000);
  ground.geometry.scaleUV(1, 1);
  ground.castsShadows = true;
  scene.addChild(ground);
 
 
  }
 
private function onAssetComplete(event:AssetEvent):void
{
  if(event.asset.assetType == AssetType.MESH)
  {
//create material object and assign it to our mesh
smartMaterial = new BitmapMaterial(new smartColor().bitmapData);
smartMaterial.bothSides = true;
smartMaterial.shadowMethod = filteredShadowMapMethod;
smartMaterial.lights = [sunLight, skyLight];
//smartMaterial.gloss = 50;
smartMaterial.specular = 0.8;
smartMaterial.ambientColor = 0xFFFFFF;
smartMaterial.ambient = 0.5;
 
//create mesh 2 object, assign object and material    
casingMesh = event.asset as Mesh;
casingMesh.material = smartMaterial;
casingMesh.castsShadows = true;
casingMesh.scale(100);
casingMesh.y = 200;
smartRoadster.addChild(casingMesh);

  //register our mesh as the lookAt target
 
 
  //default to breathe sequence
  }
 
 
  if(event.asset.name ==“seat”)
  {
 
    //create material object and assign it to our mesh
  seatMaterial = new BitmapMaterial(new seatColor().bitmapData);
  seatMaterial.bothSides = true;
  seatMaterial.shadowMethod = filteredShadowMapMethod;
  seatMaterial.lights = [sunLight, skyLight];
  //smartMaterial.gloss = 50;
  seatMaterial.specular = 0.2;
  seatMaterial.ambientColor = 0xFFFFFF;
  seatMaterial.ambient = 0.5;
 
  //create mesh object and assign our animation object and material object
  seatMesh = event.asset as Mesh;
  seatMesh.material = seatMaterial;
  seatMesh.castsShadows = true;
  seatMesh.scale(1);
  seatMesh.y = 150;
  seatMesh.x = -60;
  smartRoadster.addChild(seatMesh);
  }
 
 
 
  if(event.asset.name ==“interior”)
  {
 
    //create material object and assign it to our mesh
  interiorMaterial = new BitmapMaterial(new interiorColor().bitmapData);
  interiorMaterial.bothSides = true;
  interiorMaterial.shadowMethod = filteredShadowMapMethod;
  interiorMaterial.lights = [sunLight, skyLight];
  //smartMaterial.gloss = 50;
  interiorMaterial.specular = 0.2;
  interiorMaterial.ambientColor = 0xFFFFFF;
  interiorMaterial.ambient = 0.5;
 
  //create mesh object and assign our animation object and material object
  interiorMesh = event.asset as Mesh;
  interiorMesh.material = interiorMaterial;
  interiorMesh.castsShadows = true;
  interiorMesh.scale(1);
 
  interiorMesh.y = 200;
  interiorMesh.x = 0;
  smartRoadster.addChild(interiorMesh);
  }
 
 
 
  }

 

   

edgar, Member
Posted: 26 December 2011 10:48 AM   Total Posts: 52   [ # 6 ]

Here the code file.

Why does it not work, when I try it your way?

 

File Attachments
Eyestee.as  (File Size: 9KB - Downloads: 246)
   

Albert, Newbie
Posted: 26 December 2011 12:44 PM   Total Posts: 16   [ # 7 ]

Oh, sorry. You should check if the event.asset.assetType equals AssetType.GEOMETRY and you have to check this with every file you load. So it’s:
if(event.asset.assetType == AssetType.GEOMETRY && event.asset.name ==“interior”)
  {

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X