aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVitaliy <numzer0@yandex.ru>2021-03-30 01:25:11 +0300
committerGitHub <noreply@github.com>2021-03-30 00:25:11 +0200
commit3b78a223717c69918a5af422e21561f47ec74ce1 (patch)
treeaafa2961a6faafc58a2712dfcc277e662d149382 /src
parentfde2785fe363c55e8acfd17af71375a231df41c1 (diff)
downloadminetest-3b78a223717c69918a5af422e21561f47ec74ce1.tar.gz
minetest-3b78a223717c69918a5af422e21561f47ec74ce1.tar.bz2
minetest-3b78a223717c69918a5af422e21561f47ec74ce1.zip
Degrotate support for mesh nodes (#7840)
Diffstat (limited to 'src')
-rw-r--r--src/client/content_mapblock.cpp16
-rw-r--r--src/client/content_mapblock.h2
-rw-r--r--src/mapnode.cpp21
-rw-r--r--src/mapnode.h3
-rw-r--r--src/nodedef.cpp3
-rw-r--r--src/nodedef.h4
-rw-r--r--src/script/common/c_content.cpp3
-rw-r--r--src/script/cpp_api/s_node.cpp1
8 files changed, 45 insertions, 8 deletions
diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp
index 90284ecce..ce7235bca 100644
--- a/src/client/content_mapblock.cpp
+++ b/src/client/content_mapblock.cpp
@@ -968,7 +968,7 @@ void MapblockMeshGenerator::drawPlantlike()
draw_style = PLANT_STYLE_CROSS;
scale = BS / 2 * f->visual_scale;
offset = v3f(0, 0, 0);
- rotate_degree = 0;
+ rotate_degree = 0.0f;
random_offset_Y = false;
face_num = 0;
plant_height = 1.0;
@@ -988,7 +988,8 @@ void MapblockMeshGenerator::drawPlantlike()
break;
case CPT2_DEGROTATE:
- rotate_degree = n.param2 * 2;
+ case CPT2_COLORED_DEGROTATE:
+ rotate_degree = 1.5f * n.getDegRotate(nodedef);
break;
case CPT2_LEVELED:
@@ -1343,6 +1344,7 @@ void MapblockMeshGenerator::drawMeshNode()
u8 facedir = 0;
scene::IMesh* mesh;
bool private_mesh; // as a grab/drop pair is not thread-safe
+ int degrotate = 0;
if (f->param_type_2 == CPT2_FACEDIR ||
f->param_type_2 == CPT2_COLORED_FACEDIR) {
@@ -1354,9 +1356,12 @@ void MapblockMeshGenerator::drawMeshNode()
facedir = n.getWallMounted(nodedef);
if (!enable_mesh_cache)
facedir = wallmounted_to_facedir[facedir];
+ } else if (f->param_type_2 == CPT2_DEGROTATE ||
+ f->param_type_2 == CPT2_COLORED_DEGROTATE) {
+ degrotate = n.getDegRotate(nodedef);
}
- if (!data->m_smooth_lighting && f->mesh_ptr[facedir]) {
+ if (!data->m_smooth_lighting && f->mesh_ptr[facedir] && !degrotate) {
// use cached meshes
private_mesh = false;
mesh = f->mesh_ptr[facedir];
@@ -1364,7 +1369,10 @@ void MapblockMeshGenerator::drawMeshNode()
// no cache, clone and rotate mesh
private_mesh = true;
mesh = cloneMesh(f->mesh_ptr[0]);
- rotateMeshBy6dFacedir(mesh, facedir);
+ if (facedir)
+ rotateMeshBy6dFacedir(mesh, facedir);
+ else if (degrotate)
+ rotateMeshXZby(mesh, 1.5f * degrotate);
recalculateBoundingBox(mesh);
meshmanip->recalculateNormals(mesh, true, false);
} else
diff --git a/src/client/content_mapblock.h b/src/client/content_mapblock.h
index 487d84a07..a6c450d1f 100644
--- a/src/client/content_mapblock.h
+++ b/src/client/content_mapblock.h
@@ -139,7 +139,7 @@ public:
// plantlike-specific
PlantlikeStyle draw_style;
v3f offset;
- int rotate_degree;
+ float rotate_degree;
bool random_offset_Y;
int face_num;
float plant_height;
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index 0551f3b6f..20980b238 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -177,6 +177,16 @@ v3s16 MapNode::getWallMountedDir(const NodeDefManager *nodemgr) const
}
}
+u8 MapNode::getDegRotate(const NodeDefManager *nodemgr) const
+{
+ const ContentFeatures &f = nodemgr->get(*this);
+ if (f.param_type_2 == CPT2_DEGROTATE)
+ return getParam2() % 240;
+ if (f.param_type_2 == CPT2_COLORED_DEGROTATE)
+ return 10 * ((getParam2() & 0x1F) % 24);
+ return 0;
+}
+
void MapNode::rotateAlongYAxis(const NodeDefManager *nodemgr, Rotation rot)
{
ContentParamType2 cpt2 = nodemgr->get(*this).param_type_2;
@@ -230,6 +240,17 @@ void MapNode::rotateAlongYAxis(const NodeDefManager *nodemgr, Rotation rot)
Rotation oldrot = wallmounted_to_rot[wmountface - 2];
param2 &= ~7;
param2 |= rot_to_wallmounted[(oldrot - rot) & 3];
+ } else if (cpt2 == CPT2_DEGROTATE) {
+ int angle = param2; // in 1.5°
+ angle += 60 * rot; // don’t do that on u8
+ angle %= 240;
+ param2 = angle;
+ } else if (cpt2 == CPT2_COLORED_DEGROTATE) {
+ int angle = param2 & 0x1F; // in 15°
+ int color = param2 & 0xE0;
+ angle += 6 * rot;
+ angle %= 24;
+ param2 = color | angle;
}
}
diff --git a/src/mapnode.h b/src/mapnode.h
index a9ae63ba3..28ff9e43d 100644
--- a/src/mapnode.h
+++ b/src/mapnode.h
@@ -240,6 +240,9 @@ struct MapNode
u8 getWallMounted(const NodeDefManager *nodemgr) const;
v3s16 getWallMountedDir(const NodeDefManager *nodemgr) const;
+ /// @returns Rotation in range 0–239 (in 1.5° steps)
+ u8 getDegRotate(const NodeDefManager *nodemgr) const;
+
void rotateAlongYAxis(const NodeDefManager *nodemgr, Rotation rot);
/*!
diff --git a/src/nodedef.cpp b/src/nodedef.cpp
index 8a1f6203b..3dcac439f 100644
--- a/src/nodedef.cpp
+++ b/src/nodedef.cpp
@@ -944,7 +944,8 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
if (param_type_2 == CPT2_COLOR ||
param_type_2 == CPT2_COLORED_FACEDIR ||
- param_type_2 == CPT2_COLORED_WALLMOUNTED)
+ param_type_2 == CPT2_COLORED_WALLMOUNTED ||
+ param_type_2 == CPT2_COLORED_DEGROTATE)
palette = tsrc->getPalette(palette_name);
if (drawtype == NDT_MESH && !mesh.empty()) {
diff --git a/src/nodedef.h b/src/nodedef.h
index 3e77624eb..b8cf7c14d 100644
--- a/src/nodedef.h
+++ b/src/nodedef.h
@@ -67,7 +67,7 @@ enum ContentParamType2
CPT2_WALLMOUNTED,
// Block level like FLOWINGLIQUID
CPT2_LEVELED,
- // 2D rotation for things like plants
+ // 2D rotation
CPT2_DEGROTATE,
// Mesh options for plants
CPT2_MESHOPTIONS,
@@ -79,6 +79,8 @@ enum ContentParamType2
CPT2_COLORED_WALLMOUNTED,
// Glasslike framed drawtype internal liquid level, param2 values 0 to 63
CPT2_GLASSLIKE_LIQUID_LEVEL,
+ // 3 bits of palette index, then degrotate
+ CPT2_COLORED_DEGROTATE,
};
enum LiquidType
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index eca0c89d1..52baeae9d 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -685,7 +685,8 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
if (!f.palette_name.empty() &&
!(f.param_type_2 == CPT2_COLOR ||
f.param_type_2 == CPT2_COLORED_FACEDIR ||
- f.param_type_2 == CPT2_COLORED_WALLMOUNTED))
+ f.param_type_2 == CPT2_COLORED_WALLMOUNTED ||
+ f.param_type_2 == CPT2_COLORED_DEGROTATE))
warningstream << "Node " << f.name.c_str()
<< " has a palette, but not a suitable paramtype2." << std::endl;
diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp
index f23fbfbde..029cb6308 100644
--- a/src/script/cpp_api/s_node.cpp
+++ b/src/script/cpp_api/s_node.cpp
@@ -65,6 +65,7 @@ struct EnumString ScriptApiNode::es_ContentParamType2[] =
{CPT2_COLORED_FACEDIR, "colorfacedir"},
{CPT2_COLORED_WALLMOUNTED, "colorwallmounted"},
{CPT2_GLASSLIKE_LIQUID_LEVEL, "glasslikeliquidlevel"},
+ {CPT2_COLORED_DEGROTATE, "colordegrotate"},
{0, NULL},
};