Added a new fill_colors_interpolated helper method to Mesh. Now the test app uses this so it's not as hard to look at.

This commit is contained in:
Relintai 2024-01-13 19:15:28 +01:00
parent 46c57fc3c1
commit e2ff0f1969
3 changed files with 37 additions and 10 deletions

View File

@ -4,10 +4,10 @@
#include "core/memory.h"
#include "render_core/3rd_glad.h"
#include "render_core/app_window.h"
#include "render_core/keyboard.h"
#include "render_core/mesh_utils.h"
#include "render_immediate/renderer.h"
#include "render_core/app_window.h"
//#include "render_core/font.h"
void GameScene::input_event(const Ref<InputEvent> &event) {
@ -109,7 +109,7 @@ void GameScene::render() {
} else if (render_type == 3) {
_mesh_utils_test->clear();
MeshUtils::create_capsule(_mesh_utils_test, 0.5, 0.5);
_mesh_utils_test->fill_colors_random();
_mesh_utils_test->fill_colors_interpolated(Color(0.2, 0, 0), Color(1, 0, 0));
_mesh_utils_test->upload();
camera->bind();
@ -122,7 +122,7 @@ void GameScene::render() {
} else if (render_type == 4) {
_mesh_utils_test->clear();
MeshUtils::create_cube(_mesh_utils_test, Vector3(0.5, 0.5, 0.5));
_mesh_utils_test->fill_colors_random();
_mesh_utils_test->fill_colors_interpolated(Color(0.2, 0, 0), Color(1, 0, 0));
_mesh_utils_test->upload();
camera->bind();
@ -135,7 +135,7 @@ void GameScene::render() {
} else if (render_type == 5) {
_mesh_utils_test->clear();
MeshUtils::create_cylinder(_mesh_utils_test, 0.2, 0.5, 1);
_mesh_utils_test->fill_colors_random();
_mesh_utils_test->fill_colors_interpolated(Color(0.2, 0, 0), Color(1, 0, 0));
_mesh_utils_test->upload();
camera->bind();
@ -148,7 +148,7 @@ void GameScene::render() {
} else if (render_type == 6) {
_mesh_utils_test->clear();
MeshUtils::create_plane(_mesh_utils_test);
_mesh_utils_test->fill_colors_random();
_mesh_utils_test->fill_colors_interpolated(Color(0.2, 0, 0), Color(1, 0, 0));
_mesh_utils_test->upload();
camera->bind();
@ -161,7 +161,7 @@ void GameScene::render() {
} else if (render_type == 7) {
_mesh_utils_test->clear();
MeshUtils::create_prism(_mesh_utils_test);
_mesh_utils_test->fill_colors_random();
_mesh_utils_test->fill_colors_interpolated(Color(0.2, 0, 0), Color(1, 0, 0));
_mesh_utils_test->upload();
camera->bind();
@ -174,7 +174,7 @@ void GameScene::render() {
} else if (render_type == 8) {
_mesh_utils_test->clear();
MeshUtils::create_quad(_mesh_utils_test);
_mesh_utils_test->fill_colors_random();
_mesh_utils_test->fill_colors_interpolated(Color(0.2, 0, 0), Color(1, 0, 0));
_mesh_utils_test->upload();
camera->bind();
@ -187,7 +187,7 @@ void GameScene::render() {
} else if (render_type == 9) {
_mesh_utils_test->clear();
MeshUtils::create_quad_with_indices(_mesh_utils_test);
_mesh_utils_test->fill_colors_random();
_mesh_utils_test->fill_colors_interpolated(Color(0.2, 0, 0), Color(1, 0, 0));
_mesh_utils_test->upload();
camera->bind();
@ -200,7 +200,7 @@ void GameScene::render() {
} else if (render_type == 10) {
_mesh_utils_test->clear();
MeshUtils::create_sphere(_mesh_utils_test, 0.5, 0.5);
_mesh_utils_test->fill_colors_random();
_mesh_utils_test->fill_colors_interpolated(Color(0.2, 0, 0), Color(1, 0, 0));
_mesh_utils_test->upload();
camera->bind();
@ -213,7 +213,7 @@ void GameScene::render() {
} else if (render_type == 11) {
_mesh_utils_test->clear();
MeshUtils::create_point(_mesh_utils_test);
_mesh_utils_test->fill_colors_random();
_mesh_utils_test->fill_colors_interpolated(Color(0.2, 0, 0), Color(1, 0, 0));
_mesh_utils_test->upload();
camera->bind();

View File

@ -130,6 +130,31 @@ void Mesh::fill_colors_random() {
}
}
void Mesh::fill_colors_interpolated(const Color &p_from, const Color &p_to) {
while (colors.size() % 4 != 0) {
colors.push_back(0);
}
int needed_color_count = get_vertex_count() * 4;
if (colors.size() > needed_color_count) {
colors.resize(needed_color_count);
return;
}
RandomPCG r;
r.randomize();
while (colors.size() < needed_color_count) {
Color c = p_from.linear_interpolate(p_to, colors.size() / (real_t)needed_color_count);
colors.push_back(c.r);
colors.push_back(c.g);
colors.push_back(c.b);
colors.push_back(c.a);
}
}
void Mesh::update_aabb() {
aabb = AABB();

View File

@ -37,8 +37,10 @@ public:
void add_triangle(uint32_t i1, uint32_t i2, uint32_t i3);
void flip_faces();
void fill_colors(const Color &p_color);
void fill_colors_random();
void fill_colors_interpolated(const Color &p_from, const Color &p_to);
void update_aabb();