From 74a5bc6159d2c753786a5ef6bf785263cd0538f1 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 11 Mar 2022 23:37:05 +0200 Subject: [PATCH] Refactor face cull settings in Blender Meshes no longer have a winding test toggle. Instead mesh winding is always set and material's backface culling flag is exported. The default in RenderMethod has been changed to NO_CULL. --- blender/io_mspgl/export_material.py | 10 +++++++++- blender/io_mspgl/export_mesh.py | 5 ++--- blender/io_mspgl/material.py | 1 + blender/io_mspgl/mesh.py | 2 -- blender/io_mspgl/properties.py | 2 -- source/materials/rendermethod.h | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index 36dbdc69..aceb6cc0 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -1,5 +1,5 @@ def create_shadow_method(tech_res, material, resources, detail): - from .datafile import Statement + from .datafile import Statement, Token color_prop = next((p for p in material.properties if p.keyword and "color" in p.keyword), None) @@ -24,6 +24,9 @@ def create_shadow_method(tech_res, material, resources, detail): else: st.sub.append(Statement("shader", "occluder{}.glsl.shader".format(detail))) + if material.face_cull=='BACK': + st.sub.append(Statement("face_cull", Token("CULL_BACK"))) + return st; def create_technique_resource(material, resources): @@ -60,6 +63,9 @@ def create_technique_resource(material, resources): ss.sub.append(Statement("uniform", u.name, *u.values[:u.size])) st.sub.append(ss) + if material.face_cull=='BACK': + st.sub.append(Statement("face_cull", Token("CULL_BACK"))) + tech_res.statements.append(st) else: base_method = "blended" if material.blend_type!='NONE' else "" @@ -73,6 +79,8 @@ def create_technique_resource(material, resources): st.sub.append(Statement("receive_shadows", True)) if material.image_based_lighting: st.sub.append(Statement("image_based_lighting", True)) + if material.face_cull=='BACK': + st.sub.append(Statement("face_cull", Token("CULL_BACK"))) tech_res.statements.append(st) diff --git a/blender/io_mspgl/export_mesh.py b/blender/io_mspgl/export_mesh.py index 220670da..01238618 100644 --- a/blender/io_mspgl/export_mesh.py +++ b/blender/io_mspgl/export_mesh.py @@ -14,6 +14,8 @@ class MeshExporter: task = ctx.task("Creating statements", 1.0) + statements.append(Statement("winding", Token('COUNTERCLOCKWISE'))) + st = Statement("vertices", Token("VERTEX3_FLOAT")) stride = 12 if mesh.vertices[0].color: @@ -106,9 +108,6 @@ class MeshExporter: st.sub.append(Statement("indices", *(v.index for v in l.vertices))) statements.append(st) - if mesh.winding_test: - statements.append(Statement("winding", Token('COUNTERCLOCKWISE'))) - task.set_progress(1.0) return resource diff --git a/blender/io_mspgl/material.py b/blender/io_mspgl/material.py index fc30d339..e92aee2f 100644 --- a/blender/io_mspgl/material.py +++ b/blender/io_mspgl/material.py @@ -219,6 +219,7 @@ 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' diff --git a/blender/io_mspgl/mesh.py b/blender/io_mspgl/mesh.py index fadbcee9..3b1c74df 100644 --- a/blender/io_mspgl/mesh.py +++ b/blender/io_mspgl/mesh.py @@ -154,7 +154,6 @@ class Mesh: def __init__(self, mesh): self.name = mesh.name - self.winding_test = mesh.winding_test self.smoothing = mesh.smoothing self.use_uv = mesh.use_uv self.tangent_uvtex = mesh.tangent_uvtex @@ -817,7 +816,6 @@ def create_mesh_from_object(ctx, obj, material_atlas): bmesh = eval_obj.to_mesh() # Object.to_mesh does not copy custom properties - bmesh.winding_test = o.data.winding_test bmesh.smoothing = o.data.smoothing bmesh.use_lines = o.data.use_lines bmesh.vertex_groups = o.data.vertex_groups diff --git a/blender/io_mspgl/properties.py b/blender/io_mspgl/properties.py index ef401826..26e84b25 100644 --- a/blender/io_mspgl/properties.py +++ b/blender/io_mspgl/properties.py @@ -40,7 +40,6 @@ class MspGLMeshProperties(bpy.types.Panel): def draw(self, context): mesh = context.active_object.data - self.layout.prop(mesh, "winding_test") self.layout.prop(mesh, "smoothing") self.layout.prop(mesh, "use_strips") @@ -238,7 +237,6 @@ def register_properties(): bpy.types.World.use_sky = bpy.props.BoolProperty(name="Realtime sky", description="Use a realtime rendered sky background", default=False) bpy.types.World.sun_light = bpy.props.PointerProperty(type=bpy.types.Light, name="Sun", description="Light to use as sun for the sky") - bpy.types.Mesh.winding_test = bpy.props.BoolProperty(name="Winding test", description="Perform winding test to skip back faces") bpy.types.Mesh.smoothing = bpy.props.EnumProperty(name="Smoothing", description="Smoothing method to use", default="MSPGL", items=(("NONE", "None", "No smoothing"), ("BLENDER", "Blender", "Use Blender's vertex normals"), diff --git a/source/materials/rendermethod.h b/source/materials/rendermethod.h index 9d9ae672..9ac9337f 100644 --- a/source/materials/rendermethod.h +++ b/source/materials/rendermethod.h @@ -85,7 +85,7 @@ private: const Material *material = 0; std::string material_slot; std::vector textures; - CullMode face_cull = CULL_BACK; + CullMode face_cull = NO_CULL; Blend blend; bool receive_shadows = false; bool image_based_lighting = false; -- 2.45.2