mat_name = material.name+".mat"
mat_out = open_output(os.path.join(path, mat_name))
self.export_material(material, mat_out)
- out_file.write("material", '""', '"{}"'.format(mat_name))
+ out_file.write("material", '"surface"', '"{}"'.format(mat_name))
out_file.end()
out_file.end()
else:
add("shader", &RenderPass::shprog);
add("material", &Loader::material_inline);
add("material", &Loader::material);
+ add("material_slot", &RenderPass::material_slot);
add("back_faces",&RenderPass::back_faces);
add("texunit", &Loader::texunit);
add("texunit", &Loader::texunit_named);
const Program *shprog;
ProgramData *shdata;
RefPtr<const Material> material;
+ std::string material_slot;
Texturing *texturing;
std::map<std::string, unsigned> tex_names;
bool back_faces;
const ProgramData *get_shader_data() const { return shdata; }
void set_material(const Material *);
const Material *get_material() const { return material.get(); }
+ const std::string &get_material_slot_name() const { return material_slot; }
void set_texture(unsigned, const Texture *);
const Texturing *get_texturing() const { return texturing; }
int get_texture_index(const std::string &) const;
return replaced;
}
+bool Technique::replace_material(const string &slot, const Material &mat)
+{
+ bool replaced = false;
+ for(PassMap::iterator i=passes.begin(); i!=passes.end(); ++i)
+ {
+ const string &pass_slot = i->second.get_material_slot_name();
+ if(!pass_slot.empty() && pass_slot==slot)
+ {
+ i->second.set_material(&mat);
+ replaced = true;
+ }
+ }
+
+ return replaced;
+}
+
bool Technique::has_shaders() const
{
for(PassMap::const_iterator i=passes.begin(); i!=passes.end(); ++i)
add("texture", &InheritLoader::texture);
}
-void Technique::InheritLoader::material(const string &pass_tag, const string &name)
+void Technique::InheritLoader::material(const string &slot, const string &name)
{
- RenderPass &pass = get_item(obj.passes, pass_tag);
const Material &mat = get_collection().get<Material>(name);
+ if(obj.replace_material(slot, mat))
+ return;
+
+ // For backwards compatibility
+ RenderPass &pass = get_item(obj.passes, slot);
if(const Material *base_mat = pass.get_material())
{
for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
const RenderPass &get_pass(const Tag &) const;
const PassMap &get_passes() const { return passes; }
bool replace_texture(const std::string &, const Texture &);
+ bool replace_material(const std::string &, const Material &);
bool has_shaders() const;
};