I'm trying to fit the mesh of a human model with the MPFB Plugin until it has the same dimensions as a real world human (data read out of biplanar X-ray images and imported from matlab).
The program should check at every iteration if there is a difference between Blender model and real model and adapt the meshes step by step until it's of the same size. However, the meshes data (or coordinates of vertices) is not updated, even though the model visibly changes size, because the function "distance" gives the same output at every iteration. A while loop is too much for Blender here, therefore I'm using for loops. In this case it just loops through 20 times instead of stopping when equality is reached.
How can I make it update at every iteration?
mat = loadmat(r'P:\userspace\...\00_ToUse\mesh_sizes_mat.mat')
#define distance between two vertices function
def distance(point1, point2) -> float:
return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2)
#define how to find coordinates
obj = context.active_object
v = obj.data.vertices[0]
coords = [(obj.matrix_world @ v.co) for v in obj.data.vertices]
# To change the measure targets the model has to be in "Object mode"
bpy.ops.object.mode_set(mode='OBJECT')
thigh1 = coords[11071] #front
thigh2 = coords[11073] #back
thigh_front_back = distance(thigh1 , thigh2)
#loop until mesh of model equals data from mat
for i in range(1,20):
if thigh_front_back < mat.get('size_thigh_front_back') and abs(thigh_front_back-mat.get('size_thigh_front_back')) > 0.02:
bpy.data.scenes["Scene"].legs_l_upperleg_scale_depth_decr_incr += 0.02
obj.data.update()
thigh_front_back = distance(thigh1 , thigh2)
elif thigh_front_back > mat.get('size_thigh_front_back') and abs(thigh_front_back-mat.get('size_thigh_front_back')) > 0.02:
bpy.data.scenes["Scene"].legs_l_upperleg_scale_depth_decr_incr -= 0.02
obj.data.update()
thigh_front_back = distance(thigh1 , thigh2)
else:
print('Outline has been fitted')
break
coords = [(obj.matrix_world @ v.co) for v in obj.data.vertices]
andthigh1 = coords[11071]
etc. not be within thefor
loop? Now the coordinates are only collected once and the distance between two vertices will always be the same. $\endgroup$