Models and Materials Help

Software: Away3D 4.x

FeffersHat, Newbie
Posted: 21 June 2012 09:06 AM   Total Posts: 21

I’m embedding my model into my game and it works fine. The model format is .obj and it uses a MTL file with the path “..lib/Textures/model.mtl” The mtl file then loads the textures from a folder.
However, when I upload this to a website, or move the swf somewhere else and try to run the game, the textures cannot be loaded. I’m assuming it’s because the textures aren’t embedded neither is the mtl file.
Well, how would I make this work?

   

Richard Olsson, Administrator
Posted: 21 June 2012 10:16 AM   Total Posts: 1192   [ # 1 ]

You can embed the mtl file and textures as well, and use the AssetLoaderContext.mapUrlToData() functions to map the URLs that are being loaded to your embedded data instead.

Create an AssetLoaderContext instance, map the relevant URLs to your embedded data (ByteArrays or classes) and pass the context instance to loadData() when you start loading the OBJ file.

   

FeffersHat, Newbie
Posted: 21 June 2012 12:13 PM   Total Posts: 21   [ # 2 ]

Hey, thanks for the reply.
Would you kindly show me an example of how to do so? Couldn’t find anything on google. :[

   

Richard Olsson, Administrator
Posted: 21 June 2012 12:27 PM   Total Posts: 1192   [ # 3 ]

Just do what I explained above. Lets say you have a texture which is being loaded from the url “path/to/myTexture.jpg”. You want to map it to that file, but embed it instead. Then do the following:

// Class-scope
[Embed("path/to/myTexture.jpg")]
private var MyTextureData : Class;

// Where you want to load your file
var context AssetLoaderContext = new AssetLoaderContext();
context.mapUrlToData('path/to/myTexture.png'MyTextureData);

var 
loader AssetLoader = new AssetLoader(); // Or Loader3D if you want
loader.loadData(MyObjDatacontext); 
   

FeffersHat, Newbie
Posted: 22 June 2012 05:30 AM   Total Posts: 21   [ # 4 ]

Thanks a lot. (:
I embedded all my textures and mapped them. However, when I embed my MTL file like so:

//embedding
[Embed(source="../lib/Models/Materials/Arena.mtl"mimeType="application/octet-stream")]
public static var modelMTL:Class;

var 
arenaContext:AssetLoaderContext = new AssetLoaderContext();
//map textures
arenaContext.mapUrlToData("../lib/Models/Materials/Arena.mtl"modelMTL); 

I get a type coercion fail from MTL to ByteArray. Am I doing this completely wrong? Thanks.

   

Richard Olsson, Administrator
Posted: 22 June 2012 07:47 AM   Total Posts: 1192   [ # 5 ]

It seems like you found a bug in OBJParser, preventing it from properly handling embedded MTL files! I’ve fixed it now and made sure I can properly load an OBJ file, it’s MTL file and two textures all from embedded assets using URL mapping. The fix is in the release branch on GitHub, and the relevant commit is here: https://github.com/away3d/away3d-core-fp11/commit/7759c534101e6cfd0eb6b0a70bd0890832d04c0d

   

FeffersHat, Newbie
Posted: 23 June 2012 03:56 AM   Total Posts: 21   [ # 6 ]

Hey, thanks a ton for that. :D It loads the mtl file perfectly, however I get the following error:

TypeErrorError #1009: Cannot access a property or method of a null object reference.
 
at away3d.loaders.parsers::ParserBase/resumeParsingAfterDependencies()[C:\Users\Fefan\Desktop\Projects\New Game\Project\src\away3d\loaders\parsers\ParserBase.as:191] 

The line points to _timer.start(). If I comment it out, it all works fine.

Thanks a lot for helping me though!

   

Richard Olsson, Administrator
Posted: 23 June 2012 07:19 AM   Total Posts: 1192   [ # 7 ]

That sounds like a bug I fixed a week or so ago. Are you really using the latest version from the release branch (or did you just replicate the changes from the commit I linked to above)?

If you are indeed using the release branch and getting this error, please file a bug report, and if you can, upload your OBJ, MTL and texture files or e-mail them to me. My e-mail address can be found at http://richardolsson.se and issues should be filed in the issue tracker at http://github.com/away3d/away3d-core-fp11/issues.

Thanks!

   

FeffersHat, Newbie
Posted: 23 June 2012 10:21 AM   Total Posts: 21   [ # 8 ]

I’m really sure I’m using the latest version. I’ve downloaded quite a few different packages and their all the same.

I posted the issue on github and I’ll email the obj, mtl and texture files for you too.
Thanks

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X