import struct from PIL import Image import io import os import lzma imgName = "ceedee" hdr = "#ifndef _LI_"+imgName.upper()+"_H\n" hdr += "#define _LI_"+imgName.upper()+"_H 1\n" hdr += "#include \"vec.hpp\"\n" hdr += "#include \n" def read3D(vboName): global hdr with open(vboName + ".vbo", "rb") as vbo: totalVertex, totalIndex = struct.unpack("II", vbo.read(4 * 2)) hdr += "const uint32_t "+imgName+"ModelTotalVertices = "+hex(totalVertex)+";\n" hdr += "const uint32_t "+imgName+"ModelTotalIndices = "+hex(totalIndex)+";\n" verticies = [] indicies = [] for i in range(0, totalVertex): posX, posY, posZ = struct.unpack("fff", vbo.read(4 * 3)) norX, norY, norZ = struct.unpack("fff", vbo.read(4 * 3)) texX, texY = struct.unpack("ff", vbo.read(4 * 2)) verticies.append("{ Vec3({"+str(posX*30.0)+"f, "+str(posY*30.0)+"f, "+str(posZ*30.0)+"f}), Vec2({"+str(texX)+"f, "+str(texY)+"f}) }") for i in range(0, totalIndex): index = struct.unpack("H", vbo.read(2)) indicies.append(hex(index[0])) hdr += "static ModelVertex "+imgName+"ModelVertexBuffer["+imgName+"ModelTotalVertices] { "+", ".join(verticies)+"};\n" hdr += "static uint16_t "+imgName+"ModelIndexBuffer["+imgName+"ModelTotalIndices] { "+", ".join(indicies)+" };\n" read3D(imgName) hdr += "#endif" print(hdr)