简体   繁体   English

如何通过 Blender python 脚本更新网格数据?

[英]How to update mesh data via blender python script?

I can create a mesh in blender with this script:我可以用这个脚本在搅拌机中创建一个网格:

mesh = bpy.data.meshes.new("mymesh")
obj = bpy.data.objects.new("myobj", mesh)
bpy.context.scene.collection.objects.link(obj)
mesh.from_pydata([[0, 0, 0], [1, 0, 0], [1, 1, 0]], [], [[0, 1, 2]])

However, if I try to update the mesh data with from_pydata again, it results in an error:但是,如果我再次尝试使用from_pydata更新网格数据,则会导致错误:

RuntimeError: internal error setting the array

Is there a way to update the mesh data after the mesh has been created?有没有办法在创建网格后更新网格数据?
(I'm trying to avoid deleting the object and creating it again with new data.) (我试图避免删除对象并使用新数据再次创建它。)

The from_pydata function takes lists of data and creates a mesh data block . from_pydata函数获取数据列表并创建网格数据块 Once you have the mesh data block you can adjust the mesh properties directly.拥有网格数据块后,您可以直接调整网格属性。 These can be found in the vertices , edges andpolygons properties of the mesh data.这些可以在网格数据的verticesedgespolygons属性中找到。

obj.data.vertices[0].co.x = 1.25

Mostly this data should not be directly altered, any changes made while in edit mode will get overwritten as the edit mesh is stored as bmesh data.大多数情况下,不应直接更改此数据,因为编辑网格存储为 bmesh 数据,因此在编辑模式下所做的任何更改都将被覆盖。 The bmesh module provides faster access and methods to alter mesh data and can also update the mesh while in edit mode. bmesh 模块提供了更快的访问和更改网格数据的方法,还可以在编辑模式下更新网格。

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

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