example: add icosphere
This commit is contained in:
parent
befedb9d38
commit
e340c3ca02
@ -2,7 +2,7 @@ MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
|
||||
DIR := $(dir $(MAKEFILE_PATH))
|
||||
|
||||
LIB ?= .
|
||||
OPT ?= -O1
|
||||
OPT ?= -O3
|
||||
DEBUG ?= -g -gdwarf-4
|
||||
GENERATED ?=
|
||||
|
||||
|
@ -70,12 +70,12 @@ void transform(ta_parameter_writer& parameter,
|
||||
bool end_of_strip = i == strip_length - 1;
|
||||
|
||||
// world transform
|
||||
uint32_t vertex_ix = face[i].vertex - 1;
|
||||
uint32_t vertex_ix = face[i].vertex;
|
||||
auto& vertex = cube::vertices[vertex_ix];
|
||||
auto point = rotate(vertex, theta);
|
||||
|
||||
// lighting transform
|
||||
uint32_t normal_ix = face[i].normal - 1;
|
||||
uint32_t normal_ix = face[i].normal;
|
||||
auto& normal = cube::normals[normal_ix];
|
||||
auto n = rotate(normal, theta);
|
||||
|
||||
@ -192,7 +192,7 @@ void main()
|
||||
//lights[1].z = sin(theta + half_degree * 90.f) * 10;
|
||||
|
||||
auto parameter = ta_parameter_writer(ta_parameter_buf);
|
||||
for (uint32_t i = 0; i < 12; i++) {
|
||||
for (uint32_t i = 0; i < cube::num_faces; i++) {
|
||||
transform(parameter, i, theta, lights);
|
||||
}
|
||||
parameter.append<global_end_of_list>() = global_end_of_list();
|
||||
|
@ -107,6 +107,17 @@ CUBE_OBJ = \
|
||||
example/cube.elf: LDSCRIPT = $(LIB)/alt.lds
|
||||
example/cube.elf: $(START_OBJ) $(CUBE_OBJ)
|
||||
|
||||
ICOSPHERE_OBJ = \
|
||||
example/icosphere.o \
|
||||
vga.o \
|
||||
holly/core.o \
|
||||
holly/region_array.o \
|
||||
holly/background.o \
|
||||
holly/ta_fifo_polygon_converter.o
|
||||
|
||||
example/icosphere.elf: LDSCRIPT = $(LIB)/alt.lds
|
||||
example/icosphere.elf: $(START_OBJ) $(ICOSPHERE_OBJ)
|
||||
|
||||
MACAW_CUBE_OBJ = \
|
||||
example/macaw_cube.o \
|
||||
vga.o \
|
||||
|
295
example/icosphere.cpp
Normal file
295
example/icosphere.cpp
Normal file
@ -0,0 +1,295 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "align.hpp"
|
||||
|
||||
#include "vga.hpp"
|
||||
#include "holly.hpp"
|
||||
#include "holly/core.hpp"
|
||||
#include "holly/core_bits.hpp"
|
||||
#include "holly/ta_fifo_polygon_converter.hpp"
|
||||
#include "holly/ta_parameter.hpp"
|
||||
#include "holly/ta_bits.hpp"
|
||||
#include "holly/region_array.hpp"
|
||||
#include "holly/background.hpp"
|
||||
#include "holly/texture_memory_alloc.hpp"
|
||||
#include "memorymap.hpp"
|
||||
#include "serial.hpp"
|
||||
|
||||
#include "geometry/icosphere.hpp"
|
||||
#include "geometry/suzanne.hpp"
|
||||
#include "math/vec4.hpp"
|
||||
|
||||
constexpr float half_degree = 0.01745329f / 2;
|
||||
|
||||
#define MODEL icosphere
|
||||
|
||||
vec3 rotate(const vec3& vertex, float theta)
|
||||
{
|
||||
float x = vertex.x;
|
||||
float y = vertex.y;
|
||||
float z = vertex.z;
|
||||
float t;
|
||||
|
||||
t = y * cos(theta) - z * sin(theta);
|
||||
z = y * sin(theta) + z * cos(theta);
|
||||
y = t;
|
||||
|
||||
float theta2 = 3.14 * sin(theta / 2);
|
||||
|
||||
t = x * cos(theta2) - z * sin(theta2);
|
||||
z = x * sin(theta2) + z * cos(theta2);
|
||||
x = t;
|
||||
|
||||
return vec3(x, y, z);
|
||||
}
|
||||
|
||||
void transform(ta_parameter_writer& parameter,
|
||||
const uint32_t face_ix,
|
||||
const float theta,
|
||||
const vec3 lights[3])
|
||||
{
|
||||
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
| para_control::list_type::opaque
|
||||
| obj_control::col_type::floating_color
|
||||
| obj_control::gouraud;
|
||||
|
||||
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
|
||||
| isp_tsp_instruction_word::culling_mode::cull_if_positive;
|
||||
|
||||
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
|
||||
| tsp_instruction_word::dst_alpha_instr::zero
|
||||
| tsp_instruction_word::fog_control::no_fog;
|
||||
|
||||
parameter.append<global_polygon_type_0>() = global_polygon_type_0(parameter_control_word,
|
||||
isp_tsp_instruction_word,
|
||||
tsp_instruction_word,
|
||||
0);
|
||||
auto& face = MODEL::faces[face_ix];
|
||||
|
||||
constexpr uint32_t strip_length = 3;
|
||||
for (uint32_t i = 0; i < strip_length; i++) {
|
||||
bool end_of_strip = i == strip_length - 1;
|
||||
|
||||
// world transform
|
||||
uint32_t vertex_ix = face[i].vertex;
|
||||
auto& vertex = MODEL::vertices[vertex_ix];
|
||||
auto point = rotate(vertex, theta);
|
||||
|
||||
// lighting transform
|
||||
uint32_t normal_ix = face[i].normal;
|
||||
auto& normal = MODEL::normals[normal_ix];
|
||||
auto n = rotate(normal, theta);
|
||||
|
||||
vec4 color = {0.3, 0.3, 0.3, 1.0};
|
||||
|
||||
// intensity calculation
|
||||
{
|
||||
auto l = lights[0] - point;
|
||||
auto n_dot_l = dot(n, l);
|
||||
if (n_dot_l > 0) {
|
||||
color.x += 0.5 * n_dot_l / (length(n) * length(l));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto l = lights[1] - point;
|
||||
auto n_dot_l = dot(n, l);
|
||||
if (n_dot_l > 0) {
|
||||
color.y += 0.5 * n_dot_l / (length(n) * length(l));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto l = lights[2] - point;
|
||||
auto n_dot_l = dot(n, l);
|
||||
if (n_dot_l > 0) {
|
||||
color.z += 0.5 * n_dot_l / (length(n) * length(l));
|
||||
}
|
||||
}
|
||||
|
||||
float x = point.x;
|
||||
float y = point.y;
|
||||
float z = point.z;
|
||||
|
||||
x *= 8;
|
||||
y *= 8;
|
||||
z *= 8;
|
||||
|
||||
// camera transform
|
||||
z += 15;
|
||||
|
||||
// perspective
|
||||
x = x / z;
|
||||
y = y / z;
|
||||
|
||||
// screen space transform
|
||||
x *= 240.f;
|
||||
y *= 240.f;
|
||||
x += 320.f;
|
||||
y += 240.f;
|
||||
z = 1 / z;
|
||||
|
||||
parameter.append<vertex_polygon_type_1>() =
|
||||
vertex_polygon_type_1(x, y, z,
|
||||
color.w, // alpha
|
||||
color.x, // r
|
||||
color.y, // g
|
||||
color.z, // b
|
||||
end_of_strip);
|
||||
}
|
||||
}
|
||||
|
||||
void transform2(ta_parameter_writer& parameter,
|
||||
const vec3& pos,
|
||||
const vec4& color)
|
||||
{
|
||||
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
| para_control::list_type::opaque
|
||||
| obj_control::col_type::floating_color
|
||||
| obj_control::gouraud;
|
||||
|
||||
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
|
||||
| isp_tsp_instruction_word::culling_mode::no_culling;
|
||||
|
||||
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
|
||||
| tsp_instruction_word::dst_alpha_instr::zero
|
||||
| tsp_instruction_word::fog_control::no_fog;
|
||||
|
||||
parameter.append<global_polygon_type_0>() = global_polygon_type_0(parameter_control_word,
|
||||
isp_tsp_instruction_word,
|
||||
tsp_instruction_word,
|
||||
0);
|
||||
|
||||
constexpr vec3 triangle[] = {
|
||||
{ 0.f, -1.f, 0.f},
|
||||
{-1.f, 1.f, 0.f},
|
||||
{ 1.f, 1.f, 0.f},
|
||||
};
|
||||
|
||||
constexpr uint32_t strip_length = 3;
|
||||
for (uint32_t i = 0; i < strip_length; i++) {
|
||||
bool end_of_strip = i == strip_length - 1;
|
||||
float x = triangle[i].x;
|
||||
float y = triangle[i].y;
|
||||
float z = triangle[i].z;
|
||||
|
||||
x *= 0.2;
|
||||
y *= 0.2;
|
||||
z *= 0.2;
|
||||
|
||||
x += pos.x;
|
||||
y += pos.y;
|
||||
z += pos.z;
|
||||
|
||||
// camera transform
|
||||
z += 15;
|
||||
|
||||
// perspective
|
||||
x = x / z;
|
||||
y = y / z;
|
||||
|
||||
// screen space transform
|
||||
x *= 240.f;
|
||||
y *= 240.f;
|
||||
x += 320.f;
|
||||
y += 240.f;
|
||||
z = 1 / z;
|
||||
|
||||
parameter.append<vertex_polygon_type_1>() =
|
||||
vertex_polygon_type_1(x, y, z,
|
||||
color.w, // alpha
|
||||
color.x, // r
|
||||
color.y, // g
|
||||
color.z, // b
|
||||
end_of_strip);
|
||||
}
|
||||
}
|
||||
|
||||
void init_texture_memory(const struct opb_size& opb_size)
|
||||
{
|
||||
auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory32);
|
||||
|
||||
background_parameter(mem->background, 0xff220000);
|
||||
|
||||
region_array2(mem->region_array,
|
||||
(offsetof (struct texture_memory_alloc, object_list)),
|
||||
640 / 32, // width
|
||||
480 / 32, // height
|
||||
opb_size
|
||||
);
|
||||
}
|
||||
|
||||
uint32_t _ta_parameter_buf[((32 * (5 * 6 + 1)) + 32) / 4];
|
||||
|
||||
void main()
|
||||
{
|
||||
vga();
|
||||
|
||||
// The address of `ta_parameter_buf` must be a multiple of 32 bytes.
|
||||
// This is mandatory for ch2-dma to the ta fifo polygon converter.
|
||||
uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf);
|
||||
|
||||
constexpr uint32_t ta_alloc = ta_alloc_ctrl::pt_opb::no_list
|
||||
| ta_alloc_ctrl::tm_opb::no_list
|
||||
| ta_alloc_ctrl::t_opb::no_list
|
||||
| ta_alloc_ctrl::om_opb::no_list
|
||||
| ta_alloc_ctrl::o_opb::_16x4byte;
|
||||
|
||||
constexpr struct opb_size opb_size = { .opaque = 16 * 4
|
||||
, .opaque_modifier = 0
|
||||
, .translucent = 0
|
||||
, .translucent_modifier = 0
|
||||
, .punch_through = 0
|
||||
};
|
||||
|
||||
constexpr uint32_t tiles = (640 / 32) * (320 / 32);
|
||||
|
||||
holly.SOFTRESET = softreset::pipeline_soft_reset
|
||||
| softreset::ta_soft_reset;
|
||||
holly.SOFTRESET = 0;
|
||||
|
||||
core_init();
|
||||
init_texture_memory(opb_size);
|
||||
|
||||
uint32_t frame_ix = 0;
|
||||
constexpr uint32_t num_frames = 1;
|
||||
|
||||
float theta = 0;
|
||||
vec3 lights[3] = {
|
||||
{0.f, 0.f, 0.f},
|
||||
{0.f, 0.f, 0.f},
|
||||
{0.f, 0.f, 0.f},
|
||||
};
|
||||
|
||||
while (1) {
|
||||
ta_polygon_converter_init(opb_size.total() * tiles, ta_alloc,
|
||||
640, 480);
|
||||
|
||||
lights[0].x = cos(theta) * 10;
|
||||
lights[0].z = sin(theta) * 10;
|
||||
|
||||
lights[1].x = cos(theta + half_degree * 180.f) * 10;
|
||||
lights[1].z = sin(theta + half_degree * 180.f) * 10;
|
||||
|
||||
lights[2].x = cos(theta + half_degree * 360.f) * 10;
|
||||
lights[2].z = sin(theta + half_degree * 360.f) * 10;
|
||||
|
||||
auto parameter = ta_parameter_writer(ta_parameter_buf);
|
||||
for (uint32_t i = 0; i < MODEL::num_faces; i++) {
|
||||
transform(parameter, i, theta, lights);
|
||||
}
|
||||
transform2(parameter, lights[0], {1.f, 0.f, 0.f, 1.f});
|
||||
transform2(parameter, lights[1], {0.f, 1.f, 0.f, 1.f});
|
||||
transform2(parameter, lights[2], {0.f, 0.f, 1.f, 1.f});
|
||||
|
||||
parameter.append<global_end_of_list>() = global_end_of_list();
|
||||
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
|
||||
ta_wait_opaque_list();
|
||||
core_start_render(frame_ix, num_frames);
|
||||
|
||||
v_sync_out();
|
||||
core_wait_end_of_render_video(frame_ix, num_frames);
|
||||
theta += half_degree;
|
||||
frame_ix += 1;
|
||||
}
|
||||
}
|
@ -1,54 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "math/vec3.hpp"
|
||||
|
||||
using vec3 = vec<3, float>;
|
||||
|
||||
struct vertex__normal {
|
||||
uint8_t vertex;
|
||||
uint8_t normal;
|
||||
};
|
||||
|
||||
using face = vertex__normal[3];
|
||||
#include "geometry.hpp"
|
||||
|
||||
namespace cube {
|
||||
|
||||
constexpr vec3 vertices[] = {
|
||||
{ 1.f, 1.f, -1.f},
|
||||
{ 1.f, -1.f, -1.f},
|
||||
{ 1.f, 1.f, 1.f},
|
||||
{ 1.f, -1.f, 1.f},
|
||||
{-1.f, 1.f, -1.f},
|
||||
{-1.f, -1.f, -1.f},
|
||||
{-1.f, 1.f, 1.f},
|
||||
{-1.f, -1.f, 1.f},
|
||||
{ 1.000000f, 1.000000f, -1.000000f },
|
||||
{ 1.000000f, -1.000000f, -1.000000f },
|
||||
{ 1.000000f, 1.000000f, 1.000000f },
|
||||
{ 1.000000f, -1.000000f, 1.000000f },
|
||||
{ -1.000000f, 1.000000f, -1.000000f },
|
||||
{ -1.000000f, -1.000000f, -1.000000f },
|
||||
{ -1.000000f, 1.000000f, 1.000000f },
|
||||
{ -1.000000f, -1.000000f, 1.000000f },
|
||||
};
|
||||
|
||||
constexpr vec3 normals[] = {
|
||||
{-0.f, 1.f, -0.f},
|
||||
{-0.f, -0.f, 1.f},
|
||||
{-1.f, -0.f, -0.f},
|
||||
{-0.f, -1.f, -0.f},
|
||||
{ 1.f, -0.f, -0.f},
|
||||
{-0.f, -0.f, -1.f},
|
||||
{ -0.000000f, 1.000000f, -0.000000f },
|
||||
{ -0.000000f, -0.000000f, 1.000000f },
|
||||
{ -1.000000f, -0.000000f, -0.000000f },
|
||||
{ -0.000000f, -1.000000f, -0.000000f },
|
||||
{ 1.000000f, -0.000000f, -0.000000f },
|
||||
{ -0.000000f, -0.000000f, -1.000000f },
|
||||
};
|
||||
|
||||
constexpr face faces[] = {
|
||||
{{5, 1}, {3, 1}, {1, 1}},
|
||||
{{3, 2}, {8, 2}, {4, 2}},
|
||||
{{7, 3}, {6, 3}, {8, 3}},
|
||||
{{2, 4}, {8, 4}, {6, 4}},
|
||||
{{1, 5}, {4, 5}, {2, 5}},
|
||||
{{5, 6}, {2, 6}, {6, 6}},
|
||||
{{5, 1}, {7, 1}, {3, 1}},
|
||||
{{3, 2}, {7, 2}, {8, 2}},
|
||||
{{7, 3}, {5, 3}, {6, 3}},
|
||||
{{2, 4}, {4, 4}, {8, 4}},
|
||||
{{1, 5}, {3, 5}, {4, 5}},
|
||||
{{5, 6}, {1, 6}, {2, 6}},
|
||||
{{ 4, 0}, { 2, 0}, { 0, 0}},
|
||||
{{ 2, 1}, { 7, 1}, { 3, 1}},
|
||||
{{ 6, 2}, { 5, 2}, { 7, 2}},
|
||||
{{ 1, 3}, { 7, 3}, { 5, 3}},
|
||||
{{ 0, 4}, { 3, 4}, { 1, 4}},
|
||||
{{ 4, 5}, { 1, 5}, { 5, 5}},
|
||||
{{ 4, 0}, { 6, 0}, { 2, 0}},
|
||||
{{ 2, 1}, { 6, 1}, { 7, 1}},
|
||||
{{ 6, 2}, { 4, 2}, { 5, 2}},
|
||||
{{ 1, 3}, { 3, 3}, { 7, 3}},
|
||||
{{ 0, 4}, { 2, 4}, { 3, 4}},
|
||||
{{ 4, 5}, { 0, 5}, { 1, 5}},
|
||||
};
|
||||
|
||||
constexpr int num_faces = (sizeof (faces)) / (sizeof (face));
|
||||
constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face));
|
||||
|
||||
}
|
||||
|
30
geometry/cube.obj
Normal file
30
geometry/cube.obj
Normal file
@ -0,0 +1,30 @@
|
||||
# Blender 3.3.6
|
||||
# www.blender.org
|
||||
o Cube
|
||||
v 1.000000 1.000000 -1.000000
|
||||
v 1.000000 -1.000000 -1.000000
|
||||
v 1.000000 1.000000 1.000000
|
||||
v 1.000000 -1.000000 1.000000
|
||||
v -1.000000 1.000000 -1.000000
|
||||
v -1.000000 -1.000000 -1.000000
|
||||
v -1.000000 1.000000 1.000000
|
||||
v -1.000000 -1.000000 1.000000
|
||||
vn -0.0000 1.0000 -0.0000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -1.0000 -0.0000
|
||||
vn 1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 -1.0000
|
||||
s 0
|
||||
f 5//1 3//1 1//1
|
||||
f 3//2 8//2 4//2
|
||||
f 7//3 6//3 8//3
|
||||
f 2//4 8//4 6//4
|
||||
f 1//5 4//5 2//5
|
||||
f 5//6 2//6 6//6
|
||||
f 5//1 7//1 3//1
|
||||
f 3//2 7//2 8//2
|
||||
f 7//3 5//3 6//3
|
||||
f 2//4 4//4 8//4
|
||||
f 1//5 3//5 4//5
|
||||
f 5//6 1//6 2//6
|
16
geometry/geometry.hpp
Normal file
16
geometry/geometry.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "math/vec3.hpp"
|
||||
#include "math/vec4.hpp"
|
||||
|
||||
using vec3 = vec<3, float>;
|
||||
using vec4 = vec<4, float>;
|
||||
|
||||
struct vertex__normal {
|
||||
uint16_t vertex;
|
||||
uint16_t normal;
|
||||
};
|
||||
|
||||
using face = vertex__normal[3];
|
219
geometry/icosphere.hpp
Normal file
219
geometry/icosphere.hpp
Normal file
@ -0,0 +1,219 @@
|
||||
#pragma once
|
||||
|
||||
#include "geometry.hpp"
|
||||
|
||||
namespace icosphere {
|
||||
constexpr vec3 vertices[] = {
|
||||
{ 0.000000f, -1.000000f, 0.000000f },
|
||||
{ 0.723607f, -0.447220f, 0.525725f },
|
||||
{ -0.276388f, -0.447220f, 0.850649f },
|
||||
{ -0.894426f, -0.447216f, 0.000000f },
|
||||
{ -0.276388f, -0.447220f, -0.850649f },
|
||||
{ 0.723607f, -0.447220f, -0.525725f },
|
||||
{ 0.276388f, 0.447220f, 0.850649f },
|
||||
{ -0.723607f, 0.447220f, 0.525725f },
|
||||
{ -0.723607f, 0.447220f, -0.525725f },
|
||||
{ 0.276388f, 0.447220f, -0.850649f },
|
||||
{ 0.894426f, 0.447216f, 0.000000f },
|
||||
{ 0.000000f, 1.000000f, 0.000000f },
|
||||
{ -0.162456f, -0.850654f, 0.499995f },
|
||||
{ 0.425323f, -0.850654f, 0.309011f },
|
||||
{ 0.262869f, -0.525738f, 0.809012f },
|
||||
{ 0.850648f, -0.525736f, 0.000000f },
|
||||
{ 0.425323f, -0.850654f, -0.309011f },
|
||||
{ -0.525730f, -0.850652f, 0.000000f },
|
||||
{ -0.688189f, -0.525736f, 0.499997f },
|
||||
{ -0.162456f, -0.850654f, -0.499995f },
|
||||
{ -0.688189f, -0.525736f, -0.499997f },
|
||||
{ 0.262869f, -0.525738f, -0.809012f },
|
||||
{ 0.951058f, 0.000000f, 0.309013f },
|
||||
{ 0.951058f, 0.000000f, -0.309013f },
|
||||
{ 0.000000f, 0.000000f, 1.000000f },
|
||||
{ 0.587786f, 0.000000f, 0.809017f },
|
||||
{ -0.951058f, 0.000000f, 0.309013f },
|
||||
{ -0.587786f, 0.000000f, 0.809017f },
|
||||
{ -0.587786f, 0.000000f, -0.809017f },
|
||||
{ -0.951058f, 0.000000f, -0.309013f },
|
||||
{ 0.587786f, 0.000000f, -0.809017f },
|
||||
{ 0.000000f, 0.000000f, -1.000000f },
|
||||
{ 0.688189f, 0.525736f, 0.499997f },
|
||||
{ -0.262869f, 0.525738f, 0.809012f },
|
||||
{ -0.850648f, 0.525736f, 0.000000f },
|
||||
{ -0.262869f, 0.525738f, -0.809012f },
|
||||
{ 0.688189f, 0.525736f, -0.499997f },
|
||||
{ 0.162456f, 0.850654f, 0.499995f },
|
||||
{ 0.525730f, 0.850652f, 0.000000f },
|
||||
{ -0.425323f, 0.850654f, 0.309011f },
|
||||
{ -0.425323f, 0.850654f, -0.309011f },
|
||||
{ 0.162456f, 0.850654f, -0.499995f },
|
||||
};
|
||||
|
||||
constexpr vec3 normals[] = {
|
||||
{ 0.102400f, -0.943500f, 0.315100f },
|
||||
{ 0.700200f, -0.661700f, 0.268000f },
|
||||
{ -0.268000f, -0.943500f, 0.194700f },
|
||||
{ -0.268000f, -0.943500f, -0.194700f },
|
||||
{ 0.102400f, -0.943500f, -0.315100f },
|
||||
{ 0.905000f, -0.330400f, 0.268000f },
|
||||
{ 0.024700f, -0.330400f, 0.943500f },
|
||||
{ -0.889700f, -0.330400f, 0.315100f },
|
||||
{ -0.574600f, -0.330400f, -0.748800f },
|
||||
{ 0.534600f, -0.330400f, -0.777900f },
|
||||
{ 0.802600f, -0.125600f, 0.583100f },
|
||||
{ -0.306600f, -0.125600f, 0.943500f },
|
||||
{ -0.992100f, -0.125600f, -0.000000f },
|
||||
{ -0.306600f, -0.125600f, -0.943500f },
|
||||
{ 0.802600f, -0.125600f, -0.583100f },
|
||||
{ 0.408900f, 0.661700f, 0.628400f },
|
||||
{ -0.471300f, 0.661700f, 0.583100f },
|
||||
{ -0.700200f, 0.661700f, -0.268000f },
|
||||
{ 0.038500f, 0.661700f, -0.748800f },
|
||||
{ 0.724000f, 0.661700f, -0.194700f },
|
||||
{ 0.268000f, 0.943500f, -0.194700f },
|
||||
{ 0.491100f, 0.794700f, -0.356800f },
|
||||
{ 0.408900f, 0.661700f, -0.628400f },
|
||||
{ -0.102400f, 0.943500f, -0.315100f },
|
||||
{ -0.187600f, 0.794700f, -0.577300f },
|
||||
{ -0.471300f, 0.661700f, -0.583100f },
|
||||
{ -0.331300f, 0.943500f, -0.000000f },
|
||||
{ -0.607100f, 0.794700f, -0.000000f },
|
||||
{ -0.700200f, 0.661700f, 0.268000f },
|
||||
{ -0.102400f, 0.943500f, 0.315100f },
|
||||
{ -0.187600f, 0.794700f, 0.577300f },
|
||||
{ 0.038500f, 0.661700f, 0.748800f },
|
||||
{ 0.268000f, 0.943500f, 0.194700f },
|
||||
{ 0.491100f, 0.794700f, 0.356800f },
|
||||
{ 0.724000f, 0.661700f, 0.194700f },
|
||||
{ 0.889700f, 0.330400f, -0.315100f },
|
||||
{ 0.794700f, 0.187600f, -0.577300f },
|
||||
{ 0.574600f, 0.330400f, -0.748800f },
|
||||
{ -0.024700f, 0.330400f, -0.943500f },
|
||||
{ -0.303500f, 0.187600f, -0.934200f },
|
||||
{ -0.534600f, 0.330400f, -0.777900f },
|
||||
{ -0.905000f, 0.330400f, -0.268000f },
|
||||
{ -0.982200f, 0.187600f, -0.000000f },
|
||||
{ -0.905000f, 0.330400f, 0.268000f },
|
||||
{ -0.534600f, 0.330400f, 0.777900f },
|
||||
{ -0.303500f, 0.187600f, 0.934200f },
|
||||
{ -0.024700f, 0.330400f, 0.943500f },
|
||||
{ 0.574600f, 0.330400f, 0.748800f },
|
||||
{ 0.794700f, 0.187600f, 0.577300f },
|
||||
{ 0.889700f, 0.330400f, 0.315100f },
|
||||
{ 0.306600f, 0.125600f, -0.943500f },
|
||||
{ 0.303500f, -0.187600f, -0.934200f },
|
||||
{ 0.024700f, -0.330400f, -0.943500f },
|
||||
{ -0.802600f, 0.125600f, -0.583100f },
|
||||
{ -0.794700f, -0.187600f, -0.577300f },
|
||||
{ -0.889700f, -0.330400f, -0.315100f },
|
||||
{ -0.802600f, 0.125600f, 0.583100f },
|
||||
{ -0.794700f, -0.187600f, 0.577300f },
|
||||
{ -0.574600f, -0.330400f, 0.748800f },
|
||||
{ 0.306600f, 0.125600f, 0.943500f },
|
||||
{ 0.303500f, -0.187600f, 0.934200f },
|
||||
{ 0.534600f, -0.330400f, 0.777900f },
|
||||
{ 0.992100f, 0.125600f, -0.000000f },
|
||||
{ 0.982200f, -0.187600f, -0.000000f },
|
||||
{ 0.905000f, -0.330400f, -0.268000f },
|
||||
{ 0.471300f, -0.661700f, -0.583100f },
|
||||
{ 0.187600f, -0.794700f, -0.577300f },
|
||||
{ -0.038500f, -0.661700f, -0.748800f },
|
||||
{ -0.408900f, -0.661700f, -0.628400f },
|
||||
{ -0.491100f, -0.794700f, -0.356800f },
|
||||
{ -0.724000f, -0.661700f, -0.194700f },
|
||||
{ -0.724000f, -0.661700f, 0.194700f },
|
||||
{ -0.491100f, -0.794700f, 0.356800f },
|
||||
{ -0.408900f, -0.661700f, 0.628400f },
|
||||
{ 0.700200f, -0.661700f, -0.268000f },
|
||||
{ 0.607100f, -0.794700f, -0.000000f },
|
||||
{ 0.331300f, -0.943500f, -0.000000f },
|
||||
{ -0.038500f, -0.661700f, 0.748800f },
|
||||
{ 0.187600f, -0.794700f, 0.577300f },
|
||||
{ 0.471300f, -0.661700f, 0.583100f },
|
||||
};
|
||||
|
||||
constexpr face faces[] = {
|
||||
{{ 0, 0}, {13, 0}, {12, 0}},
|
||||
{{ 1, 1}, {13, 1}, {15, 1}},
|
||||
{{ 0, 2}, {12, 2}, {17, 2}},
|
||||
{{ 0, 3}, {17, 3}, {19, 3}},
|
||||
{{ 0, 4}, {19, 4}, {16, 4}},
|
||||
{{ 1, 5}, {15, 5}, {22, 5}},
|
||||
{{ 2, 6}, {14, 6}, {24, 6}},
|
||||
{{ 3, 7}, {18, 7}, {26, 7}},
|
||||
{{ 4, 8}, {20, 8}, {28, 8}},
|
||||
{{ 5, 9}, {21, 9}, {30, 9}},
|
||||
{{ 1, 10}, {22, 10}, {25, 10}},
|
||||
{{ 2, 11}, {24, 11}, {27, 11}},
|
||||
{{ 3, 12}, {26, 12}, {29, 12}},
|
||||
{{ 4, 13}, {28, 13}, {31, 13}},
|
||||
{{ 5, 14}, {30, 14}, {23, 14}},
|
||||
{{ 6, 15}, {32, 15}, {37, 15}},
|
||||
{{ 7, 16}, {33, 16}, {39, 16}},
|
||||
{{ 8, 17}, {34, 17}, {40, 17}},
|
||||
{{ 9, 18}, {35, 18}, {41, 18}},
|
||||
{{10, 19}, {36, 19}, {38, 19}},
|
||||
{{38, 20}, {41, 20}, {11, 20}},
|
||||
{{38, 21}, {36, 21}, {41, 21}},
|
||||
{{36, 22}, { 9, 22}, {41, 22}},
|
||||
{{41, 23}, {40, 23}, {11, 23}},
|
||||
{{41, 24}, {35, 24}, {40, 24}},
|
||||
{{35, 25}, { 8, 25}, {40, 25}},
|
||||
{{40, 26}, {39, 26}, {11, 26}},
|
||||
{{40, 27}, {34, 27}, {39, 27}},
|
||||
{{34, 28}, { 7, 28}, {39, 28}},
|
||||
{{39, 29}, {37, 29}, {11, 29}},
|
||||
{{39, 30}, {33, 30}, {37, 30}},
|
||||
{{33, 31}, { 6, 31}, {37, 31}},
|
||||
{{37, 32}, {38, 32}, {11, 32}},
|
||||
{{37, 33}, {32, 33}, {38, 33}},
|
||||
{{32, 34}, {10, 34}, {38, 34}},
|
||||
{{23, 35}, {36, 35}, {10, 35}},
|
||||
{{23, 36}, {30, 36}, {36, 36}},
|
||||
{{30, 37}, { 9, 37}, {36, 37}},
|
||||
{{31, 38}, {35, 38}, { 9, 38}},
|
||||
{{31, 39}, {28, 39}, {35, 39}},
|
||||
{{28, 40}, { 8, 40}, {35, 40}},
|
||||
{{29, 41}, {34, 41}, { 8, 41}},
|
||||
{{29, 42}, {26, 42}, {34, 42}},
|
||||
{{26, 43}, { 7, 43}, {34, 43}},
|
||||
{{27, 44}, {33, 44}, { 7, 44}},
|
||||
{{27, 45}, {24, 45}, {33, 45}},
|
||||
{{24, 46}, { 6, 46}, {33, 46}},
|
||||
{{25, 47}, {32, 47}, { 6, 47}},
|
||||
{{25, 48}, {22, 48}, {32, 48}},
|
||||
{{22, 49}, {10, 49}, {32, 49}},
|
||||
{{30, 50}, {31, 50}, { 9, 50}},
|
||||
{{30, 51}, {21, 51}, {31, 51}},
|
||||
{{21, 52}, { 4, 52}, {31, 52}},
|
||||
{{28, 53}, {29, 53}, { 8, 53}},
|
||||
{{28, 54}, {20, 54}, {29, 54}},
|
||||
{{20, 55}, { 3, 55}, {29, 55}},
|
||||
{{26, 56}, {27, 56}, { 7, 56}},
|
||||
{{26, 57}, {18, 57}, {27, 57}},
|
||||
{{18, 58}, { 2, 58}, {27, 58}},
|
||||
{{24, 59}, {25, 59}, { 6, 59}},
|
||||
{{24, 60}, {14, 60}, {25, 60}},
|
||||
{{14, 61}, { 1, 61}, {25, 61}},
|
||||
{{22, 62}, {23, 62}, {10, 62}},
|
||||
{{22, 63}, {15, 63}, {23, 63}},
|
||||
{{15, 64}, { 5, 64}, {23, 64}},
|
||||
{{16, 65}, {21, 65}, { 5, 65}},
|
||||
{{16, 66}, {19, 66}, {21, 66}},
|
||||
{{19, 67}, { 4, 67}, {21, 67}},
|
||||
{{19, 68}, {20, 68}, { 4, 68}},
|
||||
{{19, 69}, {17, 69}, {20, 69}},
|
||||
{{17, 70}, { 3, 70}, {20, 70}},
|
||||
{{17, 71}, {18, 71}, { 3, 71}},
|
||||
{{17, 72}, {12, 72}, {18, 72}},
|
||||
{{12, 73}, { 2, 73}, {18, 73}},
|
||||
{{15, 74}, {16, 74}, { 5, 74}},
|
||||
{{15, 75}, {13, 75}, {16, 75}},
|
||||
{{13, 76}, { 0, 76}, {16, 76}},
|
||||
{{12, 77}, {14, 77}, { 2, 77}},
|
||||
{{12, 78}, {13, 78}, {14, 78}},
|
||||
{{13, 79}, { 1, 79}, {14, 79}},
|
||||
};
|
||||
|
||||
constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face));
|
||||
|
||||
}
|
206
geometry/icosphere.obj
Normal file
206
geometry/icosphere.obj
Normal file
@ -0,0 +1,206 @@
|
||||
# Blender 3.3.6
|
||||
# www.blender.org
|
||||
o Icosphere
|
||||
v 0.000000 -1.000000 0.000000
|
||||
v 0.723607 -0.447220 0.525725
|
||||
v -0.276388 -0.447220 0.850649
|
||||
v -0.894426 -0.447216 0.000000
|
||||
v -0.276388 -0.447220 -0.850649
|
||||
v 0.723607 -0.447220 -0.525725
|
||||
v 0.276388 0.447220 0.850649
|
||||
v -0.723607 0.447220 0.525725
|
||||
v -0.723607 0.447220 -0.525725
|
||||
v 0.276388 0.447220 -0.850649
|
||||
v 0.894426 0.447216 0.000000
|
||||
v 0.000000 1.000000 0.000000
|
||||
v -0.162456 -0.850654 0.499995
|
||||
v 0.425323 -0.850654 0.309011
|
||||
v 0.262869 -0.525738 0.809012
|
||||
v 0.850648 -0.525736 0.000000
|
||||
v 0.425323 -0.850654 -0.309011
|
||||
v -0.525730 -0.850652 0.000000
|
||||
v -0.688189 -0.525736 0.499997
|
||||
v -0.162456 -0.850654 -0.499995
|
||||
v -0.688189 -0.525736 -0.499997
|
||||
v 0.262869 -0.525738 -0.809012
|
||||
v 0.951058 0.000000 0.309013
|
||||
v 0.951058 0.000000 -0.309013
|
||||
v 0.000000 0.000000 1.000000
|
||||
v 0.587786 0.000000 0.809017
|
||||
v -0.951058 0.000000 0.309013
|
||||
v -0.587786 0.000000 0.809017
|
||||
v -0.587786 0.000000 -0.809017
|
||||
v -0.951058 0.000000 -0.309013
|
||||
v 0.587786 0.000000 -0.809017
|
||||
v 0.000000 0.000000 -1.000000
|
||||
v 0.688189 0.525736 0.499997
|
||||
v -0.262869 0.525738 0.809012
|
||||
v -0.850648 0.525736 0.000000
|
||||
v -0.262869 0.525738 -0.809012
|
||||
v 0.688189 0.525736 -0.499997
|
||||
v 0.162456 0.850654 0.499995
|
||||
v 0.525730 0.850652 0.000000
|
||||
v -0.425323 0.850654 0.309011
|
||||
v -0.425323 0.850654 -0.309011
|
||||
v 0.162456 0.850654 -0.499995
|
||||
vn 0.1024 -0.9435 0.3151
|
||||
vn 0.7002 -0.6617 0.2680
|
||||
vn -0.2680 -0.9435 0.1947
|
||||
vn -0.2680 -0.9435 -0.1947
|
||||
vn 0.1024 -0.9435 -0.3151
|
||||
vn 0.9050 -0.3304 0.2680
|
||||
vn 0.0247 -0.3304 0.9435
|
||||
vn -0.8897 -0.3304 0.3151
|
||||
vn -0.5746 -0.3304 -0.7488
|
||||
vn 0.5346 -0.3304 -0.7779
|
||||
vn 0.8026 -0.1256 0.5831
|
||||
vn -0.3066 -0.1256 0.9435
|
||||
vn -0.9921 -0.1256 -0.0000
|
||||
vn -0.3066 -0.1256 -0.9435
|
||||
vn 0.8026 -0.1256 -0.5831
|
||||
vn 0.4089 0.6617 0.6284
|
||||
vn -0.4713 0.6617 0.5831
|
||||
vn -0.7002 0.6617 -0.2680
|
||||
vn 0.0385 0.6617 -0.7488
|
||||
vn 0.7240 0.6617 -0.1947
|
||||
vn 0.2680 0.9435 -0.1947
|
||||
vn 0.4911 0.7947 -0.3568
|
||||
vn 0.4089 0.6617 -0.6284
|
||||
vn -0.1024 0.9435 -0.3151
|
||||
vn -0.1876 0.7947 -0.5773
|
||||
vn -0.4713 0.6617 -0.5831
|
||||
vn -0.3313 0.9435 -0.0000
|
||||
vn -0.6071 0.7947 -0.0000
|
||||
vn -0.7002 0.6617 0.2680
|
||||
vn -0.1024 0.9435 0.3151
|
||||
vn -0.1876 0.7947 0.5773
|
||||
vn 0.0385 0.6617 0.7488
|
||||
vn 0.2680 0.9435 0.1947
|
||||
vn 0.4911 0.7947 0.3568
|
||||
vn 0.7240 0.6617 0.1947
|
||||
vn 0.8897 0.3304 -0.3151
|
||||
vn 0.7947 0.1876 -0.5773
|
||||
vn 0.5746 0.3304 -0.7488
|
||||
vn -0.0247 0.3304 -0.9435
|
||||
vn -0.3035 0.1876 -0.9342
|
||||
vn -0.5346 0.3304 -0.7779
|
||||
vn -0.9050 0.3304 -0.2680
|
||||
vn -0.9822 0.1876 -0.0000
|
||||
vn -0.9050 0.3304 0.2680
|
||||
vn -0.5346 0.3304 0.7779
|
||||
vn -0.3035 0.1876 0.9342
|
||||
vn -0.0247 0.3304 0.9435
|
||||
vn 0.5746 0.3304 0.7488
|
||||
vn 0.7947 0.1876 0.5773
|
||||
vn 0.8897 0.3304 0.3151
|
||||
vn 0.3066 0.1256 -0.9435
|
||||
vn 0.3035 -0.1876 -0.9342
|
||||
vn 0.0247 -0.3304 -0.9435
|
||||
vn -0.8026 0.1256 -0.5831
|
||||
vn -0.7947 -0.1876 -0.5773
|
||||
vn -0.8897 -0.3304 -0.3151
|
||||
vn -0.8026 0.1256 0.5831
|
||||
vn -0.7947 -0.1876 0.5773
|
||||
vn -0.5746 -0.3304 0.7488
|
||||
vn 0.3066 0.1256 0.9435
|
||||
vn 0.3035 -0.1876 0.9342
|
||||
vn 0.5346 -0.3304 0.7779
|
||||
vn 0.9921 0.1256 -0.0000
|
||||
vn 0.9822 -0.1876 -0.0000
|
||||
vn 0.9050 -0.3304 -0.2680
|
||||
vn 0.4713 -0.6617 -0.5831
|
||||
vn 0.1876 -0.7947 -0.5773
|
||||
vn -0.0385 -0.6617 -0.7488
|
||||
vn -0.4089 -0.6617 -0.6284
|
||||
vn -0.4911 -0.7947 -0.3568
|
||||
vn -0.7240 -0.6617 -0.1947
|
||||
vn -0.7240 -0.6617 0.1947
|
||||
vn -0.4911 -0.7947 0.3568
|
||||
vn -0.4089 -0.6617 0.6284
|
||||
vn 0.7002 -0.6617 -0.2680
|
||||
vn 0.6071 -0.7947 -0.0000
|
||||
vn 0.3313 -0.9435 -0.0000
|
||||
vn -0.0385 -0.6617 0.7488
|
||||
vn 0.1876 -0.7947 0.5773
|
||||
vn 0.4713 -0.6617 0.5831
|
||||
s 0
|
||||
f 1//1 14//1 13//1
|
||||
f 2//2 14//2 16//2
|
||||
f 1//3 13//3 18//3
|
||||
f 1//4 18//4 20//4
|
||||
f 1//5 20//5 17//5
|
||||
f 2//6 16//6 23//6
|
||||
f 3//7 15//7 25//7
|
||||
f 4//8 19//8 27//8
|
||||
f 5//9 21//9 29//9
|
||||
f 6//10 22//10 31//10
|
||||
f 2//11 23//11 26//11
|
||||
f 3//12 25//12 28//12
|
||||
f 4//13 27//13 30//13
|
||||
f 5//14 29//14 32//14
|
||||
f 6//15 31//15 24//15
|
||||
f 7//16 33//16 38//16
|
||||
f 8//17 34//17 40//17
|
||||
f 9//18 35//18 41//18
|
||||
f 10//19 36//19 42//19
|
||||
f 11//20 37//20 39//20
|
||||
f 39//21 42//21 12//21
|
||||
f 39//22 37//22 42//22
|
||||
f 37//23 10//23 42//23
|
||||
f 42//24 41//24 12//24
|
||||
f 42//25 36//25 41//25
|
||||
f 36//26 9//26 41//26
|
||||
f 41//27 40//27 12//27
|
||||
f 41//28 35//28 40//28
|
||||
f 35//29 8//29 40//29
|
||||
f 40//30 38//30 12//30
|
||||
f 40//31 34//31 38//31
|
||||
f 34//32 7//32 38//32
|
||||
f 38//33 39//33 12//33
|
||||
f 38//34 33//34 39//34
|
||||
f 33//35 11//35 39//35
|
||||
f 24//36 37//36 11//36
|
||||
f 24//37 31//37 37//37
|
||||
f 31//38 10//38 37//38
|
||||
f 32//39 36//39 10//39
|
||||
f 32//40 29//40 36//40
|
||||
f 29//41 9//41 36//41
|
||||
f 30//42 35//42 9//42
|
||||
f 30//43 27//43 35//43
|
||||
f 27//44 8//44 35//44
|
||||
f 28//45 34//45 8//45
|
||||
f 28//46 25//46 34//46
|
||||
f 25//47 7//47 34//47
|
||||
f 26//48 33//48 7//48
|
||||
f 26//49 23//49 33//49
|
||||
f 23//50 11//50 33//50
|
||||
f 31//51 32//51 10//51
|
||||
f 31//52 22//52 32//52
|
||||
f 22//53 5//53 32//53
|
||||
f 29//54 30//54 9//54
|
||||
f 29//55 21//55 30//55
|
||||
f 21//56 4//56 30//56
|
||||
f 27//57 28//57 8//57
|
||||
f 27//58 19//58 28//58
|
||||
f 19//59 3//59 28//59
|
||||
f 25//60 26//60 7//60
|
||||
f 25//61 15//61 26//61
|
||||
f 15//62 2//62 26//62
|
||||
f 23//63 24//63 11//63
|
||||
f 23//64 16//64 24//64
|
||||
f 16//65 6//65 24//65
|
||||
f 17//66 22//66 6//66
|
||||
f 17//67 20//67 22//67
|
||||
f 20//68 5//68 22//68
|
||||
f 20//69 21//69 5//69
|
||||
f 20//70 18//70 21//70
|
||||
f 18//71 4//71 21//71
|
||||
f 18//72 19//72 4//72
|
||||
f 18//73 13//73 19//73
|
||||
f 13//74 3//74 19//74
|
||||
f 16//75 17//75 6//75
|
||||
f 16//76 14//76 17//76
|
||||
f 14//77 1//77 17//77
|
||||
f 13//78 15//78 3//78
|
||||
f 13//79 14//79 15//79
|
||||
f 14//80 2//80 15//80
|
2432
geometry/suzanne.hpp
Normal file
2432
geometry/suzanne.hpp
Normal file
File diff suppressed because it is too large
Load Diff
2419
geometry/suzanne.obj
Normal file
2419
geometry/suzanne.obj
Normal file
File diff suppressed because it is too large
Load Diff
112
tools/obj_to_cpp.py
Normal file
112
tools/obj_to_cpp.py
Normal file
@ -0,0 +1,112 @@
|
||||
from dataclasses import dataclass
|
||||
import sys
|
||||
|
||||
from generate import renderer
|
||||
|
||||
with open(sys.argv[1], 'r') as f:
|
||||
lines = f.read().split("\n")
|
||||
|
||||
@dataclass
|
||||
class Vertex:
|
||||
x: float
|
||||
y: float
|
||||
z: float
|
||||
|
||||
@dataclass
|
||||
class VertexNormal:
|
||||
vertex: int
|
||||
normal: int
|
||||
|
||||
Face = tuple[VertexNormal, VertexNormal, VertexNormal]
|
||||
|
||||
name = None
|
||||
vertices = []
|
||||
normals = []
|
||||
faces = []
|
||||
|
||||
def parse_object(line):
|
||||
h, name = line.split()
|
||||
assert h == 'o'
|
||||
return name.lower()
|
||||
|
||||
def parse_vertex(line):
|
||||
h, *xyz = line.split()
|
||||
assert h == 'v' or h == 'vn'
|
||||
assert len(xyz) == 3
|
||||
return Vertex(*map(float, xyz))
|
||||
|
||||
def maybe_int(i, offset):
|
||||
if i.strip() == "":
|
||||
return None
|
||||
else:
|
||||
return int(i) + offset
|
||||
|
||||
def parse_face(line):
|
||||
h, *tri = line.split()
|
||||
assert h == 'f'
|
||||
assert len(tri) == 3
|
||||
def parse_ixs(ixs):
|
||||
ix = ixs.split('/')
|
||||
assert len(ix) == 3
|
||||
vertex_ix, uv_ix, normal_ix = [
|
||||
maybe_int(iix, offset=-1)
|
||||
for iix in ix
|
||||
]
|
||||
return VertexNormal(vertex_ix, normal_ix)
|
||||
|
||||
return tuple(map(parse_ixs, tri))
|
||||
|
||||
def generate_vertices(vertices):
|
||||
yield "constexpr vec3 vertices[] = {"
|
||||
for v in vertices:
|
||||
yield f"{{ {v.x:9f}f, {v.y:9f}f, {v.z:9f}f }},"
|
||||
yield "};"
|
||||
yield ""
|
||||
|
||||
def generate_normals(normals):
|
||||
yield "constexpr vec3 normals[] = {"
|
||||
for n in normals:
|
||||
yield f"{{ {n.x:9f}f, {n.y:9f}f, {n.z:9f}f }},"
|
||||
yield "};"
|
||||
yield ""
|
||||
|
||||
def generate_faces(faces):
|
||||
yield "constexpr face faces[] = {"
|
||||
for f in faces:
|
||||
inner = ", ".join(f"{{{vn.vertex:2}, {vn.normal:2}}}" for vn in f)
|
||||
yield f"{{{inner}}},"
|
||||
yield "};"
|
||||
yield ""
|
||||
yield "constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face));"
|
||||
yield ""
|
||||
|
||||
for line in lines:
|
||||
if line.startswith('o '):
|
||||
assert name is None
|
||||
name = parse_object(line)
|
||||
elif line.startswith('v '):
|
||||
vertices.append(parse_vertex(line))
|
||||
elif line.startswith('vn '):
|
||||
normals.append(parse_vertex(line))
|
||||
elif line.startswith('f '):
|
||||
faces.append(parse_face(line))
|
||||
else:
|
||||
pass
|
||||
|
||||
def generate_namespace():
|
||||
assert name is not None
|
||||
yield "#pragma once"
|
||||
yield ""
|
||||
yield '#include "geometry.hpp"'
|
||||
yield ""
|
||||
yield f"namespace {name} {{"
|
||||
|
||||
yield from generate_vertices(vertices)
|
||||
yield from generate_normals(normals)
|
||||
yield from generate_faces(faces)
|
||||
|
||||
yield "}"
|
||||
|
||||
render, out = renderer()
|
||||
render(generate_namespace())
|
||||
sys.stdout.write(out.getvalue())
|
Loading…
x
Reference in New Issue
Block a user