gpt4 book ai didi

python - 如何在maya中查询当前视口(viewport)渲染器

转载 作者:太空宇宙 更新时间:2023-11-03 12:59:35 27 4
gpt4 key购买 nike

有人有好的解决方案可以在 python 中查询当前的 maya 视口(viewport)渲染器(Viewport 2.0、默认视口(viewport)、高质量视口(viewport))吗?

最佳答案

@Tomek 的回答将非常有效。如果你要走 PyMEL 路线,你可以这样做:

import pymel.core.uitypes as pmui

model_panel = pmui.ModelEditor(pm.getPanel(withFocus=True))
print pmui.ModelEditor.getRendererName(model_panel)

不过,那段话似乎有些喜怒无常。它有时会抛出错误,提示找不到模型编辑器,尤其是在现成的情况下执行时。

另一种方式会有点罗嗦,但它每次都有效:

import pymel.core as pm
import pymel.core.uitypes as pmui

modelPanelList = []
modelEditorList = pm.lsUI(editors=True)
for myModelPanel in modelEditorList:
if myModelPanel.find('modelPanel') != -1:
modelPanelList.append(myModelPanel)

for modelPanel in modelPanelList:
if pmui.ModelEditor(modelPanel).getActiveView():
try:
# Always better to try in the case of active panel operations
# as the active panel might not be a viewport.
print pmui.ModelEditor(modelPanel).getRendererName()
except Exception as e:
# Handle exception
print e

一种简洁的伪 PyMEL 方法是 PyMEL 化 Tomek 的回答:

import pymel.core as pm
print pm.modelEditor(pm.getPanel(wf=True), q=True, rnm=True)

获取视口(viewport)渲染器列表:

import pymel.core.uitypes as pmui
print pmui.ModelEditor().getRendererList()

这里有一些关于模型编辑器和视口(viewport)渲染器的额外信息。要获得他们的“友好”名称:

import pymel.core.uitypes as pmui
print pmui.ModelEditor().getRendererListUI()

要简明扼要地设置它们,我会使用 PyMEL 并执行以下操作:

import pymel.core.uitypes as pmui

# assuming you know which modelPanel you want to affect
pmui.ModelEditor("modelPanel4").setRendererName("ogsRenderer")

要影响所有视口(viewport)(模型面板),我会这样做:

import pymel.core as pm
import pymel.core.uitypes as pmui

modelPanelList = []
modelEditorList = pm.lsUI(editors=True)
for myModelPanel in modelEditorList:
if myModelPanel.find('modelPanel') != -1:
modelPanelList.append(myModelPanel)

for modelPanel in modelPanelList:
pmui.ModelEditor(modelPanel).setRendererName("ogsRenderer")

仅影响焦点中的视口(viewport):

import pymel.core as pm
import pymel.core.uitypes as pmui

modelPanelList = []
modelEditorList = pm.lsUI(editors=True)
for myModelPanel in modelEditorList:
if myModelPanel.find('modelPanel') != -1:
modelPanelList.append(myModelPanel)

for modelPanel in modelPanelList:
if pmui.ModelEditor(modelPanel).getActiveView():
try:
# Always better to try in the case of active panel operations
# as the active panel might not be a viewport.
pmui.ModelEditor(modelPanel).setRendererName("ogsRenderer")
except Exception as e:
# Handle exception
print e

关于python - 如何在maya中查询当前视口(viewport)渲染器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27290602/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com