1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-06-18 11:19:59 +00:00

3d:: texture:: remap single-type textures to 3D geometries

This commit is contained in:
Zeno Rogue 2019-04-12 15:18:16 +02:00
parent f8a7cf8c74
commit 418fa37dd8
3 changed files with 53 additions and 8 deletions

View File

@ -4481,7 +4481,7 @@ void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) {
set_floor(shFullFloor);
#if CAP_TEXTURE
else if(texture::config.apply(c, Vf, darkena(fcol, fd, 0xFF))) ;
else if(DIM == 2 && texture::config.apply(c, Vf, darkena(fcol, fd, 0xFF))) ;
#endif
else if(c->land == laMirrorWall) {
@ -4937,6 +4937,9 @@ void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) {
if(DIM == 3) {
color_t dummy;
if(isWall3(c, wcol)) {
color_t wcol2 = wcol;
if(texture::config.tstate == texture::tsActive) wcol2 = texture::config.recolor(wcol);
int d = (wcol & 0xF0F0F0) >> 4;
for(int a=0; a<c->type; a++)
@ -4944,12 +4947,18 @@ void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) {
if(a < 4 && pmodel == mdPerspective && among(geometry, gHoroTris, gBinary3) && celldistAlt(c) >= celldistAlt(viewctr.at->c7)) continue;
if(a < 2 && pmodel == mdPerspective && among(geometry, gHoroRec) && celldistAlt(c) >= celldistAlt(viewctr.at->c7)) continue;
if(qfi.fshape && wmescher) {
auto& poly = queuepoly(V, shWall3D[a], darkena(wcol - d * get_darkval(a), 0, 0xFF));
poly.tinf = &qfi.fshape->tinf3;
poly.offset_texture = 0;
auto& poly = queuepoly(V, shWall3D[a], darkena(wcol2 - d * get_darkval(a), 0, 0xFF));
if(texture::config.tstate == texture::tsActive && isize(texture::config.tinf3.tvertices)) {
poly.tinf = &texture::config.tinf3;
poly.offset_texture = 0;
}
else {
poly.tinf = &qfi.fshape->tinf3;
poly.offset_texture = 0;
}
}
else
queuepoly(V, shPlainWall3D[a], darkena(wcol - d * get_darkval(a), 0, 0xFF));
queuepoly(V, shPlainWall3D[a], darkena(wcol2 - d * get_darkval(a), 0, 0xFF));
}
}
else {

View File

@ -3398,6 +3398,8 @@ namespace texture {
map<int, textureinfo> texture_map, texture_map_orig;
set<cell*> models;
basic_textureinfo tinf3;
bool texture_tuned;
string texture_tuner;

View File

@ -458,6 +458,38 @@ void texture_config::perform_mapping() {
set<int> missing_cells_known;
void texture_config::finish_mapping() {
tinf3.tvertices.clear();
tinf3.texture_id = config.data.textureid;
if(isize(texture_map) && isize(texture_map.begin()->second.triangles)) {
auto& tri = texture_map.begin()->second.triangles[0];
auto& tv = tri.tv;
const int STEP = TEXTURE_STEP_3D;
using namespace hyperpoint_vec;
auto at = [&] (hyperpoint h, int a) {
h = normalize(h);
tinf3.tvertices.push_back(glhr::pointtogl(texture_coordinates(h)));
};
for(int a=0; a<8; a++)
for(int y=0; y<STEP; y++)
for(int x=0; x<STEP; x++) {
hyperpoint center = tv[0];
hyperpoint v1 = (tv[1] - center) / STEP;
hyperpoint v2 = (tv[2] - center) / STEP;
if(x+y < STEP) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x+1) + v2 * y, 1);
at(center + v1 * x + v2 * (y+1), 2);
}
if(x+y <= STEP && x && y) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x-1) + v2 * y, 1);
at(center + v1 * x + v2 * (y-1), 2);
}
}
}
if(config.tstate == tsActive) {
for(auto& mi: texture_map)
mapTexture2(mi.second);
@ -1087,11 +1119,11 @@ void showMenu() {
dialog::addItem(XLAT("select geometry/pattern"), 'r');
if(config.tstate_max == tsAdjusting || config.tstate_max == tsActive)
dialog::addItem(XLAT("reactivate the texture"), 't');
dialog::addItem(XLAT("open PNG as texture"), 'o');
if(DIM == 2 && !rug::rugged) dialog::addItem(XLAT("open PNG as texture"), 'o');
dialog::addItem(XLAT("load texture config"), 'l');
dialog::addSelItem(XLAT("texture size"), its(config.data.twidth), 'w');
#if CAP_EDIT
dialog::addItem(XLAT("paint a new texture"), 'n');
if(DIM == 2) dialog::addItem(XLAT("paint a new texture"), 'n');
#endif
dialog::addSelItem(XLAT("precision"), its(config.gsplits), 'P');
@ -1154,7 +1186,7 @@ void showMenu() {
dialog::addBoolItem(XLAT("aura from texture"), texture_aura, 'a');
dialog::add_action([] () { texture_aura = !texture_aura; });
#if CAP_EDIT
dialog::addItem(XLAT("edit the texture"), 'e');
if(DIM == 2) dialog::addItem(XLAT("edit the texture"), 'e');
#endif
dialog::addItem(XLAT("save the full texture image"), 'S');
dialog::addItem(XLAT("save texture config"), 's');
@ -1460,7 +1492,9 @@ void drawLine(hyperpoint h1, hyperpoint h2, color_t col, int steps) {
}
void texture_config::true_remap() {
conformal::configure();
drawthemap();
if(DIM == 3) return;
clear_texture_map();
missing_cells_known.clear();
for(cell *c: dcal) {