Skip to content

Instantly share code, notes, and snippets.

@Modder4869
Last active July 20, 2022 21:21
Show Gist options
  • Save Modder4869/b85e33b7c67a3705e663b2e446984c39 to your computer and use it in GitHub Desktop.
Save Modder4869/b85e33b7c67a3705e663b2e446984c39 to your computer and use it in GitHub Desktop.
import bpy
# make sure to append shader first or uncomment the following lines and change path
# with bpy.data.libraries.load(
# "D:\Xodd\Blender-miHoYo-Shaders\miHoYo - Genshin Impact.blend"
# ) as (data_from, data_to):
# data_to.materials = data_from.materials
def findDressMaterialName(matName):
for material in bpy.data.materials:
if matName in material.name:
x = material.node_tree.nodes['Principled BSDF'].inputs['Base Color'].links[0].from_node.image.name_full
#split reverse string ]
#print(x)
return x.replace('Tex_',"").split('_')[::-1][1]
else:
pass
# deselect all
bpy.ops.object.select_all(action='DESELECT')
# set body to active
bpy.context.view_layer.objects.active = bpy.data.objects["Body"]
#select body
bpy.data.objects["Body"].select_set(state=True, view_layer=None)
meshes = ["Body", "EyeStar", "EffectMesh"]
# select anything thats not Body , EyeStar,EffectMesh
for object in bpy.context.scene.objects:
if not object.name in meshes and object.type == "MESH":
object.select_set(state=True, view_layer=None)
#join mesh
bpy.ops.object.join()
# link materials
try:
for object in bpy.data.objects:
name = object.name
if "Body" in name:
for materialSlot in object.material_slots:
if "Body" in materialSlot.name:
materialSlot.material = bpy.data.materials["miHoYo - Genshin Body"]
elif "Face" in materialSlot.name:
materialSlot.material = bpy.data.materials["miHoYo - Genshin Face"]
elif "Hair" in materialSlot.name:
materialSlot.material = bpy.data.materials["miHoYo - Genshin Hair"]
elif "Dress" in materialSlot.name:#is it Body or Hair i have no idea
matName = materialSlot.name.split('_')[-1]
materialSlot.material = bpy.data.materials["miHoYo - Genshin " + findDressMaterialName(matName)]
else:
pass
except Exception as e:
print("MAKE SURE TO APPEND FILE FIRST\n")
raise
# select all empty objects
bpy.ops.object.select_by_type(type="EMPTY")
if 'Face Light Direction' in bpy.data.objects:
bpy.data.objects['Face Light Direction'].select_set(state=False,view_layer=None)
if 'Head Driver' in bpy.data.objects:
bpy.data.objects['Head Driver'].select_set(state=False,view_layer=None)
if 'Main Light Direction' in bpy.data.objects:
bpy.data.objects['Main Light Direction'].select_set(state=False,view_layer=None)
if 'Head Forward' in bpy.data.objects:
bpy.data.objects['Head Forward'].select_set(state=False,view_layer=None)
if 'Head Up' in bpy.data.objects:
bpy.data.objects['Head Up'].select_set(state=False,view_layer=None)
# delete them
bpy.ops.object.delete()
#hides EyeStar and EffectMesh
if 'EffectMesh' in bpy.data.objects:
bpy.data.objects['EffectMesh'].hide_set(True)
if 'EyeStar' in bpy.data.objects:
bpy.data.objects['EyeStar'].hide_set(True)
#run genshin texture import script , uncomment the lines if u dont want to manually run file and change path
#bpy.ops.script.python_file_run(filepath="D:\Xodd\Blender-miHoYo-Shaders\scripts\genshin-import-linear.py")
#set view transform to standard
bpy.context.scene.view_settings.view_transform = 'Standard'
#rotate it (not sure about the values yet)
bpy.ops.object.select_all(action='DESELECT')
for object in bpy.data.objects:
if object.type == 'ARMATURE':
print(object.name)
object.select_set(state=True)
bpy.ops.transform.rotate(value=1.5708, orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment