feat: model sourcing now all at once
This commit is contained in:
33
parseObj.py
Normal file → Executable file
33
parseObj.py
Normal file → Executable file
@@ -1,5 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
|
||||
dir_name = "3dModels/"
|
||||
|
||||
|
||||
def source_model(file_name: str):
|
||||
# Open the file in read mode
|
||||
file = open("plane.obj", "r")
|
||||
file = open(dir_name + file_name + ".obj", "r")
|
||||
|
||||
# Read the entire content of the file
|
||||
content = file.read().split("\n")
|
||||
@@ -21,7 +29,6 @@ for index, line in enumerate(content):
|
||||
content = content[endVerts:]
|
||||
break
|
||||
|
||||
|
||||
normals = []
|
||||
for index, line in enumerate(content):
|
||||
if "vt" in line:
|
||||
@@ -50,8 +57,14 @@ faces = [
|
||||
]
|
||||
normals = ["{" + ",".join(normal.split(" ")[1:4]) + "}" for normal in normals]
|
||||
|
||||
mtl_file = open(dir_name + file_name + ".mtl", "r")
|
||||
shiny = mtl_file.read().split("\n")[4].split(" ")[1]
|
||||
mtl_file.close()
|
||||
print(shiny)
|
||||
out = (
|
||||
'#include "../renderer.h" \n const model testModel = {(vec3[]){'
|
||||
'#include "../renderer.h" \n const model '
|
||||
+ file_name
|
||||
+ "_model = {(vec3[]){"
|
||||
+ ",".join(verts)
|
||||
+ "},(int[]){"
|
||||
+ ",".join(faces)
|
||||
@@ -63,10 +76,20 @@ out = (
|
||||
+ str(len(verts))
|
||||
+ ","
|
||||
+ str(len(faces) * 6)
|
||||
+ ","
|
||||
+ str(float(shiny) / 20)
|
||||
+ "};"
|
||||
)
|
||||
|
||||
with open("src/models/plane.h", "w") as f:
|
||||
with open("src/models/" + file_name + ".h", "w") as f:
|
||||
f.write(out)
|
||||
print(faces)
|
||||
# Close the file
|
||||
f.close()
|
||||
|
||||
|
||||
model_files = os.listdir("3dModels")
|
||||
li = range(0, 10)
|
||||
|
||||
for file in model_files:
|
||||
if file.endswith(".obj"):
|
||||
source_model(file[:-4])
|
||||
|
||||
Reference in New Issue
Block a user