example/castle: render textures
This commit is contained in:
parent
39f496b52c
commit
94c12d690d
@ -29,6 +29,12 @@
|
||||
#include "math/vec4.hpp"
|
||||
#include "math/mat4x4.hpp"
|
||||
|
||||
#include "model/castle/castlest.data.h"
|
||||
#include "model/castle/gothic3.data.h"
|
||||
#include "model/castle/oldbric.data.h"
|
||||
#include "model/castle/shingle.data.h"
|
||||
#include "model/castle/stone2.data.h"
|
||||
|
||||
using vec2 = vec<2, float>;
|
||||
using vec3 = vec<3, float>;
|
||||
using vec4 = vec<4, float>;
|
||||
@ -177,21 +183,22 @@ void interrupt_init()
|
||||
: "r" (sr));
|
||||
}
|
||||
|
||||
void global_polygon_type_0(ta_parameter_writer& writer, uint32_t texture_address, uint32_t list, uint32_t cull)
|
||||
void global_polygon_type_0(ta_parameter_writer& writer, uint32_t texture_address, int width, int height)
|
||||
{
|
||||
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
| list
|
||||
| para_control::list_type::opaque
|
||||
| obj_control::col_type::packed_color
|
||||
| obj_control::texture
|
||||
;
|
||||
|
||||
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
|
||||
| cull;
|
||||
| isp_tsp_instruction_word::culling_mode::no_culling;
|
||||
|
||||
const uint32_t tsp_instruction_word = tsp_instruction_word::fog_control::no_fog
|
||||
| tsp_instruction_word::src_alpha_instr::one
|
||||
| tsp_instruction_word::dst_alpha_instr::zero
|
||||
| tsp_instruction_word::texture_u_size::from_int(256)
|
||||
| tsp_instruction_word::texture_v_size::from_int(256)
|
||||
| tsp_instruction_word::texture_u_size::from_int(width)
|
||||
| tsp_instruction_word::texture_v_size::from_int(height)
|
||||
;
|
||||
|
||||
const uint32_t texture_control_word = texture_control_word::pixel_format::_565
|
||||
@ -239,28 +246,34 @@ static inline void render_tri(ta_parameter_writer& writer,
|
||||
uint32_t base_color,
|
||||
vec3 ap,
|
||||
vec3 bp,
|
||||
vec3 cp)
|
||||
vec3 cp,
|
||||
vec2 at,
|
||||
vec2 bt,
|
||||
vec2 ct)
|
||||
{
|
||||
if (ap.z < 0 || bp.z < 0 || cp.z < 0)
|
||||
return;
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_0>() =
|
||||
ta_vertex_parameter::polygon_type_0(polygon_vertex_parameter_control_word(false),
|
||||
writer.append<ta_vertex_parameter::polygon_type_3>() =
|
||||
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(false),
|
||||
ap.x, ap.y, ap.z,
|
||||
base_color
|
||||
); // offset_color
|
||||
at.x, at.y,
|
||||
base_color,
|
||||
0); // offset_color
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_0>() =
|
||||
ta_vertex_parameter::polygon_type_0(polygon_vertex_parameter_control_word(false),
|
||||
writer.append<ta_vertex_parameter::polygon_type_3>() =
|
||||
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(false),
|
||||
bp.x, bp.y, bp.z,
|
||||
base_color
|
||||
); // offset_color
|
||||
bt.x, bt.y,
|
||||
base_color,
|
||||
0); // offset_color
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_0>() =
|
||||
ta_vertex_parameter::polygon_type_0(polygon_vertex_parameter_control_word(true),
|
||||
writer.append<ta_vertex_parameter::polygon_type_3>() =
|
||||
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(true),
|
||||
cp.x, cp.y, cp.z,
|
||||
base_color
|
||||
); // offset_color
|
||||
ct.x, ct.y,
|
||||
base_color,
|
||||
0); // offset_color
|
||||
}
|
||||
|
||||
constexpr inline mat4x4 screen_rotation(float theta)
|
||||
@ -307,34 +320,25 @@ uint32_t xorshift32()
|
||||
return xorshift_state = x;
|
||||
}
|
||||
|
||||
const frame * frames[] = {
|
||||
&frame_x3ds_Box08,
|
||||
&frame_x3ds_Box09,
|
||||
&frame_x3ds_Box02,
|
||||
&frame_x3ds_Cone02,
|
||||
&frame_x3ds_Cylinder02,
|
||||
&frame_x3ds_Box21,
|
||||
&frame_x3ds_Box22,
|
||||
&frame_x3ds_Box23,
|
||||
&frame_x3ds_Box24,
|
||||
&frame_x3ds_Box25,
|
||||
&frame_x3ds_Box26,
|
||||
&frame_x3ds_Box27,
|
||||
&frame_x3ds_Cylinder03,
|
||||
&frame_x3ds_Cone03,
|
||||
&frame_x3ds_Cylinder01,
|
||||
&frame_x3ds_Box01,
|
||||
&frame_x3ds_Box28,
|
||||
&frame_x3ds_Box03,
|
||||
&frame_x3ds_roof,
|
||||
&frame_x3ds_walkway,
|
||||
};
|
||||
|
||||
static inline void render_mesh(ta_parameter_writer& writer,
|
||||
const mat4x4& screen,
|
||||
const mat4x4& model,
|
||||
const mesh * mesh)
|
||||
{
|
||||
const material * m = &mesh->material_list->objects[0]->material;
|
||||
assert(m->tag == tag::material);
|
||||
const texture_filename * t = &m->objects[0]->texture_filename;
|
||||
assert(t->tag == tag::texture_filename);
|
||||
|
||||
global_polygon_type_0(writer,
|
||||
texture_memory_alloc.texture.start + t->texture_memory_offset,
|
||||
t->width,
|
||||
t->height);
|
||||
|
||||
assert(mesh->texture_coords->tag == tag::mesh_texture_coords);
|
||||
const vec2 * texture_coords = mesh->texture_coords->texture_coords;
|
||||
assert(mesh->texture_coords->n_texture_coords == mesh->n_vertices);
|
||||
|
||||
//mesh->vertices;
|
||||
for (int i = 0; i < mesh->n_faces; i++) {
|
||||
const auto& indices = mesh->faces[i].face_vertex_indices;
|
||||
@ -343,7 +347,10 @@ static inline void render_mesh(ta_parameter_writer& writer,
|
||||
base_color,
|
||||
screen_transform(screen, model * mesh->vertices[indices[0]]),
|
||||
screen_transform(screen, model * mesh->vertices[indices[1]]),
|
||||
screen_transform(screen, model * mesh->vertices[indices[2]]));
|
||||
screen_transform(screen, model * mesh->vertices[indices[2]]),
|
||||
texture_coords[indices[0]],
|
||||
texture_coords[indices[1]],
|
||||
texture_coords[indices[2]]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -380,8 +387,11 @@ static inline void render_frame(ta_parameter_writer& writer,
|
||||
|
||||
void render_castle(ta_parameter_writer& writer, const mat4x4& screen)
|
||||
{
|
||||
for (uint32_t i = 0; i < (sizeof (frames)) / (sizeof (frames[0])); i++) {
|
||||
render_frame(writer, screen, frames[i]);
|
||||
for (uint32_t i = 0; i < (sizeof (castle_objects)) / (sizeof (castle_objects[0])); i++) {
|
||||
if (castle_objects[i]->tag != tag::frame)
|
||||
continue;
|
||||
|
||||
render_frame(writer, screen, &castle_objects[i]->frame);
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,10 +400,6 @@ void transfer_scene(ta_parameter_writer& writer)
|
||||
{
|
||||
const mat4x4 screen = screen_rotation(theta);
|
||||
|
||||
global_polygon_type_0(writer, texture_memory_alloc.texture.start,
|
||||
para_control::list_type::opaque,
|
||||
isp_tsp_instruction_word::culling_mode::no_culling);
|
||||
|
||||
render_castle(writer, screen);
|
||||
|
||||
// end of opaque list
|
||||
@ -403,14 +409,14 @@ void transfer_scene(ta_parameter_writer& writer)
|
||||
theta += deg * 0.1;
|
||||
}
|
||||
|
||||
void transfer_ta_fifo_texture_memory_32byte(void * dst, void * src, int length)
|
||||
void transfer_ta_fifo_texture_memory_32byte(void * dst, const void * src, int length)
|
||||
{
|
||||
uint32_t out_addr = (uint32_t)dst;
|
||||
sh7091.CCN.QACR0 = ((reinterpret_cast<uint32_t>(out_addr) >> 24) & 0b11100);
|
||||
sh7091.CCN.QACR1 = ((reinterpret_cast<uint32_t>(out_addr) >> 24) & 0b11100);
|
||||
|
||||
volatile uint32_t * base = &store_queue[(out_addr & 0x03ffffc0) / 4];
|
||||
uint32_t * src32 = reinterpret_cast<uint32_t *>(src);
|
||||
const uint32_t * src32 = reinterpret_cast<const uint32_t *>(src);
|
||||
|
||||
length = (length + 31) & ~31; // round up to nearest multiple of 32
|
||||
while (length > 0) {
|
||||
@ -432,6 +438,39 @@ void transfer_ta_fifo_texture_memory_32byte(void * dst, void * src, int length)
|
||||
}
|
||||
}
|
||||
|
||||
void transfer_texture(const material * material)
|
||||
{
|
||||
int ix = 0;
|
||||
while (true) {
|
||||
if (material->objects[ix] == nullptr)
|
||||
return;
|
||||
if (material->objects[ix]->tag == tag::texture_filename)
|
||||
break;
|
||||
ix += 1;
|
||||
}
|
||||
|
||||
const texture_filename * t = &material->objects[ix]->texture_filename;
|
||||
assert(t->tag == tag::texture_filename);
|
||||
|
||||
uint32_t offset = texture_memory_alloc.texture.start + t->texture_memory_offset;
|
||||
void * dst = (void *)(&texture_memory64[offset / 4]);
|
||||
|
||||
transfer_ta_fifo_texture_memory_32byte(dst, t->start, t->size);
|
||||
}
|
||||
|
||||
void transfer_textures()
|
||||
{
|
||||
system.LMMODE0 = 0; // 64-bit address space
|
||||
system.LMMODE1 = 0; // 64-bit address space
|
||||
|
||||
for (uint32_t i = 0; i < (sizeof (castle_objects)) / (sizeof (castle_objects[0])); i++) {
|
||||
if (castle_objects[i]->tag != tag::material)
|
||||
continue;
|
||||
|
||||
transfer_texture(&castle_objects[i]->material);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t __attribute__((aligned(32))) ta_parameter_buf[1024 * 1024];
|
||||
|
||||
void main()
|
||||
@ -488,6 +527,7 @@ void main()
|
||||
|
||||
ta_parameter_writer writer = ta_parameter_writer(ta_parameter_buf);
|
||||
|
||||
transfer_textures();
|
||||
video_output::set_mode_vga();
|
||||
while (1) {
|
||||
ta_polygon_converter_init2(texture_memory_alloc.isp_tsp_parameters[ta].start,
|
||||
|
@ -898,6 +898,11 @@ CASTLE_OBJ = \
|
||||
holly/ta_fifo_polygon_converter.o \
|
||||
holly/video_output.o \
|
||||
sh7091/serial.o \
|
||||
model/castle/castlest.data.o \
|
||||
model/castle/gothic3.data.o \
|
||||
model/castle/oldbric.data.o \
|
||||
model/castle/shingle.data.o \
|
||||
model/castle/stone2.data.o \
|
||||
$(LIBGCC)
|
||||
|
||||
example/castle.elf: LDSCRIPT = $(LIB)/main.lds
|
||||
|
BIN
model/castle/castlest.data
Normal file
BIN
model/castle/castlest.data
Normal file
Binary file not shown.
15
model/castle/castlest.data.h
Normal file
15
model/castle/castlest.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_model_castle_castlest_data_start __asm("_binary_model_castle_castlest_data_start");
|
||||
extern uint32_t _binary_model_castle_castlest_data_end __asm("_binary_model_castle_castlest_data_end");
|
||||
extern uint32_t _binary_model_castle_castlest_data_size __asm("_binary_model_castle_castlest_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
BIN
model/castle/castlest.jpg
Normal file
BIN
model/castle/castlest.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
43
model/castle/gothic3.data
Normal file
43
model/castle/gothic3.data
Normal file
File diff suppressed because one or more lines are too long
15
model/castle/gothic3.data.h
Normal file
15
model/castle/gothic3.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_model_castle_gothic3_data_start __asm("_binary_model_castle_gothic3_data_start");
|
||||
extern uint32_t _binary_model_castle_gothic3_data_end __asm("_binary_model_castle_gothic3_data_end");
|
||||
extern uint32_t _binary_model_castle_gothic3_data_size __asm("_binary_model_castle_gothic3_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
BIN
model/castle/gothic3.jpg
Normal file
BIN
model/castle/gothic3.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 55 KiB |
@ -9789,7 +9789,11 @@ const material material_x3ds_mat_castlestone = {
|
||||
|
||||
const texture_filename texture_filename_0 = {
|
||||
.tag = tag::texture_filename,
|
||||
|
||||
.start = reinterpret_cast<const void *>(&_binary_model_castle_castlest_data_start),
|
||||
.size = reinterpret_cast<int>(&_binary_model_castle_castlest_data_size),
|
||||
.texture_memory_offset = 0,
|
||||
.width = 256,
|
||||
.height = 256,
|
||||
};
|
||||
|
||||
const material material_x3ds_mat_Material__3 = {
|
||||
@ -9807,7 +9811,11 @@ const material material_x3ds_mat_Material__3 = {
|
||||
|
||||
const texture_filename texture_filename_1 = {
|
||||
.tag = tag::texture_filename,
|
||||
|
||||
.start = reinterpret_cast<const void *>(&_binary_model_castle_oldbric_data_start),
|
||||
.size = reinterpret_cast<int>(&_binary_model_castle_oldbric_data_size),
|
||||
.texture_memory_offset = 131072,
|
||||
.width = 256,
|
||||
.height = 256,
|
||||
};
|
||||
|
||||
const material material_x3ds_mat_shingle = {
|
||||
@ -9825,7 +9833,11 @@ const material material_x3ds_mat_shingle = {
|
||||
|
||||
const texture_filename texture_filename_2 = {
|
||||
.tag = tag::texture_filename,
|
||||
|
||||
.start = reinterpret_cast<const void *>(&_binary_model_castle_shingle_data_start),
|
||||
.size = reinterpret_cast<int>(&_binary_model_castle_shingle_data_size),
|
||||
.texture_memory_offset = 262144,
|
||||
.width = 256,
|
||||
.height = 128,
|
||||
};
|
||||
|
||||
const material material_x3ds_mat_Material__8 = {
|
||||
@ -9843,7 +9855,11 @@ const material material_x3ds_mat_Material__8 = {
|
||||
|
||||
const texture_filename texture_filename_3 = {
|
||||
.tag = tag::texture_filename,
|
||||
|
||||
.start = reinterpret_cast<const void *>(&_binary_model_castle_gothic3_data_start),
|
||||
.size = reinterpret_cast<int>(&_binary_model_castle_gothic3_data_size),
|
||||
.texture_memory_offset = 327680,
|
||||
.width = 256,
|
||||
.height = 256,
|
||||
};
|
||||
|
||||
const frame frame_x3ds_Box08 = {
|
||||
@ -9872,13 +9888,9 @@ const mesh mesh_Box08 = {
|
||||
.vertices = mesh_Box08_vertices,
|
||||
.n_faces = 44,
|
||||
.faces = mesh_Box08_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_0),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_0),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_0),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_0,
|
||||
.normals = &mesh_normals_0,
|
||||
.texture_coords = &mesh_texture_coords_0,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_0 = {
|
||||
@ -10033,13 +10045,9 @@ const mesh mesh_Box09 = {
|
||||
.vertices = mesh_Box09_vertices,
|
||||
.n_faces = 136,
|
||||
.faces = mesh_Box09_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_1),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_1),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_1),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_1,
|
||||
.normals = &mesh_normals_1,
|
||||
.texture_coords = &mesh_texture_coords_1,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_1 = {
|
||||
@ -10422,13 +10430,9 @@ const mesh mesh_Box02 = {
|
||||
.vertices = mesh_Box02_vertices,
|
||||
.n_faces = 8,
|
||||
.faces = mesh_Box02_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_2),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_2),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_2),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_2,
|
||||
.normals = &mesh_normals_2,
|
||||
.texture_coords = &mesh_texture_coords_2,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_2 = {
|
||||
@ -10499,13 +10503,9 @@ const mesh mesh_Cone02 = {
|
||||
.vertices = mesh_Cone02_vertices,
|
||||
.n_faces = 32,
|
||||
.faces = mesh_Cone02_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_3),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_3),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_3),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_3,
|
||||
.normals = &mesh_normals_3,
|
||||
.texture_coords = &mesh_texture_coords_3,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_3 = {
|
||||
@ -10602,13 +10602,9 @@ const mesh mesh_Cylinder02 = {
|
||||
.vertices = mesh_Cylinder02_vertices,
|
||||
.n_faces = 16,
|
||||
.faces = mesh_Cylinder02_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_4),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_4),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_4),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_4,
|
||||
.normals = &mesh_normals_4,
|
||||
.texture_coords = &mesh_texture_coords_4,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_4 = {
|
||||
@ -10682,13 +10678,9 @@ const mesh mesh_Box21 = {
|
||||
.vertices = mesh_Box21_vertices,
|
||||
.n_faces = 176,
|
||||
.faces = mesh_Box21_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_5),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_5),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_5),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_5,
|
||||
.normals = &mesh_normals_5,
|
||||
.texture_coords = &mesh_texture_coords_5,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_5 = {
|
||||
@ -11121,13 +11113,9 @@ const mesh mesh_Box22 = {
|
||||
.vertices = mesh_Box22_vertices,
|
||||
.n_faces = 136,
|
||||
.faces = mesh_Box22_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_6),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_6),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_6),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_6,
|
||||
.normals = &mesh_normals_6,
|
||||
.texture_coords = &mesh_texture_coords_6,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_6 = {
|
||||
@ -11510,13 +11498,9 @@ const mesh mesh_Box23 = {
|
||||
.vertices = mesh_Box23_vertices,
|
||||
.n_faces = 176,
|
||||
.faces = mesh_Box23_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_7),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_7),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_7),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_7,
|
||||
.normals = &mesh_normals_7,
|
||||
.texture_coords = &mesh_texture_coords_7,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_7 = {
|
||||
@ -11949,13 +11933,9 @@ const mesh mesh_Box24 = {
|
||||
.vertices = mesh_Box24_vertices,
|
||||
.n_faces = 44,
|
||||
.faces = mesh_Box24_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_8),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_8),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_8),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_8,
|
||||
.normals = &mesh_normals_8,
|
||||
.texture_coords = &mesh_texture_coords_8,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_8 = {
|
||||
@ -12110,13 +12090,9 @@ const mesh mesh_Box25 = {
|
||||
.vertices = mesh_Box25_vertices,
|
||||
.n_faces = 136,
|
||||
.faces = mesh_Box25_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_9),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_9),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_9),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_9,
|
||||
.normals = &mesh_normals_9,
|
||||
.texture_coords = &mesh_texture_coords_9,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_9 = {
|
||||
@ -12499,13 +12475,9 @@ const mesh mesh_Box26 = {
|
||||
.vertices = mesh_Box26_vertices,
|
||||
.n_faces = 176,
|
||||
.faces = mesh_Box26_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_10),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_10),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_10),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_10,
|
||||
.normals = &mesh_normals_10,
|
||||
.texture_coords = &mesh_texture_coords_10,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_10 = {
|
||||
@ -12938,13 +12910,9 @@ const mesh mesh_Box27 = {
|
||||
.vertices = mesh_Box27_vertices,
|
||||
.n_faces = 136,
|
||||
.faces = mesh_Box27_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_11),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_11),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_11),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_11,
|
||||
.normals = &mesh_normals_11,
|
||||
.texture_coords = &mesh_texture_coords_11,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_11 = {
|
||||
@ -13327,13 +13295,9 @@ const mesh mesh_Cylinder03 = {
|
||||
.vertices = mesh_Cylinder03_vertices,
|
||||
.n_faces = 16,
|
||||
.faces = mesh_Cylinder03_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_12),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_12),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_12),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_12,
|
||||
.normals = &mesh_normals_12,
|
||||
.texture_coords = &mesh_texture_coords_12,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_12 = {
|
||||
@ -13407,13 +13371,9 @@ const mesh mesh_Cone03 = {
|
||||
.vertices = mesh_Cone03_vertices,
|
||||
.n_faces = 32,
|
||||
.faces = mesh_Cone03_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_13),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_13),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_13),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_13,
|
||||
.normals = &mesh_normals_13,
|
||||
.texture_coords = &mesh_texture_coords_13,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_13 = {
|
||||
@ -13510,13 +13470,9 @@ const mesh mesh_Cylinder01 = {
|
||||
.vertices = mesh_Cylinder01_vertices,
|
||||
.n_faces = 174,
|
||||
.faces = mesh_Cylinder01_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_14),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_14),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_14),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_14,
|
||||
.normals = &mesh_normals_14,
|
||||
.texture_coords = &mesh_texture_coords_14,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_14 = {
|
||||
@ -13976,13 +13932,9 @@ const mesh mesh_Box01 = {
|
||||
.vertices = mesh_Box01_vertices,
|
||||
.n_faces = 8,
|
||||
.faces = mesh_Box01_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_15),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_15),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_15),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_15,
|
||||
.normals = &mesh_normals_15,
|
||||
.texture_coords = &mesh_texture_coords_15,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_15 = {
|
||||
@ -14054,13 +14006,9 @@ const mesh mesh_Box28 = {
|
||||
.vertices = mesh_Box28_vertices,
|
||||
.n_faces = 8,
|
||||
.faces = mesh_Box28_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_16),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_16),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_16),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_16,
|
||||
.normals = &mesh_normals_16,
|
||||
.texture_coords = &mesh_texture_coords_16,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_16 = {
|
||||
@ -14132,13 +14080,9 @@ const mesh mesh_Box03 = {
|
||||
.vertices = mesh_Box03_vertices,
|
||||
.n_faces = 10,
|
||||
.faces = mesh_Box03_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_17),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_17),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_17),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_17,
|
||||
.normals = &mesh_normals_17,
|
||||
.texture_coords = &mesh_texture_coords_17,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_17 = {
|
||||
@ -14201,13 +14145,9 @@ const mesh mesh_roof = {
|
||||
.vertices = mesh_roof_vertices,
|
||||
.n_faces = 4,
|
||||
.faces = mesh_roof_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_18),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_18),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_18),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_18,
|
||||
.normals = &mesh_normals_18,
|
||||
.texture_coords = &mesh_texture_coords_18,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_18 = {
|
||||
@ -14268,13 +14208,9 @@ const mesh mesh_walkway = {
|
||||
.vertices = mesh_walkway_vertices,
|
||||
.n_faces = 38,
|
||||
.faces = mesh_walkway_faces,
|
||||
|
||||
.objects = {
|
||||
reinterpret_cast<const data_object *>(&mesh_material_list_19),
|
||||
reinterpret_cast<const data_object *>(&mesh_normals_19),
|
||||
reinterpret_cast<const data_object *>(&mesh_texture_coords_19),
|
||||
nullptr,
|
||||
}
|
||||
.material_list = &mesh_material_list_19,
|
||||
.normals = &mesh_normals_19,
|
||||
.texture_coords = &mesh_texture_coords_19,
|
||||
};
|
||||
|
||||
const mesh_material_list mesh_material_list_19 = {
|
||||
@ -14969,4 +14905,33 @@ const animation_key animation_key_39 = {
|
||||
},
|
||||
};
|
||||
|
||||
const data_object * castle_objects[] = {
|
||||
reinterpret_cast<const data_object *>(&header_0),
|
||||
reinterpret_cast<const data_object *>(&material_x3ds_mat_castlestone),
|
||||
reinterpret_cast<const data_object *>(&material_x3ds_mat_Material__3),
|
||||
reinterpret_cast<const data_object *>(&material_x3ds_mat_shingle),
|
||||
reinterpret_cast<const data_object *>(&material_x3ds_mat_Material__8),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box08),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box09),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box02),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Cone02),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Cylinder02),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box21),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box22),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box23),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box24),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box25),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box26),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box27),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Cylinder03),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Cone03),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Cylinder01),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box01),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box28),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_Box03),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_roof),
|
||||
reinterpret_cast<const data_object *>(&frame_x3ds_walkway),
|
||||
reinterpret_cast<const data_object *>(&animation_set_x3ds_animset_0),
|
||||
};
|
||||
|
||||
|
||||
|
206
model/castle/oldbric.data
Normal file
206
model/castle/oldbric.data
Normal file
File diff suppressed because one or more lines are too long
15
model/castle/oldbric.data.h
Normal file
15
model/castle/oldbric.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_model_castle_oldbric_data_start __asm("_binary_model_castle_oldbric_data_start");
|
||||
extern uint32_t _binary_model_castle_oldbric_data_end __asm("_binary_model_castle_oldbric_data_end");
|
||||
extern uint32_t _binary_model_castle_oldbric_data_size __asm("_binary_model_castle_oldbric_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
BIN
model/castle/oldbric.jpg
Normal file
BIN
model/castle/oldbric.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
BIN
model/castle/shingle.data
Normal file
BIN
model/castle/shingle.data
Normal file
Binary file not shown.
15
model/castle/shingle.data.h
Normal file
15
model/castle/shingle.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_model_castle_shingle_data_start __asm("_binary_model_castle_shingle_data_start");
|
||||
extern uint32_t _binary_model_castle_shingle_data_end __asm("_binary_model_castle_shingle_data_end");
|
||||
extern uint32_t _binary_model_castle_shingle_data_size __asm("_binary_model_castle_shingle_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
BIN
model/castle/shingle.jpg
Normal file
BIN
model/castle/shingle.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
BIN
model/castle/stone2.data
Normal file
BIN
model/castle/stone2.data
Normal file
Binary file not shown.
15
model/castle/stone2.data.h
Normal file
15
model/castle/stone2.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_model_castle_stone2_data_start __asm("_binary_model_castle_stone2_data_start");
|
||||
extern uint32_t _binary_model_castle_stone2_data_end __asm("_binary_model_castle_stone2_data_end");
|
||||
extern uint32_t _binary_model_castle_stone2_data_size __asm("_binary_model_castle_stone2_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
BIN
model/castle/stone2.jpg
Normal file
BIN
model/castle/stone2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
63
x/gen.py
63
x/gen.py
@ -3,9 +3,13 @@ from parse import parse_all, TokenReader
|
||||
import templates
|
||||
import dataclasses
|
||||
from collections import Counter
|
||||
from os import path
|
||||
|
||||
from pprint import pprint
|
||||
import sys
|
||||
from PIL import Image
|
||||
|
||||
x_filename = None
|
||||
|
||||
def obj_value(obj):
|
||||
if type(obj) is tuple:
|
||||
@ -32,6 +36,9 @@ def visit_objects(func, obj):
|
||||
for o in obj_value(obj).objects:
|
||||
yield from visit(func, o)
|
||||
|
||||
def visit_objects_silent(func, obj):
|
||||
yield from visit_objects(func, obj)
|
||||
|
||||
def visit_self(func, obj):
|
||||
yield from func(obj)
|
||||
|
||||
@ -67,7 +74,7 @@ visitors = {
|
||||
templates.TextureFilename : visit_self,
|
||||
templates.Frame : visit_objects,
|
||||
templates.FrameTransformMatrix : visit_self,
|
||||
templates.Mesh : visit_objects,
|
||||
templates.Mesh : visit_objects_silent,
|
||||
templates.MeshMaterialList : visit_objects,
|
||||
templates.MeshNormals : visit_self,
|
||||
templates.MeshTextureCoords : visit_self,
|
||||
@ -147,6 +154,18 @@ def type_declaration(obj):
|
||||
string_name = get_obj_name(obj)
|
||||
return f"const {type_name} {string_name}"
|
||||
|
||||
def find_object_by_type(objects, type):
|
||||
return [
|
||||
obj for obj in objects if obj_type(obj) is type
|
||||
]
|
||||
|
||||
def one_object_name_or_nullptr(objects):
|
||||
assert len(objects) in {0, 1}, objects
|
||||
if len(objects) == 1:
|
||||
return get_obj_name(objects[0])
|
||||
else:
|
||||
return "nullptr"
|
||||
|
||||
def generate_vec3(name, name2, vertices):
|
||||
yield f"vec3 {name}_{name2}[] = {{"
|
||||
for v in vertices:
|
||||
@ -194,8 +213,26 @@ def generate_material(obj):
|
||||
yield f".specular_color = {{{specular_color}}},"
|
||||
yield f".emissive_color = {{{emissive_color}}},"
|
||||
|
||||
texture_memory_offset = 0
|
||||
def generate_texture_filename(obj):
|
||||
yield ""
|
||||
global x_filename
|
||||
global texture_memory_offset
|
||||
directory, _ = path.split(x_filename)
|
||||
image_path = path.join(directory, obj.filename.lower())
|
||||
with Image.open(image_path) as im:
|
||||
width, height = im.size
|
||||
|
||||
noext, _ = path.splitext(image_path)
|
||||
data = noext.replace("/", "_")
|
||||
data_name = f"_binary_{data}_data"
|
||||
|
||||
yield f".start = reinterpret_cast<const void *>(&{data_name}_start),"
|
||||
yield f".size = reinterpret_cast<int>(&{data_name}_size),"
|
||||
yield f".texture_memory_offset = {texture_memory_offset},"
|
||||
yield f".width = {width},"
|
||||
yield f".height = {height},"
|
||||
|
||||
texture_memory_offset += width * height * 2
|
||||
|
||||
def generate_frame(obj):
|
||||
return
|
||||
@ -218,6 +255,16 @@ def generate_mesh(obj):
|
||||
yield f".n_faces = {obj.nFaces},"
|
||||
yield f".faces = {name}_faces,"
|
||||
|
||||
material_list = one_object_name_or_nullptr(
|
||||
find_object_by_type(obj.objects, templates.MeshMaterialList))
|
||||
normals = one_object_name_or_nullptr(
|
||||
find_object_by_type(obj.objects, templates.MeshNormals))
|
||||
texture_coords = one_object_name_or_nullptr(
|
||||
find_object_by_type(obj.objects, templates.MeshTextureCoords))
|
||||
yield f".material_list = &{material_list},"
|
||||
yield f".normals = &{normals},"
|
||||
yield f".texture_coords = &{texture_coords},"
|
||||
|
||||
def generate_mesh_material_list(obj):
|
||||
name = get_obj_name(obj)
|
||||
yield f".n_materials = {obj.nMaterials},"
|
||||
@ -313,16 +360,22 @@ def visit_all(func, objects):
|
||||
for obj in objects:
|
||||
yield from visit(func, obj)
|
||||
|
||||
def gen(objects):
|
||||
def gen(prefix, objects):
|
||||
yield from visit_all(generate_predeclaration, objects)
|
||||
yield from visit_all(generate_definition, objects)
|
||||
yield f"const data_object * {prefix}_objects[] = {{"
|
||||
for obj in objects:
|
||||
yield f"reinterpret_cast<const data_object *>(&{get_obj_name(obj)}),"
|
||||
yield "};"
|
||||
|
||||
with open(sys.argv[1], "rb") as f:
|
||||
prefix = sys.argv[2]
|
||||
x_filename = sys.argv[1]
|
||||
with open(x_filename, "rb") as f:
|
||||
buf = f.read()
|
||||
objects = list(parse_all(TokenReader(buf)))
|
||||
|
||||
_ = list(visit_all(add_name_map, objects))
|
||||
|
||||
render, out = generate.renderer()
|
||||
render(gen(objects))
|
||||
render(gen(prefix, objects))
|
||||
print(out.getvalue())
|
||||
|
22
x/x.hpp
22
x/x.hpp
@ -51,7 +51,12 @@ struct material {
|
||||
|
||||
struct texture_filename {
|
||||
enum tag tag;
|
||||
const char * filename;
|
||||
//const char * filename;
|
||||
const void * start;
|
||||
int size;
|
||||
int texture_memory_offset;
|
||||
int16_t width;
|
||||
int16_t height;
|
||||
};
|
||||
|
||||
struct frame {
|
||||
@ -64,13 +69,22 @@ struct frame_transform_matrix {
|
||||
mat4x4 frame_matrix;
|
||||
};
|
||||
|
||||
struct mesh_material_list;
|
||||
struct mesh_normals;
|
||||
struct mesh_texture_coords;
|
||||
|
||||
struct mesh {
|
||||
enum tag tag;
|
||||
int n_vertices;
|
||||
vec3 * vertices;
|
||||
int n_faces;
|
||||
struct mesh_face * faces;
|
||||
const data_object * objects[];
|
||||
mesh_face * faces;
|
||||
//
|
||||
const mesh_material_list * material_list;
|
||||
const mesh_normals * normals;
|
||||
const mesh_texture_coords * texture_coords;
|
||||
|
||||
//const data_object * objects[];
|
||||
};
|
||||
|
||||
struct mesh_material_list {
|
||||
@ -86,7 +100,7 @@ struct mesh_normals {
|
||||
int n_normals;
|
||||
vec3 * normals;
|
||||
int n_face_normals;
|
||||
struct mesh_face * face_normals;
|
||||
mesh_face * face_normals;
|
||||
};
|
||||
|
||||
struct mesh_texture_coords {
|
||||
|
Loading…
x
Reference in New Issue
Block a user