Advertisement
artemx32

GMOD STARFALL MESHES CONVERTER

Nov 11th, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | Gaming | 0 0
  1. #converter_v2.py
  2. import os
  3. import shutil
  4. from pathlib import Path
  5. destination_dir = 'noload__obj_to_txt'
  6. module_name = "MODULE_statim_vehicle"
  7. print(f"\n\nPython .obj converter to GMOD StarfallEx include structure to avoid using server meshes hosting. Usage: put this script to folder with your .obj meshes and call it. Script will convert all existing .obj files in current directory and put it via starfallEx structure inside inner directory called as variable module_name ({module_name})\n\n")
  8. script = """
  9. --@name """ + module_name + """
  10. --@shared
  11.    -- powered by python obj module generator by artybyte (2024)
  12.    local MODULE = { }
  13. """
  14. Path(module_name).mkdir(parents=True, exist_ok=True)
  15. for filename in os.listdir('.'):
  16.     if filename.endswith('.obj'):
  17.         file_name = os.path.basename(filename)
  18.         file_name = file_name.__str__()
  19.         with open(filename) as f:
  20.             file = f"""
  21.            --@name {file_name}
  22.            --@shared
  23.            
  24.            local model = [[{f.read()}]]
  25.            
  26.            return model
  27.            """
  28.             mdl = open(f"{module_name}/{file_name}.txt", "w")
  29.             mdl.write(file)
  30.             mdl.close()
  31.        
  32.         script = script + f"""
  33.            --@include {module_name}/{file_name}.txt
  34.            local model_ = require('{module_name}/{file_name}.txt')
  35.            MODULE["{file_name}"] = model_
  36.        """
  37. script += "\n\n\n"
  38. script += "return MODULE"
  39. f = open(f"{module_name}/entry_point.txt", "w")
  40. f.write(script)
  41. f.close()
  42. print(f"Conversion done successfully inside folder {module_name}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement