alcea

Sims4 Extend fbx Texture to ingame format

Nov 14th, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. extend_texture_(1024_2048)Sims4 (non send to, interactive cmd):
  2. --------------------------------------------------------------
  3.  
  4. extend_texture_(1024_2048)Sims4
  5. ---
  6.  
  7. @echo off
  8. echo Drag and drop the OLD texture file here, then press Enter:
  9. set /p OLD_TEX=
  10. echo Drag and drop the NEW (extended) texture file here, then press Enter:
  11. set /p NEW_TEX=
  12. echo Drag and drop the FBX file here, then press Enter:
  13. set /p FBX_FILE=
  14. :: Path to Blender executable
  15. set "BLENDER_EXE=C:\portableapps\blender36\blender.exe"
  16. :: Run Blender in background with Python script
  17. "%BLENDER_EXE%" --background --python replace_fbx_texture_blender.py -- "%FBX_FILE%" "%OLD_TEX%" "%NEW_TEX%"
  18. pause
  19.  
  20.  
  21.  
  22. replace_fbx_texture_blender.py
  23. ---
  24.  
  25. import bpy
  26. import sys
  27. import os
  28. argv = sys.argv
  29. argv = argv[argv.index("--") + 1:] # arguments after --
  30. if len(argv) != 3:
  31. print("Usage: blender --background --python replace_fbx_texture_blender.py -- FBX_FILE OLD_TEX NEW_TEX")
  32. sys.exit(1)
  33. fbx_path = os.path.abspath(argv[0])
  34. old_tex_path = os.path.abspath(argv[1])
  35. new_tex_path = os.path.abspath(argv[2])
  36. bpy.ops.wm.read_factory_settings(use_empty=True)
  37. bpy.ops.import_scene.fbx(filepath=fbx_path)
  38. for mat in bpy.data.materials:
  39. if mat.node_tree:
  40. for node in mat.node_tree.nodes:
  41. if node.type == 'TEX_IMAGE' and node.image:
  42. img_path = bpy.path.abspath(node.image.filepath)
  43. if os.path.normcase(img_path) == os.path.normcase(old_tex_path):
  44. print(f"Replacing texture in material: {mat.name}")
  45. node.image.filepath = new_tex_path
  46. node.image.reload()
  47. # Original old texture size
  48. old_w, old_h = 519, 507
  49. # New extended texture size
  50. new_w, new_h = 1024, 2048
  51.  
  52. scale_x = old_w / new_w
  53. scale_y = old_h / new_h
  54. offset_x = 0
  55. offset_y = 1 - scale_y # top-left corner
  56.  
  57. for obj in bpy.data.objects:
  58. if obj.type == 'MESH':
  59. mesh = obj.data
  60. for uv_layer in mesh.uv_layers:
  61. for uv in uv_layer.data:
  62. # Scale and offset UV
  63. uv.uv.x = uv.uv.x * scale_x + offset_x
  64. uv.uv.y = uv.uv.y * scale_y + offset_y
  65. fbx_dir, fbx_name = os.path.split(fbx_path)
  66. new_fbx_name = os.path.splitext(fbx_name)[0] + "_new.fbx"
  67. new_fbx_path = os.path.join(fbx_dir, new_fbx_name)
  68.  
  69. bpy.ops.export_scene.fbx(filepath=new_fbx_path, embed_textures=False)
  70. print(f"Saved new FBX to: {new_fbx_path}")
  71.  
  72.  
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment