Help on snippet
-
Hi I'm trying to convert a python script from blender to C++. The script is used to import 3D data from a file. Things have been going right until I got to this part of the script:
# Generate verts and faces lists, without duplicates
verts = []
coords = {}
index = 0for f in faces:
if f: # Line might be blank
for i, v in enumerate(f):
try:
f[i]= coords[v]
except:
f[i]= coords[v] = index
index += 1
verts.append(v)Since I don't know python, I need help to interpretate this part of the code.
-
Hi I'm trying to convert a python script from blender to C++. The script is used to import 3D data from a file. Things have been going right until I got to this part of the script:
# Generate verts and faces lists, without duplicates
verts = []
coords = {}
index = 0for f in faces:
if f: # Line might be blank
for i, v in enumerate(f):
try:
f[i]= coords[v]
except:
f[i]= coords[v] = index
index += 1
verts.append(v)Since I don't know python, I need help to interpretate this part of the code.
Hi - since my C++ is a bit rusty, I'll give you a pseudocode representation of the snippet:
for each face in faces
do
if "face is not a blank line"
then
for i = 1 to length(face)
do
v = face[i]
if v is not in coords // coords is a hashtable
then
coords.add_item(key=v, value=index)
index += 1
verts.append(v)
fi
face[i] = coords.get_item(key=v)
end for
fi
end forI think that should be it. Hope it helps. Meh, just saw the date on this post - but now I have already typed it, so might as well submit :P
-
Hi - since my C++ is a bit rusty, I'll give you a pseudocode representation of the snippet:
for each face in faces
do
if "face is not a blank line"
then
for i = 1 to length(face)
do
v = face[i]
if v is not in coords // coords is a hashtable
then
coords.add_item(key=v, value=index)
index += 1
verts.append(v)
fi
face[i] = coords.get_item(key=v)
end for
fi
end forI think that should be it. Hope it helps. Meh, just saw the date on this post - but now I have already typed it, so might as well submit :P
It's ok! And thanks, it helped!