arrays - Blender from_pydata 从文件中读取顶点位置时出错

标签 arrays file blender

我得到了错误;

Error: Array length mismatch (expected 3, got 13)
TypeError: a float is required
Traceback (most recent call last):
File "\Test.py", line 393, in from_pydata
File "C:\Program Files (x86)\Blender Foundation\Blender\2.68\2.68\scripts\modules\bpy_types.py", line 393, in from_pydata
self.vertices.foreach_set("co", vertices_flat)
TypeError: couldn't access the py sequence
Error: Python script fail, look in the console for now...

这是代码:
filePath = "C:\\Users\\siba\\Desktop\\1x1x1.blb"

f = open(filePath)
line = f.readline()

while line:
    if(line == "POSITION:\n"):
        POS1 = f.readline().replace('\n','')

    line = f.readline()
f.close()

coord1 = POS1
Verts = [coord1]


import bpy
profile_mesh = bpy.data.meshes.new("Base_Profile_Data")
profile_mesh.from_pydata(Verts, [], [])
profile_mesh.update()
profile_object = bpy.data.objects.new("Base_Profile", profile_mesh)
profile_object.data = profile_mesh
scene = bpy.context.scene
scene.objects.link(profile_object)
profile_object.select = True

这是 1x1x1.blb:
POSITION:
0.5 0.5 0.5

最佳答案

只是在黑暗中刺伤,因为我没有编写 Blender 脚本,我也懒得去找文档,但我可以想象 Verts需要是一个浮点数列表,并且您提供了一个以空格分隔的字符串,因此这可能有效:

coord1 = POS1.split(' ')
map(float, coord1)
Verts = coord1

关于arrays - Blender from_pydata 从文件中读取顶点位置时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19424846/

相关文章:

arrays - 字符串与数组索引的语法

javascript - Array.prototype.filter(Number) 中的 'Number' 是如何工作的?

postgresql - Bytea 到 postgresql 中的实际文本值

用 C 创建一个简单的配置文件和解析器

python - 从 Blender 中的每个像素读取 Alpha

blender - 如何禁用轴镜并使两半独立?

java - 使用OpenGL和3D建模软件之间的区别

c++ - 我可以查询指针是否是动态分配数组中的第一个吗?

php - 如何将一维数组转换为二维数组

C# 压缩位图大小而不保存它