[0.4.8] LuaVoxelManipulator

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: [0.4.8] LuaVoxelManipulator

by paramat » Sun Mar 22, 2015 21:40

1. Yes you can get and set a big chunk of param2 (rotation) data, i'm now doing this in flexrealm to rotate nodes properly https://github.com/paramat/flexrealm/blob/master/init.lua
Note you can also do this with param1 (light) data also.

2. Voxelmanip is exactly that, a way to get, process and write a big chunk of nodes in lua at once, instead of accessing the map via C++ (which is slow) one node at a time with get_node/add_node. The speedup is huge, my first lua mapgens took 1 minute per chunk to generate.
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [0.4.8] LuaVoxelManipulator

by neko259 » Sun Mar 22, 2015 21:44

paramat wrote:1. Yes you can get and set a big chunk of param2 (rotation) data, i'm now doing this in flexrealm to rotate nodes properly https://github.com/paramat/flexrealm/blob/master/init.lua
Note you can also do this with param1 (light) data also.

2. Voxelmanip is exactly that, a way to get, process and write a big chunk of nodes in lua at once, instead of accessing the map via C++ one node at a time with get_node/add_node. The speedup is huge, my first lua mapgens took 1 minute per chunk to generate.

Thanks. Wiki did't say anything about param1 and param2 data :(
2. Yes, I see that. But why a different interface? Why not make something like data[pos].set_node with the exact same parameters as a set_node(pos)?
And, emm, why light is named "param1" and facedir a "param2"?
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [0.4.8] LuaVoxelManipulator

by neko259 » Sun Mar 22, 2015 21:53

paramat wrote:Note you can also do this with param1 (light) data also.

How do I set a "default" one as remove_node does?
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [0.4.8] LuaVoxelManipulator

by neko259 » Sun Mar 22, 2015 21:58

There also is set_node_at and get_node_at. Can I use these to move nodes, or it won't be faster than set_node? And does it "move" the metadata?
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: [0.4.8] LuaVoxelManipulator

by paramat » Mon Mar 23, 2015 20:12

The wiki is out of date, best to refer to lua_api.txt.
Param2 is usually the rotation but not always, it can be used for other things, see lua_api.txt.

> How do I set a "default" one as remove_node does?

There isn't a default value for light level, it's best to leave that alone because light level for each node is calculated at the end in 'vm:calc_lighting()' or 'vm:update_map()'.

> set_node_at and get_node_at. Can I use these to move nodes, or it won't be faster than set_node? And does it "move" the metadata?

Those allow you to get or set individual nodes in the voxelmanip while you are processing it. They allow you to get/set the node name, node light level (param1) and node rotation (param2). Those are for when you want to get/set just a few nodes plus their param1/param2 data in the vm without having to read/write a whole mapchunk's worth (500000 nodes) of param data. So for a just few nodes those methods are faster.
For your use with setting rotation of large objects it's best to not use those.
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [0.4.8] LuaVoxelManipulator

by neko259 » Mon Mar 23, 2015 21:41

paramat wrote:There isn't a default value for light level, it's best to leave that alone because light level for each node is calculated at the end in 'vm:calc_lighting()' or 'vm:update_map()'.

Wiki says these 2 methods are to be used only when implementing a map generator. But I need to move a structure of nodes along with their facedir and light data. When it moves, the space behind it becomes air and I need to "reset" its lighting.
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: [0.4.8] LuaVoxelManipulator

by paramat » Tue Mar 24, 2015 22:04

> set_node_at and get_node_at [...] And does it "move" the metadata?

No, as far as i know.

> Wiki says these 2 methods are to be used only when implementing a map generator.

Ignore that, you can use anything for anything as long as it works.

> I need to move a structure of nodes along with their facedir and light data. When it moves, the space behind it becomes air and I need to "reset" its lighting.

Don't bother moving light data. Light levels, including any lights inside your airship will be re-calculated by 'update_map()' at the end. For example if you fly under a floatland you need the airship exterior to go dark.
The space of air behind the airship can only be reset by re-calculating light levels using 'update_map()'.
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [0.4.8] LuaVoxelManipulator

by neko259 » Tue Mar 24, 2015 22:06

paramat wrote:> set_node_at and get_node_at [...] And does it "move" the metadata?

No, as far as i know.

> Wiki says these 2 methods are to be used only when implementing a map generator.

Ignore that, you can use anything for anything as long as it works.

> I need to move a structure of nodes along with their facedir and light data. When it moves, the space behind it becomes air and I need to "reset" its lighting.

Don't bother moving light data. Light levels, including any lights inside your airship will be re-calculated by 'update_map()' at the end. For example if you fly under a floatland you need the airship exterior to go dark.
The space of air behind the airship can only be reset by re-calculating light levels using 'update_map()'.

Do I need only calc_lighting or update_map is needed anyway?
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: [0.4.8] LuaVoxelManipulator

by paramat » Tue Mar 24, 2015 22:15

There are 2 types of voxelmanip, one is for mapgen and worlks on a whole 80^3 mapchunk. The one you should use is the 'non-mapgen voxelmanip' that i use here to move rain clouds https://github.com/paramat/rain/blob/master/init.lua You define the voxelmanip volume yourself to any size or shape.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(pos1, pos2)
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
local data = vm:get_data()
...
...
...
vm:set_data(data)
vm:write_to_map()
vm:update_map()
Last edited by paramat on Tue Mar 24, 2015 22:18, edited 1 time in total.
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [0.4.8] LuaVoxelManipulator

by neko259 » Tue Mar 24, 2015 22:18

There are 2 types of voxelmanip, one is for mapgen and worlks on a whole 80^3 mapchunk.

I use this one. I'm only interested if I need to run update_map or just calc_lighting. What's the difference?
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: [0.4.8] LuaVoxelManipulator

by paramat » Tue Mar 24, 2015 22:20

calc_lighting is for the 'mapgen object voxelmanip'.
update_map is for the other voxelmanip and does the same thing, it resets lighting.
However your mod will not work properly using the mapgen object voxelmanip.
 

bobomb
Member
 
Posts: 101
Joined: Sat May 23, 2015 20:28
GitHub: bobombolo
IRC: bobomb

Re: [0.4.8] LuaVoxelManipulator

by bobomb » Thu Jun 04, 2015 05:03

Can someone explain how one would use voxel manipulator to make ABMs more efficient? you still need to register an abm to trigger a manipulation, then what? i have a situation where I want to run an abm action on all nodes of a similar type at once. wouldn't i have to still allow all nodes of the type to be identified by the abm search? is there a way to use vm to make this search process more efficient? or would vm only be useful to apply the transformation? what i need is a way to get the extent of a volume that would enclose all of a given node type (actually based on an identifier in the metadata), and apply a transformation to all these at once. but then the abm must stop scanning all those nodes individually to gain a benefit. can someone enlighten me?
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: [0.4.8] LuaVoxelManipulator

by Hybrid Dog » Sat Jul 18, 2015 19:01

bobomb wrote:Can someone explain how one would use voxel manipulator to make ABMs more efficient? you still need to register an abm to trigger a manipulation, then what? i have a situation where I want to run an abm action on all nodes of a similar type at once. wouldn't i have to still allow all nodes of the type to be identified by the abm search? is there a way to use vm to make this search process more efficient? or would vm only be useful to apply the transformation? what i need is a way to get the extent of a volume that would enclose all of a given node type (actually based on an identifier in the metadata), and apply a transformation to all these at once. but then the abm must stop scanning all those nodes individually to gain a benefit. can someone enlighten me?

l did it for lavacooling
https://github.com/HybridDog/minetest_g ... s.lua#L134

if you want to get nodes touching each other, just use tables https://github.com/HybridDog/minetest-m ... it.lua#L28 https://github.com/HybridDog/replacer/b ... t.lua#L302 https://github.com/HybridDog/cave_light ... it.lua#L49
 

Previous

Return to Minetest News

Who is online

Users browsing this forum: No registered users and 5 guests

cron