[SOLVED] OBJ with UV map textures from Blender to Irrlicht

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Nems
Posts: 6
Joined: Sun Sep 16, 2012 8:40 pm

[SOLVED] OBJ with UV map textures from Blender to Irrlicht

Post by Nems »

(edit) I found the solution, you can't use transparency in your textures without setting the material to EMT_TRANSPARENT_ALPHA_CHANNEL, and even then you will lose the original object colour, so better forget about transparency and bake everything onto the texture.

Hi all. Like the post title says, I want to export a Blender-created object or scene to Irrlicht, using the Alias Wavefront OBJ format. The catch is, one or more objects have UV mapped textures, that are seen and rendered perfectly in Blender, but that show fully black when loaded in Irrlicht.

The funny thing is, I actually managed to get it working, just once. When I happily tried to recreate the same procedure with other objects, it turned wrong again, and I have spent all afternoon going through every parameter and possibility trying to get it right again, to no avail.

Yes, I have made sure that UV coordinates are exported. Yes, I have turned the lightning off for the mesh. I've seen posts similar to this one, here and in Blender's forums, but no luck. What bothers me more is that, for a moment, I got the solution, and I lost it.

Oh, I tried importing the OBJ again to Blender, and everything worked, so I guess the issue is on Irrlicht's side.

I have prepared a simple example so you can check what I say: http://www.gamefront.com/files/22267821 ... _uvmap.zip

(edit) If the GameFront link gives you "bad gateway", just keep refreshing.
Last edited by Nems on Tue Sep 18, 2012 6:07 pm, edited 6 times in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by hybrid »

Try to export normals as well, maybe the setup without does not work properly. About links: In your next post you can use them,just not in thte very first one :-)
Nems
Posts: 6
Joined: Sun Sep 16, 2012 8:40 pm

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by Nems »

Yes, I made sure the "Export normals" option was checked in Blender's exporter. I even entered edit mode, selected all faces, and pressed Ctrl+N to make all normals consistent (looking outwards). No luck, still black. Ctrl+Shift+N, which sets the normals inwards, did not work either, just inverted the mesh. Thanks anyway.

(edit) Ok, I can put links now.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by greenya »

I'm not any good in Blender, but i can describe how to make textured cube (checked only diffuse map (a color channel)) in Blender (checked with 2.61) to be same looking in Irrlicht:

- create new folder, call it like "model1"
- place into it some texture like "texture_diffuse.png"

- open blender
- select default cube
- goto to tab Textures, choose Type "Image or Movie", click Open and select texture_diffuse.png, in Mapping rollout choose Coordinates "UV"
- goto Edit Mode (hit TAB in 3d view) and hit "Unwrap" (at left panel), go back to Object Mode (hit TAB again)
- File -> Export -> Wavefront (.obj), check all checkboxes except "Animation", set Scale to "10.00", navigate to folder "model1" and type "mesh.obj" and hit "Export OBJ"

- now we have "mesh.obj" and "mesh.mtl" generated near our "texture_diffuse.png", so 3 files in total inside the folder.

Then you load "model1/mesh.obj" in your Irrlicht app and turn off the lighting.
Nems
Posts: 6
Joined: Sun Sep 16, 2012 8:40 pm

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by Nems »

I carefully followed your procedure, step by step, and the result is the same: a black cube (it was basically the same procedure i was using before, only that I assigned the texture after creating the UV map, not before). Irrlicht reports no errors, in fact it even loads the texture and OBJ correctly, but it does not render the UV textured objects.

Did it work for you? In that case, would be you so kind as to upload the files (.blend, .obj and .mtl) so I can check them?
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by mongoose7 »

The problem is with the texture file. It looks as if Irrlicht cannot read the PNG file although it doesn't give an error. Maybe covert it to a JPG file?
Last edited by mongoose7 on Tue Sep 18, 2012 3:16 pm, edited 1 time in total.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by greenya »

Your cube is black because of next:
- or you didn't turned of the lighting
- or your uv are empty (0,0) and your texture has black pixel at 0,0

I have checked my instructions and they worked for me well.
The only thing i want to warn you about "going to Edit mode" and back to "object mode": i don't know how familiar your are with Blender, but when you hit any key - this command will be send only to the active window, and the active window is that which has mouse cursor over it, so when you hit TAB -- make sure your mouse cursor is over the "3d view", or change mode via Blender' UI (without keyboard). If you didn't exit Edit mode, UV will not be exported.

Here model1.zip -- http://filebeam.com/b8f61e0c8445fa7ba593a2a145093624
Here the screen:
Image
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by mongoose7 »

Who me? Nah, Irrlicht can't read the PNG file. If you look at the example you will see UV coordinates (0, 0), (0, 1), (1, 0), (1, 1). Also, the lighting was turned off. In fact, I didn't run the example, I used MeshViewer, and it showed a black plane. Did you use Irrlicht?

I'm guessing that PNG is an extensible format, which means you can read the file skipping the tags you don't understand, ending up with no colour information and no error.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by greenya »

I just tried your PNG (from archive you provided in 1st post), and it worked for me after i additionally specified a material type as TransparentAlphaChannel.
Image
P.S.: also i changed the background color to be white.
Nems
Posts: 6
Joined: Sun Sep 16, 2012 8:40 pm

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by Nems »

Thank you all for your input. I have discovered the answer thanks to you: the problem is that either the OBJ format or Irrlicht's loader have problems when you use a texture that has transparency for the UV map.

greenya: I'm actually quite pro at Blender... or so I think. :roll:

Your example worked because you have used a plain texture, with white colour. My texture only had the writing, the rest was transparency. It was loaded OK when I converted the PNG to JPG, and then back to PNG and TGA. Tested all three formats and they worked. There is not need to activate all checkboxes in the exporter, just the UV one (and if you want, the normals).

moongose7: you were more or less right, Irrlicht seems to support PNG textures well (it's not always have been like that, though). It's the transparency that gives problems.

I added the following line to my code:

Code: Select all

node->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
The problem is that only the contents of the texture (the writing) were then rendered. The underlying material (that orange colour I had applied to the cube) was lost. Sometimes the whole object is rendered black, and sometimes (my last tests) it is always rendered white plus the writing. Which tells me I will have to manually bake the colour (or whatever should be under the alpha texture) on the texture, and forget about using alpha channel... :(

If anyone discovers a workaround, please do tell me.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by hendu »

That's not how the GPU works (drawing vertex color + then the texture on top - it only draws tris once), so no surprises there ;)

You're not the first one to be tripped by how a modeler works vs how the gpu works.
Nems
Posts: 6
Joined: Sun Sep 16, 2012 8:40 pm

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by Nems »

Ahhhh thanks for the explanation. I thought (idiot me) that somehow Blender would automatically bake all textures together, or that Irrlicht would create two separate materials, or something (one for vertex colour, the other for transparent texture). Anyway, at leat I managed to get my code working and I'm a bit wiser now: I will manually bake all textures.

How can I mark the post as solved?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: OBJ with UV mapped textures, from Blender to Irrlicht

Post by hendu »

Edit the first post, then change the title.


Note that if you want that behavior, you can write a shader to do so (overlay texture on the vertex color, based on its alpha channel). I doubt it can be done using the fixed pipeline.
Nems
Posts: 6
Joined: Sun Sep 16, 2012 8:40 pm

Re: [SOLVED] OBJ with UV map textures from Blender to Irrlic

Post by Nems »

So, you mean that it could not be done manually with two Irrlicht materials (first transparent based on texture alpha, second diffuse)?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: [SOLVED] OBJ with UV map textures from Blender to Irrlic

Post by hendu »

No, irrlicht materials don't work that way. You can't stack them.

Irr material = the one material of this surface.


What you *can* do is have more than one texture in the same material. But still need to write a shader to be able to use them any way you like, the fixed pipeline is limited in what it can do.
Post Reply