我正在尝试制作一个脚本,它基本上可以完成“缩放到框”工具的功能。跟踪选项是没有问题的,因为它不跟踪相机移动。
我在网上找到了这个,修复它可以工作,但不断收到“3d cam position is yet TODO”这很旧,也许有新的选择可以做到这一点?感谢您的提示...
我也可以尝试使用经典的相机命令来做到这一点,例如:
source=GetActiveSource()
#view = GetRenderView()
#view.CameraFocalPoint = [1, 0, 0]
#view.CameraViewAngle = 90
#view.CameraViewUp = [0, 0, 0]
#view.CameraPosition = [0, 0, 0]
#view.ViewSize = [1528, 542]
#view.ResetCamera()
但我不确定有没有办法放大?
上面链接中的固定脚本:
source=GetActiveSource()
rep = Show(source)
# run the pipeline here to get the bounds
Render()
bounds = source.GetDataInformation().GetBounds()
bounds_dx = bounds[1] - bounds[0]
bounds_dy = bounds[3] - bounds[2]
bounds_dz = bounds[5] - bounds[4]
bounds_cx = (bounds[0] + bounds[1])/2.0
bounds_cy = (bounds[2] + bounds[3])/2.0
bounds_cz = (bounds[4] + bounds[5])/2.0
if bounds_dx == 0:
# yz
dimMode = 2
aspect = bounds_dz/bounds_dy
elif bounds_dy == 0:
# xz
dimMode = 1
aspect = bounds_dz/bounds_dx
elif bounds_dz == 0:
# xy
dimMode = 0
aspect = bounds_dy/bounds_dx
else:
# 3d
dimMode = 3
aspect = 1.0 # TODO
lastObj = source
view = GetRenderView()
# view.ViewTime = steps[step] # unwanted
# view.UseOffscreenRenderingForScreenshots = 0 # obsolete
rep = Show(lastObj)
# rep.Representation = 'Outline' # unwanted
Render()
# position the camera
# far = config.camFac
far = 1
near = 0
if dimMode == 0:
# xy
pos = max(bounds_dx, bounds_dy)
camUp = [0.0, 1.0, 0.0]
camPos = [bounds_cx, bounds_cy, pos*far]
camFoc = [bounds_cx, bounds_cy, -pos*near]
elif dimMode == 1:
# xz
pos = max(bounds_dx, bounds_dz)
camUp = [0.0, 0.0, 1.0]
camPos = [bounds_cx, -pos*far, bounds_cz]
camFoc = [bounds_cx, pos*near, bounds_cz]
elif dimMode == 2:
# yz
pos = max(bounds_dy, bounds_dz)
camUp = [0.0, 0.0, 1.0]
camPos = [ pos*far, bounds_cy, bounds_cz]
camFoc = [-pos*near, bounds_cy, bounds_cz]
else:
# 3d
print('3d cam position is yet TODO')
camUp=[0,0,0]
camPos=[1,0,0]
camFoc=[0,0,0]
view = GetRenderView()
view.CameraViewUp = camUp
view.CameraPosition = camPos
view.CameraFocalPoint = camFoc
#view.UseOffscreenRenderingForScreenshots = 0 # obsolete
view.CenterAxesVisibility = 0
ren = Render()
#width = int(config.outputWidth)
#height = int(config.outputWidth*aspect)