0

I'm having my first go with Away3D and am having great difficulties in simply loading a 3D model at runtime.
I’m using AIR 4.0 and the latest Away3D Library. The setup seems fine, I can compile without errors!!

I have tried all sorts I have found on the web but I’ll spare u my futile attempts. This is my latest one, what is missing to show the model? It seems to be loading according to the traces, but i can't get it to display!

If it helps I can show what else I’ve tried, but I doubt it will!

package  {

//imports ...

public class Main extends MovieClip{

    private var view:View3D;
    private var scene:Scene3D;  
    private var cam:Camera3D;
    private var _loader:Loader3D;

    public function Main() {
        trace("Main()");

        initAway();
    }

    private function initAway():void
    {
        addChild(new AwayStats());

        view = new View3D();            
        scene = new Scene3D();
        cam = new Camera3D();

        view.scene = scene;
        view.camera = cam;
        view.camera.lookAt(new Vector3D());

        addChild(view);

        Parsers.enableAllBundled();     

        _loader = new Loader3D();
        _loader.load(new URLRequest('/assets/test.obj'));
        _loader.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onSceneResourceComplete);
        _loader.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);

    }

    private function onAssetComplete(event:AssetEvent):void
    {
        trace("assetType = " + event.asset.assetType ); 
        /*
        OUTPUT:
        assetType = geometry
        assetType = mesh
        assetType = material
        assetType = material        
        */  
    }

    private function onSceneResourceComplete(event : LoaderEvent) : void {
        trace("loaded " + event.currentTarget);
        // OUTPUT: loaded [object Loader3D
        //view.scene.addChild(_loader); //not working
        var container : ObjectContainer3D = ObjectContainer3D(event.target);
        view.scene.addChild(container);

    }  

}

}

In /assets there is a .obj and the coresponding .mtl file

M4tchB0X3r
  • 1,531
  • 1
  • 15
  • 28
  • 1
    Do you set up your camera position? Is it in different part of your code or not at all? If it's at (0,0,0) and you run `lookAt` to (0,0,0) also, then you may have broken your view matrices. – kolenda Mar 11 '14 at 10:54
  • this is the code as is atm. I did set a cam position at one point before the lookAt method but it didnt seem to make a differnce then i took it out again. I'll give it another try tho. So you're saing this code in the LoaderEvent should display the model? thx for reply btw – M4tchB0X3r Mar 11 '14 at 11:01
  • just tried, still an empty stage ... – M4tchB0X3r Mar 11 '14 at 11:16
  • I don't know specifics of your libs so I can't help you here, I just have some ideas to check:). Can you render any geometry on the screen? – kolenda Mar 11 '14 at 12:51

4 Answers4

1

I have this issue all the time with 3D.

If everything else seems to be working, it's probably that your model is at (0,0,0) and your camera is at (0,0,0) (Inside it).

Move your loaded model to say (0,0,10) and have your camera lookAt vector (0,0,10).

Jono
  • 3,949
  • 4
  • 28
  • 48
0

Does your object has some material on it, which is visible? Also try moving, rotating, scaling your object and moving camera.

First add some row element "sphere, etc" and see if your positions are correct. Then add your object to it.

Chand Priyankara
  • 6,739
  • 2
  • 40
  • 63
0

Try this, I always do this and it works:

private function onAssetComplete(event:AssetEvent):void
    {
        trace("assetType = " + event.asset.assetType ); 
        /*
        OUTPUT:
        assetType = geometry
        assetType = mesh
        assetType = material
        assetType = material        
        */  
        if (event.assetType == "mesh") {
             var m:Mesh = event.asset as Mesh;
             view.scene.addChild(m);
             //If still your mesh is invisible, try scaling rotating moving it.
        }
    }
GRIM2D
  • 11
  • 2
0

You have to render your view with view.render() for anything to show up.

Sammy
  • 48
  • 6