]> git.lizzy.rs Git - minetest.git/commitdiff
Add backwards-compatible behaviour if too few CAO textures specified
authorsfan5 <sfan5@live.de>
Mon, 22 Nov 2021 17:27:49 +0000 (18:27 +0100)
committerGitHub <noreply@github.com>
Mon, 22 Nov 2021 17:27:49 +0000 (17:27 +0000)
(#11766)

doc/lua_api.txt
src/client/content_cao.cpp

index efc9585e4659338cd7322583a6d9f59287a4db55..36db23b6f44182c1c74ff76711bb3663edb7aeb7 100644 (file)
@@ -7184,6 +7184,7 @@ Player properties need to be saved manually.
         -- "sprite" uses 1 texture.
         -- "upright_sprite" uses 2 textures: {front, back}.
         -- "wielditem" expects 'textures = {itemname}' (see 'visual' above).
+        -- "mesh" requires one texture for each mesh buffer/material (in order)
 
         colors = {},
         -- Number of required colors depends on visual
index bb78b594d2c4bebdc7faddaf7a4378e3abfae73a..24a9e7921683bbcc955d4b7b5ca56b2e825389b1 100644 (file)
@@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "client/sound.h"
 #include "client/tile.h"
 #include "util/basic_macros.h"
-#include "util/numeric.h" // For IntervalLimiter & setPitchYawRoll
+#include "util/numeric.h"
 #include "util/serialize.h"
 #include "camera.h" // CameraModes
 #include "collision.h"
@@ -171,6 +171,20 @@ static void updatePositionRecursive(scene::ISceneNode *node)
        node->updateAbsolutePosition();
 }
 
+static bool logOnce(const std::ostringstream &from, std::ostream &log_to)
+{
+       thread_local std::vector<u64> logged;
+
+       std::string message = from.str();
+       u64 hash = murmur_hash_64_ua(message.data(), message.length(), 0xBADBABE);
+
+       if (std::find(logged.begin(), logged.end(), hash) != logged.end())
+               return false;
+       logged.push_back(hash);
+       log_to << message << std::endl;
+       return true;
+}
+
 /*
        TestCAO
 */
@@ -822,6 +836,28 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
        updateAttachments();
        setNodeLight(m_last_light);
        updateMeshCulling();
+
+       if (m_animated_meshnode) {
+               u32 mat_count = m_animated_meshnode->getMaterialCount();
+               if (mat_count == 0 || m_prop.textures.empty()) {
+                       // nothing
+               } else if (mat_count > m_prop.textures.size()) {
+                       std::ostringstream oss;
+                       oss << "GenericCAO::addToScene(): Model "
+                               << m_prop.mesh << " loaded with " << mat_count
+                               << " mesh buffers but only " << m_prop.textures.size()
+                               << " texture(s) specifed, this is deprecated.";
+                       logOnce(oss, warningstream);
+
+                       video::ITexture *last = m_animated_meshnode->getMaterial(0).TextureLayer[0].Texture;
+                       for (s32 i = 1; i < mat_count; i++) {
+                               auto &layer = m_animated_meshnode->getMaterial(i).TextureLayer[0];
+                               if (!layer.Texture)
+                                       layer.Texture = last;
+                               last = layer.Texture;
+                       }
+               }
+       }
 }
 
 void GenericCAO::updateLight(u32 day_night_ratio)