【问题标题】:Blender from_pydata error with reading vertex positions from fileBlender from_pydata 错误,从文件中读取顶点位置
【发布时间】:2013-10-25 19:58:42
【问题描述】:

我得到了错误;

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 是一个 Python 脚本程序。你能指出我可能违反的一条潜在规则吗?
  • 我没有注意到脚本;请把它作为你问题的一部分,这样它就更明显了。你可能没有违反规则;这些东西不是非黑即白的。
  • 并且类型错误通常通过强制转换来解决; coord1 = float(POS1) 可能会这样做。
  • 啊。我把它放在海盗垫上,因为它正常显示很糟糕。

标签: arrays file blender


【解决方案1】:

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

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

【讨论】:

  • 不,仍然得到'需要浮动':s
  • 它是 python 3,所以不确定map 仍然存在。但想法是正确的,尝试使用循环迭代数组并将每个元素转换为浮点数。如果您遇到错误,请具体说明在哪里 - 很难预测您已经进行了哪些修改。
猜你喜欢
  • 2015-01-29
  • 2021-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多