Hello Frank,
Here's the script (mesh model should be generated before the script run):
#Script compatibility - Agisoft PhotoScan Professional v. 1.1.6
import PhotoScan
def calculate_color(z, max, min):
thresh = [(max + 2 * min) / 3, (max + min) / 2, (2 * max + min) / 3, max]
if z < thresh[0]:
r = 0
g = (z - min )/ (thresh[0] - min) * 255
b = 255
color = (r, g, b)
elif z < thresh[1]:
r = 0
g = 255
b = (thresh[1] - z) / (thresh[1] - thresh[0]) * 255
color = (r, g, b)
elif z < thresh[2]:
r = (z - thresh[1]) / (thresh[2] - thresh[1]) * 255
g = 255
b = 0
color = (r, g, b)
else:
r = 255
g = (thresh[3] - z) / (thresh[3] - thresh[2]) * 255
b = 0
color = (r, g, b)
return color
doc = PhotoScan.app.document
chunk = doc.chunk
num = len(chunk.model.vertices)
min, max = 5.1E9, -5.1E9
if not chunk.crs: #Local coordinates
print('Script only works correctly for real coordinate systems\nPerforming script for local coordinates')
PhotoScan.app.messageBox('Script only works correctly for real coordinate systems\nPerforming script for local coordinates')
for i in range (0, num):
p = chunk.model.vertices[i]
vt = chunk.transform.matrix.mulp(p.coord)
if vt.z > max:
max = vt.z
else:
if vt.z < min:
min = vt.z
for i in range (0, num):
p = chunk.model.vertices[i]
vt = chunk.transform.matrix.mulp(p.coord)
p.color = calculate_color(vt.z, max, min)
else: #projected
PhotoScan.app.messageBox("Performing script")
proj = chunk.crs
for i in range (0, num):
p = chunk.model.vertices[i]
vt = chunk.transform.matrix.mulp(p.coord)
vt = proj.project(vt)
if vt.z > max:
max = vt.z
else:
if vt.z < min:
min = vt.z
for i in range (0, num):
p = chunk.model.vertices[i]
vt = chunk.transform.matrix.mulp(p.coord)
vt = proj.project(vt)
p.color = calculate_color(vt.z, max, min)
PhotoScan.app.messageBox("Script finished, please, update view window")
PhotoScan.app.update()