1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-06-24 22:23:18 +00:00

rogueviz::objmodels:: improved preparing

This commit is contained in:
Zeno Rogue 2021-03-31 10:53:59 +02:00
parent 73c4cef0cc
commit 50ddd5c6fc
3 changed files with 26 additions and 19 deletions

View File

@ -19,13 +19,13 @@ namespace hypcity {
using namespace rogueviz::objmodels;
model city("rogueviz/models/", "emilejohansson_p2.obj");
void prepare_tf();
model city("rogueviz/models/", "emilejohansson_p2.obj", default_transformer, prepare_tf);
hyperpoint low, high;
void prepare_tf() {
if(!city.prepared) return;
city.prepared = true;
prec = 40;
@ -78,8 +78,6 @@ void prepare_tf() {
}
bool draw_city_at(cell *c, const shiftmatrix& V) {
prepare_tf();
if(nil) {
auto co = nilv::get_coord(c->master);
if(co[1]) return false;

View File

@ -27,6 +27,8 @@ void model::load_obj(model_data& md) {
if(!fs.f)
throw hr_exception("failed to open model file: " + path + fname);
preparer();
vector<hyperpoint> vertices;
vector<hyperpoint> normals;

View File

@ -243,36 +243,43 @@ namespace objmodels {
color_t color;
};
using model_type = vector<shared_ptr<object>>;
struct model_data : gi_extension {
vector<shared_ptr<object>> objs;
void render(const shiftmatrix& V);
};
inline tf_result default_transformer(hyperpoint h) { return {0, direct_exp(h) };};
inline int default_subdivider(vector<hyperpoint>& hys) {
if(euclid) return 1;
ld maxlen = prec * max(hypot_d(3, hys[1] - hys[0]), max(hypot_d(3, hys[2] - hys[0]), hypot_d(3, hys[2] - hys[1])));
return int(ceil(maxlen));
}
struct model {
string path, fname;
reaction_t preparer;
transformer tf;
subdivider sd;
bool is_available, av_checked;
model(string path = "", string fn = "",
transformer tf = [] (hyperpoint h) {
return tf_result{0, direct_exp(h)};
},
subdivider sd = [] (vector<hyperpoint>& hys) {
if(euclid) return 1;
ld maxlen = prec * max(hypot_d(3, hys[1] - hys[0]), max(hypot_d(3, hys[2] - hys[0]), hypot_d(3, hys[2] - hys[1])));
return int(ceil(maxlen));
}
) : path(path), fname(fn), tf(tf), sd(sd) { av_checked = false; }
transformer tf = default_transformer,
reaction_t prep = [] {},
subdivider sd = default_subdivider
) : path(path), fname(fn), preparer(prep), tf(tf), sd(sd) { av_checked = false; }
map<string, texture::texture_data> materials;
map<string, color_t> colors;
map<string, model_type> models;
/* private */
void load_obj(model_type& objects);
void load_obj(model_data& objects);
void render(const shiftmatrix& V);
model_data& get();
void render(const shiftmatrix& V) { get().render(V); }
bool available();
};