[SOLVED] VoxelManip schematic placement woes

Post Reply
User avatar
Beerholder
Member
Posts: 199
Joined: Wed Aug 03, 2016 20:23
GitHub: evrooije
In-game: Beerholder

[SOLVED] VoxelManip schematic placement woes

by Beerholder » Post

I must be doing something wrong but can't wrap my head around it ... Making an extension of duane's wonderful underworlds mod and created a sort of a back to normal underworld that does "normal biomes". I replace the stone with things like dirt, snow, ice, sand etc. successfully.

I then keep track of a table with what trees need to be placed so I can do a place schematic on voxel manip call after the terrain has been created. But for some reason some of the trees are floating ... Especially around steeper terrain.

The code (at least, the relevant snippets). First, the loop setting x, y, z:

Code: Select all

for z = minp.z, maxp.z do
	for x = minp.x, maxp.x do
<snip>
		for y = minp.y-1, maxp.y+1 do
Duane's code replaced stone with special nodes, so I reused that to replace it with biome specific dirts/ blocks, e.g.:

Code: Select all

data[ivm] = node["default:dirt_with_snow"]
I have a pos defined, and I tried both area:position(ivm) based on the voxelmanip index, and setting pos.x = x, pos.y = y and pos.z = z based on the index of the surrounding loop. I store a reference to the schematic to be generated, "keyed" on pos (though this is just an table, not a hash map). This in order to write the schematics after terrain generation or the trees will just be overwritten when vm:set_data(data) is called

Code: Select all

table.insert(generate_trees, {pos, minetest.get_modpath("default").."/schematics/pine_tree.mts"})
And once the mapgen is done, I loop through the tree table for that particular area and place the schematics:

Code: Select all

for i = 1, #generate_trees do
	minetest.place_schematic_on_vmanip(vm, generate_trees[i][1], generate_trees[i][2], "random", nil, false)
end
The result is:
Spoiler
Image
Spoiler
Image
Spoiler
Image
What I do not get is, if data[ivm] is truly replaced with the node I want (e.g. dirt with snow), then why is the x, y, z incorrect. This index should point to this exact position right? And I even tried with area:position(ivm) just to be sure. It also does not explain why the schematics are correctly placed on flat ground but floats on steep terrain.

I tried a ystride and testing when I hit a data[ivm] ~= node["air"] before storing the position. This resulted in all trees (steep terrain or flat terrain) being sunk into the ground... This I also do not get as striding down should hit data as it generates from negative y upwards to positive y (so striding from positive to negative I should see the nodes that had been set ...?) Obviously offsetting y also did not work, it "solves" the problem for steep terrain but then trees on flat terrain are sunk.

So ... What am I doing wrong? O_o

Full code https://github.com/evrooije/beerarchy/t ... nderworlds in mapgen.lua and undergen.lua (not the nicest code for now sorry, currently it is a huge if else but am actually considering something different ...)
Last edited by Beerholder on Sun Aug 13, 2017 11:37, edited 1 time in total.

Sokomine
Member
Posts: 4290
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: VoxelManip schematic placement woes

by Sokomine » Post

Without taking a closer look I'd suspect mudflow to be a candidate for your troubles. In general keep in mind that mapgen does not only change the core area it's working on but may also affect the sourrounding shell of 16 nodes in each direction.
A list of my mods can be found here.

User avatar
duane
Member
Posts: 1715
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r
Location: Oklahoma City
Contact:

Re: VoxelManip schematic placement woes

by duane » Post

I have never managed to get place_schematic_on_vmanip to work reliably, and I don't recommend its use. Take a look at what I did in squaresville to place trees.

https://github.com/duane-r/squaresville ... cs.lua#L42

This function just unrolls a schematic onto the voxelmanip, which is then set as normal. The function requires a table for input, but it's trivial to convert mts files, as I do further down. Keeping them as tables lets me copy and manipulate them to make weirder trees.

https://github.com/duane-r/squaresville ... s.lua#L135

Your alternative is to set the voxelmanip data, do all the update/calc calls, and then place schematics from a table using the regular minetest.place_schematic function, which is a bit slower (but not bad).

Edit: I used a simpler place_schematic method in underworlds, but it needs updating. You'd be better off using the one from squaresville.
Believe in people and you don't need to believe anything else.

User avatar
Beerholder
Member
Posts: 199
Joined: Wed Aug 03, 2016 20:23
GitHub: evrooije
In-game: Beerholder

Re: VoxelManip schematic placement woes

by Beerholder » Post

Hi duane thanks for the pointers, I noticed the custom schematic placement in underworlds and sort of wanted to avoid using that one, but the squaresville one looks promising I will most definitely give that one a try! Cheers

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

Re: VoxelManip schematic placement woes

by paramat » Post

This is a schematic position offset issue.
Schematics are placed with their minimum point (corner of minimum x, y, z) at the position you specify, you need to offset the schematic in x and z by half the width of the schematic so that the trunk is at the position you specify.

Using lua functions to do the same thing will be much slower.
Last edited by paramat on Fri Aug 11, 2017 10:02, edited 1 time in total.

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

Re: VoxelManip schematic placement woes

by paramat » Post

duane wrote:I have never managed to get place_schematic_on_vmanip to work reliably, and I don't recommend its use.
You're probably doing something wrong, if there is a bug please open an issue with details so we can fix it.

User avatar
duane
Member
Posts: 1715
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r
Location: Oklahoma City
Contact:

Re: VoxelManip schematic placement woes

by duane » Post

paramat wrote:
duane wrote:I have never managed to get place_schematic_on_vmanip to work reliably, and I don't recommend its use.
You're probably doing something wrong, if there is a bug please open an issue with details so we can fix it.
Well, paramat is right, as usual. I don't know what I was doing wrong before, but now that I try it again, it seems to work fine. You have to center, which I think I was doing originally, and more importantly, you have to call set_data/set_param2 before you place the schematics, otherwise your modified data will overwrite them.

However, the time saved is negligible in my case. It's swamped by all the other processes going on.
Believe in people and you don't need to believe anything else.

User avatar
Beerholder
Member
Posts: 199
Joined: Wed Aug 03, 2016 20:23
GitHub: evrooije
In-game: Beerholder

Re: VoxelManip schematic placement woes

by Beerholder » Post

paramat wrote:This is a schematic position offset issue.
That sounds logical, as the schematic is a volume of course, and the symptoms are exactly what you'd expect. E.g. thinking out loud a 3, y, 3 tree schematic volume has the trunk at (relative to origin) 1, 0, 1, meaning I need to offset position it at x = x - 1, y = y, z = z -1 (sort of).

I will fiddle around with that, should be pretty straight forward in my code :) And I can keep using the VoxelManip schematic placement function then. Thanks!

EDIT: Yeah works like a charm, I'll make a note of this on the dev wiki

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

Re: VoxelManip schematic placement woes

by paramat » Post

For Acacia trees, offset by -4 in X and Z. For all other trees, offset by -2 in X and Z.

User avatar
Beerholder
Member
Posts: 199
Joined: Wed Aug 03, 2016 20:23
GitHub: evrooije
In-game: Beerholder

Re: VoxelManip schematic placement woes

by Beerholder » Post

Thanks for the review, wiki updated (copied old code -_-)

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests