#include "treestore.h"
#include "logger.h"
#include "app.h"
+#include "dbg_gui.h"
#if defined(WIN32) || defined(__WIN32__)
#include <malloc.h>
#include <alloca.h>
#endif
-struct MaterialEdit {
- std::regex name_re;
+enum MaterialEditType {
+ MTL_EDIT_TEXTURE,
+ MTL_EDIT_MIRROR
+};
+
+struct MaterialEditTexture {
int attr;
Texture *tex;
};
+struct MaterialEditMirror {
+ float reflectivity;
+};
+
+struct MaterialEdit {
+ std::regex name_re;
+ MaterialEditType type;
+
+ MaterialEditTexture tex;
+ MaterialEditMirror mirror;
+};
+
static bool proc_node(MetaScene *mscn, struct ts_node *node);
static bool proc_scenefile(MetaScene *mscn, struct ts_node *node);
static bool proc_mtledit(MetaScene *mscn, MaterialEdit *med, struct ts_node *node);
void MetaScene::update(float dt)
{
+ bool expanded;
+ static char text[256];
+ if(debug_gui) {
+ ImGui::Begin("MetaScene nodes", 0, 0);
+ ImGui::Columns(2);
+
+ static bool once;
+ if(!once) {
+ float x = ImGui::GetColumnOffset(1);
+ ImGui::SetColumnOffset(1, x * 1.7);
+ once = true;
+ }
+ }
+
int nscn = scenes.size();
for(int i=0; i<nscn; i++) {
+
+ if(debug_gui) {
+ if(scenes[i]->name.empty()) {
+ sprintf(text, "scene %3d", i);
+ } else {
+ sprintf(text, "scene %3d: %s", i, scenes[i]->name.c_str());
+ }
+ expanded = parent_expanded = ImGui::TreeNode(text);
+ ImGui::NextColumn();
+ ImGui::NextColumn();
+ }
+
scenes[i]->update(dt);
+
+ if(debug_gui && expanded) {
+ ImGui::TreePop();
+ }
+ }
+
+ if(debug_gui) {
+ ImGui::Columns(1);
+ ImGui::End();
}
}
+// XXX not used, renderer draws
void MetaScene::draw() const
{
int nscn = scenes.size();
if(amtl && amtl->val.type == TS_STRING) {
restr = amtl->val.str;
}
-
med->name_re = std::regex(restr);
node = node->child_list;
}
}
- med->attr = textype;
+ med->tex.attr = textype;
if(!afile || !afile->val.str || !*afile->val.str) {
// remove
- med->tex = 0;
+ med->tex.tex = 0;
} else {
- med->tex = texman.get_texture(afile->val.str, TEX_2D, &mscn->datamap);
+ med->tex.tex = texman.get_texture(afile->val.str, TEX_2D, &mscn->datamap);
+ }
+
+ med->type = MTL_EDIT_TEXTURE;
+ break;
+ }
+
+ if(strcmp(cn->name, "mirror") == 0) {
+ // make this object a flat mirror (hopefully the object is flat otherwise this won't work)
+ float refl = 1.0f;
+
+ struct ts_attr *arefl = ts_get_attr(cn, "reflect");
+ if(arefl) {
+ if(arefl->val.type == TS_NUMBER) {
+ refl = arefl->val.fnum;
+ } else {
+ error_log("invalid reflect attribute in mirror mtledit: %s\n", arefl->val.str);
+ continue;
+ }
}
+
+ med->type = MTL_EDIT_MIRROR;
+ med->mirror.reflectivity = refl;
+ break;
}
- // TODO add more edit modes
}
return true;
static void apply_mtledit(Material *mtl, const MaterialEdit &med)
{
// TODO more edit modes...
- if(med.tex) {
- mtl->add_texture(med.tex, med.attr);
- } else {
- Texture *tex = mtl->stdtex[med.attr];
- if(tex) {
- mtl->remove_texture(tex);
+ switch(med.type) {
+ case MTL_EDIT_TEXTURE:
+ if(med.tex.tex) {
+ mtl->add_texture(med.tex.tex, med.tex.attr);
+ } else {
+ Texture *tex = mtl->stdtex[med.tex.attr];
+ if(tex) {
+ mtl->remove_texture(tex);
+ }
}
+ break;
+
+ case MTL_EDIT_MIRROR:
+ mtl->flat_mirror = med.mirror.reflectivity > 1e-6;
+ mtl->reflect = med.mirror.reflectivity;
+ break;
}
}