# Baked Textures and .X Files

This topic is 5369 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to use baked textures with an X model file... [help]I get the feeling theres some really simple Tutorial or How-To about this floating around on the net, evading me, but I've been Googling and forum browsing for a couple hours and I haven't found anything straight forward yet... [dead] So, I'm using 3DS Max 5, and I've created a scene with radiosity lighting. I've already managed to bake a couple textures for the scene without much problem. (Though there seems to be something wrong with my copy, since 80% of the time it stops baking with "unknown system error." A few tries will eventually get past this.) The 3DS docs are pretty clear on this step. But they keep saying, "You can use them with Direct 3D!" My game has been using X files all along without any trouble, so when I redered these textures, I expected to just copy them and the new model into my game's archive and everthing would work... [headshake] After a lot of Doc reading and searching online, I discovered that no matter what I do, the MS X file converter will only give me one set of texture coords. Fine, no light map for me, so I try doing a CompleteMap, and the resulting X file gets NO texcoords. I write it off as a bug in the converter, which is apparently well known for it's bugginess. I downloaded another exporter, which I found here: [google] It's quite a bit more functional and elegant than the MS converter / exporter, despite the broken English. It definitely seems to include both the original texture and the lightmap in the exported file. However, I can't really make sense of the texture coords I'm getting. I haven't modified my code yet from just drawing a single texture stage for models, because I'm not sure what to do next. Some of the baked objects use the original texture on their single pass, while others use the lightmap, mapped incorrectly (wrong texcoords). What the heck? [bawling] Basically what this boils down to is, is it even possible for me to do lightmapping with X files, and if so, how? Is someone going to tell me I should use another format? I can accept that, assuming I can find some loading code out there somewhere. (I'm kind of in a hurry to get this working, since there are some bug-fixes I need to release with the next version as soon as possible.) If the answer to my question is in some easy to read Tutorial or FAQ which I stupidly missed, I expected as much, and simply pointing me at it will make me happy. [tears]

##### Share on other sites
This is a good tutorial on texture baking. Make sure you follow it very closely, though. Also, have you tried the Panda DirectX Exporter?

##### Share on other sites
Thanks! Those are the useful links I was looking for! [wink]
I'm going to try using the Panda Exporter with my regular diffuse texture and blending in a low-res lightmap, since I reuse lots of textures and that should save me some disk space. I'm still not sure on how to do that, though. Ie, where are text coords, and how do I get more than one texture from a single mesh subset? My model drawing code is pretty boilerplate. (Though in C, but don't let that mess you up.)
void DrawModel(LPD3DXMESH mesh,D3DMATERIAL8* mtrl,LPDIRECT3DTEXTURE8* tex,DWORD nmtrl){   int i;   if(!mesh)return;   for( i=0; i<(signed)nmtrl; i++ )   {      // Set the material and texture for this subset      device->lpVtbl->SetMaterial( device, &mtrl );      if(tex)device->lpVtbl->SetTexture( device, 0, (void*)tex );      else return;      // Draw the mesh subset      mesh->lpVtbl->DrawSubset( (void*)mesh, i );      device->lpVtbl->SetTexture( device,0,NULL);   }}

I really don't see how to add the additional SetTexture, or where to get the pointer to it. I'll a play around with it on my own, but if anybody knows the answer to this, I would appreciate a hint...

If all else fails, that first article, on Unreal skinning, will definitely solve my problem. (I was wondering how to get the same UV mapping back after reapplying the texture!) But I'd like to avoid that solution, because, like I say, It'll ruin all my texture reuse, and I'll likely end up with ugly, low-res mappings that way.

Anyway, thanks for the great links[attention]

##### Share on other sites
One of the problems with X files is that you can only have one material (one texture) per vertex. This means you *can't* store both the diffuse material data and the lightmap material data for each vertex. You can only have one material per subset. A common workaround to this is to store you texturing information outside of the X file (ie in a config file or something, with all of the texture types and file names).

I'd recommend checking out DirectMesh. It's a keyframed animation format that is a lot easier to use than the X file format. It also supports multiple textures per mesh.

However, version 1.0 does have many limitations. I'm currently working on v1.1, and it accounts for all of these. New features will include:

- Skeletal animation (bones, instead of keyframes)
- Morph targets
- Multiple meshes in one model (aka subsets)
- Animation blending
- File compression using zLib

##### Share on other sites
That's the conclusion I was coming to from reading all this stuff, so I went ahead and worked on the solution from that Unreal Skinning article above. I think this screenshot speaks for itself:

There are still some issues to work out with resolution, and I'll have to raise my minimum spec to deal with the large lightmap textures, but I sure am glad to get this working, and by my own deadline, too!

I read over that sticky thread on DirectMesh earlier while I was trying to figure all this stuff out, and I was tempted to switch over to it. It definitely seems like a useful API. Only reason I didn't is because all my X File code was in place, and I had to get this working fast. I'll definitely consider using it for my next project, though. [wink]

##### Share on other sites
Wow, this screenshot looks very fine!!!

I'm trying to use lightmaps in my engine too using x files. I export the mesh with Panda Exporter and seems that the lightmap coordinates are well exported. Now I try to visualize it in the Mesh Viewer and it crashes.

How can I read this information in my engine to use the lightmap's coordinates?

Thank you very much.

• 13
• 18
• 29
• 11
• 28