From f150245a7284939e53f7703db2ccf4c462e87903 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Wed, 15 Apr 2020 11:49:29 +0200 Subject: [PATCH] basic WRL export (no menus) --- drawing.cpp | 3 ++ screenshot.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++++++++- sysconfig.h | 4 +++ 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/drawing.cpp b/drawing.cpp index 6ae2969f..84e78915 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -2032,6 +2032,9 @@ EX hookset *hooks_vr_draw_all; #endif EX void drawqueue() { + + if(wrl::in) { wrl::render(); return; } + callhooks(hook_drawqueue); current_display->next_shader_flags = 0; reset_projection(); diff --git a/screenshot.cpp b/screenshot.cpp index fa6ac574..814329e0 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -233,6 +233,89 @@ auto ah = addHook(hooks_args, 0, read_args); #endif EX } +/** wrl renderer */ +EX namespace wrl { +#if !CAP_WRL +EX always_false in; +#endif + +#if CAP_WRL + EX bool in; + + fhstream f; + + string coord(ld val) { + char buf[100]; + snprintf(buf, 100, "%f", val); + return buf; + } + + string coord(const hyperpoint& v, int q) { + char buf[100]; + if(q == 3) snprintf(buf, 100, "%f, %f, %f", v[0], v[1], v[2]); + if(q == 2) snprintf(buf, 100, "%f, %f", v[0], v[1]); + return buf; + } + + string color(color_t col, ld v) { + char buf[100]; + snprintf(buf, 100, "%.3f %.3f %.3f", part(col, 0)*v/255, part(col, 1)*v/255, part(col, 2)*v/255); + return buf; + } + + EX void polygon(dqi_poly& p) { + if(!(p.flags & POLY_TRIANGLES)) return; + println(f, "Shape {"); + println(f, " appearance Appearance {"); + println(f, " material Material {"); + println(f, " diffuseColor ", color(p.color, .8)); + println(f, " }"); + println(f, " }"); + // println(f, "# V = ", p.V); + println(f, " geometry IndexedFaceSet {"); + println(f, " coord Coordinate {"); + println(f, " point ["); + for(int i=0; i(&*p); + if(p2) + polygon(*p2); + } + } + + EX void take(const string& fname, const function& what IS(shot::default_screenshot_content)) { + dynamicval v2(in, true); + + f.f = fopen(fname.c_str(), "wt"); + + println(f, "#VRML V2.0 utf8"); + println(f, "WorldInfo { title \"3D model exported from HyperRogue\" info [ \"3D models exported from HyperRogue are public domain\" ] }"); + + ptds.clear(); + what(); + } +#endif +EX } #if CAP_PNG void IMAGESAVE(SDL_Surface *s, const char *fname) { @@ -250,6 +333,7 @@ purehookset hooks_hqshot; EX int shotx = 2000; EX int shoty = 2000; EX bool make_svg = false; +EX bool make_wrl = false; EX bool transparent = true; EX ld gamma = 1; EX int shotformat = -1; @@ -351,8 +435,14 @@ EX void take(string fname, const function& what IS(default_screenshot_co calcparam(); models::configure(); callhooks(hooks_take); + + if(make_wrl) { + #if CAP_WRL + wrl::take(fname); + #endif + } - if(make_svg) { + else if(make_svg) { #if CAP_SVG svg::render(fname, what); #endif @@ -417,6 +507,12 @@ int png_read_args() { else if(argis("-shotaa")) { shift(); shot_aa = argi(); } + else if(argis("-wrlshot")) { + PHASE(3); shift(); start_game(); + printf("saving WRL screenshot to %s\n", argcs()); + shot::make_wrl = true; + shot::take(argcs()); + } else return 1; return 0; } diff --git a/sysconfig.h b/sysconfig.h index c5b71623..11aad49d 100644 --- a/sysconfig.h +++ b/sysconfig.h @@ -227,6 +227,10 @@ #define CAP_SVG (CAP_FILES && !ISMOBILE && !ISMINI) #endif +#ifndef CAP_WRL +#define CAP_WRL (CAP_FILES && !ISMOBILE && !ISMINI) +#endif + #ifndef CAP_POLY #define CAP_POLY (CAP_SDLGFX || CAP_GL || CAP_SVG) #endif