Mar-01-2024, 11:38 AM
I would like to preprocess some very large OBJ file see https://en.wikipedia.org/wiki/Wavefront_.obj_file.
In python I would like to preprocess the file before using a c++ routine to process vertex and face definition.
Specifically I would like to create a python dictionary or array of the following information
materials : usemtl {material} rest of line
objects : o {name} rest of line
groups : g {name} rest of line
examples
usemtl copper
o fredObj
g fredGroup
In the case of objects and groups, the associated material
I tried something like
I could loop through processing every line but these are potentially very large files and think there must be a better way,
In python I would like to preprocess the file before using a c++ routine to process vertex and face definition.
Specifically I would like to create a python dictionary or array of the following information
materials : usemtl {material} rest of line
objects : o {name} rest of line
groups : g {name} rest of line
examples
usemtl copper
o fredObj
g fredGroup
In the case of objects and groups, the associated material
I tried something like
def processOBJ(doc, filename): import re print("import OBJ as GDML Tessellated") fp = pythonopen(filename) data = fp.read() materials = re.findall('usemtl',data) print(f"Materials {materials}") objects = re.findall('o',data) print(f"objects {objects}") groups = re.findall('g',data) print(f"groups {groups}") returnWhich finds thing okay but I am not sure how I could access the rest of the line.
I could loop through processing every line but these are potentially very large files and think there must be a better way,