feat: rewrite to c

This commit is contained in:
2026-04-01 23:51:02 +02:00
parent a13a9c5489
commit f19e61b585
10 changed files with 1136 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
# Open the file in read mode
file = open("test.obj", "r")
file = open("plane.obj", "r")
# Read the entire content of the file
content = file.read().split("\n")
@@ -8,13 +8,13 @@ file.close()
startVerts = 0
verts = []
for index,line in enumerate(content):
if line[0] == 'o':
for index, line in enumerate(content):
if line[0] == "o":
startVerts = index + 1
content = content[startVerts:]
break
for index,line in enumerate(content):
for index, line in enumerate(content):
if "vn" in line:
endVerts = index
verts = content[:endVerts]
@@ -23,28 +23,41 @@ for index,line in enumerate(content):
normals = []
for index,line in enumerate(content):
for index, line in enumerate(content):
if "vt" in line:
normals = content[:index]
content = content[index:]
break
startFaces = 0;
startFaces = 0
faces = []
for index,line in enumerate(content):
if line[0] == 'f':
for index, line in enumerate(content):
if line[0] == "f":
startFaces = index
faces = content[startFaces:-1]
break
colors = ["vec3(" +",".join(vert.split(" ")[4:7]) + ")" for vert in verts]
verts = ["vec3(" +",".join(vert.split(" ")[1:4]) + ")" for vert in verts]
faces = [ ",".join(["{" + str(int((d.split("/")[0])) - 1) + "," + str(int((d.split("/")[2])) - 1) + "}" for d in face.split(" ")[1:4]]) for face in faces]
colors = ["vec3(" + ",".join(vert.split(" ")[4:7]) + ")" for vert in verts]
verts = ["{" + ",".join(vert.split(" ")[1:4]) + "}" for vert in verts]
faces = [
",".join([str(int((d.split("/")[0])) - 1) for d in face.split(" ")[1:4]])
for face in faces
]
normals = ["vec3(" + ",".join(normal.split(" ")[1:4]) + ")" for normal in normals]
out = "#include \"model.hpp\" \n const model testModel({" + ",".join(verts) +"},{" + ",".join(faces) + "},{" + ",".join(normals) + "},{"+ ",".join(colors)+"});"
out = (
'#include "../renderer.h" \n const model testModel = {(vec3[]){'
+ ",".join(verts)
+ "},(int[]){"
+ ",".join(faces)
+ "},"
+ str(len(verts))
+ ","
+ str(len(faces) * 3)
+ "};"
)
with open("testModel.hpp", "w") as f:
f.write(out)
print(out)
with open("src/models/plane.h", "w") as f:
f.write(out)
print(faces)
# Close the file