mp0 = 0
mpy = 0
mpx = 0
fp0 = 0
fpy = 0
fpx = 0
#setting for Y up, Z forward -> needed for mixamo/unity
vector0 = PhotoScan.Vector((0,0,0))
vectorY = PhotoScan.Vector((0,0,distancepy)) # Specify Y Distance
vectorX = PhotoScan.Vector((distancepx,0,0)) # Specify X Distance
c1 = 0
c2 = 0
c3 = 0
c4 = 0
c = 0
for m in chunk.markers:
if m.label == c1target:
log ("Center 1 point found")
c1 = c
if m.label == c2target:
log ("Center 2 point found")
c2 = c
if m.label == c3target:
log ("Center 3 point found")
c3 = c
if m.label == c4target:
log ("Center 4 point found")
c4 = c
if m.label == p0:
mp0 = c
fp0 = 1
m.reference.location = vector0
m.reference.enabled = 1
log ("Found floormat center point")
if m.label == py:
mpy = c
fpy = 1
m.reference.location = vectorY
m.reference.enabled = 1
log ("found floormat Y point")
if m.label == px:
mpx = c
fpx = 1
m.reference.location = vectorX
m.reference.enabled = 1
log ("found floormat X point")
c = c + 1
if fp0 and fpx and fpy:
log ("Found all markers")
chunk.updateTransform()
else:
log ("Error: not all markers found")
newregion = chunk.region
T = chunk.transform.matrix
v_t = T * PhotoScan.Vector( [0,0,0,1] )
m = PhotoScan.Matrix.Diag([1,1,1,1])
m = m * T
s = math.sqrt(m[0,0] ** 2 + m[0,1] ** 2 + m[0,2] ** 2) #scale factor
R = PhotoScan.Matrix( [[m[0,0],m[0,1],m[0,2]], [m[1,0],m[1,1],m[1,2]], [m[2,0],m[2,1],m[2,2]]])
R = R * (1. / s)
newregion.rot = R.t()
# Calculate center point of the bounding box, by taking the average of 2 left and 2 right markers
mx = (chunk.markers[c1].position + chunk.markers[c2].position + chunk.markers[c3].position + chunk.markers[c4].position) / 4
mx = PhotoScan.Vector([mx[0], mx[1], mx[2]])
newregion.center = mx
dist = chunk.markers[mp0].position - chunk.markers[mpy].position
dist = dist.norm()
ratio = dist / distancepy
newregion.size = PhotoScan.Vector([boxwidth* ratio, boxheight* ratio, boxdepth * ratio])
chunk.region = newregion
chunk.updateTransform()
log("Bounding box should be aligned now")