#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);
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;
}
}