Problem with embedded OBJ.

Software: Away3D 4.x

Tom.de, Newbie
Posted: 24 April 2012 06:35 PM   Total Posts: 30

Hey,

I am having a problem loading an embedded object file. (As of today I am using the latest Away3D 4 version)
The model, texture and material file work if I load them directly via the load functionality.
However, for this project I need to embed them.

// model  
[Embed(source "/../assets/models/icecube/ice_cube01_lg.obj"mimeType "application/octet-stream")]
private var IceCubeModel:Class;

// material
[Embed(source="/../assets/models/icecube/ice_cube01_lg.mtl"mimeType "application/octet-stream")]
private var IceCubeMaterial:Class;

// texture
[Embed(source="/../assets/models/icecube/ice01.png")]
private var IceCubeBitmap:Class; 

Then, when I try to load it I do the following:

var context AssetLoaderContext = new AssetLoaderContext();
context.mapUrlToData('ice_cube01_lg.mtl', new IceCubeMaterial());
context.mapUrlToData('ice01.png', new IceCubeBitmap());

Parsers.enableAllBundled();
m_Loader3D = new Loader3D(false);
m_Loader3D.addEventListener(AssetEvent.ASSET_COMPLETEonAssetRetrieved); 
m_Loader3D.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete); 
m_Loader3D.addEventListener(LoaderEvent.LOAD_ERRORonLoadError);
m_Loader3D.loadData(new IceCubeModel(), context); 

When I check onAssetRetrieved I can see that the meshes load fine, but it bombs out the moment the first texture is loaded.

This is where and how it crashes:
[Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.

It points to the following file / line:
Line 191 “_timer.start();” in function “resumeParsingAfterDependencies()” in file “ParserBase.as”.

I have attached the files in question. As said, they do work fine when loaded directly, just embedding fails. I’ve tried and tried, but don’t seem to be any closer to a solution so far.

If I remove the texture reference from the “mtl” file it will load, but obviously without the texture.

Any ideas what I am doing wrong?
Many thanks in advance!

 

File Attachments
CubeTest.zip  (File Size: 497KB - Downloads: 156)
   

Tom.de, Newbie
Posted: 25 April 2012 09:15 AM   Total Posts: 30   [ # 1 ]

I’ve done some further experiments this morning wielding quite some interesting results.

I am loading 3 models with a texture each.
If I use the regular loader, loading an external URL, this is how they come through in AssetComplete:

texture - IceCubeBitmap_0
mesh - IceCubeMesh_0
texture - IceCubeBitmap_1
texture - IceCubeBitmap_2
mesh - IceCubeMesh_2
mesh - IceCubeMesh_1

The texture always comes through before the model.

Now here is the order I get when I use loaddata to load my embedded data:

mesh - IceCubeMesh_0
mesh - IceCubeMesh_1
mesh - IceCubeMesh_2
texture - IceCubeBitmap_0
—-CRASH—-

The model comes in first and it crashes when the parser comes to the textures. (see details in my last post)

I’ve put a breakpoint into startParsing() in ParserBase.as to find out what is going on.
The result?

texture - IceCubeBitmap_0
texture - IceCubeBitmap_1
texture - IceCubeBitmap_2
mesh - IceCubeMesh_0
mesh - IceCubeMesh_1
mesh - IceCubeMesh_2

Textures come in first, the meshes second and everything works.

Is this a timing issue? Every time I put in a breakpoint it works. How can I reproduce this without breakpoints? I am truly confused…

   

Tom.de, Newbie
Posted: 25 April 2012 01:13 PM   Total Posts: 30   [ # 2 ]

Getting the .mtl file to work remains elusive.
I have now ditched the mtl files completely and apply my textures when onResourceComplete is triggered.
Works fine for now, although I would love to use .mtl still. smile

   

angvzp0x, Newbie
Posted: 04 June 2012 08:42 PM   Total Posts: 10   [ # 3 ]

I really need multiple textures per model asap - whats the problem with .mtl files? how do i get the right path ?

nevermind i got it - i have to hand edit the paths on the .obj & .mtl files.

   

Avatar
Fabrice Closier, Administrator
Posted: 05 June 2012 08:15 AM   Total Posts: 1265   [ # 4 ]

If you embed it, why not choose for a lighter and faster approach?
Drop your file in Prefab and export it as AS3. Use the output in your project.
The optional export of a project will show you that only 2 lines would be required.
import yourClass;
view.scene.addChild(new yourClass());

Here a quick flow:
Load the obj in Prefab, as you want to have a single mesh with multiple textures. Select the meshes you want to group together (by click/shifting them) rightMouse on one of them, select Weld from the menu, to remove eventual unnecessary data, rightClick again, and select Merge.If you have multiple TextureMaterials, Prefab will ask you if you want to generate an atlas (the material merge will even look further if it cannot merge more on geometry side). It is eventually time to rename the resulting merged Mesh.
Go to export menu, select AS3.

Note that I do plan to add an interface to the material Merger, because it is atm not flexible enough for my taste. The outputs are giving excellent performance results on mobiles, so I think it deserve a bit more attention.


Of course, if you still preffer to go for obj, that’s up to you.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X