Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Pettifogging Legalist!
retired moderator
Original Poster
#1 Old 4th Feb 2010 at 9:40 AM Last edited by plasticbox : 10th Feb 2010 at 8:57 PM.
Default [Howto] [RFC] UV-mapping an .obj for TS3 (blender 2.46)
Now that I've figured out how to map an .obj so that the game will understand it, I thought I'd sum it up in a little how-to, since I haven't seen this documented anywhere. I am not sure if the way I do it is the best way (so please comment if you know how to do this more effectively) but so far it works. Many thanks to cmomoney who helped me figure it out =).


The issue: people who have done stuff for TS2 (by working with .objs) will be used to be able to put together their mesh, then map it in any way they please. For TS3, this approach does not work – Wes has summed it up here:

Quote:
.obj files are laid out differently from the way the game requires vertices to be laid out. You cannot share vertices in this game between faces if they do not share identical UV locations.
Quote:
[..] you should look at the way the EA-made TS3 game meshes are constructed. You will not import any that have UV seams without duplicated vertices. That's because the file format does not allow for that... UV coordinates are associated with vertices, following a one-to-one mapping (along with normals, assignmanets, weights and tangent normals).

Many modelling programs associate UV coordinates and normals with polygons as separate pooled items. That yields lower vertex counts, but that requires three indices per polygon point instead of one. It is, in the end, a design tradeoff. More of this, or more of that. In the end, if your mesh is more complex, it takes more resources to render.

Base didn't say what kind of mesh they were working on, 2050 polys is not a lot for a TS3 mesh. If you want to reduce the impact your mesh has, you will need to reduce the poly count. You can weld vertices all day long, and the exporter will keep splitting them at the seams. To not do so will yield broken meshes in the game.



So, I didn't know this, and while my mesh itself was working fine, the UV and normals were broken in game, and the object had weird soft edges in some places (and re-exporting and checking yielded that the UV had indeed changed during export). This is what the problem looks like:

obj imported in Milkshape:

obj exported to s3asc, then re-imported:

In-game:

This basically looks exactly like in the Milkshape preview, only that you can't see very much in that – for obvious issues, it's a lot faster to re-import the .s3asc into Milkshape and checking it there, more subtle problems you'll only be able to see when testing in game.

How the UV map has changed:

On the left is the original map (selected is a leg side that had a stretched face in game); on the right is how it looked after importing to Milkshape, then exporting to s3asc, re-importing, exporting to obj again and opening that in blender.


One way to solve this would be to set up the UV map differently, typically with e.g. table legs mapped as cylinders – that seems to be what EA do most of the time, but it results in a lot of texture mirroring which looks a bit stupid in-game with textures like wood, or patterns that aren't symmetric.

Another way is to split the mesh at the seams, so that the object has the duplicate vertices it needs – then you can map it like you want, e.g. with only one seam in the texture on each table leg in this case (so that you can wrap the texture around the leg, rather than mirror it).


If you have a lot of edges you want to split here's how to "batch split" them:

1. mark all the edges you want to split as "Sharp" – hit Ctrl-E > Mark Sharp (or in the bottom menu: Mesh > Edges > Mark Sharp)

2. in the Buttons panel, set up a modifier: Add modifier > EdgeSplit, select *only* "From Sharp Edges", and hit "Apply". Voilà – now the mesh is split along those edges.

I think you can also just set up the modifier, and only apply it when exporting the obj (but I'm too much of a control freak for that – I want to be able to see exactly what happens, that's why I apply it immediately). Make sure you don't forget to clear the "sharp" tag again, unles you actually want the adge to be sharp.


If you only need to split a few edges (or when you have Mesh Tools open all the time anyway):

1. select the edge

2. in the Buttons panel, go to Editing > Mesh Tools and hit "Split".

Both ways result in the same thing, only the first one has a keyboard shortcut (so it's faster for lots of edges), the second one doesn't require remembering to actually split stuff at the end.


Now exactly where you will need to split the mesh depends on your project – I've found that the best way to think about it is map it first (whichever way you please), and when you're done, look at the parts in the map and think of each of them as a separate sheet of paper. Wherever the bits of paper have an edge, the mesh must have an edge too (which means TWO edges – one for the one face, one for the other, so that's where you have to split), so that the vertices in the mesh and the map correspond 1:1.

One thing I haven't really understood about this yet is that it didn't work for me to only split the inner edges of the table legs (the UV map was fine after that, but it still resulted in broken normals and messy edges) – I solved it by making each side of each leg a separate "sheet of paper", but that's a bit of a brute force approach. I encountered the same phenomenon with the next mesh I made – here I modified an EA object (the expensive crib); the original was set up so that the curved tops of the crib sides were mapped with the inner/outer/top side in one piece, and the bottom side as another piece, but that didn't work in my object (same effect: UV map was fine, but normals were broken and edges were soft). Splitting all edges solved it. But if there's a better way to do this, I'd really like to know!

Here's the final result for the table:


Now the texture wraps around the legs, rather than being mirrored, and the game understands it – no more broken normals, missing faces, or soft edges. Huzzah!


OK. I hope this helps somebody who's tearing their hair out over the same issue. Let me know if there's a better/simpler/more effective way to do any of the above, I'd be happy to hear about it. This may or may not become obsolete if/when/in case we'll be able to work directly in blender at some point (rather than having to export and re-import an obj), but I guess even then it'll be important to understand this difference between mapping for TS2 and TS3.


Also, tip for blender users (putting this here since it also relates to mapping): in case you haven't seen the Render > Bake Render Meshes > Ambient Occlusion option yet, please direct your mouse pointers there immediately. What this does is render the shadow texture for your object onto the UV map with 100% precision – there's no need to puzzle it together in Photoshop, and since for TS3 all that's needed is the shadow, this is worth its weight in platinum. Export the result, convert to dds, done. Note: for this it rather important that you construct your map with "Snap to pixels" on, otherwise you'll have to do a lot of manual fixing (so, rendering a new texture for an EA map is very much not recommended, urgh) since blender can't very well render half pixels.

With the default setting of 5 samples, it's pretty fast but results in a lot of noise (good for a preview but will look shitty in game); in Buttons panel > Shading > World > AmbOcc you can either use raytracing (default) and set it to a higher number of samples (I use 15, which takes a little while to render, but yields a kick ass result), or use Approximate instead (less accurate but faster; I haven't tried it personally but cmomoney says it works fine and since she's now my personal blender guru I take her his word for it =P – see his post immediately below for what settings to use). You may need to turn on the World panel in the Panels menu first (for me it isn't enabled by default).

Have fun!


All of this is in blender 2.46 for OS X / Intel.
Screenshots

Stuff for TS2 · TS3 · TS4 | Please do not PM me with technical questions – we have Create forums for that.

In the kingdom of the blind, do as the Romans do.
Advertisement
˙uʍop ǝpᴉsdn ǝɹ,noʎ 'oN
#2 Old 4th Feb 2010 at 1:33 PM
Very descriptive, PB.

Just to add, the Ambient Occlusion settings for Approximate are:

Passes = 0 - 1 ( I ususally use 1)
Method = Approximate
Correction = 0.000
Error = 0.000 (higher if you get, um, errors)
Falloff/Pixel cache = optional

AO baking is also good for taking the hi-res details from a high poly model and putting them on a low poly model. But that's another tutorial.

note: I'm a "he", not a "she"
Screenshots

"Part of being a mesher is being persistent through your own confusedness" - HystericalParoxysm
| (• ◡•)| (❍ᴥ❍ʋ) [◕ ‿ ◕]
Alchemist
#3 Old 4th Feb 2010 at 3:04 PM
I didn't know Blender allow hard edges to be specified. Pretty cool, that is the sort of things that are only in the big-$$$ tools.

Your normal problem has the same root cause as the UV issues, but I don't think the exporter tries to fix it. To make a sharp edge, you need two normals... one sticks out perpendicular to one face, and the other at (usually) 90 degrees, perpendicular to the other face... this makes an abrupt transition in the shading.

Having a soft edge means one normal instead of two, and it is midway between the two that would be there if it was a hard edge. This gives a gradual change in the shading, and thus a rounded appearance.

Pictures below:
Screenshots

If you like to say what you think, be sure you know which to do first.
˙uʍop ǝpᴉsdn ǝɹ,noʎ 'oN
#4 Old 4th Feb 2010 at 3:16 PM
Quote:
Another way is to split the mesh at the seams, so that the object has the duplicate vertices it needs – then you can map it like you want, e.g. with only one seam in the texture on each table leg in this case (so that you can wrap the texture around the leg, rather than mirror it). I didn't find a direct way to do this in blender, but this is what worked for me (it is a bit roundabout, so if anyone knows a better way, please post =):

When in edit mode, under Editing->Mesh Tools, there is a Split button. You just select the edges you want split and click that button. Is that what you're talking about?

"Part of being a mesher is being persistent through your own confusedness" - HystericalParoxysm
| (• ◡•)| (❍ᴥ❍ʋ) [◕ ‿ ◕]
Pettifogging Legalist!
retired moderator
Original Poster
#5 Old 4th Feb 2010 at 3:48 PM
Wes: the normals issue resolved itself once I had split the edges – on the vertices I originally only had one normal since, well, there was only one vertex in the first place =). So neither the exporter nor the user need to do anything to fix the normals, just split edges and it'll automagically be fine.

cmomoney: aaah thank you! Found! (I don't often use the buttons menus, so I tend to be a little blind in regards to those)

Stuff for TS2 · TS3 · TS4 | Please do not PM me with technical questions – we have Create forums for that.

In the kingdom of the blind, do as the Romans do.
One horse disagreer of the Apocalypse
#6 Old 4th Feb 2010 at 4:57 PM
Lol! Always the salesman :D

"You can do refraction by raymarching through the depth buffer" (c. Reddeyfish 2017)
Pettifogging Legalist!
retired moderator
Original Poster
#7 Old 4th Feb 2010 at 8:09 PM
Please keep this thread on topic, which is: stuff that is currently 1. working, 2. in blender. Not "for the wishlist" vaporware. Thanks.

Stuff for TS2 · TS3 · TS4 | Please do not PM me with technical questions – we have Create forums for that.

In the kingdom of the blind, do as the Romans do.
Back to top