Reputation: 1531
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
Upvotes: 0
Views: 1375
Reputation: 48
You have to render your view with view.render()
for anything to show up.
Upvotes: 0
Reputation: 11
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.
}
}
Upvotes: 0
Reputation: 6784
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.
Upvotes: 0
Reputation: 4076
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).
Upvotes: 1