Wednesday 20 November 2019

UV mapped model to TRLE wad using Blender 2.80

teme9 published a technique for converting a UV mapped model to a form that was suitable for a Tomb Raider level Editor (TRLE) .wad file using Blender 2.7x.

https://www.tombraiderforums.com/showthread.php?t=208076

This post is an update of teme9’s tutorial for Blender 2.80.



Installing the addon

Go to https://github.com/sapper-trle/sappers-TRLE-addons/releases and download v2.3 sappers-TRLE-addons281.zip file.


download2


In Blender 2.80 click to Edit>Preferences.

blender-pref

In the dialog click Add-ons and then Install.

addons

Select the zip file you downloaded and click Install Add-on from File.

install

Activate the addon by checking the checkbox. Use the search box or Import-Export filter to locate the addon.

activate

In File>Export you should see the options TextureAdd and StrPix Metasequoia. These will be unavailable (greyed out) if no mesh object is selected or the selected object has no UVs or the viewport is not in object mode. Note if the object contains ngons (polygons with more than 4 vertices) an error will be generated and no object will be exported

file_export

Converting the model

Models for a TRLE wad must be low poly, the main restriction being StrPix’s limits of 1500 vertices and 1500 polygons. Also the polygons must only be triangles or quads (triangulate any ngons before unwrapping). Make sure the model you choose meets these requirements.

Import your low poly model into Blender with File>Import and click it to select it. To see the model textured in the viewport select the Look Dev viewport shading.

The importer may have used a rotation transform to match the model’s up with Blender’s up. If so, you will see a non zero value in the rotation transform for the object.

lookdev

To ensure the model has the same orientation in the exported MQO as you see in the viewport you need to apply the rotation transform using the Object>Apply>Rotation menu or pressing Ctrl+A and selecting Rotation.

apply_transform

Select the Modelling workspace and use Mesh>Clean Up to fix any problems with the mesh such as duplicate vertices.

cleanup

The number of vertices and faces in the visible models in the scene is displayed in the status bar, bottom right, so you can check that the model is within limits for StrPix.

verts_and _faces

With the model selected press Shift+D to duplicate the model. It is very important that the duplicate model is positioned at exactly the same spot as the original. I ensure this by clicking the right mouse button. (I have left mouse button click set up to select.)

We are going to bake the textures from the original model to the duplicate model and this process requires that the duplicate model fully encloses the original model.

With the duplicate model selected, select the Shading workspace and in the Shader Editor viewport click the button labelled “2” next to the material name. This makes the duplicate model use its own material and not share it with the original model.

shading

Note here I assume the importer you used set up a material that uses nodes.

In the Image Texture node click the “X” next to the image name and then click New and create a new 256 * 256 image.

unlink_image

new_image

image

Finally in the Shader Editor disconnect the Image Texture Node by clicking and dragging the end of the link off the node it’s connected to.

disconnect_node
With the duplicate model still selected, switch to the UV Editing workspace.

In the 3D view viewport (Edit mode) select all the faces by pressing A and then select UV>Lightmap Pack from the menu.

lightmap_unwrap

In the dialog select All Faces, check Share Tex Space, set Image Size to 256 and Margin to 0.25. You can try different values of Margin here to see which gives the best result. If you created a new image in the step above leave New Image unchecked.

lightmappack

This step transforms the model’s UVs into rectangles and right-angled triangles required by the TRLE wad.

new_uvs

The next step is to bake the textures from the original model to the duplicate model.

Switch to the Layout workspace and make sure Object Mode is set.

In the Outliner viewport first click on the original model name and then hold Shift and click on the duplicate model name. Note that the models must be visible (i.e. “eye” icon open) for them to be selected in the Outliner. The names become different shades of orange when this step is completed.

EDIT: In Blender 2.81, 2.82 you have to do this the other way round or use Ctrl instead of Shift. I don't know why, maybe a bug. Anyway, you need the original object highlighted in orange and the duplicate object highlighted in yellow as in the picture below.

outliner

In the Properties viewport below the Outliner select the Render context tab (camera icon) and change the Render Engine to Cycles. Currently the baking option is only available with the Cycles renderer.

cycles

Expand the Bake panel.
  • Set the Bake type to Diffuse.
  • Under Influence turn off Direct and Indirect. Keep Color on.
  • Check Selected to Active.
  • Expand Selected to Active and set Ray Distance to one.
  • IMPORTANT Ray Distance must be greater than zero or the baked texture will not be good.
Click the Bake button to bake the texture.

bake

The duplicate model will not yet appear textured since we disconnected the Image Texture node in the Shader Editor. So make sure the duplicate model is the only selected model and switch to the Shading workspace and reconnect the Image Texture node to the Shader node in the Shader Editor viewport. You connect by clicking on the Color output on the Image Texture node and dragging to the Base Color input node on the Shader Node.

connect

Switch to the UV Editing workspace and in the Image Editor viewport save the bake texture image.

save_image

Switch to the Layout workspace. Make sure the duplicate model is selected only and the viewport is in Object Mode.

From File>Export
  • Export the model as StrPix Metasequoia. In the file dialog set the scale if required and optionally the name of the image.
  • Export the UVs as TextureAdd records file
export

scale

If you are not satisfied with the baking result you can repeat the steps from the UV unwrap and try different values for margin etc.

Now we can import the model into a .wad file.
  • First open your .wad file in TextureAdd
  • Import your image in the Texture Pages section. Must be first texture page in .wad.
  • Import the records file in the Texture Position section. Click  “Yes” to overwrite.
  • Save the .wad.
textureADD
  • Open the .wad file in StrPix
  • Import the .mqo file.
  • Save the .wad.
strpix

For more information about this technique see DJFull’s video [link] or read through the thread linked at the top of this post.

Note that DJFull is using Blender 2.79 in his video.

If you exported the .mqo from Blender with an image name the model will be textured in Metasequoia.

meta

A note about scaling

teme9 suggests the following Blender settings for TRLE modelling. With these settings 4 x 4 units in the grid is one block in TRLE. If you model according to these units export the .mqo with scale 100.

teme1

teme2

No comments:

Post a Comment