Guest User

Import JSON emote to blender

a guest
May 26th, 2023
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.90 KB | Source Code | 0 0
  1. import bpy  
  2. import json
  3. import os        
  4.  
  5. # Thanks ЗАРАЗЕН <3
  6.  
  7. emote_path = os.path.expanduser('~') + '\\AppData\\Roaming\\.minecraft\\emotes\\YOUR EMOTE.json'
  8.  
  9. def import_to_blender(emote_path):
  10.     with open(emote_path, "r", encoding="utf-8") as f:
  11.         emote_data = json.load(f)
  12.  
  13.     data = emote_data["emote"]
  14.     bpy.context.scene.frame_start = data["returnTick"]
  15.     bpy.context.scene.frame_end = data["endTick"]
  16.  
  17.     for i in data["moves"]:
  18.        
  19.        
  20.         bpy.context.scene.frame_set(i["tick"])
  21.        
  22.         name = list(i.keys())[3]
  23.  
  24.         bpy.data.objects[name].select_set(True)
  25.        
  26.        
  27.        
  28.         typ = list(i[name].keys())[0]
  29.         value = i[name][typ]
  30.        
  31.        
  32.         if (name == "rightItem" or name == "leftItem"):
  33.             if (typ == "z"):
  34.                 typ = "y"
  35.             elif (typ == "y"):
  36.                 typ = "z"
  37.                
  38.         if (name == "rightItem" or name == "leftItem"):
  39.             if (typ == "roll"):
  40.                 typ = "yaw"
  41.             elif (typ == "yaw"):
  42.                 typ = "roll"
  43.        
  44.        
  45.         if(name == 'rightArm' or name == 'leftArm'):
  46.             if typ == 'y':
  47.                 value -= 12
  48.        
  49.         if(typ == 'z' or typ == 'x'):
  50.             if(name == "rightLeg"):
  51.                 value -= 0.1
  52.             elif(name == "leftLeg"):
  53.                 value += 0.1
  54.        
  55.         if(typ == 'y'):
  56.             if(name == "rightLeg" or name == "leftLeg"):
  57.                 value -= 12
  58.        
  59.         elif (name != "rightItem" and name != "leftItem"):
  60.             pass
  61.         elif(not (name == 'torso' and not (typ == 'roll' or typ == 'bend'))): # rotation correction (*-1) except for torzo roll/bend
  62.             value = value * -1
  63.        
  64.         if(typ == "x" or typ == "y" or typ == "z"):
  65.             if(not name == 'torso'):
  66.                 value = value / 4
  67.                 if (name != "rightItem" and name != "leftItem"):
  68.                     value = value * -1
  69.             else:
  70.                 value = value / 0.25
  71.                 if(typ == 'z'):
  72.                     value = value * -1
  73.        
  74.         if(name == 'head' and typ == 'y'):
  75.             value += 3
  76.        
  77.        
  78.        
  79.        
  80.         if (name == "rightItem" or name == "leftItem"):
  81.             if(typ == "z" or typ == "x"):
  82.                 value = value * -1
  83.        
  84.        
  85.         if (name == "torso" and (typ == "pitch" or typ == "yaw")):
  86.             value = value * -1
  87.        
  88.  
  89.        
  90.        
  91.         if typ == "pitch":
  92.             bpy.data.objects[name].rotation_euler[0] = -value
  93.             bpy.data.objects[name].keyframe_insert(data_path = "rotation_euler")
  94.            
  95.         elif typ == "yaw":
  96.             bpy.data.objects[name].rotation_euler[2] = -value
  97.             bpy.data.objects[name].keyframe_insert(data_path = "rotation_euler")
  98.            
  99.         elif typ == "roll":
  100.             bpy.data.objects[name].rotation_euler[1] = -value
  101.             bpy.data.objects[name].keyframe_insert(data_path = "rotation_euler")
  102.            
  103.         elif typ == "x":
  104.             bpy.data.objects[name].location[0] = value
  105.             bpy.data.objects[name].keyframe_insert(data_path = "location")
  106.            
  107.         elif typ == "y":
  108.             bpy.data.objects[name].location[2] = value
  109.             bpy.data.objects[name].keyframe_insert(data_path = "location")
  110.            
  111.         elif typ == "z":
  112.             bpy.data.objects[name].location[1] = value
  113.             bpy.data.objects[name].keyframe_insert(data_path = "location")
  114.            
  115.         elif typ == "bend":
  116.             bpy.data.objects[name + "_bend"].rotation_euler[0] = -value
  117.             bpy.data.objects[name + "_bend"].keyframe_insert(data_path = "rotation_euler")
  118.            
  119.        
  120.        
  121.         bpy.data.objects[name].select_set(False)
  122.  
  123.     bpy.ops.wm.save_mainfile()
Advertisement
Add Comment
Please, Sign In to add comment