概括
本文介绍了如何使用 Python 生成和查询场景图数据(例如位置属性)。
更多信息
用户可能希望编写 Python 脚本来查询场景图位置上的属性值。为了实现这一点,必须首先对场景进行烹饪。厨师代表场景图的评估,这意味着必须评估节点图才能计算场景数据。如果不执行此步骤,则属性数据不存在,无法查询。
这可以通过创建Geolib3 客户端来实现,该客户端可以请求生成场景数据。请看下面的例子:
# We first need to get a hold of the runtime the UI is using runtime = FnGeolib.GetRegisteredRuntimeInstance() # Transactions are used to batch together actions txn = runtime.createTransaction() # Make a client, and attach it to an Op in the tree, we get the Op from a reference to a Node. client = txn.createClient() op = Nodes3DAPI.GetOp(txn, NodegraphAPI.GetNode('Render')) txn.setClientOp(client, op) # Commit the transaction to the runtime, if we don't the client will exist, but won't yet be pointing to an Op runtime.commit(txn)
然后,您可以使用客户端来烹饪位置并检查其属性值,例如获取相机位置的centerOfInterest属性:
location = client.cookLocation('/root/world/cam/camera')
attrs = location.getAttrs()
COI = attrs.getChildByName('geometry.centerOfInterest')
print(COI.getValue())
有关 Geolib3 和 Op API 的更多详细信息,请参阅Katana用户指南 的 Op API 部分。
请注意,烘焙场景图可能是一项计算成本高昂的操作。应特别注意避免不必要的烹饪。例如,不建议为每个节点图更改自动进行烹饪,但在用户触发的事件(如按钮脚本)中进行烹饪就可以了。
如果您发现自己想要进行大量烹饪以实现所需的工作流程,请考虑使用 Op 或 OpScript 的不同方法。通过将问题分解为几个协同工作的操作,可以实现许多工作流程。
如果您还有其他问题,或者在找到查询属性的正确工作流程时遇到任何问题,请打开支持票证并让我们知道您遇到的问题或您想要实现的所需工作流程。
有关如何开立支持票证的更多信息,请参阅Q100064:如何提出支持票证。
我们很遗憾听到
请告诉我们