Visualize 3D maps of movement?

Post Reply
WyomingWill
Member
Posts: 22
Joined: Sun Aug 16, 2020 05:41

Visualize 3D maps of movement?

by WyomingWill » Post

Hello, I've been wondering if anyone has done anything to be
able to visualize the minetest world in 3D. The "wireframe" view
is useful, and I'd like to do something similar.

Namely, print out the coordinates of where I'm at, so that as I move
around through the caves I generate a cluster of 3D points that I can
then visualize separately (with my own software, or other software).

I notice that the screen can show me my coordinates, but debug.txt
does not contain this information. Is it possible to dump the coordinates
to a file?

Thanks, Bill

User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: Visualize 3D maps of movement?

by sorcerykid » Post

Here's a script that should do what you need. It's intended for use with singleplayer, but could be adapted for multiplayer too. The coordinates are exported to a file named "coords.txt" in your world directory.

Code: Select all

local track_player
local log_file
local last_pos
local last_dir

minetest.register_on_joinplayer( function ( player )
        log_file = io.open( minetest.get_worldpath( ) .. "/coords.txt", "w" )

        if log_file then
                track_player = player
                last_pos = player:get_pos( )
                last_dir = vector.new( )
        end
end )

minetest.register_on_shutdown( function ( )
        if log_file then log_file:close( ) end
end )

minetest.register_globalstep( function( dtime )
        if track_player then
                local pos = track_player:get_pos( )
                local dir = vector.direction( last_pos, pos )

                if math.abs( last_dir.x - dir.x ) > 0.1 or math.abs( last_dir.y - dir.y ) > 0.1 or math.abs( last_dir.z - dir.z ) > 0.1 then
                        log_file:write( minetest.pos_to_string( last_pos ) .. "\n" )
                        last_dir = dir
                end

                last_pos = pos
        end
end )

WyomingWill
Member
Posts: 22
Joined: Sun Aug 16, 2020 05:41

Re: Visualize 3D maps of movement?

by WyomingWill » Post

Wow - thanks! I didn't get email about your reply and only accidentally found it.
Is this a so-called "lua" script? I don't want to waste your time but could you
point me to a link on how to use this? If I had to hazard a guess I would create
a new "mod" directory (with some name) and place your code in a file called
"init.lua" in that directory? Thank you very much. Bill

UPDATE: Bingo - it worked as I guessed. Fantastic! No need to answer me.

WyomingWill
Member
Posts: 22
Joined: Sun Aug 16, 2020 05:41

Re: Visualize 3D maps of movement?

by WyomingWill » Post

Hello, SorceryKid, I have had one issue with your script. It occasionally crashes with:


2020-08-29 22:54:18: ERROR[Main]: ServerError: AsyncErr: environment_Step: Runtime error from mod 'track' in callback environment_Step(): /usr/share/minetest/builtin/common/vector.lua:67: attempt to index local 'pos2' (a nil value)
2020-08-29 22:54:18: ERROR[Main]: stack traceback:
2020-08-29 22:54:18: ERROR[Main]: /usr/share/minetest/builtin/common/vector.lua:67: in function 'direction'
2020-08-29 22:54:18: ERROR[Main]: /home/wspears/.minetest/mods/track/init.lua:23: in function </home/wspears/.minetest/mods/track/init.lua:20>
2020-08-29 22:54:18: ERROR[Main]: /usr/share/minetest/builtin/game/register.lua:429: in function </usr/share/minetest/builtin/game/register.lua:413>
2020-08-29 22:54:18: ERROR[Main]: stack traceback:

Any thoughts on this? BTW, I like how you filter out data from non-movement. I figured I was going to have to do that myself you got it handled.

WyomingWill
Member
Posts: 22
Joined: Sun Aug 16, 2020 05:41

Re: Visualize 3D maps of movement?

by WyomingWill » Post

I have modified one line of your code to:


if track_player ~= nil then


and am testing. I have no idea whether this even reasonable. I don't know
lua (yet).

User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: Visualize 3D maps of movement?

by sorcerykid » Post

Glad to know it's useful!

And yes, if you log off rather than shutdown the server, then it will crash the game. But the check you added should suffice.

WyomingWill
Member
Posts: 22
Joined: Sun Aug 16, 2020 05:41

Re: Visualize 3D maps of movement?

by WyomingWill » Post

Works great! Here is a small example.... Love it.
Thanks again! I hope I attached this image correctly.

Image
Attachments
snapshot.png
snapshot.png (26.38 KiB) Viewed 696 times

User avatar
bosapara
Member
Posts: 637
Joined: Fri Apr 07, 2017 08:49

Re: Visualize 3D maps of movement?

by bosapara » Post

WyomingWill wrote:
Mon Aug 31, 2020 04:32
Works great! Here is a small example.... Love it.
Thanks again! I hope I attached this image correctly.

Image
Looks good.

My 2D try: minetestmapper + google sheets + krita

Image

WyomingWill
Member
Posts: 22
Joined: Sun Aug 16, 2020 05:41

Re: Visualize 3D maps of movement?

by WyomingWill » Post

That is very cool. I did use minetestermap, before starting this thread, actually. I like it!

How did you overlay the track onto the map?

I was really interested in examining my mines, so needed a 3D visualization.... here is one mine.
Red at the top (like your path) and blue at the bottom. Now I can add more mines and see how close
they are to each other.

It might be very interesting to merge the two. The surface map, with the "mine map".
snapshot2.png
snapshot2.png (17.13 KiB) Viewed 696 times

User avatar
bosapara
Member
Posts: 637
Joined: Fri Apr 07, 2017 08:49

Re: Visualize 3D maps of movement?

by bosapara » Post

WyomingWill wrote:
Tue Sep 01, 2020 08:01

How did you overlay the track onto the map?
I used Google Sheets -> diagram -> overlay settings -> Krita

This is not perfect, but no idea how to make it better.

WyomingWill
Member
Posts: 22
Joined: Sun Aug 16, 2020 05:41

Re: Visualize 3D maps of movement?

by WyomingWill » Post

Might be feasible to modify the minetestmap source code to add the track by reading in the coordinates and making those pixels red.... using void Image::setPixel(int x, int y, const Color &c) in Image.cpp?

WyomingWill
Member
Posts: 22
Joined: Sun Aug 16, 2020 05:41

Re: Visualize 3D maps of movement?

by WyomingWill » Post

Might be feasible to modify the minetestmap source code to add the track by reading in the coordinates and making those pixels red.... using void Image::setPixel(int x, int y, const Color &c) in Image.cpp?

WyomingWill
Member
Posts: 22
Joined: Sun Aug 16, 2020 05:41

Re: Visualize 3D maps of movement?

by WyomingWill » Post

I've worked up some mods to the minetestmap source code that appear to do the trick. No, my mods aren't pretty, or in the style of C++. But I'll include them here in case anyone wants them.

First, put your "track" into a file called "track" in your minetestmap directory. It has the data from the lua script (where I removed the parentheses and commas) and has a format like this:

48.86898803711 1.5 374.13000488281
348.86898803711 1.5 374.13000488281
349.19900512695 1.5 373.92401123047
349.19900512695 1.5 373.92401123047
349.5290222168 1.5 373.71701049805
349.5290222168 1.5 373.71701049805
349.84799194336 1.5 373.49499511719
349.84799194336 1.5 373.49499511719
350.13000488281 1.5 373.25302124023
350.13000488281 1.5 373.25302124023
350.22601318359 1.5 373.16500854492
350.22601318359 1.5 373.16500854492
350.22799682617 1.5 373.16000366211
350.22799682617 1.5 373.16000366211
350.32501220703 1.5 372.97702026367
350.32501220703 1.5 372.97702026367


Then modify the end of function TileGenerator::generate() in
TileGenerator.cpp as follows:

if (m_drawPlayers) {
renderPlayers(input_path);
}

// My additions start here. WMS 09/02/2020
double x, y, z;
FILE *fpin;

if ((fpin = fopen("track", "r")) == NULL)
printf("Cannot open track file\n");
else {
while (fscanf(fpin, "%lf %lf %lf", &x, &y, &z) != EOF) {
x = m_zoom * x;
z = m_zoom * z;
x = x + getImageX(0, true); // Add X-origin location
z = getImageY(0, true) - z; // Flip sign and use Y-origin

m_image->drawFilledRect((int)x, (int)z,
m_zoom, m_zoom, Color(255,0,0));
printf("%f %f\n", x, z);
}
}
// And end here

writeImage(output);
printUnknown();
}


Yes, due to weird coordinate systems, it is a little confusing.
But it seems to work ok. If anyone finds any problems, let me know!
Compile as before and run as normal.

I add a picture, showing a red track where I walked around on my paths
in the world.

Maker2.png
Maker2.png (854.4 KiB) Viewed 696 times

User avatar
bosapara
Member
Posts: 637
Joined: Fri Apr 07, 2017 08:49

Re: Visualize 3D maps of movement?

by bosapara » Post

WyomingWill,

Looks good, definitely faster and more convenient than using my method.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests