Tuesday, March 20, 2012

Blender to UDK: How I do it - Static Meshes

I have finally got a handle on making base-featured models. That is, a model with accurate collision and LOD data. When exporting from blender to UDK, you have a few options for format. I have been using the ASE exporter made by MCampagnini, one of the UDK community members, and up till today it had been going ok. My main issue with it was that the error messages were vague and unpredictable. In a fit of frustration today I decided to switch to the FBX exporter, which ships with blender 2.62. After a few hiccups here and there I found out how it works, and I gotta say I like it. However, it does have some very nearly fatal quirks for the uninitiated. Before I forget what they are, I thought I had better write them down. I still use the ASE exporter for LOD models, since UDK didn't seem to like them as FBX.

    General setup

  • When you are exporting to .FBX, there is a little options panel on the left of the screen when you are naming your file. If you go ahead and leave everything at default settings you will export a whole heap of shit you may not want to. To make it handle more intuitively, I make sure I tick the "selected" box and un-toggle all the object type buttons except "mesh" I also changed the default scale to 16, since I cbf making my objects to scale in blender, and 16x is about right. Finally, I tick "apply modifiers" because I use the edge split modifier for smoothing groups and other stuff sometimes. Once you have it set out how you want, press the plus sign next to the "operator presets" dropdown and name your new default setup. Now you just have to select the preset when you export, rather than re-selecting everything. Here's what my FBX options look like:
    file>export>FBX
  • Naming conventions

  • UDK looks for a reference (visual) mesh and collision (physical) mesh on import of a model file. The way it tells them apart is by the names of the objects. A reference mesh can be called anything you want, but for continuity I avoid underscores, dashes, dots or spaces. This is because when UDK looks for a collision mesh it looks for the prefix UCX_[modelname]. If there are multiple UCX_ objects, it fucks up when there is an underscore in there for some reason. I assume it's because the script is expecting UCX_[modelname]_01, UCX_[modelname]_02 etc. In any case, if you have a conflicting name then it won't show in UDK. There are no error warnings for this so it's something you have to know. Unfortunately this means I am naming models modularshack01wall01top but it's the only way I could get it to work consistently. In case you didn't know, you can name your meshes in the properties sidebar ('n' in 3d viewport to toggle, and find the "item" dialogue) or the object panel in the buttons view (the orange cube icon).
  • Exporting a mesh

  • Now that we have the exporter options and mesh names all set up, select the meshes you want to export. At this juncture let's assume you want a reference (visual) mesh and collision (physical) mesh. Blender will let you export the file without any UV or material data, but UDK will call you names so make sure you at least have the model UV unwrapped. I'm not sure about having a material applied but if you're having issues try that. When you're ready, select the objects and export them. UDK will use the FBX filename for the model name in engine, so now's the time to fix up the bigmodelname01withnumbers04andothershit issues.
  • Concave collision

  • When making a collision mesh you can't have any concave meshes. If you need a concave collision model you'll need to make it out of other convex meshes. To export them correctly, make them as separate objects and export them in the same file as the reference mesh.
  • Make sure all of the convex meshes are prefixed with UCX_[modelname]. I also number them, UCX_[modelname]_01, UCX_[modelname]_02 etc. This means that you can have several objects in the same file. You can have multiple reference meshes as well, don't prefix them and UDK will display them all as the one mesh.
  • UDK apparently has a few different prefixes that it can use for collision meshes. For simplicity's sake I stick to UCX_. I got UBX_ to work but I'm pretty sure it only works on cube primitives.
  • If UDK doesn't like your collision mesh it will just discard it and go about business as usual. If you can't get it to work, go back and make sure your collision mesh has been unwrapped, has a material applied and a texture applied within that material, try smooth shading the whole thing and applying or deleting any modifiers you may have. To view your collision mesh, click the green icon with the pink outline in the toolbar in the Static Mesh Editor. If a wireframe overlay of your collision mesh does not show up, it has not been imported.
  • LOD models

  • When importing LOD models to UDK, you can opt to use .FBX or .ASE but my first try at using FBX didn't work, whereas the ASE did. The ASE exporter can be an asshole though so make sure to educate yourself about it. Some troubleshooting tips are below.
  • You assign LOD models in the Static Mesh Editor in UDK, but there are still some things I do to make sure the blender ASE exporter works as often as possible. For starters I get a lot of "material not assigned" errors even when I have unwrapped the mesh and applied a material and texture image. There's obviously something I'm missing but I'm not one to stop and look for answers. Instead, I duplicate the reference object and modify it to make a relevant LOD model. I make sure not to create any new faces that don't have a material applied. I do this by extruding ('e') all the faces I need, rather than filling ('f') them or adding new meshes at all. This sounds dumb, I know, but what's even dumber is that it really did solve the problem I was having, even after assigning the materials to the new verts.
  • Make sure that if you rename the file from the exporter interface in blender you put ".ase" on the end of it or blender will output a typeless file and UDK will say mean things. You can just rename it from explorer if you want, the data is still there.
  • When you export your LOD model, export it into the same directory as your reference model, this just helps because UDK remembers where it got the ref mesh from and when you import your LOD it will be in the same folder. I hate having to click stuff.
  • You don't need a collision mesh for your LOD, only a reference.
  • In UDKs Static Mesh Editor (double click on your model in the content browser to bring it up), select mesh>import mesh LOD... and select your first LOD model (the first one the model will swap to, you can have up to 3, I think). It will give you a dropdown box asking what you want to do with it, import it to the first LOD slot in the model. If you import more than one, make sure you change the option or it will overwrite the old slot. The new LOD model can be viewed by pressing the numbered buttons in the toolbar in the Static Mesh Editor.
  • You'll see that the new LOD model has the same material as the base mesh. You'll most likely want to change that. Polies rendering 12pixels high don't need a 2048x2048 dif spec nor set.I usually make a new material with just the diffuse map and at half to a quarter of the original texture resolution (you can't even notice a 2048 to 512 drop usually). Make a regular old material in UDK and assign it to the LOD models by however you do it usually. You'll need to open up the LOD data dropdowns in the right properties panel to find the material input bit.
  • Have a play with the LOD distance ratio settings to make sure your LODs are swapping out when they should. The higher the number, the further out the LOD models will swap in. There is probably a way to set this manually for each LOD mesh but I can't find it. Here's a pic to show where the junk is:
    get comfortable with these settings

I don't think I missed anything here, but if I have I'll probably remember it when I need it most, and then I'll update this or start a new post. If anyone actually reads this and has any questions or suggestions, comment and I'll try to help you out or assimilate the information. I'll also do a skeletal mesh checklist at some point.

2 comments:

  1. disculpe podria hacer un video tutorial ,estoy seguro que ayudaria a mucha gente si lo hace,gracias

    ReplyDelete
    Replies
    1. I don't think I'll do a video tutorial for this just yet, but if you have a look at my livestream I sometimes help people out live. So far only in the source engine though, because my UDK skillz are still in development.

      Delete