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.x = 5;
stats.y = 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_COMPLETE, onResourceComplete);
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.y = -5;
rcCar.z = -475;
view.scene.addChild(rcCar);
// Render
this.addEventListener(Event.ENTER_FRAME, render);
}
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();
}
}
}