X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=blender%2Fio_mspgl%2Fmaterial.py;h=ccbf0083f143988af633523c2b4ec2b30e10d55c;hb=4291fcf9489087492085b70e7960bdb3dbb5dc9c;hp=633f030f2ede62bc82c487ec8eb454e2e85b98b4;hpb=5606e48ae489255882203abd3976033d4cdc519c;p=libs%2Fgl.git diff --git a/blender/io_mspgl/material.py b/blender/io_mspgl/material.py index 633f030f..ccbf0083 100644 --- a/blender/io_mspgl/material.py +++ b/blender/io_mspgl/material.py @@ -219,10 +219,13 @@ class Material: self.technique = material.technique self.render_methods = material.render_methods[:] self.uniforms = material.uniforms[:] + self.face_cull = 'BACK' if material.use_backface_culling else 'NONE' self.receive_shadows = material.receive_shadows self.cast_shadows = (material.shadow_method!='NONE') self.blend_type = 'ALPHA' if material.blend_method=='BLEND' else 'NONE' + self.alpha_cutoff = material.alpha_threshold if material.blend_method=='CLIP' else 0.0 self.image_based_lighting = material.image_based_lighting + self.instancing = material.instancing if self.render_mode=='EXTERNAL' and not self.technique: raise Exception("Invalid configuration on material {}: No technique for external rendering".format(self.name)) @@ -294,70 +297,3 @@ class Material: prop = MaterialProperty(*args) self.properties.append(prop) return prop - - -class MaterialAtlas: - def __init__(self, materials): - self.render_mode = materials[0].render_mode - if self.render_mode=='EXTERNAL': - raise Exception("Material atlas with external render mode does not make sense") - - 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 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") - - count = len(self.materials) - size = 1 - while size*size*2=count: - self.size = (size, size) - else: - self.size = (size*2, size) - - from .util import get_colormap - - cm = get_colormap(True) - self.base_color_data = "" - for m in map(Material, self.materials): - if any(p.texture for p in m.properties): - raise Exception("Texturing is incompatible with material atlas") - base_color = [int(cm(c)*255) for c in m.base_color.value] - self.base_color_data += "\\x{:02X}\\x{:02X}\\x{:02X}\\xFF".format(*base_color) - self.base_color_data += "\\x00\\x00\\x00\\x00"*(self.size[0]*self.size[1]-count) - - def get_material_uv(self, material): - index = self.material_names.index(material.name) - x = index%self.size[0] - y = index//self.size[0] - return ((x+0.5)/self.size[0], (y+0.5)/self.size[1]) - -def create_material_atlas(context, material): - if not material.material_atlas: - raise Exception("Material is not part of a material atlas") - - method_hash = compute_render_method_hash(material) - materials = [] - for m in context.blend_data.materials: - if m.material_atlas and compute_render_method_hash(m)==method_hash: - materials.append(m) - - return MaterialAtlas(materials)