1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-21 20:39:57 +01:00

Continue obj2array

This commit is contained in:
Miloslav Číž 2019-05-25 19:57:05 +02:00
parent 2d52b7fb10
commit a2a73a08eb

View file

@ -1,12 +1,7 @@
# Python tool to convert a 3D model from the text obj format to C arrays to be # Python tool to convert a 3D model from the text obj format to C arrays to be
# used with small3dlib. # used with small3dlib.
# #
# # by drummyfish
#
#
# TODO
#
# by drummfish
# released under CC0 1.0. # released under CC0 1.0.
import sys import sys
@ -16,7 +11,8 @@ def printHelp():
print("usage:\n") print("usage:\n")
print(" python obj2array.py [-c -sX -uY -vZ -n] file\n") print(" python obj2array.py [-c -sX -uY -vZ -n] file\n")
print(" -c compact format (off by default)") print(" -c compact format (off by default)")
print(" -n use direct instead of indexed UV coords (off by default) ") print(" -t use direct instead of indexed UV coords (off by default)")
print(" -nS use the name S for the model (defaut: \"model\")")
print(" -sX scale the model by X (default: 512)") print(" -sX scale the model by X (default: 512)")
print(" -uY scale the U texture coord by Y (default: 512)") print(" -uY scale the U texture coord by Y (default: 512)")
print(" -vZ scale the V texture coord by Z (default: 512)") print(" -vZ scale the V texture coord by Z (default: 512)")
@ -28,7 +24,7 @@ if len(sys.argv) < 2:
printHelp() printHelp()
quit() quit()
fileName = "" FILENAME = ""
VERTEX_SCALE = 512 VERTEX_SCALE = 512
U_SCALE = 512 U_SCALE = 512
V_SCALE = 512 V_SCALE = 512
@ -39,7 +35,7 @@ INDEXED_UVS = True
for s in sys.argv: for s in sys.argv:
if s == "-c": if s == "-c":
COMPACT = True COMPACT = True
elif s == "-n": elif s == "-t":
INDEXED_UVS = False INDEXED_UVS = False
elif s[:2] == "-s": elif s[:2] == "-s":
VERTEX_SCALE = int(s[2:]) VERTEX_SCALE = int(s[2:])
@ -47,10 +43,12 @@ for s in sys.argv:
U_SCALE = int(s[2:]) U_SCALE = int(s[2:])
elif s[:2] == "-v": elif s[:2] == "-v":
V_SCALE = int(s[2:]) V_SCALE = int(s[2:])
elif s[:2] == "-n":
NAME = s[2:]
else: else:
fileName = s FILENAME = s
objFile = open(fileName) objFile = open(FILENAME)
vertices = [] vertices = []
uvs = [] uvs = []
@ -165,3 +163,17 @@ else:
print(arrayString(NAME + "TriangleUVs",uvs2,6,[U_SCALE,V_SCALE],5,False)) print(arrayString(NAME + "TriangleUVs",uvs2,6,[U_SCALE,V_SCALE],5,False))
print("S3L_Model " + NAME + " = ")
if COMPACT:
print("{.vertices=" +
NAME + "Verices,.vertexCount=" + str(len(vertices)) +
",.triangles=" + NAME + "\nTriangles,.triangleCount=" +
str(len(triangles)) + "};");
else:
print("{")
print(" .vertices = " + NAME + "Vertices,")
print(" .vertexCount = " + str(len(vertices)) + ",")
print(" .triangles = " + NAME + "Triangles,")
print(" .triangleCount = " + str(len(triangles)))
print("};")