-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Degrotate support for mesh nodes #7840
Conversation
@paramat Note that the rotated meshes aren’t cached; that’s too cumbersome and probably pointless. But rotation can be optimized heavily by replacing |
For other drawtypes, fine rotation is of little use IMO:
Technically speaking, non-connected |
240 seems optimum to me. |
I agree that 240 is the optimum, for the simple reason that 240 is the highest highly-composite number (https://en.wikipedia.org/wiki/Highly_composite_number) in the range from 1 to 255. This means with 240 steps, there will be 20 ways to divide the circle in n equally large parts, not just 18. So yes, this is an improvement. I also like to note that this will unlock two very important angles: 45° (one eighth) and 22.5° (one sixteenth).
Which means that you can have halves, thirds, fourths, fifts, sixths, eighths, tenths, and many more fractions with 240. Ninths have to go, but this doesn't seem like a big loss to me. The choice of 24 for |
About caching:
Just to check, does this affect in-game performance or is just more processing on client startup? |
Didn’t know that term, thanks) (When choosing the number, I considered mostly prime factors and 8 (for exact diagonals); but for small numbers that’s almost the same).
Depends on your needs. To allow 8 colors, step count must not be larger that 32. Actually, to allow 2^n colors, step count must be at most 2^(8-n), for a natural n. I consider supporting less than 8 colors pointless, so 32 is the top for me, and 24 is the optimum due to better divisibility. |
Caching would increase startup time and especially memory usage. And the in-game processing should be fast. Actually, due to a far from optimal implementation of |
I see thanks. So there will be a little in-game performance loss while calculating a specific orientation. Or alternatively, very intensive on startup while caching all orientations although many of those orientations are not used. So i agree that not caching is best. |
Nodeboxes are converted to meshnodes, and:
I assume these 24 facedir rotations continue to be cached as currently? |
I don’t change that in this PR. These are cached if that feature is enabled but smooth lighting is disabled. |
Would it be possible to specify the position of the rotation axis in the node definition? |
No, that would require so much extra information in param2 you would lose the 240 orientations, making degrotate unusable for what it is applied to. The number of orientations has to be similar or larger than the previous 180. |
@paramat In case your comment is meant as a response to my question (I hope I understood it correctly.), I didn't mean to store the position of the rotation axis param2, but to store the exact position of the rotation axis in nodedef. This way, it would be possible to make off-center rotations. Not all mesh models are neccessarily centered. |
@Thomas--S That’s possible ofc, but that would totally break world symmetry, preventing one from rotating constructions as a whole (I mean rebuilding or using WorldEdit). And what could be the use cases? |
|
@numberZero I have no special use cases in mind, it was just an idea/suggestion. I don't have a problem when the rotation axis feature is not implemented 🙂 |
Fixed colors. Now everything seems to work) |
Thomas--S sorry i misunderstood, i was talking about axis orientation instead of position. |
What's holding this up? |
Nothing apart from tests and reviews. |
0e3b135
to
39c54e1
Compare
Rebased.
Assuming that’s still true. @paramat |
Please also add support for the new paramtype2 here: minetest/builtin/game/item.lua Lines 341 to 348 in 27d611f
minetest/builtin/game/item.lua Lines 158 to 174 in 27d611f
Other than that, the code looks good. |
^ This is sort of an issue since it breaks backwards compatibility. |
I see these words constantly here. At the time the PR was proposed, that was okay:
A long time passed since then, but: degrotate could only be used for plantlike. Will such change in plant orientation be even noticed? |
@SmallJoker Done. |
That's a good question and the answer is probably not. |
The answer is definitely yes. Take
The game/mod author chooses That having said, I still prefer 240 over 180. I wonder how it could be done without breaking things. Maybe |
I still support breaking this API, 240 steps is far better. Degrotate is probably not heavily used. |
|
Do we have numbers on this? |
I certainly disapprove of adding another paramtype2 just to avoid a minor breakage. How much degrotate is used in mods is just my informed guess. |
My attempt at testing this feature... somehow it changes the color on rotate. Help needed. diff for devtest (v2, corrected)diff --git a/games/devtest/mods/testnodes/drawtypes.lua b/games/devtest/mods/testnodes/drawtypes.lua
index 82d862819..5239717c8 100644
--- a/games/devtest/mods/testnodes/drawtypes.lua
+++ b/games/devtest/mods/testnodes/drawtypes.lua
@@ -204,6 +204,31 @@ minetest.register_node("testnodes:plantlike_waving", {
-- param2 will rotate
+local function rotate_on_rightclick(pos, node, clicker)
+ local def = minetest.registered_nodes[node.name]
+ local aux1 = clicker:get_player_control().aux1
+
+ local deg, deg_max
+ local color, color_mult = 0, 0
+ if def.paramtype2 == "degrotate" then
+ -- MSB [3x null, 5x rotation] LSB
+ deg = node.param2
+ deg_max = 240
+ elseif def.paramtype2 == "colordegrotate" then
+ -- MSB [3x color, 5x rotation] LSB
+ deg = node.param2 % 2^5
+ deg_max = 24
+ color_mult = 2^5
+ color = math.floor(node.param2 / color_mult)
+ end
+
+ deg = (deg + (aux1 and 10 or 1)) % deg_max
+ node.param2 = color * color_mult + deg
+ minetest.swap_node(pos, node)
+ minetest.chat_send_player(clicker:get_player_name(),
+ "Rotation is now " .. deg .. " / " .. deg_max)
+end
+
minetest.register_node("testnodes:plantlike_degrotate", {
description = S("Degrotate Plantlike Drawtype Test Node"),
drawtype = "plantlike",
@@ -211,12 +236,42 @@ minetest.register_node("testnodes:plantlike_degrotate", {
paramtype2 = "degrotate",
tiles = { "testnodes_plantlike_degrotate.png" },
-
+ on_rightclick = rotate_on_rightclick,
+ place_param2 = 7,
walkable = false,
sunlight_propagates = true,
groups = { dig_immediate = 3 },
})
+minetest.register_node("testnodes:mesh_degrotate", {
+ description = S("Degrotate Mesh Drawtype Test Node"),
+ drawtype = "mesh",
+ paramtype = "light",
+ paramtype2 = "degrotate",
+ mesh = "testnodes_pyramid.obj",
+ tiles = { "testnodes_mesh_stripes2.png" },
+
+ on_rightclick = rotate_on_rightclick,
+ place_param2 = 7,
+ sunlight_propagates = true,
+ groups = { dig_immediate = 3 },
+})
+
+minetest.register_node("testnodes:mesh_colordegrotate", {
+ description = S("Color Degrotate Mesh Drawtype Test Node"),
+ drawtype = "mesh",
+ paramtype2 = "colordegrotate",
+ palette = "testnodes_palette_facedir.png",
+ mesh = "testnodes_pyramid.obj",
+ tiles = { "testnodes_mesh_stripes2.png" },
+
+ on_rightclick = rotate_on_rightclick,
+ -- color index 1, 7 steps rotated
+ place_param2 = 1 * 2^5 + 7,
+ sunlight_propagates = true,
+ groups = { dig_immediate = 3 },
+})
+
-- param2 will change height
minetest.register_node("testnodes:plantlike_leveled", {
description = S("Leveled Plantlike Drawtype Test Node"),
|
@SmallJoker The palette should have 8 entries, not 256 (so color index 15 is out of range btw, fix |
Thank you. I updated the code above accordingly. Would you please be so nice and include it in devtest as well (might require rebase)? It might be helpful for future tests. |
rebased, added the test nodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-tested. Works.
I suggest merging this right now so we can see how many people complain during 5.5.0-dev |
For convenience,
degrotate
range is changed from 180 (2° steps) to 240 (1.5° steps). Most importantly that allows exact diagonals, as requested, while still allowing thirds and fifths (but not ninths).This also adds a new option,
colordegrotate
. It has reduced range (24, 15° steps) to support 8 colors but still allows exact diagonals. The range could be 32 (11.25° steps) at most with the same number of colors but I considered thirds more important than additional two-fold.