Tomb Raider Forums  

Go Back   Tomb Raider Forums > Tomb Raider Level Editor and Modding > Tomb Raider Modding

Reply
 
Thread Tools
Old 21-02-24, 13:31   #71
TRDaz
Member
 
TRDaz's Avatar
 
Joined: May 2011
Posts: 10,466
Default

It's a mod using a model from the old import yeah, do you mean just import the mod with the new one and export with the new?
TRDaz is offline   Reply With Quote
Old 21-02-24, 13:45   #72
MuruCoder
Member
 
MuruCoder's Avatar
 
Joined: Jan 2018
Posts: 1,417
Default Installing Blender Addons

In order to use addons they must be installed in Blender.

Name:  blender_addon_github.png
Views: 454
Size:  3.7 KB

First get a zip file containing the addon. If you're using my GitHub version, download the one named like "io_tombraider123r_vX_X_X.zip" from the Assets of the latest release. Source code (zip) or (tar.gz) archives don't work directly.

Click image for larger version

Name:	blender_addon_install.png
Views:	322
Size:	12.9 KB
ID:	4063

In Blender go Edit > Preferences... to open the preferences window.

Click the Add-ons button on the left.

Click the Install... button and find & select the zip file you saved.

Now you need to find TRM Format (Tomb Raider I-III Remastered) in the addons list, type "tomb" in the search bar to filter them if you want.

Press its little check box to activate.

Press the menu button on the bottom left of window. If Auto-Save Preferences is not checked, manually press Save Preferences.

Now close and go to your File > Import/Export menus and see if Tomb Raider items are added.

You need to do this only once, they are now permanently added as import/export menu options.

When a newer version is released updating will be done from this window as well. You first need to deactivate the installed version by unchecking the checkbox. Then you install the new version zip.

Last edited by MuruCoder; 14-03-24 at 21:40.
MuruCoder is offline   Reply With Quote
Old 21-02-24, 13:47   #73
MuruCoder
Member
 
MuruCoder's Avatar
 
Joined: Jan 2018
Posts: 1,417
Default

Quote:
Originally Posted by TRDaz View Post
It's a mod using a model from the old import yeah, do you mean just import the mod with the new one and export with the new?
Yes, just import & export from scratch. Resize & rotate if you need but don't bother with rigging and all.
MuruCoder is offline   Reply With Quote
Old 21-02-24, 15:18   #74
AmazingOomoo
Member
 
Joined: Feb 2024
Posts: 30
Default

I can't seem to work out how to edit the textures in .dds without them turning completely black in-game? I'm using Paint.NET and sometimes they turn completely black and sometimes they come out a weird spectrum, depending on the type of DDS I save as, but I'm stumped as to how to get them to save properly. Any ideas? Sorry, I know this is quite off-topic but we don't have a dedicated TRI-III remastered mod thread set up yet, and I didn't think my post warranted its own topic...
AmazingOomoo is offline   Reply With Quote
Old 21-02-24, 15:25   #75
mralexmods
Member
 
Joined: Feb 2024
Posts: 8
Default

Quote:
Originally Posted by MuruCoder View Post
trm_export.py
Code:
# v0.3

import bpy
import struct
import string
import math
import bmesh

def write_trm_data(context, filepath, use_trm_setting):
    print("EXPORTING...")
    f = open(filepath, 'wb')

    # TRM\x02 marker
    f.write(struct.pack(">I", 0x54524d02))

    # SELECT ACTIVE OBJECT & COPY
    trm = bpy.context.active_object
    trm_mesh = trm.data.copy()

    # TRIANGULATE COPY
    bm = bmesh.new()
    bm.from_mesh(trm_mesh)
    bmesh.ops.triangulate(bm, faces=bm.faces)
    bm.to_mesh(trm_mesh)
    bm.free()

    trm_mesh.calc_normals_split()

    # VERTEX PACKER
    def PackVertex(coordinate, normal, material, groups, uv):
        vx = -coordinate.x
        vy = -coordinate.z
        vz = -coordinate.y
        nr = NormalFLOAT2BYTE(-normal[0], -normal[2], -normal[1])
        nx = nr[0]
        ny = nr[1]
        nz = nr[2]
        mat = material + 1
        tu = int(uv[0] * 255)
        tv = 255 - int(uv[1] * 255)
        if len(groups) > 0:
            g1 = groups[0].group
            w1 = int(groups[0].weight * 255)
        else:
            g1 = 0
            w1 = 255
        if len(groups) > 1:
            g2 = groups[1].group
            w2 = int(groups[1].weight * 255)
        else:
            g2 = 0
            w2 = 0
        if len(groups) > 2:
            g3 = groups[2].group
            w3 = int(groups[2].weight * 255)
        else:
            g3 = 0
            w3 = 0
        return struct.pack("<fff12B", vx,vy,vz, nx,ny,nz, mat, g1,g2,g3, tu, w1,w2,w3, tv)

    # PREPARE INDICES & VERTICES DATA
    indices = []
    vertices = []

    uvs = trm_mesh.uv_layers.active
    v_order = [0, 2, 1]

    for p in trm_mesh.polygons:
        for i in v_order:
            loop = trm_mesh.loops[p.loop_indices[i]]
            groups = trm_mesh.vertices[loop.vertex_index].groups
            vertex = PackVertex(
                trm_mesh.vertices[loop.vertex_index].co,
                loop.normal,
                p.material_index,
                groups,
                uvs.data[p.loop_indices[i]].uv
            )
            if vertex in vertices:
                indices.append(vertices.index(vertex))
            else:
                indices.append(len(vertices))
                vertices.append(vertex)

    # GET ELEMENT COUNTS
    num_materials = len(trm_mesh.materials)
    print ("Materials: ", num_materials)
    num_indices = len(indices)
    print ("Indices: ", num_indices)
    num_vertices = len(vertices)
    print ("Vertices: ", num_vertices)

    # UNKNOWN DATA FILL
    f.write(struct.pack("<12I", 1, 0, 0, 0, 0, 0, 0, num_indices, num_indices, 0, num_indices, 0))

    # MATERIALS
    f.write(struct.pack("<I", num_materials))
    for n in range(num_materials):
        m = trm_mesh.materials[n]
        f.write(struct.pack("<H", int(m.name.split("_",1)[0])))

    # BYTE ALIGN
    while f.tell() % 4:
        f.write(b"\x00")

    # UNKNOWN and INDICE & VERTICE COUNTS
    f.write(struct.pack("<3I", 0, num_indices, num_vertices))

    # WRITE INDICES
    f.write(struct.pack("<%sH" % num_indices, *indices))

    # BYTE ALIGN
    while f.tell() % 4:
        f.write(b"\x00")

    # WRITE VERTICES
    for n in range(len(vertices)):
        f.write(vertices[n])

    f.close()
    print("DONE!")
    ShowAlert("Export Completed.", "COMPLETE!", "INFO")

    return {'FINISHED'}

def NormalFLOAT2BYTE(x, y, z):
    x = round(x * 126)
    y = round(y * 126)
    z = round(z * 126)
    return ( x + 127, y + 127, z + 127 )

def ShowAlert(message = '', title = '', icon = ''):
    def draw(self, context):
        self.layout.label(text = message)
    bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)

from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty
from bpy.types import Operator

class ExportTRMData(Operator, ExportHelper):
    """This appears in the tooltip of the operator and in the generated docs"""
    bl_idname = "export_tombraider.trm_data"
    bl_label = "Export TRM Data"

    filename_ext = ".TRM"

    filter_glob: StringProperty(
        default="*.TRM",
        options={'HIDDEN'},
        maxlen=255,
    )

    use_setting: BoolProperty(
        name="Example Boolean",
        description="Example Tooltip",
        default=True,
    )

    type: EnumProperty(
        name="Example Enum",
        description="Choose between two items",
        items=(
            ('OPT_A', "First Option", "Description one"),
            ('OPT_B', "Second Option", "Description two"),
        ),
        default='OPT_A',
    )

    def execute(self, context):
        return write_trm_data(context, self.filepath, self.use_setting)


def menu_func_export(self, context):
    self.layout.operator(ExportTRMData.bl_idname, text="TRM Export Operator")

def register():
    bpy.utils.register_class(ExportTRMData)
    bpy.types.TOPBAR_MT_file_export.append(menu_func_export)

def unregister():
    bpy.utils.unregister_class(ExportTRMData)
    bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)

if __name__ == "__main__":
    register()

    bpy.ops.export_tombraider.trm_data('INVOKE_DEFAULT')
After import again a WIP mod and export it again with the new script, the mod works awesome!

thank you so much
mralexmods is offline   Reply With Quote
Old 21-02-24, 15:48   #76
MBJ_01
Member
 
Joined: Feb 2024
Posts: 3
Default

Quote:
Originally Posted by MuruCoder View Post
Yes, just import & export from scratch. Resize & rotate if you need but don't bother with rigging and all.
Hey there, fellas! New member here.

Sorry if I'm jumping onto this, but want to ask a question; so, does this mean I don't need to rig a new mesh and just export it via your TRM script? Or do I have to rig it before exporting?
MBJ_01 is offline   Reply With Quote
Old 21-02-24, 16:02   #77
AmazingOomoo
Member
 
Joined: Feb 2024
Posts: 30
Default

Quote:
Originally Posted by MBJ_01 View Post
Hey there, fellas! New member here.

Sorry if I'm jumping onto this, but want to ask a question; so, does this mean I don't need to rig a new mesh and just export it via your TRM script? Or do I have to rig it before exporting?
A mesh would still need to be rigged with bone weights before exporting, the script doesn't do that for you. You can try bone weight copying from a default mesh but for precise areas such as the shoulder joints you'll probably want to do those bits manually.
AmazingOomoo is offline   Reply With Quote
Old 21-02-24, 16:03   #78
MBJ_01
Member
 
Joined: Feb 2024
Posts: 3
Default

Ah, okay. Got it. Thanks for the response!
MBJ_01 is offline   Reply With Quote
Old 21-02-24, 16:21   #79
MuruCoder
Member
 
MuruCoder's Avatar
 
Joined: Jan 2018
Posts: 1,417
Default

Quote:
Originally Posted by AmazingOomoo View Post
I can't seem to work out how to edit the textures in .dds without them turning completely black in-game?
For textures check out this thread. Basically DDS has many different inner workings so it's not so straightforward getting them right.

Quote:
Originally Posted by mralexmods View Post
thank you so much
You're welcome, happy modding

Quote:
Originally Posted by MBJ_01 View Post
Does this mean I don't need to rig a new mesh and just export it via your TRM script? Or do I have to rig it before exporting?
This depends on what you mean by rigging. You don't necessarily need to create an Armature (or skeleton) if you don't need to test how joints bend. What you need however is to assign vertices of the mesh to Vertex Groups in Blender. These vertex groups need to be in a specific order to work correctly. Even joint names don't matter. Just their vertex assignments and order. Lara outfits need 15 Blender vertex groups. If you import a model from another game, try to match this count and order their vertex groups like this and it might work well enough. For example a character's Right Hand vertex group should be moved to 11th place (or index 10 starting counting from 0).

Code:
0 Hip
1 Thigh left
2 Calf left
3 Foot left
4 Thigh right
5 Calf right
6 Foot right
7 Torso
8 Arm right
9 Elbow right
10 Hand right
11 Arm left
12 Elbow left
13 Hand left
14 Head

Last edited by MuruCoder; 21-02-24 at 16:25.
MuruCoder is offline   Reply With Quote
Old 21-02-24, 16:35   #80
AmazingOomoo
Member
 
Joined: Feb 2024
Posts: 30
Default

Quote:
Originally Posted by MuruCoder View Post
For textures check out this thread. Basically DDS has many different inner workings so it's not so straightforward getting them right.
Thank you!!

I just want to say, your scripts are fantastic. I just made a braid mod for Lara, it took me all of ten minutes to completely replace and re-rig the new braid model and I've put it on Nexus Mods already. Your script worked perfectly, it's so fast to iterate and improve. Thank you for doing this!!
AmazingOomoo is offline   Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 11:07.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Tomb Raider Forums is not owned or operated by CDE Entertainment Ltd.
Lara Croft and Tomb Raider are trademarks of CDE Entertainment Ltd.