简体   繁体   English

Maya python 适合相机视图到网格

[英]Maya python fit camera-view to mesh

I want to fit a camera-view to a mesh from a fixed point.我想将相机视图从固定点拟合到网格。 See attached image.见附图。

Example例子

So I need to adjust the camera rotation, focal length and frame width/height.所以我需要调整相机旋转、焦距和帧宽/高。
What is the best way to do this with python?使用 python 执行此操作的最佳方法是什么?

What you're asking is relatively complex in terms of operation.您要问的操作相对复杂。 You're adjusting multiple camera properties to frame an object.您正在调整多个相机属性以构图 object。

I recommend you decompose the problem into parts and ignore focal length all together.我建议您将问题分解为多个部分并忽略焦距。 Simply transform a camera so it frames the object.只需转换相机,使其构图 object。 You can then add a supplementary step to modify the width and height of the camera to tightly frame it.然后,您可以添加一个补充步骤来修改相机的宽度和高度以紧密地构图。

The gist of what you want to do is as follows:您想要做的事情的要点如下:

  • get bounding box of object获取 object 的边界框
  • get camera aspect ratio获取相机纵横比
  • get active viewport representation获取活动视口表示
  • get camera matrix based on object bounding box and corresponding camera aspect ratio mapped from active viewport获取基于 object 边界框的相机矩阵和从活动视口映射的相应相机纵横比
  • apply matrix to camera将矩阵应用于相机

This will be much easier if you're familiar with the OpenMaya API.如果您熟悉 OpenMaya API,这会容易得多。 The OpenMayaUI.M3dView and the OpenMaya.MFnCamera classes should get you started. OpenMayaUI.M3dView 和 OpenMaya.MFnCamera 类应该可以帮助您入门。

https://help.autodesk.com/view/MAYAUL/2019/ENU/?guid=__py_ref_class_open_maya_u_i_1_1_m3d_view_html https://help.autodesk.com/view/MAYAUL/2019/ENU/?guid=__py_ref_class_open_maya_u_i_1_1_m3d_view_html

https://help.autodesk.com/view/MAYAUL/2019/ENU/?guid=__py_ref_class_open_maya_1_1_m_fn_camera_html https://help.autodesk.com/view/MAYAUL/2019/ENU/?guid=__py_ref_class_open_maya_1_1_m_fn_camera_html

If you're unfamiliar with the API, then scour the mel scripts and check how the FrameSelectedWithoutChildren Runtime Command (F key in the viewport) shortcut works, and use that to automate the process.如果您不熟悉 API,请浏览 mel 脚本并检查 FrameSelectedWithoutChildren 运行时命令(视口中的 F 键)快捷方式的工作原理,并使用它来自动执行该过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM