Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extend_texture_(1024_2048)Sims4 (non send to, interactive cmd):
- --------------------------------------------------------------
- extend_texture_(1024_2048)Sims4
- ---
- @echo off
- echo Drag and drop the OLD texture file here, then press Enter:
- set /p OLD_TEX=
- echo Drag and drop the NEW (extended) texture file here, then press Enter:
- set /p NEW_TEX=
- echo Drag and drop the FBX file here, then press Enter:
- set /p FBX_FILE=
- :: Path to Blender executable
- set "BLENDER_EXE=C:\portableapps\blender36\blender.exe"
- :: Run Blender in background with Python script
- "%BLENDER_EXE%" --background --python replace_fbx_texture_blender.py -- "%FBX_FILE%" "%OLD_TEX%" "%NEW_TEX%"
- pause
- replace_fbx_texture_blender.py
- ---
- import bpy
- import sys
- import os
- argv = sys.argv
- argv = argv[argv.index("--") + 1:] # arguments after --
- if len(argv) != 3:
- print("Usage: blender --background --python replace_fbx_texture_blender.py -- FBX_FILE OLD_TEX NEW_TEX")
- sys.exit(1)
- fbx_path = os.path.abspath(argv[0])
- old_tex_path = os.path.abspath(argv[1])
- new_tex_path = os.path.abspath(argv[2])
- bpy.ops.wm.read_factory_settings(use_empty=True)
- bpy.ops.import_scene.fbx(filepath=fbx_path)
- for mat in bpy.data.materials:
- if mat.node_tree:
- for node in mat.node_tree.nodes:
- if node.type == 'TEX_IMAGE' and node.image:
- img_path = bpy.path.abspath(node.image.filepath)
- if os.path.normcase(img_path) == os.path.normcase(old_tex_path):
- print(f"Replacing texture in material: {mat.name}")
- node.image.filepath = new_tex_path
- node.image.reload()
- # Original old texture size
- old_w, old_h = 519, 507
- # New extended texture size
- new_w, new_h = 1024, 2048
- scale_x = old_w / new_w
- scale_y = old_h / new_h
- offset_x = 0
- offset_y = 1 - scale_y # top-left corner
- for obj in bpy.data.objects:
- if obj.type == 'MESH':
- mesh = obj.data
- for uv_layer in mesh.uv_layers:
- for uv in uv_layer.data:
- # Scale and offset UV
- uv.uv.x = uv.uv.x * scale_x + offset_x
- uv.uv.y = uv.uv.y * scale_y + offset_y
- fbx_dir, fbx_name = os.path.split(fbx_path)
- new_fbx_name = os.path.splitext(fbx_name)[0] + "_new.fbx"
- new_fbx_path = os.path.join(fbx_dir, new_fbx_name)
- bpy.ops.export_scene.fbx(filepath=new_fbx_path, embed_textures=False)
- print(f"Saved new FBX to: {new_fbx_path}")
Advertisement
Add Comment
Please, Sign In to add comment