class Material(_NodeType):
TYPE_NAME = 'MATERIAL'
TYPE_ID = 0x08
ref_no = _FieldInt('MATERIAL_REF_NO')
name = _FieldString('MATERIAL_NAME')
cls = _FieldString('MATERIAL_CLASS')
ambient = _FieldInt('MATERIAL_AMBIENT', asciirepr='hex')
diffuse = _FieldInt('MATERIAL_DIFFUSE', asciirepr='hex')
specular = _FieldInt('MATERIAL_SPECULAR', asciirepr='hex')
shine = _FieldFloat('MATERIAL_SHINE')
shinestrength = _FieldFloat('MATERIAL_SHINESTRENGTH')
transparency = _FieldFloat('MATERIAL_TRANSPARENCY')
wiresize = _FieldFloat('MATERIAL_WIRESIZE')
shading = _FieldInt('MATERIAL_SHADING')
xp_fallof = _FieldFloat('MATERIAL_XP_FALLOFF')
selfillum = _FieldFloat('MATERIAL_SELFILLUM')
fallof = _FieldInt('MATERIAL_FALLOF')
xp_type = _FieldInt('MATERIAL_XP_TYPE')
texture_list = _FieldSubnode('TEXTURE_LIST', TextureList, optional=True)
material_list = _FieldSubnode('MATERIAL_LIST', MaterialList, optional=True)
And the API for loading a binary GMF and iterating over some materials looks like this:
with open('/home/q3k/Games/RA2/Robot Arena 2 v1.4/Components/cannon/cannon.gmf', 'rb') as f:
g = GMI()
g.from_binary(f)
print('Scene information:')
print(g.scene)
print('Materials:')
for material in g.material_list.materials:
print("-> " + str(material))
if material.texture_list:
print(" Has textures:")
for texture in material.texture_list.textures:
print(" -> " + str(texture))
else:
print(" No textures.")
if material.material_list:
print(" Has submaterials:")
for submaterial in material.material_list.materials:
print(" -> " + str(submaterial))
else:
print(" No submaterials.")
That would display:
q3k@anathema ~/Projects/pyra25/pyra25 $ python gmf.py
Scene information:
<pyra25.SCENE: SCENE_FILENAME=cannonMapped.max, SCENE_FIRSTFRAME=0, SCENE_LASTFRAME=100...>
Materials:
-> <pyra25.MATERIAL: MATERIAL_REF_NO=0, MATERIAL_NAME=11 - Default, MATERIAL_CLASS=Standard...>
No textures.
No submaterials.
-> <pyra25.MATERIAL: MATERIAL_REF_NO=1, MATERIAL_NAME=6 - Default, MATERIAL_CLASS=Standard...>
Has textures:
-> <pyra25.TEXTURE: MAP_NAME=Map #10, MAP_CLASS=Bitmap, BITMAP=cannon.tga...>
No submaterials.
-> <pyra25.MATERIAL: MATERIAL_REF_NO=2, MATERIAL_NAME=5 - Default, MATERIAL_CLASS=Standard...>
Has textures:
-> <pyra25.TEXTURE: MAP_NAME=Map #9, MAP_CLASS=Bitmap, BITMAP=cannonball.tga...>
No submaterials.
No idea when this will be done. I'm at the boring part where I'm going over all node types and implementing them. Nice part is that once this is done, we can hopefully autogenerate some pretty concise documentation on the GMF/GMA file format!