mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 05:52:59 +00:00 
			
		
		
		
	rogueviz::objmodels:: improved preparing
This commit is contained in:
		| @@ -19,13 +19,13 @@ namespace hypcity { | |||||||
|  |  | ||||||
| using namespace rogueviz::objmodels; | 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; | hyperpoint low, high; | ||||||
|  |  | ||||||
| void prepare_tf() { | void prepare_tf() { | ||||||
|   if(!city.prepared) return; |  | ||||||
|   city.prepared = true; |  | ||||||
|    |    | ||||||
|   prec = 40; |   prec = 40; | ||||||
|  |  | ||||||
| @@ -78,8 +78,6 @@ void prepare_tf() { | |||||||
|   } |   } | ||||||
|  |  | ||||||
| bool draw_city_at(cell *c, const shiftmatrix& V) { | bool draw_city_at(cell *c, const shiftmatrix& V) { | ||||||
|   prepare_tf(); |  | ||||||
|    |  | ||||||
|   if(nil) { |   if(nil) { | ||||||
|     auto co = nilv::get_coord(c->master); |     auto co = nilv::get_coord(c->master); | ||||||
|     if(co[1]) return false; |     if(co[1]) return false; | ||||||
|   | |||||||
| @@ -28,6 +28,8 @@ void model::load_obj(model_data& md) { | |||||||
|   if(!fs.f)  |   if(!fs.f)  | ||||||
|     throw hr_exception("failed to open model file: " + path + fname); |     throw hr_exception("failed to open model file: " + path + fname); | ||||||
|    |    | ||||||
|  |   preparer(); | ||||||
|  |  | ||||||
|   vector<hyperpoint> vertices; |   vector<hyperpoint> vertices; | ||||||
|   vector<hyperpoint> normals; |   vector<hyperpoint> normals; | ||||||
|   vector<hyperpoint> tvertices; |   vector<hyperpoint> tvertices; | ||||||
|   | |||||||
| @@ -243,36 +243,43 @@ namespace objmodels { | |||||||
|     color_t color; |     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 { |   struct model { | ||||||
|    |    | ||||||
|     string path, fname; |     string path, fname; | ||||||
|  |     reaction_t preparer; | ||||||
|     transformer tf; |     transformer tf; | ||||||
|     subdivider sd; |     subdivider sd; | ||||||
|    |    | ||||||
|     bool is_available, av_checked; |     bool is_available, av_checked; | ||||||
|  |  | ||||||
|     model(string path = "", string fn = "",  |     model(string path = "", string fn = "",  | ||||||
|       transformer tf = [] (hyperpoint h) {  |       transformer tf = default_transformer, | ||||||
|         return tf_result{0, direct_exp(h)}; |       reaction_t prep = [] {}, | ||||||
|         }, |       subdivider sd = default_subdivider | ||||||
|       subdivider sd = [] (vector<hyperpoint>& hys) {  |       ) : path(path), fname(fn), preparer(prep), tf(tf), sd(sd) { av_checked = false; } | ||||||
|         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; } |  | ||||||
|    |    | ||||||
|     map<string, texture::texture_data> materials; |     map<string, texture::texture_data> materials; | ||||||
|     map<string, color_t> colors; |     map<string, color_t> colors; | ||||||
|      |      | ||||||
|     map<string, model_type> models; |  | ||||||
|  |  | ||||||
|     /* private */ |     /* 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(); |     bool available(); | ||||||
|     }; |     }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue