import maya.standalone
maya.standalone.initialize()
import maya.cmds as cmds
import math
# Open the Maya file
file_path = '/path/to/your/file.ma'
cmds.file(file_path, open=True, force=True)
# Set the desired view
view_name = 'persp'
cmds.modelEditor(view_name, edit=True, camera=view_name)
# Set the target object name
target_object = 'my_object'
# Get the bounding box of the target object
bbox = cmds.exactWorldBoundingBox(target_object)
# Calculate the camera position and look at point
center = [(bbox[0] + bbox[3]) / 2, (bbox[1] + bbox[4]) / 2, (bbox[2] + bbox[5]) / 2]
distance = max(bbox[3] - bbox[0], bbox[4] - bbox[1], bbox[5] - bbox[2]) * 2
# Set the camera position and look at point
cmds.viewPlace(view_name, distance=distance, focusPoint=center)
# Set the image resolution
width = 1920
height = 1080
cmds.setAttr('defaultResolution.width', width)
cmds.setAttr('defaultResolution.height', height)
# Capture the view and save as an image
output_path = '/path/to/save/image.png'
cmds.playblast(frame=1, format='image', viewer=False, offScreen=True, framePadding=4, completeFilename=output_path)
# Close the Maya application
maya.standalone.uninitialize()
伪代码 maya batch 为 物体 拍照
最新推荐文章于 2024-05-23 22:15:57 发布