2024-06-04 21:49:41 +00:00
local core = worldeditadditions_core
local Vector3 = core.Vector3
2024-05-25 13:45:56 +00:00
---
-- @module worldeditadditions_core.param2
core.param2: add todo reimplement notice
Ref https://discord.com/channels/1135598362821935254/1247681375935533119
---------------------------------------
Hi, a wild //orient+ appeared! While it (probably) doesn't crash, it also unfortunately doesn't work yet.
This is because facedir e.g. points towards the direction the node is pointing, and minetest.facedir_to_dir doesn't capture all the nuance of how the node is pointing, and e.g. if a node is pointing +y and you want to rotate by (0, 90, 0) [degrees], then the current implementation won't do anything.
Then I decided that this is silly and there has to be a solution. After all, screwdriver2 has a great implementation! https://content.minetest.net/packages/12Me21/screwdriver2/
....then I found this lookup table in their codebase: https://github.com/12Me21/screwdriver2/blob/master/init.lua#L75-L79
....aaaaarrrggggghhhhh //orient+ is such a pain to implement!
and my existing implementation is so neat 😢 https://github.com/sbrl/Minetest-WorldEditAdditions/blob/1dd073f14bcac8e26a5ced2abe54c709099b1de2/worldeditadditions_core/utils/param2.lua
so, in other words, although I've implemented //orient+ I'm going to have to reimplement the nuts-and-bolts function that does the rotation, which may make it slightly more complicated and annoying to implement support for nodes with param2 types other than facedir.
/rant about Minetest's param2 value and rotations 😛
2024-06-04 23:14:17 +00:00
-- TODO Reimplement for facedir ref https://github.com/12Me21/screwdriver2/blob/master/init.lua#L75-L79
2024-05-25 13:45:56 +00:00
-- //set <nodename>
-- //set param2|p2 <param2>
2024-06-04 21:49:41 +00:00
-- In future, we'll support more param2_type values here.
2024-05-25 13:45:56 +00:00
local function param2_to_dir ( param2_type , param2 )
2024-06-04 21:49:41 +00:00
if param2_type == " facedir " then
2024-06-04 22:07:05 +00:00
return Vector3.clone ( minetest.facedir_to_dir ( param2 ) )
2024-05-25 13:45:56 +00:00
else
return nil
end
end
2024-06-04 21:49:41 +00:00
local function dir_to_param2 ( param2_type , dir )
if param2_type == " facedir " then
return minetest.dir_to_facedir ( dir , true )
else
return nil
end
2024-05-25 13:45:56 +00:00
end
2024-06-04 21:49:41 +00:00
core.param2: add todo reimplement notice
Ref https://discord.com/channels/1135598362821935254/1247681375935533119
---------------------------------------
Hi, a wild //orient+ appeared! While it (probably) doesn't crash, it also unfortunately doesn't work yet.
This is because facedir e.g. points towards the direction the node is pointing, and minetest.facedir_to_dir doesn't capture all the nuance of how the node is pointing, and e.g. if a node is pointing +y and you want to rotate by (0, 90, 0) [degrees], then the current implementation won't do anything.
Then I decided that this is silly and there has to be a solution. After all, screwdriver2 has a great implementation! https://content.minetest.net/packages/12Me21/screwdriver2/
....then I found this lookup table in their codebase: https://github.com/12Me21/screwdriver2/blob/master/init.lua#L75-L79
....aaaaarrrggggghhhhh //orient+ is such a pain to implement!
and my existing implementation is so neat 😢 https://github.com/sbrl/Minetest-WorldEditAdditions/blob/1dd073f14bcac8e26a5ced2abe54c709099b1de2/worldeditadditions_core/utils/param2.lua
so, in other words, although I've implemented //orient+ I'm going to have to reimplement the nuts-and-bolts function that does the rotation, which may make it slightly more complicated and annoying to implement support for nodes with param2 types other than facedir.
/rant about Minetest's param2 value and rotations 😛
2024-06-04 23:14:17 +00:00
2024-06-04 21:49:41 +00:00
--- Rotates the given param2 value of the given type by the given COMPILED list of rotations.
-- In other words, reorients a given param2 value of a given param2_type (aka paramtype2 in the Minetest engine but the Minetest engine naming scheme is dumb in this case) according to a given COMPILED rotation list.
-- @param param2 number The param2 value to rotate.
-- @param param2_type string The type of param2 value we're talking about here. Currently, only a value of `facedir` is supported.
-- @param rotlist_c Vector3[] The list of vector rotations to apply to param2. Call `worldeditadditions_core.rotation.rotlist_compile` on a rotation list to get this value. Each one is iteratively applied using the `rotate` argument to Vector3.rotate3d.
-- @returns number? Returns the rotated param2 value, or nil if an invalid param2_type value was passed.
local function orient ( param2 , param2_type , rotlist_c )
2024-06-04 22:07:05 +00:00
local dir = param2_to_dir ( param2_type , param2 )
print ( " DEBUG:param2>orient dir " , core.inspect ( dir ) , " param2_type " , param2_type )
2024-06-04 21:49:41 +00:00
if dir == nil then return nil end
local origin = Vector3.new ( 0 , 0 , 0 )
for _i , rot in ipairs ( rotlist_c ) do
dir = Vector3.rotate3d ( origin , dir , rot )
2024-06-04 22:07:05 +00:00
print ( " DEBUG:param2>orient STEP AFTER dir " , dir , " ROT " , rot , " ORIGIN " , origin )
2024-06-04 21:49:41 +00:00
end
dir = dir : round ( ) -- Deal with floating-point rounding errors ref https://en.wikipedia.org/wiki/Round-off_error
-- TODO may need to do this every iteration in the above for loop un the unlikely event we have issues here
2024-05-25 13:45:56 +00:00
2024-06-04 22:07:05 +00:00
print ( " DEBUG:param2>orient FINAL dir " , dir )
2024-06-04 21:49:41 +00:00
return dir_to_param2 ( param2_type , dir )
2024-05-25 13:45:56 +00:00
end
return {
orient = orient
}