now export/import gouraud textured meshes with UV!
This commit is contained in:
parent
fb55941d29
commit
2b145222d3
7
Makefile
7
Makefile
@ -1,10 +1,9 @@
|
||||
|
||||
TARGET = primdrawG
|
||||
TARGET = primdrawGT
|
||||
TYPE = ps-exe
|
||||
|
||||
SRCS = primdrawG.c \
|
||||
SRCS = primdrawGT.c \
|
||||
../common/crt0/crt0.s \
|
||||
#~ trisamp.c \
|
||||
TIM/cube.tim \
|
||||
|
||||
CPPFLAGS += -I../psyq/include
|
||||
LDFLAGS += -L../psyq/lib
|
||||
|
49
cube.c
49
cube.c
@ -24,10 +24,49 @@ SVECTOR modelCube_normal[] = {
|
||||
2.0861631355728605e-07,1.0,1.7881397695873602e-07,0
|
||||
};
|
||||
|
||||
SVECTOR modelCube_uv[] = {
|
||||
83.71398162841797,83.71389770507812, 0, 0,
|
||||
125.03179168701172,42.396141052246094, 0, 0,
|
||||
83.71398162841797,42.396141052246094, 0, 0,
|
||||
125.03179168701172,83.71392059326172, 0, 0,
|
||||
83.71398162841797,125.03166770935059, 0, 0,
|
||||
125.03179168701172,125.03169059753418, 0, 0,
|
||||
1.0784510374069214,83.71392059326172, 0, 0,
|
||||
42.39619445800781,125.03169059753418, 0, 0,
|
||||
42.39621353149414,83.71392440795898, 0, 0,
|
||||
42.39621353149414,125.03166770935059, 0, 0,
|
||||
83.71398162841797,83.71392440795898, 0, 0,
|
||||
42.39621353149414,83.71390151977539, 0, 0,
|
||||
42.39619445800781,1.0783309936523438, 0, 0,
|
||||
1.0784281492233276,42.39611053466797, 0, 0,
|
||||
42.39619445800781,42.39612579345703, 0, 0,
|
||||
42.39619064331055,83.71392059326172, 0, 0,
|
||||
1.0784281492233276,42.396141052246094, 0, 0,
|
||||
1.0784281492233276,83.71392059326172, 0, 0,
|
||||
83.71398162841797,83.71389770507812, 0, 0,
|
||||
125.03179168701172,83.71390151977539, 0, 0,
|
||||
125.03179168701172,42.396141052246094, 0, 0,
|
||||
125.03179168701172,83.71392059326172, 0, 0,
|
||||
83.71399688720703,83.71392440795898, 0, 0,
|
||||
83.71398162841797,125.03166770935059, 0, 0,
|
||||
1.0784510374069214,83.71392059326172, 0, 0,
|
||||
1.0784281492233276,125.03169059753418, 0, 0,
|
||||
42.39619445800781,125.03169059753418, 0, 0,
|
||||
42.39621353149414,125.03166770935059, 0, 0,
|
||||
83.71398162841797,125.03169059753418, 0, 0,
|
||||
83.71398162841797,83.71392440795898, 0, 0,
|
||||
42.39619445800781,1.0783309936523438, 0, 0,
|
||||
1.0784281492233276,1.0783309936523438, 0, 0,
|
||||
1.0784281492233276,42.39611053466797, 0, 0,
|
||||
42.39619064331055,83.71392059326172, 0, 0,
|
||||
42.39619445800781,42.396141052246094, 0, 0,
|
||||
1.0784281492233276,42.396141052246094, 0, 0
|
||||
};
|
||||
|
||||
CVECTOR modelCube_color[] = {
|
||||
255,255,255, 0,
|
||||
255,255,255, 0,
|
||||
54,65,255, 0,
|
||||
255,0,251, 0,
|
||||
255,255,255, 0,
|
||||
255,5,7, 0,
|
||||
255,255,255, 0,
|
||||
@ -81,7 +120,13 @@ int modelCube_index[] = {
|
||||
TMESH modelCube = {
|
||||
modelCube_mesh,
|
||||
modelCube_normal,
|
||||
0,
|
||||
modelCube_uv,
|
||||
modelCube_color,
|
||||
12
|
||||
};
|
||||
|
||||
extern unsigned long _binary_TIM_cube_tim_start[];
|
||||
extern unsigned long _binary_TIM_cube_tim_end[];
|
||||
extern unsigned long _binary_TIM_cube_tim_length;
|
||||
|
||||
TIM_IMAGE tim_cube;
|
||||
|
@ -21,10 +21,16 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
filename_ext = ".c";
|
||||
|
||||
def execute(self, context):
|
||||
|
||||
# Leave edit mode to avoid errors
|
||||
bpy.ops.object.editmode_toggle()
|
||||
|
||||
scale = 20
|
||||
f = open(os.path.normpath(self.filepath),"w+")
|
||||
for m in bpy.data.meshes:
|
||||
|
||||
# Write vertices vectors
|
||||
|
||||
f.write("SVECTOR "+"model"+m.name+"_mesh[] = {\n")
|
||||
for i in range(len(m.vertices)):
|
||||
v = m.vertices[i].co
|
||||
@ -33,6 +39,8 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
f.write(",")
|
||||
f.write("\n")
|
||||
f.write("};\n\n")
|
||||
|
||||
# Write normals vectors
|
||||
|
||||
f.write("SVECTOR "+"model"+m.name+"_normal[] = {\n")
|
||||
for i in range(len(m.polygons)):
|
||||
@ -43,8 +51,33 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
f.write("\n")
|
||||
f.write("};\n\n")
|
||||
|
||||
f.write("CVECTOR "+"model"+m.name+"_color[] = {\n")
|
||||
# Write UVs vectors
|
||||
# get name of texture image https://docs.blender.org/api/2.79b/bpy.types.Image.html#bpy.types.Image
|
||||
# bpy.context.active_object.data.uv_textures.active.data[0].image.name
|
||||
# bpy.context.active_object.data.uv_textures.active.data[0].image.filepath
|
||||
# bpy.context.active_object.data.uv_textures.active.data[0].image.filepath_from_user()
|
||||
#
|
||||
# get image size x, y
|
||||
# print(bpy.data.meshes[0].uv_textures[0].data[0].image.size[0]) # x
|
||||
# print(bpy.data.meshes[0].uv_textures[0].data[0].image.size[1]) # y
|
||||
|
||||
f.write("SVECTOR "+"model"+m.name+"_uv[] = {\n")
|
||||
texture_image = m.uv_textures[0].data[0].image
|
||||
tex_width = texture_image.size[0]
|
||||
tex_height = texture_image.size[1]
|
||||
uv_layer = m.uv_layers[0].data
|
||||
for i in range(len(uv_layer)):
|
||||
u = uv_layer[i].uv
|
||||
# psx UV coordinates are Top Left, while Blender is Bottom Left
|
||||
f.write("\t"+str(u.x * tex_width)+","+str(tex_height - u.y * tex_height)+", 0, 0")
|
||||
if i != len(uv_layer) - 1:
|
||||
f.write(",")
|
||||
f.write("\n")
|
||||
f.write("};\n\n")
|
||||
|
||||
# Write vertex colors vectors
|
||||
|
||||
f.write("CVECTOR "+"model"+m.name+"_color[] = {\n")
|
||||
# If vertex colors exist, use them
|
||||
if len(m.vertex_colors) != 0:
|
||||
colors = m.vertex_colors["Col"].data
|
||||
@ -64,7 +97,8 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
f.write(",")
|
||||
f.write("\n")
|
||||
f.write("};\n\n")
|
||||
|
||||
|
||||
# Write polygons index
|
||||
f.write("int "+"model"+m.name+"_index[] = {\n")
|
||||
for i in range(len(m.polygons)):
|
||||
poly = m.polygons[i]
|
||||
@ -74,15 +108,26 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
f.write("\n")
|
||||
f.write("};\n\n")
|
||||
|
||||
|
||||
# Write TMESH struct
|
||||
f.write("TMESH "+"model"+m.name+" = {\n")
|
||||
f.write("\t"+"model"+m.name+"_mesh,\n")
|
||||
f.write("\t"+"model"+m.name+"_normal,\n")
|
||||
f.write("\t0,\n")
|
||||
f.write("\t"+"model"+m.name+"_uv,\n")
|
||||
f.write("\t"+"model"+m.name+"_color,\n")
|
||||
|
||||
# According to libgte.h, TMESH.len should be # of vertices. Meh...
|
||||
f.write("\t"+str(len(m.polygons))+"\n")
|
||||
f.write("};\n")
|
||||
f.write("};\n\n")
|
||||
|
||||
# write texture binary name and declare TIM_IMAGE
|
||||
# by default, load the file from the TIM folder
|
||||
tex_name = texture_image.name
|
||||
prefix = str.partition(tex_name, ".")[0]
|
||||
f.write("extern unsigned long "+"_binary_TIM_" + prefix + "_tim_start[];\n")
|
||||
f.write("extern unsigned long "+"_binary_TIM_" + prefix + "_tim_end[];\n")
|
||||
f.write("extern unsigned long "+"_binary_TIM_" + prefix + "_tim_length;\n\n")
|
||||
f.write("TIM_IMAGE tim_" + prefix + ";\n")
|
||||
|
||||
f.close()
|
||||
return {'FINISHED'};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user