0L4F, Newbie Posted: 14 October 2011 08:42 AM Total Posts: 15
I still can’t seem to figure out how to load a model with materials into Away3D 4.0. I’ve got some .3ds and .obj models that I’d like to try, where .3ds is my preferred format.
I’ve looked at the updated 3DS parser, and the new examples, but it’s still not clear to me. The latest ‘soldier ant’ example has the texture embedded in the .swf…
Can it be done? If so, could you help me with some code hints?
Thanks in advance!
Richard Olsson, Administrator Posted: 14 October 2011 06:00 PM Total Posts: 1192
[ # 1 ]
Just load the 3DS file using Loader3D, AssetLoader or the AssetLibrary. The dependencies (e.g. textures) will be loaded automatically. If the path is incorrect, an error will be thrown (or an event be dispatched if you are listening for it.)
0L4F, Newbie Posted: 19 October 2011 12:52 PM Total Posts: 15
[ # 2 ]
Hi Richard,
thanks for your reply! But still no joy. This is the code I’m trying to get to work:
loader = new AssetLoader(); loader.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete); loader.load(new URLRequest('embeds/wagen1.3ds'));
private function onAssetComplete(event:AssetEvent):void { if (event.asset.assetType == AssetType.MESH) { var mesh:Mesh = event.asset as Mesh;
} else if (event.asset.assetType == AssetType.MATERIAL) { var material:BitmapMaterial = event.asset as BitmapMaterial; material.lights = [light]; material.gloss = 30; material.specular = 1; material.ambientColor = 0x303040; } }
...but I can’t figure out how to add the loaded asset to the scene. Sorry for these noob questions
I’d love to see a simple code example that loads a 3ds model and adds it to the scene, maybe it will make the concept click for me.
Thanks in advance!
Richard Olsson, Administrator Posted: 19 October 2011 12:58 PM Total Posts: 1192
[ # 3 ]
80prozent, Sr. Member Posted: 19 October 2011 01:12 PM Total Posts: 430
[ # 4 ]
hi
to set your material to your mesh, you have to do something like this (code not tested):
loader = new AssetLoader(); loader.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete); loader.load(new URLRequest('embeds/wagen1.3ds'));
private var mesh:Mesh;
private function onAssetComplete(event:AssetEvent):void { if (event.asset.assetType == AssetType.MESH) { mesh = event.asset as Mesh; scene.addChild(mesh);
} else if (event.asset.assetType == AssetType.MATERIAL) { var material:BitmapMaterial = event.asset as BitmapMaterial; material.lights = [light]; material.gloss = 30; material.specular = 1; material.ambientColor = 0x303040; mesh.material=material; } }
Marcos Neves, Newbie Posted: 17 November 2011 07:06 PM Total Posts: 6
[ # 5 ]
private function loadModels():void { Parsers.enableAllBundled();
//Loader model.ac acLoader = new Loader3D(); acLoader.addEventListener(AssetEvent.ASSET_COMPLETE, onMeshLoadComplete); acLoader.load( new URLRequest('TREE_AC/TREE_AC.ac') );
//Loader model.3ds var maxParser:Max3DSParser = new Max3DSParser(); maxLoader = new Loader3D(); maxLoader.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onMaxLoaded); maxLoader.load( new URLRequest('tree13.3ds'), null, null, maxParser);