static bool load_material(Lib3dsFile *file, const char *name, Material *mat) { Lib3dsMaterial *m; if(!name || !*name || !(m = lib3ds_file_material_by_name(file, name))) { return false; } mat->name = name; mat->ambient_color = CONV_RGBA(m->ambient); mat->diffuse_color = CONV_RGBA(m->diffuse); mat->specular_color = CONV_RGBA(m->specular) * m->shin_strength; if(m->self_illum) { std::cerr << "self illuminating material: " << name << std::endl; mat->emissive_color = 1.0; } scalar_t s = pow(2.0, 10.0 * m->shininess); mat->specular_power = s > 128.0 ? 128.0 : s; mat->alpha = 1.0 - m->transparency; if(m->shading == LIB3DS_WIRE_FRAME || m->use_wire) { mat->wireframe = true; } if(m->shading == LIB3DS_FLAT) { mat->shading = SHADING_FLAT; } // load the textures Texture *tex = 0, *detail = 0, *env = 0, *light = 0, *bump = 0; const char *tpath; tpath = tex_path(m->texture1_map.name); if(tpath && (tex = get_texture(tpath))) { mat->set_texture(tex, TEXTYPE_DIFFUSE); } tpath = tex_path(m->texture2_map.name); if(tpath && (detail = get_texture(tpath))) { mat->set_texture(detail, TEXTYPE_DETAIL); } tpath = tex_path(m->reflection_map.name); if(tpath && (env = get_texture(tpath))) { mat->set_texture(env, TEXTYPE_ENVMAP); mat->env_intensity = m->reflection_map.percent; } tpath = tex_path(m->bump_map.name); if(tpath && (bump = get_texture(tpath))) { //FIXME: make dot3 work first mat->set_texture(bump, TEXTYPE_BUMPMAP); } tpath = tex_path(m->self_illum_map.name); if(tpath && (light = get_texture(tpath))) { mat->set_texture(light, TEXTYPE_LIGHTMAP); } if(m->autorefl_map.flags & LIB3DS_USE_REFL_MAP) { mat->env_intensity = m->reflection_map.percent; int cube_sz = m->autorefl_map.size; if(!is_pow_two(cube_sz)) { warning("Material \"%s\" specifies a non power of 2 cube map and won't render correctly!", m->name); } Texture *cube_tex = new Texture(cube_sz, cube_sz, TEX_CUBE); add_texture(cube_tex); mat->set_texture(cube_tex, TEXTYPE_ENVMAP); if(m->autorefl_map.flags & LIB3DS_READ_FIRST_FRAME_ONLY || m->autorefl_map.flags & 0x8 || m->autorefl_map.frame_step == 1000) { mat->auto_refl = false; } mat->auto_refl_upd = m->autorefl_map.frame_step; } return true; }
inline str_ptr toon_name(Cstr_ptr& name) { return tex_path() + name; }