change mesh example

This commit is contained in:
ABelliqueux 2020-12-30 22:09:12 +01:00
parent fe4f6b2b99
commit 47d60bcd14
4 changed files with 1317 additions and 19 deletions

View File

@ -3,8 +3,9 @@ TYPE = ps-exe
SRCS = primdrawGT-db-abs.c \
../common/crt0/crt0.s \
TIM/cube.tim \
TIM/bousai.tim \
#~ TIM/cube.tim \
#~ TIM/bousai.tim \
TIM/home.tim \
CPPFLAGS += -I../psyq/include
LDFLAGS += -L../psyq/lib

1272
coridor.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -21,18 +21,34 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
filename_ext = ".c";
def execute(self, context):
import bmesh
def triangulate_object(obj): # Stolen from here : https://blender.stackexchange.com/questions/45698/triangulate-mesh-in-python/45722#45722
me = obj.data
# Get a BMesh representation
bm = bmesh.new()
bm.from_mesh(me)
bmesh.ops.triangulate(bm, faces=bm.faces[:], quad_method=0, ngon_method=0)
# Finish up, write the bmesh back to the mesh
bm.to_mesh(me)
bm.free()
# Leave edit mode to avoid errors
bpy.ops.object.mode_set(mode='OBJECT')
scale = 20
# triangulate objects of type mesh
for m in range(len(bpy.data.objects)):
if bpy.data.objects[m].type == 'MESH':
triangulate_object(bpy.data.objects[m])
scale = 120
f = open(os.path.normpath(self.filepath),"w+")
# write typedef struct
f.write("typedef struct { \n"+
"\tTMESH * tmesh;\n" +
"\tTIM_IMAGE * tim; \n" +
"\tint * index;\n" +
"\tTIM_IMAGE * tim; \n" +
"\tu_long * tim_data;\n"
"\t} MESH;\n\n")
@ -70,9 +86,9 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
# 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
if len(m.uv_textures) != 0:
if m.uv_textures[0].data[0].image != None:
f.write("SVECTOR "+"model"+m.name+"_uv[] = {\n")
texture_image = m.uv_textures[l].data[0].image
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
@ -91,7 +107,7 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
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
colors = m.vertex_colors[0].data
for i in range(len(colors)):
f.write("\t"+str(int(colors[i].color.r*255))+","+str(int(colors[i].color.g*255))+","+str(int(colors[i].color.b*255))+", 0")
if i != len(colors) - 1:
@ -123,10 +139,12 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
f.write("TMESH "+"model"+m.name+" = {\n")
f.write("\t"+"model"+m.name+"_mesh, \n")
f.write("\t"+"model"+m.name+"_normal,\n")
if len(m.uv_textures) != 0:
if m.uv_textures[0].data[0].image != None:
f.write("\t"+"model"+m.name+"_uv,\n")
else:
f.write("\t0,\n")
f.write("\t"+"model"+m.name+"_color, \n")
# According to libgte.h, TMESH.len should be # of vertices. Meh...
@ -135,9 +153,10 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
# write texture binary name and declare TIM_IMAGE
# by default, load the file from the TIM folder
if len(m.uv_textures) != 0:
# ~ if len(m.uv_textures) != 0:
if m.uv_textures[0].data[0].image != None:
tex_name = texture_image.name
prefix = str.partition(tex_name, ".")[0]
prefix = str.partition(tex_name, ".")[0].replace('-','_')
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")
@ -145,9 +164,15 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
f.write("MESH mesh"+m.name+" = {\n")
f.write("\t&model"+ m.name +",\n")
f.write("\t&tim_"+ prefix + ",\n")
f.write("\tmodel" + m.name + "_index,\n")
f.write("\t_binary_TIM_" + prefix + "_tim_start\n")
if m.uv_textures[0].data[0].image != None:
f.write("\t&tim_"+ prefix + ",\n")
f.write("\t_binary_TIM_" + prefix + "_tim_start\n")
else:
f.write("0,\n" +
"0,\n")
f.write("};\n\n")
f.write("MESH * meshes[" + str(len(bpy.data.meshes)) + "] = {\n")

View File

@ -36,9 +36,9 @@
#include <stdio.h>
// Sample vector model
#include "cube.c"
#include "coridor.c"
#define VMODE 1
#define VMODE 0
#define HAS_TEX 0
#define SCREENXRES 320
@ -87,7 +87,7 @@ void init(){
// Initialize and setup the GTE
InitGeom();
SetGeomOffset(CENTERX, CENTERY); // x, y offset
SetGeomScreen(CENTERX); // Distance between eye and screen
SetGeomScreen(CENTERX*2); // Distance between eye and screen
// Set the display and draw environments
SetDefDispEnv(&disp[0], 0, 0 , SCREENXRES, SCREENYRES);
@ -164,7 +164,7 @@ int main() {
SVECTOR Rotate={ 0 }; // Rotation coordinates
VECTOR Trans={ 0, 0, CENTERX, 0 }; // Translation coordinates
VECTOR Trans={ 0, 0, CENTERX*2, 0 }; // Translation coordinates
// Scaling coordinates
VECTOR Scale={ ONE, ONE, ONE, 0 }; // ONE == 4096
MATRIX Matrix={0}; // Matrix data for the GTE
@ -262,7 +262,7 @@ int main() {
setRGB0(poly, meshes[k]->tmesh->c[i].r , meshes[k]->tmesh->c[i].g , meshes[k]->tmesh->c[i].b);
setRGB1(poly, meshes[k]->tmesh->c[i+1].r, meshes[k]->tmesh->c[i+1].g, meshes[k]->tmesh->c[i+1].b);
setRGB2(poly, meshes[k]->tmesh->c[i+2].r, meshes[k]->tmesh->c[i+2].g, meshes[k]->tmesh->c[i+2].b);
((POLY_GT3 *)poly)->tpage = getTPage(meshes[k]->tim->mode&0x3, 0,
meshes[k]->tim->prect->x,
meshes[k]->tim->prect->y
@ -320,7 +320,7 @@ int main() {
//~ FntPrint("\n\nGOURAUD SHADED TMESH EXAMPLE\n");
//~ FntPrint("SCHNAPPY, 2020 \n");
//~ FntPrint("BASED ON PRIMDRAW BY LAMEGUY64, 2014 \n");
FntPrint("# tris :%d \n", modelCube.len);
FntPrint("# tris :%d \n", sizeof(ot[db])/sizeof(POLY_GT3));
FntPrint("Vsync :%d \n", vs);
FntPrint("%d ", sizeof(meshes)/sizeof(TMESH *));
FntPrint("%d ", meshes[0]->tim->prect->y);