|
dubletar, Member
Posted: 30 March 2012 12:20 AM Total Posts: 73
Hi,
I understand how to load a 3d object (.OBJ) with a single texture.
private function initMaterials():void { //setup custom bitmap material headMaterial = new TextureMaterial(new BitmapTexture(new Diffuse().bitmapData)); headMaterial.normalMap = new BitmapTexture(new Normal().bitmapData); headMaterial.specularMap = new BitmapTexture(new Specular().bitmapData); headMaterial.lightPicker = lightPicker; headMaterial.gloss = 10; headMaterial.specular = 3; headMaterial.ambientColor = 0x303040; headMaterial.ambient = 1; }
However, does anyone know how to load a 3D Object with multiple textures?
|
Donny, Jr. Member
Posted: 30 March 2012 12:38 AM Total Posts: 34
[ # 1 ]
Are you using modelling software to export the OBJ file? The textures can be applied in the modelling software and exporting out. As well as the OBJ file, there should be an accompanying MTL file that loads the required textures. Just ensure the MTL file uses paths relative to the swf export. To load this, you could use:
AssetLibrary.enableParser(OBJParser); AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete); AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onFullyLoaded); AssetLibrary.loadData(new MyOBJModel());
|
dubletar, Member
Posted: 30 March 2012 01:19 AM Total Posts: 73
[ # 2 ]
Thank you.
Ive changed the section to the following:
private function init(_view, _scene):void { var view = _view; var scene = _scene; Parsers.enableAllBundled() function initObjects():void { //default available parsers to all AssetLibrary.enableParser(OBJParser); AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete); AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onFullyLoaded); AssetLibrary.loadData(new _myobj()); } function onFullyLoaded(evt:LoaderEvent):void { scene.addChild(_myobj); } function onAssetComplete(evt:AssetEvent):void { } }
I am still new to away3d.
What do I do with the assets? How would I apply it to the object?
(onAssetComplete)
I truly appreciate the help.
|
Donny, Jr. Member
Posted: 30 March 2012 01:26 AM Total Posts: 34
[ # 3 ]
function onAssetComplete(evt:AssetEvent):void { if (evt.asset.assetType == AssetType.MESH) { var mesh:Mesh = evt.asset as Mesh; scene.addChild(mesh); var material:TextureMaterial = TextureMaterial(mesh.material); } }
That would add the objects to the scene as they loaded. If you need to modify the material, you can select that also.
|
dubletar, Member
Posted: 30 March 2012 01:44 AM Total Posts: 73
[ # 4 ]
If I add
scene.addChild
to both ‘onFullyLoaded’ and ‘onAssetComplete’, wont I be adding the object to the scene twice?
Im confused. What I’m trying to accomplish is just having a .OBJ file loaded as-is, without modifying the textures, for now.
|
Donny, Jr. Member
Posted: 30 March 2012 01:46 AM Total Posts: 34
[ # 5 ]
From your code, I’m not sure what your OBJ variable is called. Remove the addChild from onFullyLoaded for now and see if it works.
|
dubletar, Member
Posted: 30 March 2012 01:57 AM Total Posts: 73
[ # 6 ]
Oh, here’s the full code to this class:
package { import away3d.cameras.*; import away3d.containers.*; import away3d.controllers.*; import away3d.core.base.*; import away3d.debug.*; import away3d.entities.Mesh; import away3d.events.*; import away3d.library.*; import away3d.library.assets.*; import away3d.lights.*; import away3d.loaders.*; import away3d.loaders.misc.*; import away3d.loaders.parsers.*; import away3d.materials.*; import away3d.materials.lightpickers.StaticLightPicker; import away3d.materials.methods.*; import away3d.textures.BitmapTexture; import flash.display.*; import flash.events.*; import flash.geom.Vector3D; import flash.utils.getTimer; /** * ... * @author SimNations */ public class building1 extends Sprite { //Embed [Embed(source="../../3d_objects/Houses/textXport.obj", mimeType="application/octet-stream")] private var _myobj:Class; private var _model:Mesh; public function building1(_view,_scene) { //initiate init(_view, _scene); } private function init(_view, _scene):void { //set the view and scene passed in var view = _view; var scene = _scene; //Parsers.enableAllBundled() function initObjects():void { //default available parsers to all AssetLibrary.enableParser(OBJParser); AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete); AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onFullyLoaded); AssetLibrary.loadData(new _myobj()); } function onFullyLoaded(evt:LoaderEvent):void { //scene.addChild(_myobj); } function onAssetComplete(evt:AssetEvent):void { if (evt.asset.AssetType == AssetType.MESH) { var mesh:Mesh = evt.asset as Mesh; scene.addChild(mesh); var material:TextureMaterial = TextureMaterial(mesh.material); } } } }
}
I commented out the scene.addChild in onFullyLoaded and I get this error:
(66): col: 19 Error: Access of possibly undefined property AssetType through a reference with static type away3d.library.assets:IAsset.
This is a pic of the obj im trying to load.
https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-snc7/423706_402641886418385_199975193351723_1817876_505616630_n.jpg
|
dubletar, Member
Posted: 30 March 2012 02:26 PM Total Posts: 73
[ # 7 ]
Anyone? Pls? It seems like I’m so close! I just need to understand how to load it properly and I can go on from there.
|
dubletar, Member
Posted: 06 April 2012 06:19 PM Total Posts: 73
[ # 8 ]
Please, can anyone help me?
I need to successfully import/load 1 3d object and go from there. I’m having the toughest of times with Away3D.4.
|
dubletar, Member
Posted: 11 April 2012 12:48 PM Total Posts: 73
[ # 9 ]
|
Donny, Jr. Member
Posted: 11 April 2012 10:49 PM Total Posts: 34
[ # 10 ]
Comment out the reference to the material, do you still get an error?
And is onFullyLoaded being called?
|
dubletar, Member
Posted: 12 April 2012 12:27 AM Total Posts: 73
[ # 11 ]
Donny - 11 April 2012 10:49 PM Comment out the reference to the material, do you still get an error?
And is onFullyLoaded being called?
I did as you said, and hmmm, it seems that onFullyLoaded is not kicking in.
function initObjects():void { //default available parsers to all AssetLibrary.enableParser(OBJParser); //AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete); AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onFullyLoaded); AssetLibrary.loadData(new _myobj()); } function onFullyLoaded(evt:LoaderEvent):void { scene.addChild(_myobj); var tod = stage.getChildByName('navigationMC'); tod.alpha = 0; } /*function onAssetComplete(evt:AssetEvent):void { if (evt.asset.AssetType == AssetType.MESH) { var mesh:Mesh = evt.asset as Mesh; scene.addChild(mesh); var material:TextureMaterial = TextureMaterial(mesh.material); } }*/
|
Donny, Jr. Member
Posted: 12 April 2012 12:29 AM Total Posts: 34
[ # 12 ]
Have you put a trace in just to make sure?
|
dubletar, Member
Posted: 12 April 2012 12:32 AM Total Posts: 73
[ # 13 ]
I put, in place of trace the following code:
var tod = stage.getChildByName('navigationMC'); tod.alpha = 0;
I used trace at first too.
Both do nothing as onFullyLoaded is not called, and Im wondering why.
(I appreciate the help, Donny).
|
Donny, Jr. Member
Posted: 12 April 2012 12:38 AM Total Posts: 34
[ # 14 ]
Looking back at the code you posted previously, how are you calling initObjects()? Why is this method nested within init() too?
|
dubletar, Member
Posted: 12 April 2012 12:47 AM Total Posts: 73
[ # 15 ]
Donny - 12 April 2012 12:38 AM Looking back at the code you posted previously, how are you calling initObjects()? Why is this method nested within init() too?
Oops. I was deleting code and adding to test. I guess I forgot to add the initObjects back. I added it back and ran the code again, and nothing still. No errors and onFullyLoaded isnt called.
I nested inside of init() to pass the scene and view to be used by the object.
The goal is to load the object, then onFullyLoaded, add the object to the current view/scene.
I also modeled the init() function after the away3d examples, for learning purposes.
The code is below, with initObjects included.
package { import away3d.cameras.*; import away3d.containers.*; import away3d.controllers.*; import away3d.core.base.*; import away3d.debug.*; import away3d.entities.Mesh; import away3d.events.*; import away3d.library.*; import away3d.library.assets.*; import away3d.lights.*; import away3d.loaders.*; import away3d.loaders.misc.*; import away3d.loaders.parsers.*; import away3d.materials.*; import away3d.materials.lightpickers.StaticLightPicker; import away3d.materials.methods.*; import away3d.textures.BitmapTexture; import flash.net.URLRequest; import flash.display.*; import flash.events.*; import flash.geom.Vector3D; import flash.utils.getTimer; /** * ... * @author SimNations */ public class building1 extends Sprite { //Embed [Embed(source="../../3d_objects/Houses/textXport.obj", mimeType="application/octet-stream")] private var _myobj:Class; private var _model:Mesh; public function building1(_view,_scene) { //initiate init(_view, _scene); } private function init(_view, _scene):void { //set the view and scene passed in var view = _view; var scene = _scene; initObjects(); //Parsers.enableAllBundled() function initObjects():void { //default available parsers to all AssetLibrary.enableParser(OBJParser); //AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete); AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onFullyLoaded); AssetLibrary.loadData(new _myobj()); } function onFullyLoaded(evt:LoaderEvent):void { scene.addChild(_myobj); var tod = stage.getChildByName('navigationMC'); tod.alpha = 0; } /*function onAssetComplete(evt:AssetEvent):void { if (evt.asset.AssetType == AssetType.MESH) { var mesh:Mesh = evt.asset as Mesh; scene.addChild(mesh); var material:TextureMaterial = TextureMaterial(mesh.material); } }*/ } }
}
|