SuperAPI AI 工具集

viewport

编程与开发

查看项目

更新于 11-06 16:23

技能介绍

用途:该技能用于在虚幻编辑器(Unreal Editor)中通过 Python 控制关卡视口(Viewport)的状态与渲染参数,主要围绕 ViewportService 提供的方法完成相机视图类型、视图模式、视野、裁剪面、曝光、布局、实时渲染和相机速度等设置。

主要能力:ViewportService 提供以下方法:get_viewport_info() 获取视口完整状态(类型、相机、FOV、曝光、布局);set_viewport_type(type) 与 get_viewport_type() 切换和读取透视/正交视图;set_view_mode(mode) 与 get_view_mode() 切换和读取渲染模式(lit、unlit、wireframe、detaillighting、lightingonly、lightcomplexity、shadercomplexity、pathtracing、clay);set_fov(degrees) 与 get_fov() 设置和读取视野(5-170,默认 90);set_near_clip_plane(distance) 设置近裁剪面(-1 为引擎默认);set_far_clip_plane(distance) 设置远裁剪面(0 为无限远);set_exposure(fixed, ev100) 设置固定或自动曝光及 EV100 值;set_exposure_game_settings() 重置为自动曝光(游戏设置);set_game_view(enable) 切换游戏视图(隐藏编辑器图标);set_allow_cinematic_control(allow) 允许 Sequencer 控制视口相机;set_realtime(enable) 切换实时渲染;set_camera_speed(speed) 设置相机移动速度(1-8);set_viewport_layout(name) 与 get_viewport_layout() 切换和读取视口布局。

使用方式:在 Python 中导入 unreal 后调用 unreal.ViewportService 的相应方法,例如 unreal.ViewportService.set_viewport_type("perspective") 或 unreal.ViewportService.set_view_mode("wireframe")。相机位置与旋转不再由 ViewportService 提供,已迁移至 Unreal 5.8 的 EditorAppToolset(GetCameraTransform / SetCameraTransform,以及 FocusOnActors 用于聚焦 Actor),需通过 call_tool 调用,可先用 describe_toolset 查看 EditorAppToolset 的动作名称与参数。也可通过 unreal.get_editor_subsystem(unreal.UnrealEditorSubsystem).set_level_viewport_camera_info 设置关卡视口相机信息,注意 Rotator 参数顺序为 (Roll, Pitch, Yaw),建议使用关键字参数。示例脚本位于 scripts/set_camera.txt,可通过 execute_python_code 运行。

关键规则:set_viewport_type 仅接受 "perspective"、"top"、"bottom"、"left"、"right"、"front"、"back"(大小写不敏感),不接受 "ortho"、"iso" 等;set_view_mode 仅接受 "lit"、"unlit"、"wireframe"、"detaillighting"、"lightingonly"、"lightcomplexity"、"shadercomplexity"、"pathtracing"、"clay";set_viewport_layout 仅接受 "OnePane"、"TwoPanesHoriz"、"TwoPanesVert"、"ThreePanesLeft"、"ThreePanesRight"、"ThreePanesTop"、"ThreePanesBottom"、"FourPanesLeft"、"FourPanesRight"、"FourPanesTop"、"FourPanesBottom"、"FourPanes2x2"、"Quad"(Quad 为 FourPanes2x2 别名)。FOV 仅在透视模式下生效,正交视图下设置无效,应先切换到透视。set_realtime(False) 时视口仅在交互时重绘,所有 ViewportService 方法会在修改后强制重绘,但用户不会看到连续动画/粒子,直到重新启用实时。多窗格布局下 get_viewport_info().is_realtime 读取的是活动窗格,若活动窗格不是主窗格,set_realtime(True) 可能成功但读回 False,建议在 OnePane 布局下验证实时状态,或在分屏布局中不要依赖该读回值进行逻辑判断;其他字段(视图类型、FOV、相机)跨布局读回正常。

适用场景:检查当前视口状态;循环切换正交视图;切换到四窗格布局再切回;为建筑评审设置透视窄 FOV、游戏视图、固定曝光和实时渲染;使用线框模式检查网格拓扑;设置裁剪面进行特写或远距离渲染优化;固定曝光进行光照评审;通过 EditorAppToolset 或 UnrealEditorSubsystem 定位相机;聚焦特定 Actor。

限制:资料未提供收费、价格、平台版本、安装命令等细节。相机位置与旋转需使用 engine EditorAppToolset(通过 call_tool),ViewportService 不再提供 set_camera_location / set_camera_rotation。FOV 在正交视图无效。多窗格下实时状态读回存在已知注意事项。