• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

MDX_Texturelist

This bundle is marked as pending. It has not been reviewed by a staff member yet.
MDX_Texturelist is a tool I made (with ChatGPT assistance) to automatically use MdxConv to convert all mdx files in a folder, separate the mdx files and mdl files into separate directories, and output a TextureList.txt file in the root directory that contains all textures used by all the models that were processed.

Why is this necessary you ask? I have loads of maps that have lots of unused resources in them. To figure out what mdx files are in use is relatively easy to narrow down, but opening each of those mdx files with a model editor to check what textures they all use is a tedious process, which led me to create this tool. With this you can easily find out exactly what textures are in use, and delete the ones that aren't (just remember to not delete textures that aren't in use by models such as UI textures, map textures and so on).

NOTE: Finding out what models are used in a map is quite easy, so the tool doesn't do this. Basically you select an object in-editor, click "Edit>View in object editor", copy its model path, search for it in your map (which should be saved as a folder), then drag it out of the map. Once you have done that, while still having the object selected, choose "Edit>Select all special" and then hit DEL. Repeat with all objects until your map is empty. Ofc this doesn't include models created by spawn effects and such, so try to be aware of that.

Limitations: When processing too many models the program won't properly function. Batches of 50 should work just fine.

I'll leave the original Python code here in case anyone wants to inspect it (improvements are very welcome).

How to use it:
  1. Have the MDX_Texturelist.exe in the same folder as the mdx files you want to process (sub folders are not processed).
  2. Make sure MdlxConv is also in the same folder.
  3. Run MDX_Texturelist.exe.

Requirements: https://www.hiveworkshop.com/threads/mdlx-converter.62991/

Python:
import os
import re
import subprocess
import shutil
import time
import pyautogui

mdx_files = [f for f in os.listdir() if f.endswith('.mdx')]

processes = []
for i, mdx_file in enumerate(mdx_files):
    p = subprocess.Popen(['MdlxConv.exe', mdx_file])
    processes.append(p)
    if i == len(mdx_files) - 1:
        # start timer when processing the last mdx file
        time.sleep(1)
        # Get a list of all currently open windows
        windows = pyautogui.getAllWindows()
        # Loop through all windows
        for window in windows:
            # Check if window name matches any of the specified names
            if window.title in ["Assertion failure", "Conversion Result", "Warcraft III Mdlx Converter 1.03"]:
                # Close the window
                window.close()
        time.sleep(2)
        # run code to create texture list
        root_dir = os.getcwd()
        output_file = os.path.join(root_dir, 'TextureList.txt')

        unique_images = set()

        with open(output_file, 'w') as outfile:
            for root, dirs, files in os.walk(root_dir):
                for filename in files:
                    if filename.endswith('.mdl'):
                        filepath = os.path.join(root, filename)
                        with open(filepath, 'r') as infile:
                            mdl_contents = infile.read()
                            pattern = r'Image\s+"([^"]+)"'
                            matches = re.findall(pattern, mdl_contents)
                            for match in matches:
                                if match not in unique_images:
                                    unique_images.add(match)
                                    outfile.write(f'{match}\n')

# wait for all MdlxConv processes to finish
for p in processes:
    p.wait()

# create new directories if they don't exist
if not os.path.exists('mdl files new directory'):
    os.mkdir('mdl files new directory')
if not os.path.exists('mdx files new directory'):
    os.mkdir('mdx files new directory')

# move files to new directories
for f in os.listdir():
    if f.endswith('.mdl') or f.endswith('.mdx'):
        # check if file is currently being used by a process
        file_used = False
        for p in processes:
            if p.poll() is None and f in p.args:
                file_used = True
                break
        if not file_used:
            if f.endswith('.mdl'):
                shutil.move(f, 'mdl files new directory')
            elif f.endswith('.mdx'):
                shutil.move(f, 'mdx files new directory')

  • 30.03.2023 - Uploaded
Contents

MDX_Texturelist (Binary)

Hello,
Aren't those features already available with this tool? : Model Optimizer and Converter v1.2.1
EDIT: Well it doesn't output a "TextureList.txt file in the root directory that contains all textures used by all the models that were processed." so that's a plus.
Sure, bulk converting models isn't something new. This tool is only for the texture list.
 
Top