Add option to disable backface culling for models 3209/head
authorBlockMen <nmuelll@web.de>
Mon, 28 Sep 2015 18:49:38 +0000 (20:49 +0200)
committerBlockMen <nmuelll@web.de>
Sun, 25 Oct 2015 11:06:08 +0000 (12:06 +0100)
- Disabled by default (except players)
- Fixes #2984

doc/lua_api.txt
src/content_cao.cpp
src/object_properties.cpp
src/object_properties.h
src/script/common/c_content.cpp

index e9d19ad279bb3f517d6736bc4d60966ef4b60711..5ad88b12167b523d6c8b55e7fa1a4b3fd6f46343 100644 (file)
@@ -3045,6 +3045,7 @@ Definition tables
         stepheight = 0,
         automatic_face_movement_dir = 0.0,
     --  ^ automatically set yaw to movement direction; offset in degrees; false to disable
+        backface_culling = true, -- false to disable backface_culling for model
     }
 
 ### Entity definition (`register_entity`)
index e864063a41784d6f92dfc6f060928db5cfef5c69..72f6145b067c25b6179e63fb902e471b58bcd0f3 100644 (file)
@@ -934,10 +934,15 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
                        u8 li = m_last_light;
                        setMeshColor(m_animated_meshnode->getMesh(), video::SColor(255,li,li,li));
 
+                       bool backface_culling = m_prop.backface_culling;
+                       if (m_is_player)
+                               backface_culling = false;
+
                        m_animated_meshnode->setMaterialFlag(video::EMF_LIGHTING, false);
                        m_animated_meshnode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
                        m_animated_meshnode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
                        m_animated_meshnode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
+                       m_animated_meshnode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, backface_culling);
                }
                else
                        errorstream<<"GenericCAO::addToScene(): Could not load mesh "<<m_prop.mesh<<std::endl;
index f560f59343a6d6507e6993d8b2aaacb43c84b2af..dc1eddf4eeae2c296a82aa4eb76b2d7c891f2302 100644 (file)
@@ -42,7 +42,8 @@ ObjectProperties::ObjectProperties():
        automatic_rotate(0),
        stepheight(0),
        automatic_face_movement_dir(false),
-       automatic_face_movement_dir_offset(0.0)
+       automatic_face_movement_dir_offset(0.0),
+       backface_culling(true)
 {
        textures.push_back("unknown_object.png");
        colors.push_back(video::SColor(255,255,255,255));
@@ -74,6 +75,7 @@ std::string ObjectProperties::dump()
        os<<", is_visible="<<is_visible;
        os<<", makes_footstep_sound="<<makes_footstep_sound;
        os<<", automatic_rotate="<<automatic_rotate;
+       os<<", backface_culling="<<backface_culling;
        return os.str();
 }
 
@@ -106,6 +108,7 @@ void ObjectProperties::serialize(std::ostream &os) const
        writeF1000(os,stepheight);
        writeU8(os, automatic_face_movement_dir);
        writeF1000(os, automatic_face_movement_dir_offset);
+       writeU8(os, backface_culling);
        // Add stuff only at the bottom.
        // Never remove anything, because we don't want new versions of this
 }
@@ -142,6 +145,7 @@ void ObjectProperties::deSerialize(std::istream &is)
                        stepheight = readF1000(is);
                        automatic_face_movement_dir = readU8(is);
                        automatic_face_movement_dir_offset = readF1000(is);
+                       backface_culling = readU8(is);
                }catch(SerializationError &e){}
        }
        else
@@ -149,4 +153,3 @@ void ObjectProperties::deSerialize(std::istream &is)
                throw SerializationError("unsupported ObjectProperties version");
        }
 }
-
index 4b7f9a5eb4f5c8501bf1d31f497dd73d08e8b24e..eee3be228f37b886df10cb6d0eb7d383c151f754 100644 (file)
@@ -47,6 +47,7 @@ struct ObjectProperties
        f32 stepheight;
        bool automatic_face_movement_dir;
        f32 automatic_face_movement_dir_offset;
+       bool backface_culling;
 
 
        ObjectProperties();
@@ -56,4 +57,3 @@ struct ObjectProperties
 };
 
 #endif
-
index 00ec85b2f1bcac05de534cae1c4fa920448e34bf..787541ad05a25985a076935c44760de71eada12a 100644 (file)
@@ -197,6 +197,7 @@ void read_object_properties(lua_State *L, int index,
                prop->automatic_face_movement_dir_offset = 0.0;
        }
        lua_pop(L, 1);
+       getboolfield(L, -1, "backface_culling", prop->backface_culling);
 }
 
 /******************************************************************************/
@@ -255,6 +256,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
        else
                lua_pushboolean(L, false);
        lua_setfield(L, -2, "automatic_face_movement_dir");
+       lua_pushboolean(L, prop->backface_culling);
+       lua_setfield(L, -2, "backface_culling");
 }
 
 /******************************************************************************/
@@ -1231,4 +1234,3 @@ void read_json_value(lua_State *L, Json::Value &root, int index, u8 recursion)
        }
        lua_pop(L, 1); // Pop value
 }
-