[0.4.8] LuaVoxelManipulator

hmmmm
Developer
 
Posts: 47
Joined: Tue Apr 02, 2013 04:04

[0.4.8] LuaVoxelManipulator

by hmmmm » Fri Jun 28, 2013 05:19

Hello modding community,
I am pleased to announce the addition of the LuaVoxelManip to Minetest's Lua API. Ever since the beginning, modders have been looking for a way to manipulate nodes on the map in bulk. Just until recently with the addition of the Schematic API, this was not possible. However, now with VoxelManip, there is a fast, complete, and official way to accomplish this task. It may seem that this API is much more technical and less user friendly to use than others, but this is necessary in order to maximize speed - its central purpose.
Within on_generate callbacks, the same exact VoxelManip object used to generate the chunk being handled with the internal map generator can be obtained using the new minetest.get_mapgen_object API. Paired with the singlenode map generator, this is especially convenient for creating completely Lua-based mapgens.

For testing purposes, I made a very simple 3d noise-based map generator, which can also be used as a decent reference of how to use VoxelManip:
Image

How well does it perform?
Setup:
CPU: Intel Xeon E3-1230v2
OS: FreeBSD/amd64 9.1-RELEASE
CC: g++ 4.2.2, -g, -O1

On average, to generate an 80x80x80 chunk of this, it takes:
minetest.env:set_node: 6854.4ms
VoxelManip: 153.5ms
Mapgen in core: 60ms (estimated)

So, generating map with VoxelManip in pure Lua is only about 2.5x slower than a mapgen in the core, but a whole 45x faster than using set_node for everything.


I strongly encourage everybody to use this interface and *not* the Schematic API for VoxelManip tasks. The primary purpose of the Schematic API is to define discrete, relatively static structures such as trees, spikes, huts, etc. so they can be randomly placed on the map at generation time. minetest.create_structure is to make a new structure. minetest.place_structure is not exactly a necessary API, but convenient for checking to see that the correct structure was created and did not take much additional effort at all to implement; an added bonus was that it could be used in the same way WorldEdit schematics were - this was not the intent however. Further, defining the schematic completely within Lua via the node table was again a feature added for flexibility, and because it did not take much effort to add.
VoxelManip is even faster than the Schematic API, adds vastly more flexibility, is not hackish, and allows reading the map as well, which is needed for many node placement tasks. There is really no reason not to use it.

Also:
Apparently, having no way to find the real name of a node was a long-standing problem in mods.
As luck would have it, two API that were added needed by VoxelManip, minetest.get_content_id() and minetest.get_name_from_content_id(), can be used to find the real name of a node alias as follows:
local c = minetest.get_content_id(alias_name)
local real_name = minetest.get_name_from_content_id(c)

Enjoy!
Last edited by sfan5 on Fri Jun 28, 2013 12:07, edited 1 time in total.
 

paramat
Developer
 
Posts: 2864
Joined: Sun Oct 28, 2012 00:05
Location: UK
GitHub: paramat
IRC: paramat

by paramat » Fri Jun 28, 2013 05:29

*faints*
I rely on donations to help provide an income https://forum.minetest.net/viewtopic.php?f=3&t=14935
 

Nore
Developer
 
Posts: 469
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Fri Jun 28, 2013 07:29

Where does the VoxelArea thing come from? It gives me a nil value error when I try to run that code...
 

User avatar
MirceaKitsune
Member
 
Posts: 829
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Fri Jun 28, 2013 10:11

Very nice! Glad to see this idea is finally reality and in upstream, it will certainly help a lot. I still wouldn't trust making a whole mapgen with it, but at least it will make that possible in theory which could be interesting.

I'll switch my Structures mod to it as soon as it's safe. There's one thing I don't understand though: How do you send a list of nodes to the engine for spawning? read_from_map(p1, p2) has two corners you can specify like I thought, but write_to_map() takes no parameters. Instead it takes another data writing function which I wasn't able to understand. How would I handle a list of the form { { pos1, node1 }, { pos2, node2 } }?
Last edited by MirceaKitsune on Fri Jun 28, 2013 10:11, edited 1 time in total.
 

User avatar
Casimir
Member
 
Posts: 1144
Joined: Fri Aug 03, 2012 16:59

by Casimir » Fri Jun 28, 2013 13:08

I need to buy sunglasses, so I can wear them while using the LuaVoxelManipulator.
 

hmmmm
Developer
 
Posts: 47
Joined: Tue Apr 02, 2013 04:04

by hmmmm » Fri Jun 28, 2013 15:16

Nore wrote:Where does the VoxelArea thing come from? It gives me a nil value error when I try to run that code...

VoxelArea was my own helper class; though as of today, builtin/voxelarea.lua is part of upstream.

MirceaKitsune wrote:I'll switch my Structures mod to it as soon as it's safe. There's one thing I don't understand though: How do you send a list of nodes to the engine for spawning? read_from_map(p1, p2) has two corners you can specify like I thought, but write_to_map() takes no parameters. Instead it takes another data writing function which I wasn't able to understand. How would I handle a list of the form { { pos1, node1 }, { pos2, node2 } }?

read_from_map() and write_to_map() deal with the internal VoxelManipulator object pulling and pushing data to the actual map. To get and set the array of nodes in Lua, you need to use local data = get_data() and set_data(data).
To handle that sort of list, you would do something like:
local vi = area:indexp(yourtable.pos1)
data[vi] = minetest.get_content_id(yourtable.node1)

(although I would prefetch the results from minetest.get_content_id() and not call it in a loop if i were you)
Setting node strings instead of content IDs is an option coming soon. It's easier in some circumstances, but would be slower. This was designed for being fast.
 

ch98
Member
 
Posts: 463
Joined: Wed Jan 02, 2013 06:14

by ch98 » Sat Jun 29, 2013 02:11

Is this the thing that makes large spaceships possible? If it is, Minetest is now close to complete!
I have stopped playing minetest, and may not come back to it again. I would like to thank everyone that made the amazing time I had playing it. This account is not in use anymore, and the email has been linked to a unused account. If any administrator reading this has time, feel free to delete my account. Thank you very much for the great experience.
 

User avatar
Zeg9
Member
 
Posts: 608
Joined: Fri Sep 21, 2012 11:02
Location: France

by Zeg9 » Sat Jun 29, 2013 08:14

ch98 wrote:Is this the thing that makes large spaceships possible? If it is, Minetest is now close to complete!

If you mean moving spaceships, no. This is a just a way to set nodes faster.
I made a few (a lot of?) mods for minetest: here is a list.
See also the MT-Faithful texture pack (work in progress).
 

oxenfreedan
Member
 
Posts: 218
Joined: Tue Jan 22, 2013 01:39
Location: mars

by oxenfreedan » Sat Jun 29, 2013 21:55

AWESOME!
My Awesome Map please try:
http://forum.minetest.net/viewtopic.php?id=5028
I've played minetest since 0.3.1 came out!
Mostly when on forums I'm using a uniden tablet!
 

User avatar
PilzAdam
Developer
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Tue Jul 16, 2013 22:38

hmmmm wrote:Also:
Apparently, having no way to find the real name of a node was a long-standing problem in mods.
As luck would have it, two API that were added needed by VoxelManip, minetest.get_content_id() and minetest.get_name_from_content_id(), can be used to find the real name of a node alias as follows:
local c = minetest.get_content_id(alias_name)
local real_name = minetest.get_name_from_content_id(c)

It turned out this is wrong. There is a non-hacky way of solving it:
Code: Select all
ItemStack("alias"):get_name()

This will return the real itemname.
 

User avatar
Casimir
Member
 
Posts: 1144
Joined: Fri Aug 03, 2012 16:59

by Casimir » Fri Aug 09, 2013 13:36


Thank you. But some comments in that code would help to understand it. I think that's the reason nobody used it until now, because nobody understands it (except you).
 

paramat
Developer
 
Posts: 2864
Joined: Sun Oct 28, 2012 00:05
Location: UK
GitHub: paramat
IRC: paramat

by paramat » Fri Aug 09, 2013 21:48

There is a branch of PilzAdam's nether mod that uses LVM, also latest worldedit mod, 2 more you can study.
Last edited by paramat on Fri Aug 09, 2013 21:49, edited 1 time in total.
I rely on donations to help provide an income https://forum.minetest.net/viewtopic.php?f=3&t=14935
 

User avatar
Splizard
Member
 
Posts: 220
Joined: Wed Jan 25, 2012 07:20
Location: New Zealand
GitHub: Splizard
IRC: Splizard
In-game: Splizard

by Splizard » Fri Aug 09, 2013 22:43

Dev version of Snow mod uses it now,
https://github.com/Splizard/minetest-mod-snow/blob/master/mapgen_v6.lua (see line 238 and below)
I understood it, you just need to try it out.
Games: The Hungry Games.
Mods: Lifters (Simple Lifts), Snow Biomes and Gates.
Also checkout my texture pack Gridtoon!
View all of them plus more at http://minetest.splizard.com! (may not always be online).
 

User avatar
Casimir
Member
 
Posts: 1144
Joined: Fri Aug 03, 2012 16:59

by Casimir » Fri Aug 09, 2013 23:02

OK cut my last sentence. I got it to work the way I wanted too. But it would be nice if there would be some explanation somewhere.
 

paramat
Developer
 
Posts: 2864
Joined: Sun Oct 28, 2012 00:05
Location: UK
GitHub: paramat
IRC: paramat

by paramat » Sat Aug 10, 2013 22:31

It works on unloaded chunks too apparently.
I rely on donations to help provide an income https://forum.minetest.net/viewtopic.php?f=3&t=14935
 

miner65536
Member
 
Posts: 41
Joined: Tue Aug 20, 2013 22:16

by miner65536 » Fri Sep 06, 2013 13:45

Whats the easiest way to load regions prior to writing to them with setnode or using this? In singleplayer I'm doing something similar and all i can think of moving the player to the position and waiting a bit for the server to load or generate that region.
 

User avatar
rubenwardy
Developer
 
Posts: 4671
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

by rubenwardy » Fri Sep 06, 2013 14:15

Can some one give me an example that does set node using this?
To multiple people: No one cares if you think "God's not dead".
My Twitter
Mods: Awards - 15 more
Other: Node Box Editor - Mods 4 Android - Minetest Modding Book
 

paramat
Developer
 
Posts: 2864
Joined: Sun Oct 28, 2012 00:05
Location: UK
GitHub: paramat
IRC: paramat

by paramat » Fri Sep 06, 2013 18:38

Set node = add node and is done like this:
Code: Select all
data[vi] = c_dirt

If you want another example mod see my LVM version of moonrealm mod.
Last edited by paramat on Fri Sep 06, 2013 18:40, edited 1 time in total.
I rely on donations to help provide an income https://forum.minetest.net/viewtopic.php?f=3&t=14935
 

george90867
Member
 
Posts: 25
Joined: Fri Jul 26, 2013 17:42
 

paramat
Developer
 
Posts: 2864
Joined: Sun Oct 28, 2012 00:05
Location: UK
GitHub: paramat
IRC: paramat

by paramat » Sun Sep 08, 2013 02:26

Yes you can :)
I rely on donations to help provide an income https://forum.minetest.net/viewtopic.php?f=3&t=14935
 

Prestotron562
Member
 
Posts: 22
Joined: Mon Sep 02, 2013 22:37
Location: Internet

by Prestotron562 » Sun Sep 29, 2013 19:54

Can't wait for this. This will help my mod "More Biomes"
 

User avatar
Evergreen
Member
 
Posts: 2131
Joined: Sun Jan 06, 2013 01:22
Location: A forest in the midwest
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen

by Evergreen » Sun Sep 29, 2013 20:17

Prestotron562 wrote:Can't wait for this. This will help my mod "More Biomes"
There will be a biome api in mg v7.
"Help! I searched for a mod but I couldn't find it!"
http://krock-works.16mb.com/MTstuff/modSearch.php
 

leetelate
Member
 
Posts: 205
Joined: Thu Aug 29, 2013 18:07
Location: 한인 타운, Huntsville,Alabama,USA

by leetelate » Mon Nov 04, 2013 22:48

paramat wrote:it is helpful to work through a chunk column by column, and working down each column instead of up


yep, y, then either x or z first, and z+ is north if your biomes are n/s/ or e/w oriented - following you nicely - i don't use perlin noise anymore, but if you think of it as a basically horizontal tube and work the area with that in mind, it gets easier to visualize

don't know if you've hit it yet but watch out for missing content id's - you specify c_snow but you fail to do the declare to say that c_snow is default:snow, that is where the fire comes from, since a missed content id = fire

enjoy, the lua voxel manip is the best thing about MT
Last edited by leetelate on Mon Nov 04, 2013 23:01, edited 1 time in total.
MT IS MC'S SMARTER BROTHER
minetest 0.4.8 compiled from latest git on linux mint 15 with qjoypad and wired 360 controller
freeminer, pilztest, buildcraft and next are the idea factories
my minetest page is http://1337318.zymichost.com if zymic isn't down - meh, it is free...
 

leetelate
Member
 
Posts: 205
Joined: Thu Aug 29, 2013 18:07
Location: 한인 타운, Huntsville,Alabama,USA

by leetelate » Sun Nov 10, 2013 17:12

http://www.scribblethink.org/Work/Crunge/crunge.pdf gives an overview of the Weiner interpolation - so much faster!
i am still working on this one, but here's the latest attempt:
make a noise 1 and a noise 2, then make a bunch of random points based on the average of noise1+noise2 at those points
expand each point(like doing a simple gaussian blur) until you hit a non-0
interesting, though i'm still getting artifacts - cool mountain ranges! - they even have ridge lines!
Image
wiaworld
Image
cliffs
Image
overhangs
Image

let me work on it a bit more and i'll put the code up, maybe even on github
MT IS MC'S SMARTER BROTHER
minetest 0.4.8 compiled from latest git on linux mint 15 with qjoypad and wired 360 controller
freeminer, pilztest, buildcraft and next are the idea factories
my minetest page is http://1337318.zymichost.com if zymic isn't down - meh, it is free...
 

paramat
Developer
 
Posts: 2864
Joined: Sun Oct 28, 2012 00:05
Location: UK
GitHub: paramat
IRC: paramat

by paramat » Mon Nov 11, 2013 01:18

That looks surprisingly good considering it's simplicity, i like these gem-like facets at various angles.
I rely on donations to help provide an income https://forum.minetest.net/viewtopic.php?f=3&t=14935
 

Next

Return to News



Who is online

Users browsing this forum: No registered users and 1 guest