Hello Jay,
Can you please check, if the following code fits your needs: the center of the model and center of origin are moved to (0,0,0) point. Center of the model is calculated rather roughly, but should be fine for most cases.
import Metashape
def model_to_region_center(chunk):
model = chunk.model
if not model:
print("No model in chunk, script aborted")
return 0
vertices = model.vertices
T = chunk.transform.matrix
s = chunk.transform.matrix.scale()
step = int(min(1E4, len(vertices)) / 1E4) + 1
sum = Metashape.Vector([0,0,0])
N = 0
for i in range(0, len(vertices), step):
sum += vertices[i].coord
N += 1
avg = sum / N
chunk.region.center = avg
M = Metashape.Matrix().Diag([s,s,s,1])
origin = (-1) * M.mulp(chunk.region.center)
chunk.transform.matrix = Metashape.Matrix().Translation(origin) * (s * Metashape.Matrix().Rotation(T.rotation()))
return 1
chunk = Metashape.app.document.chunk
model_to_region_center(chunk)