mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-27 22:39:53 +00:00
rv:: objmodels fixes
This commit is contained in:
parent
4d234a96f8
commit
19019c907a
@ -81,7 +81,8 @@ void model::load_obj(model_data& md) {
|
|||||||
emit_material();
|
emit_material();
|
||||||
nextcol = 0xFFFFFFFF;
|
nextcol = 0xFFFFFFFF;
|
||||||
texname = "";
|
texname = "";
|
||||||
mtlname = scanline(fsm);
|
fsm.get<char>();
|
||||||
|
scan(fsm, mtlname);
|
||||||
}
|
}
|
||||||
if(s == "map_Kd") {
|
if(s == "map_Kd") {
|
||||||
scan(fsm, texname);
|
scan(fsm, texname);
|
||||||
@ -93,8 +94,13 @@ void model::load_obj(model_data& md) {
|
|||||||
next_object:
|
next_object:
|
||||||
object *co = nullptr;
|
object *co = nullptr;
|
||||||
bool textured = false;
|
bool textured = false;
|
||||||
string oname = scanline(fs);
|
fs.get<char>();
|
||||||
|
string oname;
|
||||||
|
scan(fs, oname);
|
||||||
println(hlog, "reading object: ", oname);
|
println(hlog, "reading object: ", oname);
|
||||||
|
md.objindex.push_back(isize(md.objs));
|
||||||
|
hyperpoint ctr = Hypc;
|
||||||
|
int cqty = 0;
|
||||||
while(true) {
|
while(true) {
|
||||||
if(feof(fs.f)) {
|
if(feof(fs.f)) {
|
||||||
if(co) cgi.finishshape();
|
if(co) cgi.finishshape();
|
||||||
@ -117,6 +123,7 @@ void model::load_obj(model_data& md) {
|
|||||||
h[1] /= 100;
|
h[1] /= 100;
|
||||||
h[2] /= 100;
|
h[2] /= 100;
|
||||||
vertices.push_back(h);
|
vertices.push_back(h);
|
||||||
|
ctr += h; cqty++;
|
||||||
}
|
}
|
||||||
else if(s == "vt") {
|
else if(s == "vt") {
|
||||||
ld u, v;
|
ld u, v;
|
||||||
@ -134,7 +141,10 @@ void model::load_obj(model_data& md) {
|
|||||||
else if(s == "usemtl") {
|
else if(s == "usemtl") {
|
||||||
if(co) cgi.finishshape();
|
if(co) cgi.finishshape();
|
||||||
if(co) println(hlog, "vertices = ", co->sh.e-co->sh.s, " tvertices = ", isize(co->tv.tvertices));
|
if(co) println(hlog, "vertices = ", co->sh.e-co->sh.s, " tvertices = ", isize(co->tv.tvertices));
|
||||||
string mtlname = scanline(fs);
|
fs.get<char>();
|
||||||
|
string mtlname;
|
||||||
|
scan(fs, mtlname);
|
||||||
|
//string mtlname = scanline(fs);
|
||||||
co = nullptr;
|
co = nullptr;
|
||||||
if(mtlname.find("Layer_Layer0") != string::npos) continue;
|
if(mtlname.find("Layer_Layer0") != string::npos) continue;
|
||||||
objects.push_back(make_shared<object>());
|
objects.push_back(make_shared<object>());
|
||||||
@ -197,6 +207,14 @@ void model::load_obj(model_data& md) {
|
|||||||
}
|
}
|
||||||
if(!co) continue;
|
if(!co) continue;
|
||||||
|
|
||||||
|
if(shift_to_ctr) {
|
||||||
|
hyperpoint ctr1 = ctr / cqty;
|
||||||
|
ctr1[3] = 0;
|
||||||
|
println(hlog, "ctr1 = ", ctr1, "hys = ", hys[0]);
|
||||||
|
for(auto& h: hys)
|
||||||
|
h -= ctr1;
|
||||||
|
}
|
||||||
|
|
||||||
hyperpoint norm = (hys[1] - hys[0]) ^ (hys[2] - hys[0]);
|
hyperpoint norm = (hys[1] - hys[0]) ^ (hys[2] - hys[0]);
|
||||||
norm /= hypot_d(3, norm);
|
norm /= hypot_d(3, norm);
|
||||||
ld y = .5 + (.2 * norm[0] + .16 * norm[1] + .14 * norm[2]);
|
ld y = .5 + (.2 * norm[0] + .16 * norm[1] + .14 * norm[2]);
|
||||||
@ -255,6 +273,7 @@ void model::load_obj(model_data& md) {
|
|||||||
|
|
||||||
println(hlog, "reading finished");
|
println(hlog, "reading finished");
|
||||||
|
|
||||||
|
md.objindex.push_back(isize(md.objs));
|
||||||
cgi.extra_vertices();
|
cgi.extra_vertices();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,7 +296,7 @@ model_data& model::get() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void model_data::render(const shiftmatrix& V) {
|
void model_data::render(const shiftmatrix& V) {
|
||||||
for(auto& obj: objs) {
|
for(auto& obj: objs) if(obj->color) {
|
||||||
queuepoly(V, obj->sh, obj->color);
|
queuepoly(V, obj->sh, obj->color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,6 +322,7 @@ auto cf = addHook(hooks_configfile, 100, [] {
|
|||||||
->editable(1, 100, 1, "3D model precision", "higher-precision models take more time to load and to render.", 'p')
|
->editable(1, 100, 1, "3D model precision", "higher-precision models take more time to load and to render.", 'p')
|
||||||
->set_sets([] { dialog::numberdark = dialog::DONT_SHOW; })
|
->set_sets([] { dialog::numberdark = dialog::DONT_SHOW; })
|
||||||
;
|
;
|
||||||
|
param_b(shift_to_ctr, "shift_to_ctr");
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user