【发布时间】:2015-07-20 16:01:04
【问题描述】:
我想用这个文本语法结构将 3D 模型编码到 Blender:
<p>
c(255,84,22)
fs(-1)
p(-9,-8,27)
p(-9,-23,27)
p(-7,-24,63)
p(-7,-11,63)
</p>
与创建网格相关的是:
<p>标记一个人脸容器(就像在 HTML 中一样)c标记颜色-
p标记顶点坐标(每个面容器中最少 3 个) -
</p>标志着脸的尽头 -
fs:忽略这个
显然,网格包含很多这样的面部容器,所以手动创建这个网格真的很浪费时间。 我已经编写了一个工作脚本,但这仅提取坐标并且不包含人脸。
现在我想实现这些面孔,所以我扩展了脚本,但它不起作用:
faces = [] #Array, where all the vertex Indecies from curFace are stored
verts = [] #Array, where all the vertex coordinates from coords are stored
vertIndex = 0
with open(filepath, 'r') as file:
for line in file:
if not line.startswith('<p>'):
continue #Skip lines which don't contain a <p>
if line.startswith('<p>'):
curFace = []
for container in line: #Do a loop while </p> is reached
if container.startswith('p'):
coords = container.strip('\np()/ ').split(',') #Remove certain characters and split line into 3 parts (XYZ)
coords = list(map(float, coords))
verts.append(coords) #Send the vertex coordinates from the current face to verts[]
curFace.append(vertIndex)
vertIndex += 1
elif container.startswith('</p>'):
faces.append(curFace) #Send the vertex Indecies from the current face to faces[]
break #Stop the face-for-loop and return to main line-for-loop
elif not container.startswith('p') or not container.startswith('</p>'):
continue #Skip lines in the container which don't start with 'p' or '</p>'
mesh.from_pydata(verts,[],faces) #Create the entire mesh with the arrays
P.S.:这只是主要部分的摘录。 控制台没有显示错误。有人可以帮我吗?
【问题讨论】:
标签: python text multidimensional-array blender mesh