Load 3D Object with Multiple Textures

Software: Away3D 4.x

Donny, Jr. Member
Posted: 12 April 2012 12:58 AM   Total Posts: 34   [ # 16 ]

Just get the obj visible first, I’ve stripped down some code you can use, just replace the obj reference.

package {
 
 
 import away3d
.cameras.*;
 
import away3d.containers.*;
 
import away3d.controllers.*;
 
import away3d.core.base.*;
 
import away3d.core.managers.*;
 
import away3d.debug.*;
 
import away3d.entities.*;
 
import away3d.events.*;
 
import away3d.library.*;
 
import away3d.library.assets.*;
 
import away3d.loaders.*;
 
import away3d.loaders.misc.*;
 
import away3d.loaders.parsers.*;
 
import away3d.materials.*;
 
import away3d.materials.lightpickers.*;
 
import away3d.materials.methods.*;
 
import away3d.primitives.*;
 
import away3d.textures.*;
 
import away3d.lights.*;
 
import away3d.tools.helpers.LightsHelper;
 
 
 
import flash.display.*;
 
import flash.events.*;
 
import flash.geom.*;
 
import flash.text.*;
 
import flash.utils.*;
 
import flash.external.ExternalInterface;
 
import flash.net.URLRequest;
 
 
 
 
[SWF(backgroundColor="#000000"frameRate="60"quality="LOW")]
 
public class Tester extends Sprite {
  
  
  [Embed
(source="/NAB_INTS/nab7.obj"mimeType="application/octet-stream")]
  
private var NabModel:Class;
  
  
//engine variables
  
private var scene:Scene3D;
  private var 
camera:Camera3D;
  private var 
view:View3D;
  private var 
cameraController:HoverController;
  
  private var 
loader:Loader3D;
  
  
  
  
  
/**
   * Constructor
   */
  
public function Tester() {
   init
();
  
}
  
  
  
/**
   * Global initialise function
   */
  
private function init():void {
   initEngine
();
   
initObjects();
   
initListeners();
  
}
  
  
  
/**
   * Initialise the engine
   */
  
private function initEngine():void {
   
   stage
.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
   
scene = new Scene3D();
   
   
camera = new Camera3D();
   
   
view = new View3D();
   
view.scene scene;
   
view.camera camera;
   
   
cameraController = new HoverController(cameranull);
   
addChild(view);
  
}
  
  
  
/**
   * Initialise the scene objects
   */
  
private function initObjects():void {
   
   Parsers
.enableAllBundled();
   
   
loader = new Loader3D();
   
loader.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
   
loader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonFullyLoaded);
   
loader.loadData(new NabModel()); 
   
scene.addChild(loader);
   
  
}
  
  
  
/**
   * Initialise the listeners
   */
  
private function initListeners():void {
   addEventListener
(Event.ENTER_FRAMEonEnterFrame);
  
}
  
  
  
/**
   * Navigation and render loop
   */
  
private function onEnterFrame(event:Event):void {
   view
.render();
  
}
  
  
  
/**
   * Listener function for asset complete event on loader
   */
  
private function onAssetComplete(event:AssetEvent):void {
   
   
  }
  
  
  
/**
   * Completely loaded
   */
  
private function onFullyLoaded (event:LoaderEvent):void {
   
  }
 
  
 }
 
 
   

dubletar, Member
Posted: 12 April 2012 01:19 AM   Total Posts: 73   [ # 17 ]

Ok. I copied the code and changed the path to my 3d object, and ran the code. No errors, just a black screen.

package  
{
 import away3d
.cameras.*;
 
import away3d.containers.*;
 
import away3d.controllers.*;
 
import away3d.core.base.*;
 
import away3d.core.managers.*;
 
import away3d.debug.*;
 
import away3d.entities.*;
 
import away3d.events.*;
 
import away3d.library.*;
 
import away3d.library.assets.*;
 
import away3d.loaders.*;
 
import away3d.loaders.misc.*;
 
import away3d.loaders.parsers.*;
 
import away3d.materials.*;
 
import away3d.materials.lightpickers.*;
 
import away3d.materials.methods.*;
 
import away3d.primitives.*;
 
import away3d.textures.*;
 
import away3d.lights.*;
 
import away3d.tools.helpers.LightsHelper;
 
 
 
import flash.display.*;
 
import flash.events.*;
 
import flash.geom.*;
 
import flash.text.*;
 
import flash.utils.*;
 
import flash.external.ExternalInterface;
 
import flash.net.URLRequest;
 
/**
  * ...
  * @author SimNations
  */
 
[SWF(backgroundColor="#000000"frameRate="60"quality="LOW")]
 
public class buildingAlone extends Sprite
 {
  
//Embed
  
[Embed(source "../../3d_objects/Houses/textXport.obj"mimeType "application/octet-stream")]
  
private var NabModel:Class;
  
    
//engine variables
    
private var scene:Scene3D;
    private var 
camera:Camera3D;
    private var 
view:View3D;
    private var 
cameraController:HoverController;
    
    private var 
loader:Loader3D;

    
/**
     * Constructor
     */
  
  
public function buildingAlone() 
  
{
   init
();
  
}
   
/**
   * Global initialise function
   */
  
private function init():void {
   initEngine
();
   
initObjects();
   
initListeners();
  
}
  
  
  
/**
   * Initialise the engine
   */
  
private function initEngine():void {
   
   stage
.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
   
scene = new Scene3D();
   
   
camera = new Camera3D();
   
   
view = new View3D();
   
view.scene scene;
   
view.camera camera;
   
   
cameraController = new HoverController(cameranull);
   
addChild(view);
  
}
  
  
  
/**
   * Initialise the scene objects
   */
  
private function initObjects():void {
   
   Parsers
.enableAllBundled();
   
   
loader = new Loader3D();
   
loader.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
   
loader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonFullyLoaded);
   
loader.loadData(new NabModel()); 
   
scene.addChild(loader);
   
  
}
  
  
  
/**
   * Initialise the listeners
   */
  
private function initListeners():void {
   addEventListener
(Event.ENTER_FRAMEonEnterFrame);
  
}
  
  
  
/**
   * Navigation and render loop
   */
  
private function onEnterFrame(event:Event):void {
   view
.render();
  
}
  
  
  
/**
   * Listener function for asset complete event on loader
   */
  
private function onAssetComplete(event:AssetEvent):void {
   
   
  }
  
  
  
/**
   * Completely loaded
   */
  
private function onFullyLoaded (event:LoaderEvent):void {
   
  }
 
  
 }
 
 
   

dubletar, Member
Posted: 12 April 2012 01:23 AM   Total Posts: 73   [ # 18 ]

If the 3d object isnt loading, could it be corrupt? May it need to be exported (via 3dsmax) again? In the directory exists the .obj file and .mtl file (from the export).

   

Donny, Jr. Member
Posted: 12 April 2012 01:23 AM   Total Posts: 34   [ # 19 ]

Traces in onAssetComplete() and onFullyLoaded() come through?

   

dubletar, Member
Posted: 12 April 2012 02:46 AM   Total Posts: 73   [ # 20 ]

Yes, traces work.

BUT, I think I found the problem! I googled the method for uploading the files. Im uploading from my server (dedicated hosting).

Turns out my server was sending an error and restricting the >mimeType = “application/octet-stream”<. By default, it didnt allow streaming! I have to install a media server to my server and it should fix the issue right up.

I just spoke to tech support for my host, and they confirmed this is a common issue and referred me to Red5, an open source media server.

Ill attempt to install it over the next few days and update this thread.

Thanks again Donny.

   

dubletar, Member
Posted: 17 April 2012 12:21 PM   Total Posts: 73   [ # 21 ]

Hi all, especially Donny!

Ok, here’s the update…

I installed Flash Media Server. Embedding and using a stream is working.

Here’s the new issue: Now that the streaming is allowed, the as3 script attempts to embed the obj, but fails with this error…

Error 3684 Invalid bitmapDataWidth and height must be power of 2 and cannot exceed 2048 

The problem is that all the texctures DONT exceed 2048 and are all divisible by 2 (example, 1012x1012, 512x512).

My 3D object was made via 3dsMax 2012, exported with .obj and .mtl files.

What could be causing it? I spent an entire day,  literally,  trying to see and I cant fix it! Please help.

   

Avatar
Fabrice Closier, Administrator
Posted: 17 April 2012 01:23 PM   Total Posts: 1265   [ # 22 ]

1012 is not power of 2. 1024 is.

   

dubletar, Member
Posted: 18 April 2012 01:17 AM   Total Posts: 73   [ # 23 ]
Fabrice Closier - 17 April 2012 01:23 PM

1012 is not power of 2. 1024 is.

Aha! Powers of two, not multiples!

2,4,8,16,32,64,128,256, 512,1024, 2048

Ok. All errors have ceased! The object loads into the scene!

This is how it looks:
How it Looks Now

This is how I need it to look:
How it needs to look

So the new question is… how to get the textures to look like they should?

Side Questions:
Why does it look so weird?
Whats going on with the dark area?

package  
{
 import away3d
.cameras.*;
 
import away3d.containers.*;
 
import away3d.controllers.*;
 
import away3d.core.base.*;
 
import away3d.core.managers.*;
 
import away3d.debug.*;
 
import away3d.entities.*;
 
import away3d.events.*;
 
import away3d.library.*;
 
import away3d.library.assets.*;
 
import away3d.loaders.*;
 
import away3d.loaders.misc.*;
 
import away3d.loaders.parsers.*;
 
import away3d.materials.*;
 
import away3d.materials.lightpickers.*;
 
import away3d.materials.methods.*;
 
import away3d.primitives.*;
 
import away3d.textures.*;
 
import away3d.lights.*;
 
import away3d.tools.helpers.LightsHelper;
 
 
 
import flash.display.*;
 
import flash.events.*;
 
import flash.geom.*;
 
import flash.text.*;
 
import flash.utils.*;
 
import flash.external.ExternalInterface;
 
import flash.net.URLRequest;
 
/**
  * ...
  * @author SimNations
  */
 
[SWF(backgroundColor="#000000"frameRate="60"quality="LOW")]
 
public class buildingAlone extends Sprite
 {
  
//Embed
  
[Embed(source "../../3d_objects/Houses/house2.obj"mimeType "application/octet-stream")]
  
private var NabModel:Class;
  
    
//engine variables
    
private var scene:Scene3D;
    private var 
camera:Camera3D;
    private var 
view:View3D;
    private var 
cameraController:HoverController;
    
    private var 
loader:Loader3D;
    
/**
     * Constructor
     */
  
  
public function buildingAlone() 
  
{
   
//trace('test');
   
init();
  
}
   
/**
    * Global initialise function
    */
   
private function init():void {
    initEngine
();
    
initObjects();
    
initListeners();
   
}
   
   
   
/**
    * Initialise the engine
    */
   
private function initEngine():void {
    
    stage
.scaleMode StageScaleMode.NO_SCALE;
    
stage.align StageAlign.TOP_LEFT;
    
    
scene = new Scene3D();
    
    
camera = new Camera3D();
    
    
view = new View3D();
    
view.scene scene;
    
view.camera camera;
    
    
cameraController = new HoverController(cameranull451020);
    
addChild(view);
   
}
   
   
   
/**
    * Initialise the scene objects
    */
   
private function initObjects():void {
    
    Parsers
.enableAllBundled();
    
    
loader = new Loader3D();
    
loader.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
    
loader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonFullyLoaded);
    
loader.loadData(new NabModel()); 
    
scene.addChild(loader);
    
   
}
   
   
   
/**
    * Initialise the listeners
    */
   
private function initListeners():void {
    addEventListener
(Event.ENTER_FRAMEonEnterFrame);
   
}
   
   
   
/**
    * Navigation and render loop
    */
   
private function onEnterFrame(event:Event):void {
    view
.render();
   
}
   
   
   
/**
    * Listener function for asset complete event on loader
    */
   
private function onAssetComplete(event:AssetEvent):void {
    
   }
   
   
   
/**
    * Completely loaded
    */
   
private function onFullyLoaded (event:LoaderEvent):void {
    trace
('test');   
   
}
 
  
 }
 
 
   

dubletar, Member
Posted: 18 April 2012 01:32 AM   Total Posts: 73   [ # 24 ]

Fyi, I really appreciate the help. If I can get one object from 3dsMax to flash, successfully, looking as it should, it makes me learn the process, make adjustments, and understand Away3D. Your help is invaluable.

   

Avatar
Fabrice Closier, Administrator
Posted: 18 April 2012 08:03 AM   Total Posts: 1265   [ # 25 ]

There are lots of possible causes, but as your first png is poststamp sized: it doesn’t say much.
If your obj data is triangulated, propperly mapped, and holding normals pointing in teh right direction. You should see same as on your second rendering. You might need to set the repeat to some materials if you have tiled, and probably define/set some lights/lightpickers to get some “volume”.
About your “dark area’s”. You do not define your camera.lens.near & camera.lens.far in your code. It uses the default values. Your model probably doesn’t fit in between these values.

   

dubletar, Member
Posted: 20 April 2012 05:08 AM   Total Posts: 73   [ # 26 ]
Fabrice Closier - 18 April 2012 08:03 AM

There are lots of possible causes, but as your first png is poststamp sized: it doesn’t say much.
If your obj data is triangulated, propperly mapped, and holding normals pointing in teh right direction. You should see same as on your second rendering. You might need to set the repeat to some materials if you have tiled, and probably define/set some lights/lightpickers to get some “volume”.
About your “dark area’s”. You do not define your camera.lens.near & camera.lens.far in your code. It uses the default values. Your model probably doesn’t fit in between these values.


Ok, I remade the building, but there’s still a problem.

It goes back to the original issue (title of this thread), loading multiple textures.

There are 8 textures being used in the object. But only one of them appear (the grey brick).

This is how it looks in flash:
http://www.simnations.com/buildingnow.png

This is how it should look:
https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-snc7/423706_402641886418385_199975193351723_1817876_505616630_n.jpg

   

Avatar
Fabrice Closier, Administrator
Posted: 20 April 2012 09:19 AM   Total Posts: 1265   [ # 27 ]

you need to build you model so that it has one material per mesh. I guess you export a multiple material mesh.

   

dubletar, Member
Posted: 20 April 2012 11:43 AM   Total Posts: 73   [ # 28 ]

The mesh I showed above is multi-materialed exported mesh. :/

Is there anyway to have all textures show up, or is away3D limited to one texture per mesh?

   

Avatar
Fabrice Closier, Administrator
Posted: 20 April 2012 02:37 PM   Total Posts: 1265   [ # 29 ]

Yes and no: yes there is a way, yes a mesh can in Away have multiple materials. No the parser isn’t ready for this. Tho, it would be handy if you would provide me the obj (offline) so I could take a closer look, be able to test and possibly implement this feature.

   

dubletar, Member
Posted: 21 April 2012 02:30 PM   Total Posts: 73   [ # 30 ]

That would be a great idea. How should I send it to you?

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X