struct MaterialEditMirror {
float reflectivity;
+ int plane;
};
struct MaterialEdit {
mir->reflect = obj->mtl.reflect;
if(obj->mtl.flat_mirror == MTL_MIRROR_AUTO) {
- // assume the object is actually flat, so grab the first triangle and make a plane
+ // grab the first triangle and make a plane
Triangle face = Triangle(0, (const Vec3*)mesh->get_attrib_data(MESH_ATTR_VERTEX),
mesh->get_index_data());
face.calc_normal();
mir->plane.pt = face.v[0];
mir->plane.normal = face.normal;
} else {
+ int plane_idx = obj->mtl.flat_mirror - MTL_MIRROR_AABB_PX;
+ if(obj->node) {
+ mir->plane = obj->node->get_bounds().get_plane(plane_idx);
+ } else {
+ mir->plane = obj->get_aabox().get_plane(plane_idx);
+ }
+ debug_log("mirror plane: p(%f %f %f) n(%f %f %f)\n", mir->plane.pt.x, mir->plane.pt.y,
+ mir->plane.pt.z, mir->plane.normal.x, mir->plane.normal.y, mir->plane.normal.z);
}
// check to see if we have found this mirror plane already
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;
+ int plane = MTL_MIRROR_AUTO;
+
+ struct ts_attr *aplane = ts_get_attr(cn, "plane");
+ if(aplane) {
+ if(aplane->val.type == TS_NUMBER) {
+ plane = MTL_MIRROR_AABB_PX + aplane->val.inum;
+ } else {
+ char csign, caxis;
+ if(sscanf(aplane->val.str, "aabb%c%c", &csign, &caxis) != 2 || (csign != '+' && csign != '-')) {
+ error_log("invalid reflect plane specifier: %s\n", aplane->val.str);
+ continue;
+ }
+
+ switch(tolower(caxis)) {
+ case 'x':
+ plane = caxis == '+' ? MTL_MIRROR_AABB_PX : MTL_MIRROR_AABB_NX;
+ break;
+ case 'y':
+ plane = caxis == '+' ? MTL_MIRROR_AABB_PY : MTL_MIRROR_AABB_NY;
+ break;
+ case 'z':
+ plane = caxis == '+' ? MTL_MIRROR_AABB_PZ : MTL_MIRROR_AABB_NZ;
+ break;
+ default:
+ error_log("invalid reflect plane specifier: %s\n", aplane->val.str);
+ continue;
+ }
+ }
+ }
struct ts_attr *arefl = ts_get_attr(cn, "reflect");
if(arefl) {
med->type = MTL_EDIT_MIRROR;
med->mirror.reflectivity = refl;
+ med->mirror.plane = plane;
break;
}
}
break;
case MTL_EDIT_MIRROR:
- mtl->flat_mirror = med.mirror.reflectivity > 1e-6;
+ mtl->flat_mirror = med.mirror.plane;
mtl->reflect = med.mirror.reflectivity;
break;
}