gpt4 book ai didi

python - 强制 matrix_world 在 Blender 中重新计算

转载 作者:太空狗 更新时间:2023-10-30 02:12:44 31 4
gpt4 key购买 nike

我正在为 blender 设计一个附加组件,它可以更改对象某些顶点的位置。 Blender 中的每个对象都有一个 matrix_world 属性,它包含一个矩阵,该矩阵将顶点坐标从对象转置到世界坐标系。

print(object.matrix_world) # unit matrix (as expected)
object.location += mathutils.Vector((5,0,0))
object.rotation_quaternion *= mathutils.Quaternion((0.0, 1.0, 0.0), math.radians(45))
print(object.matrix_world) # Also unit matrix!?!

上面的代码片段表明,在翻译之后,您仍然拥有相同的 matrix_world。我如何强制 blender 重新计算 matrix_world?

最佳答案

你应该调用Scene.update更改这些值后,否则 Blender 不会重新计算 matrix_world 直到需要 [其他地方]。原因,根据"Gotcha's" section在 API 文档中,这种重新计算是一项昂贵的操作,因此不会立即完成:

Sometimes you want to modify values from python and immediately access the updated values, eg:

Once changing the objects bpy.types.Object.location you may want to access its transformation right after from bpy.types.Object.matrix_world, but this doesn’t work as you might expect.

Consider the calculations that might go into working out the objects final transformation, this includes:

  • animation function curves.
  • drivers and their pythons expressions.
  • constraints
  • parent objects and all of their f-curves, constraints etc.

To avoid expensive recalculations every time a property is modified, Blender defers making the actual calculations until they are needed.

However, while the script runs you may want to access the updated values.

This can be done by calling bpy.types.Scene.update after modifying values which recalculates all data that is tagged to be updated.

关于python - 强制 matrix_world 在 Blender 中重新计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13840418/

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