X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=blender%2Fio_mspgl%2Fmaterial.py;h=eb4c7c2444b18da82b6318585ff098b5f2af9e05;hb=08942dd73918a51baefbe7344b62afc0cad42e55;hp=1d6a06a0b0730974365d21e65a3f19760b566bea;hpb=dbc91b65728ab9c0e574bb1127cfe4d2da55de7f;p=libs%2Fgl.git diff --git a/blender/io_mspgl/material.py b/blender/io_mspgl/material.py index 1d6a06a0..eb4c7c24 100644 --- a/blender/io_mspgl/material.py +++ b/blender/io_mspgl/material.py @@ -1,5 +1,13 @@ import os +def compute_render_method_hash(material): + descr = "" + for m in material.render_methods: + if descr: + descr += "," + descr += "{}={}".format(m.tag, m.shader) + return hash(descr) + def check_group(node_tree, group, func): from .util import get_linked_node_and_socket @@ -93,15 +101,15 @@ class Material: self.render_mode = material.render_mode self.technique = material.technique - self.shader = material.shader + self.render_methods = material.render_methods[:] self.receive_shadows = material.receive_shadows self.cast_shadows = (material.shadow_method!='NONE') self.image_based_lighting = material.image_based_lighting if self.render_mode=='EXTERNAL' and not self.technique: raise Exception("Invalid configuration on material {}: No technique for external rendering".format(self.name)) - elif self.render_mode=='CUSTOM' and not self.shader: - raise Exception("Invalid configuration on material {}: No shader for custom rendering".format(self.name)) + elif self.render_mode=='CUSTOM' and not self.render_methods: + raise Exception("Invalid configuration on material {}: No render methods for custom rendering".format(self.name)) out_node = next((n for n in material.node_tree.nodes if n.type=='OUTPUT_MATERIAL'), None) if not out_node: @@ -164,19 +172,24 @@ class MaterialAtlas: if self.render_mode=='EXTERNAL': raise Exception("Material atlas with external render mode does not make sense") - self.shader = materials[0].shader - if self.shader: - self.name = "material_atlas_"+os.path.splitext(self.shader)[0] + if self.render_mode=='CUSTOM': + self.render_methods = materials[0].render_methods + else: + self.render_methods = None + if self.render_methods: + self.name = "material_atlas_"+os.path.splitext(self.render_methods[0].shader)[0] else: self.name = "material_atlas" self.receive_shadows = materials[0].receive_shadows self.cast_shadows = (materials[0].shadow_method!='NONE') self.materials = materials self.material_names = [m.name for m in self.materials] + self.uniforms = None + method_hash = compute_render_method_hash(self) for m in self.materials: if m.render_mode!=self.render_mode: raise Exception("Conflicting render modes in MaterialAtlas constructor") - if self.render_mode=='CUSTOM' and m.shader!=self.shader: + if self.render_mode=='CUSTOM' and compute_render_method_hash(m)!=method_hash: raise Exception("Conflicting shaders in MaterialAtlas constructor") if m.receive_shadows!=self.receive_shadows or m.shadow_method!=materials[0].shadow_method: raise Exception("Conflicting shadow settings in MaterialAtlas constructor") @@ -211,10 +224,10 @@ def create_material_atlas(context, material): if not material.material_atlas: raise Exception("Material is not part of a material atlas") - shader = material.shader + method_hash = compute_render_method_hash(material) materials = [] for m in context.blend_data.materials: - if m.material_atlas and m.shader==shader: + if m.material_atlas and compute_render_method_hash(m)==method_hash: materials.append(m) return MaterialAtlas(materials)