我想将具有此文本语法结构的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。:这只是主要部分的摘录。 控制台显示没有错误。有人可以帮助我吗?
答案 0 :(得分:0)
如果您的样本数据与您的文件匹配,那么循环的基本逻辑就会消失。
循环的逻辑取决于一行上的所有面部数据。
<html lang = "nl">
<head>
<title>Thermostaat P7</title>
<meta charset = "UTF-8" />
</head>
<body>
<h1>Living room</h1>
<form name="thermostat" method="POST">
<fieldset>
<legend>Temperature measurement</legend>
<p>
<?php
$file = file_get_contents('/usr/local/bin/python/Templog', true);
echo "The current temperature is $file °C.";
?>
</p>
</fieldset>
<p>
<fieldset>
<legend>Temperature setting</legend>
<p>
<label for="settemp" class="inline">Desired temperature</label>
<select name="settemp" id="comboA" onChange="getComboA(this)">
<option value=null SELECTED><?php $curSet = file_get_contents('/usr/local/bin/python/Tempset'); echo $curSet; ?> °C </option>
<option value = "12">12 °C</option>
<option value = "16">16 °C</option>
<option value = "19">19 °C</option>
<option value = "19.5">19,5 °C</option>
<option value = "20">20 °C</option>
<option value = "20.5">20,5 °C</option>
<option value = "21">21 °C</option>
<option value = "21.5">21,5 °C</option>
</select>
</p>
</fieldset>
</form>
</body>
</html>