AssetLibrary.getAsset()

Software: Away3D 4.x

skitley, Newbie
Posted: 10 August 2011 01:17 AM   Total Posts: 6

Im having trouble getting my .obj back as a mesh because any name I try to recall from the AssetLibrary doesn’t exactly work. I keep getting a null obj ref. Is there something more to the process that I’m missing?

From my RcCar.obj (I use ‘Cube’ as the name in the AS):

# Blender v2.58 (sub 1) OBJ File: 'RcCar.blend'
# www.blender.org
o Cube
v 1.000000 0.284554 
-1.965757
v 1.000000 0.478558 2.029535 

And my AS:

public class Main extends Sprite
 {
  
  [Embed
(source "assets/RcCar.obj"mimeType="application/octet-stream")]
  
private var RcCarData:Class;
  
  
[Embed(source "assets/RcCar.png")]
  
private var RcCarTexture:Class;
  
  private var 
lib:AssetLibrary;
  private var 
view:View3D;
  private var 
rcCar:Mesh;
  private var 
rcCarMat:BitmapMaterial;
  
  private var 
light:PointLight;
  
  private var 
stats:AwayStats;
  
  
// CONSTRUCTOR
  
public function Main():void
  {
   this
.addEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
  
}
 
  
private function addedToStageHandler(e:Event):void
  {
   this
.removeEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
   
   
stage.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
   
// Startup
   
initView();
   
initObjs();
   
//initLights();
   
  
}

  
  
private function initView():void {
   view 
= new View3D();
   
view.camera.lens.far 10000;
   
view.antiAlias 2;
   
addChild(view);
   
   
// Stats
   
stats = new AwayStats();
   
stats.5;
   
stats.5;
   
this.addChild(stats);
   
   
// Resize handler
   
stage.addEventListener(Event.RESIZE,resizeHandler);
   
resizeHandler(null);
   
   
trace('Method initView() complete.');
  
}
  
  
private function initObjs():void {
   
   
var bmp:Bitmap = new RcCarTexture() as Bitmap;
   
   
rcCarMat = new BitmapMaterial(bmp.bitmapData);
   
   
AssetLibrary.enableParser(OBJParser);
   
AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
   
AssetLibrary.parseData(RcCarData);
   
   
trace('Method initObjs() complete.');
  
}
  
  
private function onResourceComplete(event:LoaderEvent):void 
  {
   trace
(AssetLibrary.getAsset('Cube')); //returns null
   
   
rcCar Mesh(AssetLibrary.getAsset('Cube')); //returns null
   
rcCar.material rcCarMat;
   
   
rcCar.= -5;
   
rcCar.= -475;
   
   
view.scene.addChild(rcCar);
   
   
// Render
   
this.addEventListener(Event.ENTER_FRAMErender);
  
}
  
  
private function resizeHandler(e:Event):void
  {
   view
.width stage.stageWidth;
   
view.height stage.stageHeight
  
}
  
  
private function render(e:Event):void
  {
   rcCar
.rotationY += 1;
   
//rcCar.rotationZ -= 0.5;
   
view.render();
  
}
 }
   

EFFalcon, Jr. Member
Posted: 10 August 2011 03:20 AM   Total Posts: 44   [ # 1 ]

See here regarding Mesh names in OBJ parsed files.
http://away3d.com/forum/viewthread/437/
http://away3d.com/forum/viewthread/454/

   

skitley, Newbie
Posted: 10 August 2011 03:30 AM   Total Posts: 6   [ # 2 ]

Thanks EFFalcon! 3DS format it is

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X