Hello Julian,
Please try the following script:
#compatibility PhotoScan Professional version 1.3.4
#sets up the bounding box according to four markers
import PhotoScan, math
CORNERS = ["P5", "P6", "P10", "P1"]
def vect(a, b):
result = PhotoScan.Vector([a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y *b.x])
return result.normalized()
def get_marker(label, chunk):
for marker in chunk.markers:
if marker.label.lower() == label.lower():
return marker
return None
doc = PhotoScan.app.document
chunk = doc.chunk #active chunk
region = chunk.region
if chunk.transform.matrix:
T = chunk.transform.matrix
s = chunk.transform.scale
else:
T = PhotoScan.Matrix().Diag([1,1,1,1])
s = 1
points2 = [get_marker(x, chunk).position for x in CORNERS]
new_region = chunk.region
new_center = (points2[0] + points2[1] + points2[2] + points2[3]) / 4.
side1 = points2[0] - points2[1]
side2 = points2[0] - points2[-1]
side1g = T.mulp(points2[0]) - T.mulp(points2[1])
side2g = T.mulp(points2[0]) - T.mulp(points2[-1])
new_size = PhotoScan.Vector([side2g.norm()/s , side1g.norm()/s, new_region.size.z])
horizontal = side2
vertical = side1
normal = vect(vertical, horizontal)
horizontal = -vect(vertical, normal)
vertical = vertical.normalized()
R = PhotoScan.Matrix ([horizontal, vertical, -normal])
new_region.rot = R.t()
new_region.center = new_center
new_region.size = new_size
chunk.region = new_region
print("Finished")
It will use the markers P5, P6, P10, P1 to define the origin of the box and vectors P5 -> P6, P5 -> P1 to define the sides of the box. The vertical size of the box would remain unchanged compared to the original box size.
Let me know which kind of modifications are required for the script, if it works more or less as expected.