Hello.
I’ve recently been updating an old import/export plugin written by someone else. It deals with meshes stored in text format. I think I’ve gotten the exporter working correctly but I’m having trouble with the importer. The existing code already parses the file and generates python data, but I can’t quite get my head round converting them to meshes.
Here’s an example of what it generates:
(there can be multiple meshes, the existing loop for all of them calls them “obj” )
'NAME': '@h01',
'POINTS': [(-0.439504, -0.058225, 0.76561), (-0.439504, -0.058225, 0.882061), (-0.439504, 0.058225, 0.76561), (-0.439504, 0.058225, 0.882061), (-0.323053, -0.058225, 0.76561), (-0.323053, -0.058225, 0.882061), (-0.323053, 0.058225, 0.76561), (-0.323053, 0.058225, 0.882061)],
'FACES': [
{'VISIBILITY': 'N', 'MATERIAL': 0, 'VERTICES': (5, 6, 7), 'UV': ((0.625, 0.75), (0.375, 0.5), (0.625, 0.5))},
{'VISIBILITY': 'N', 'MATERIAL': 0, 'VERTICES': (1, 4, 5), 'UV': ((0.625, 1.0), (0.375, 0.75), (0.625, 0.75))},
...(one of each above line for each face)...
]
Visiblity seems redundant (it always seems to be N)
Material will be the face’s material index, and is related to a set of materials that are specified elsewhere in the file.
Vertices refer to the indices in the points array and UV is the UV mapping.
I’ve been searching around but I think I’m going round in circles, which is funny because I’m sure the answer lies in loops.
So far I’ve been able to generate meshes (but with no UV mapping or materials) with this code:
for obj in <some list>:
faces = []
for f in obj['FACES']:
faces.append(f['VERTICES']) # only get the vertex IDs
mesh = bpy.data.meshes.new(obj['NAME'])
mesh.from_pydata(obj['POINTS'], [], faces)
mesh.uv_layers.new() #probably needed for the UV coords, definitely for the exporter
Can anyone advise me on what I should be doing to get all the data in? Is the above code a good start with just a couple of extra things needed, or is there a much better approach, such as take off and nuke the site from orbit?