Hi! I’m importing a model with a python script from a game format; I parent all the different objects of a character/asset to an empty if they have no skeletons. However, when the models are imported fine, the empty parent doesn’t affect their children (moving it doesn’t move the children). The only way I find to update the scene is to add another object using the interface.
I tried using scene_update() in different parts of the script, but doing it doesn’t change the behavior. Would be great if someone knows something quick I can try without having to read my code. If not, I’ll try to make it reproducible and working by itself.
#First meshes and objects are created in blender. buildMesh returns the name in blender.
#object.parent is set in buildObject.
meshes = buildMesh(ModelPath,GameFolder)
objects = buildObject(Meshes = meshes[1], Parent_Name = meshes[0])
for o in objects:
bpy.context.scene.objects.link(o[0])
bpy.context.scene.update()
Please take a look at this code, here’s where I set the parents, please let me know if it’s not clear; I’m still working to make a reproducible example without needing the sample files to be imported.
def buildObject (Meshes, Parent_Name = "Parent", Matrix = [], layer_index = 0,skel_filepath = "", weight_data=""):
import bpy
objects = []
IsParent = True
ob_p = bpy.data.objects.new((Parent_Name),None)
objects.append([ob_p,layer_index,IsParent])
if Meshes == None:
return None
if skel_filepath != "":
bones_list = readSkel(skel_filepath)
#buildSkel(bones_list)
else:
bones_list = []
for index,m in enumerate(Meshes):
ob = bpy.data.objects.new((m),bpy.data.meshes[m])
IsParent = False
ob.parent = ob_p ###############################Parent set
objects.append([ob,layer_index,IsParent])
if bones_list != []:
perBoneWeightList = weightReverse(weight_data[index])
for i in bones_list:
ob.vertex_groups.new(i[1])
for bone_index, weights in perBoneWeightList.items():
for vert_index, weight_value in weights:
ob.vertex_groups[bone_index].add([vert_index],weight_value,'ADD')
if Matrix == []:
ob_p.location = bpy.context.scene.cursor_location
else:
ob_p.matrix_world = Matrix
return objects