Maya-reset_camera
2024年6月9日
python
import maya.cmds as cmds
import maya.mel as mel
def reset_camera(camera):
# 重置指定摄像机的位置、旋转和缩放
cameraTransform = cmds.listRelatives(camera, parent=True)
if cameraTransform:
cmds.setAttr(cameraTransform[0] + ".translate", 0, 0, 0, type="double3")
cmds.setAttr(cameraTransform[0] + ".rotate", 0, 0, 0, type="double3")
cmds.setAttr(cameraTransform[0] + ".scale", 1, 1, 1, type="double3")
def reset_all_cameras():
# 重置场景中的所有摄像机
allCameras = cmds.ls(type='camera')
for camera in allCameras:
reset_camera(camera)
def set_clip_planes(camera, near_clip, far_clip):
# 设置指定摄像机的裁剪平面
cmds.setAttr(camera + ".nearClipPlane", near_clip)
cmds.setAttr(camera + ".farClipPlane", far_clip)
def apply_to_all_cameras(near_clip, far_clip):
# 将裁剪平面设置应用于所有摄像机
for camera in cmds.ls(type='camera'):
set_clip_planes(camera, near_clip, far_clip)
def create_window():
window_name = "CameraClipPlane"
if cmds.window(window_name, exists=True):
cmds.deleteUI(window_name)
cmds.window(window_name, title="CameraClipPlane", widthHeight=(300, 150), sizeable=True)
cmds.columnLayout(adjustableColumn=True)
cmds.text(label="为所有摄像机设置裁剪平面")
cmds.floatFieldGrp('nearClipField', label='近裁剪平面', value1=0.1)
cmds.floatFieldGrp('farClipField', label='远裁剪平面', value1=1000000)
cmds.button(label="应用到所有摄像机", command=lambda x: apply_to_all_cameras(
cmds.floatFieldGrp('nearClipField', query=True, value1=True),
cmds.floatFieldGrp('farClipField', query=True, value1=True)
))
cmds.button(label="重置所有摄像机", command=lambda x: reset_all_cameras())
cmds.showWindow(window_name)
create_window()