mirror of
https://github.com/Relintai/godot_voxel.git
synced 2024-11-11 20:35:08 +01:00
Fix UVs, change tables to use OpenGL convention...
This commit is contained in:
parent
b052f7fc2d
commit
d0ab02a397
@ -10,8 +10,8 @@ namespace Cube {
|
||||
// 4-------5 |
|
||||
// | 3----|--2
|
||||
// | / | / y z
|
||||
// |/ |/ |/
|
||||
// 0-------1 o--x
|
||||
// |/ |/ |/ OpenGL axis convention
|
||||
// 0-------1 x--o
|
||||
//
|
||||
//
|
||||
// o---10----o
|
||||
@ -29,47 +29,37 @@ namespace Cube {
|
||||
// Edges are ordered according to the Voxel::Edge enum (only g_edge_inormals!).
|
||||
//
|
||||
|
||||
//static const unsigned int CORNER_COUNT = 8;
|
||||
//static const unsigned int EDGE_COUNT = 12;
|
||||
|
||||
// Order doesn't technically matter here, they are for reading convenience.
|
||||
// If you need a special ordering, combine index with other tables
|
||||
// Ordered as per the cube corners diagram
|
||||
const Vector3 g_corner_position[CORNER_COUNT] = {
|
||||
Vector3(0, 0, 0),
|
||||
Vector3(1, 0, 0),
|
||||
Vector3(1, 0, 1),
|
||||
Vector3(0, 0, 0),
|
||||
Vector3(0, 0, 1),
|
||||
Vector3(0, 1, 0),
|
||||
Vector3(1, 0, 1),
|
||||
Vector3(1, 1, 0),
|
||||
Vector3(1, 1, 1),
|
||||
Vector3(0, 1, 1)
|
||||
Vector3(0, 1, 0),
|
||||
Vector3(0, 1, 1),
|
||||
Vector3(1, 1, 1)
|
||||
};
|
||||
|
||||
const int g_side_quad_triangles[SIDE_COUNT][6] = {
|
||||
// LEFT
|
||||
{ 0, 1, 2, 0, 2, 3 },
|
||||
// RIGHT
|
||||
{ 0, 1, 2, 0, 2, 3 },
|
||||
// BOTTOM
|
||||
{ 0, 1, 2, 0, 2, 3 },
|
||||
// TOP
|
||||
{ 0, 1, 2, 0, 2, 3 },
|
||||
// BACK
|
||||
{ 0, 1, 2, 0, 2, 3 },
|
||||
// FRONT
|
||||
{ 0, 1, 2, 0, 2, 3 },
|
||||
{ 0, 2, 1, 0, 3, 2 }, // LEFT (+x)
|
||||
{ 0, 2, 1, 0, 3, 2 }, // RIGHT (-x)
|
||||
{ 0, 2, 1, 0, 3, 2 }, // BOTTOM (-y)
|
||||
{ 0, 2, 1, 0, 3, 2 }, // TOP (+y)
|
||||
{ 0, 2, 1, 0, 3, 2 }, // BACK (-z)
|
||||
{ 0, 2, 1, 0, 3, 2 }, // FRONT (+z)
|
||||
};
|
||||
|
||||
const unsigned int g_side_coord[SIDE_COUNT] = { 0, 0, 1, 1, 2, 2 };
|
||||
const unsigned int g_side_sign[SIDE_COUNT] = { 0, 1, 0, 1, 0, 1 };
|
||||
//const unsigned int g_side_coord[SIDE_COUNT] = { 0, 0, 1, 1, 2, 2 };
|
||||
//const unsigned int g_side_sign[SIDE_COUNT] = { 0, 1, 0, 1, 0, 1 };
|
||||
|
||||
const Vector3i g_side_normals[SIDE_COUNT] = {
|
||||
Vector3i(-1, 0, 0),
|
||||
Vector3i(1, 0, 0),
|
||||
Vector3i(0, -1, 0),
|
||||
Vector3i(0, 1, 0),
|
||||
Vector3i(0, 0, -1),
|
||||
Vector3i(0, 0, 1),
|
||||
Vector3i(1, 0, 0), // LEFT
|
||||
Vector3i(-1, 0, 0), // RIGHT
|
||||
Vector3i(0, -1, 0), // BOTTOM
|
||||
Vector3i(0, 1, 0), // TOP
|
||||
Vector3i(0, 0, -1), // BACK
|
||||
Vector3i(0, 0, 1), // FRONT
|
||||
};
|
||||
|
||||
// Corners have same winding, relative to the face's normal
|
||||
@ -104,32 +94,32 @@ const unsigned int g_side_edges[SIDE_COUNT][4] = {
|
||||
//};
|
||||
|
||||
const Vector3i g_corner_inormals[CORNER_COUNT] = {
|
||||
Vector3i(-1, -1, -1),
|
||||
Vector3i(1, -1, -1),
|
||||
Vector3i(1, -1, 1),
|
||||
Vector3i(-1, -1, -1),
|
||||
Vector3i(-1, -1, 1),
|
||||
Vector3i(1, -1, 1),
|
||||
|
||||
Vector3i(-1, 1, -1),
|
||||
Vector3i(1, 1, -1),
|
||||
Vector3i(1, 1, 1),
|
||||
Vector3i(-1, 1, 1)
|
||||
Vector3i(-1, 1, -1),
|
||||
Vector3i(-1, 1, 1),
|
||||
Vector3i(1, 1, 1)
|
||||
};
|
||||
|
||||
const Vector3i g_edge_inormals[EDGE_COUNT] = {
|
||||
Vector3i(0, -1, -1),
|
||||
Vector3i(1, -1, 0),
|
||||
Vector3i(0, -1, 1),
|
||||
Vector3i(-1, -1, 0),
|
||||
Vector3i(0, -1, 1),
|
||||
Vector3i(1, -1, 0),
|
||||
|
||||
Vector3i(-1, 0, -1),
|
||||
Vector3i(1, 0, -1),
|
||||
Vector3i(1, 0, 1),
|
||||
Vector3i(-1, 0, -1),
|
||||
Vector3i(-1, 0, 1),
|
||||
Vector3i(1, 0, 1),
|
||||
|
||||
Vector3i(0, 1, -1),
|
||||
Vector3i(1, 1, 0),
|
||||
Vector3i(-1, 1, 0),
|
||||
Vector3i(0, 1, 1),
|
||||
Vector3i(-1, 1, 0)
|
||||
Vector3i(1, 1, 0)
|
||||
};
|
||||
|
||||
const unsigned int g_edge_corners[EDGE_COUNT][2] = {
|
||||
|
@ -54,8 +54,8 @@ extern const Vector3 g_corner_position[CORNER_COUNT];
|
||||
|
||||
extern const int g_side_quad_triangles[SIDE_COUNT][6];
|
||||
|
||||
extern const unsigned int g_side_coord[SIDE_COUNT];
|
||||
extern const unsigned int g_side_sign[SIDE_COUNT];
|
||||
//extern const unsigned int g_side_coord[SIDE_COUNT];
|
||||
//extern const unsigned int g_side_sign[SIDE_COUNT];
|
||||
|
||||
extern const Vector3i g_side_normals[SIDE_COUNT];
|
||||
|
||||
|
13
voxel.cpp
13
voxel.cpp
@ -220,14 +220,19 @@ void Voxel::update_cube_uv_sides() {
|
||||
}
|
||||
|
||||
float e = 0.001;
|
||||
// Winding is the same as the one chosen in Cube:: vertices
|
||||
// I am confused. I read in at least 3 OpenGL tutorials that texture coordinates start at bottom-left (0,0).
|
||||
// But even though Godot is said to follow OpenGL's convention, the engine starts at top-left!
|
||||
const Vector2 uv[4] = {
|
||||
Vector2(e, e),
|
||||
Vector2(1.f - e, e),
|
||||
Vector2(1.f - e, 1.f - e),
|
||||
Vector2(e, 1.f - e),
|
||||
Vector2(1.f - e, 1.f - e),
|
||||
Vector2(1.f - e, e),
|
||||
Vector2(e, e),
|
||||
};
|
||||
|
||||
float s = 1.0 / (float)library->get_atlas_size();
|
||||
float atlas_size = (float)library->get_atlas_size();
|
||||
CRASH_COND(atlas_size <= 0);
|
||||
float s = 1.0 / atlas_size;
|
||||
|
||||
for (unsigned int side = 0; side < Cube::SIDE_COUNT; ++side) {
|
||||
_model_side_uvs[side].resize(4);
|
||||
|
@ -131,8 +131,8 @@ Array VoxelMesher::build(const VoxelBuffer &buffer, unsigned int channel, Vector
|
||||
int deck_size = buffer.get_size().x * row_size;
|
||||
|
||||
int side_neighbor_lut[Cube::SIDE_COUNT];
|
||||
side_neighbor_lut[Cube::SIDE_LEFT] = -row_size;
|
||||
side_neighbor_lut[Cube::SIDE_RIGHT] = row_size;
|
||||
side_neighbor_lut[Cube::SIDE_LEFT] = row_size;
|
||||
side_neighbor_lut[Cube::SIDE_RIGHT] = -row_size;
|
||||
side_neighbor_lut[Cube::SIDE_BACK] = -deck_size;
|
||||
side_neighbor_lut[Cube::SIDE_FRONT] = deck_size;
|
||||
side_neighbor_lut[Cube::SIDE_BOTTOM] = -1;
|
||||
@ -363,6 +363,14 @@ Array VoxelMesher::build(const VoxelBuffer &buffer, unsigned int channel, Vector
|
||||
const Arrays &arrays = _arrays[i];
|
||||
if (arrays.positions.size() != 0) {
|
||||
|
||||
/*print_line("Arrays:");
|
||||
for(int i = 0; i < arrays.positions.size(); ++i)
|
||||
print_line(String(" P {0}").format(varray(arrays.positions[i])));
|
||||
for(int i = 0; i < arrays.normals.size(); ++i)
|
||||
print_line(String(" N {0}").format(varray(arrays.normals[i])));
|
||||
for(int i = 0; i < arrays.uvs.size(); ++i)
|
||||
print_line(String(" UV {0}").format(varray(arrays.uvs[i])));*/
|
||||
|
||||
Array mesh_arrays;
|
||||
mesh_arrays.resize(Mesh::ARRAY_MAX);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user