]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor face cull settings in Blender
authorMikko Rasa <tdb@tdb.fi>
Fri, 11 Mar 2022 21:37:05 +0000 (23:37 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 11 Mar 2022 21:37:05 +0000 (23:37 +0200)
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
blender/io_mspgl/export_mesh.py
blender/io_mspgl/material.py
blender/io_mspgl/mesh.py
blender/io_mspgl/properties.py
source/materials/rendermethod.h

index 36dbdc690696346b544e2e367518859df60da693..aceb6cc0d833ccfb2ab186ff4f4eb017f09cca5c 100644 (file)
@@ -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)
 
index 220670da28fd881d270e2bbbc230085d3551db8d..012386185faa7755388f3aa108e5d02a093446ec 100644 (file)
@@ -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
index fc30d3399c94e77ec562c40fb810f017db005bc8..e92aee2f3e55303c0ddc25461316221e865c7df1 100644 (file)
@@ -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'
index fadbcee9a18e7ac1e397559c63eddb68504a2218..3b1c74dfbec9675403226a3435fed354ffed7ef8 100644 (file)
@@ -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
index ef4018264e98613811f1eea0d4be1a0bb4b59be1..26e84b2530e59476976daf68800c16e7c80e2659 100644 (file)
@@ -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"),
index 9d9ae6725437161355c605250bb00128d95c26f9..9ac9337fe321989ca187ccce126fda422b363277 100644 (file)
@@ -85,7 +85,7 @@ private:
        const Material *material = 0;
        std::string material_slot;
        std::vector<TextureSlot> textures;
-       CullMode face_cull = CULL_BACK;
+       CullMode face_cull = NO_CULL;
        Blend blend;
        bool receive_shadows = false;
        bool image_based_lighting = false;