Skip to content

Commit 9e6c017

Browse files
committed
initial commit
1 parent 390a851 commit 9e6c017

12 files changed

+610
-0
lines changed

CMakeLists.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.11.0)
2+
if(UNIX)
3+
set(CMAKE_C_COMPILER /usr/bin/gcc)
4+
set(CMAKE_CXX_COMPILER /usr/bin/g++)
5+
set(CMAKE_CXX_FLAGS -pthread)
6+
else(WIN32)
7+
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc.exe)
8+
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++.exe)
9+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc")
10+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
11+
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static-libgcc -s")
12+
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static-libgcc -static-libstdc++ -s")
13+
endif()
14+
set(CMAKE_CXX_STANDARD 20)
15+
project(MapMaker)
16+
set(STB_PATH "${PROJECT_SOURCE_DIR}/stb")
17+
set(JSON_PATH "${PROJECT_SOURCE_DIR}/json")
18+
19+
include_directories(${STB_PATH} ${JSON_PATH} ${PROJECT_SOURCE_DIR}/src)
20+
link_directories(${STB_PATH} ${JSON_PATH} ${PROJECT_SOURCE_DIR}/src)
21+
22+
file(GLOB_RECURSE SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
23+
add_executable(${PROJECT_NAME} ${SOURCES})

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# MinecraftMapMaker_Showcase
2+
A showcase of minecraft map image generator that renders a map image based on the data given.
3+
4+
# What does it do?
5+
6+
Basically, it gives you an image as an output. All you need is to provide a block height map (currently no tools to do it, as it's just a showcase) and tweak settings. This program will use all of your computer cores during rendering to speed up the process.
7+
8+
There are multiple settings (located in input/settings.json):
9+
10+
* Block height map and color map which are essential for this to work. This showcase contains an example so you can tweak it and get different map images.
11+
* Darkening coefficient that, obviously, randomly darkens pixel so the output image looks a bit better.
12+
13+
> No darkening.
14+
15+
![](https://github.com/Blika/MinecraftMapMaker_Showcase/assets/61899272/891cc169-966d-4144-91f1-bfd392b1ec71)
16+
17+
> Darkening set at 0.1.
18+
19+
![](https://github.com/Blika/MinecraftMapMaker_Showcase/assets/61899272/1cdb5f9e-44c0-4a0d-a54a-75be3c1260e5)
20+
21+
* Shading coeffiecent that further darkens pixels when shadows or outlines are processed.
22+
* Light direction which decides from there the light is processed. (Essential for outlines and shadows to work)
23+
* Light radius. You can think that "light" in this project is a sun, and this settings desides how big this sun is. Without it the shadows would be somewhat unnatural (very long and tall). (Essential for shadows to work)
24+
* Light offset that decides where the light is actually located. If we only provide a light direction the program won't know exactly how to render light so we would have to assume it (meaning it would be hardcoded). (Essential for shadows to work)
25+
* Drawing outlines. It renders outlines based on light direction. As a result, it adds volume to the output map.
26+
27+
> Darkening 0.1, outlines enabled. The result looks so much better now.
28+
29+
![](https://github.com/Blika/MinecraftMapMaker_Showcase/assets/61899272/6228078e-ef1a-401a-9a35-b8652e83a18b)
30+
31+
* Drawing shadows decides if shadows are rendered. It heavily depends on light settings for obvious reasons and by tweaking this you're going to get different outputs. Sadly, as we only provide a height map, so we assume that there isn't any empty space under blocks. Therefore, some shadows may look strange but still quite good if your light settings are okay.
32+
33+
> Darkening 0.1, outlines enabled, shadows enabled. Based on shadows you can guess each object actual height. Trees are quite tall so from here their shadows may not look good but buildings' shadows are okay.
34+
35+
![](https://github.com/Blika/MinecraftMapMaker_Showcase/assets/61899272/ae50f1c8-356c-4765-8e6c-0a8529a70c91)
36+
37+
# Usage
38+
39+
To use this tool you can either download it from releases or build it yourself using cmake. Currently only Windows release is available.

build.bat

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if not exist build mkdir build
2+
cd build
3+
cmake -S ../ -B . -G "MinGW Makefiles"
4+
mingw32-make.exe
5+
move MapMaker.exe ../
6+
cd ..
7+
pause

build.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
mkdir -p build
4+
cd build
5+
cmake -S ../ -B . -G "Unix Makefiles"
6+
make
7+
mv MapMaker ../
8+
cd ..

input/blocks.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"Grass": "#282f12",
3+
"Double Tallgrass": "#2e3515",
4+
"Large Fern": "#2e3515",
5+
"Tall Grass": "#2e3515",
6+
"Sunflower": "#2d3612",
7+
"Fern": "#2e341d",
8+
"Clay Block": "#3d403d",
9+
"Sand": "#3c3025",
10+
"Lilac": "#2d261d",
11+
"Birch Leaves": "#1F2512",
12+
"Dandelion": "#1F2512",
13+
"Oak Leaves": "#1F2512",
14+
"Spruce Leaves": "#1F2512",
15+
"default_leaves": "#1F2512",
16+
"Water": "#211e16",
17+
"Bricks": "#5B2E19",
18+
"Dirt": "#3f3628",
19+
"Brown Mushroom Block": "#3f3628",
20+
"Nether Bricks": "#3b2b24",
21+
"Mossy Cobblestone": "#3f3e3e",
22+
"Spruce Wood": "#331C00",
23+
"Oak Wood": "#331C00",
24+
"Concrete": "#3f3e3e",
25+
"Cobblestone": "#3f3e3e",
26+
"Coal Ore": "#3f3e3e",
27+
"Nether Brick Slab": "#3b2b24",
28+
"Nether Brick Stairs": "#3b2b24",
29+
"Nether Brick Fence": "#3b2b24",
30+
"Infested Stone": "#3f3a3a",
31+
"Oak Trapdoor": "#46403a",
32+
"Oak Planks": "#46403a",
33+
"Oak Fence Gate": "#46403a",
34+
"Birch Slab": "#46403a",
35+
"Birch Planks": "#46403a",
36+
"Jungle Planks": "#46403a",
37+
"Jungle Stairs": "#46403a",
38+
"Stone Bricks": "#3f3a3a",
39+
"Stone": "#3f3a3a",
40+
"Smooth Stone Slab": "#3f3a3a",
41+
"Iron Bars": "#565252",
42+
"Iron Trapdoor": "#565252",
43+
"Chiseled Quartz Block": "#666666",
44+
"Quartz Block": "#666666",
45+
"Quartz Slab": "#666666",
46+
"Stained Clay": "#666666",
47+
"Wool": "#666666",
48+
"Gravel": "#393939",
49+
"Dead Bush": "#362b21",
50+
"diag_clay": "#434643",
51+
"diag_gravel": "#3F3F3F",
52+
"diag_dirt": "#453B2C",
53+
"diag_grass": "#2C3414",
54+
"diag_sand": "#423529",
55+
"diag_nether_brick": "#3b2b24",
56+
"diag_planks_oak": "#46403a"
57+
}

input/map.json

+1
Large diffs are not rendered by default.

input/settings.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"draw_outlines": true,
3+
"draw_shadows": true,
4+
"light_offset": [-320, 360, -258],
5+
"light_radius": 2,
6+
"light_direction": 0,
7+
"darken": 0.1,
8+
"shading": 0.2
9+
}

src/image.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "image.hpp"
2+
#define STB_IMAGE_IMPLEMENTATION
3+
#include <stb_image.h>
4+
#define STBI_MSC_SECURE_CRT
5+
#define STB_IMAGE_WRITE_IMPLEMENTATION
6+
#include <stb_image_write.h>
7+
8+
namespace mapmaker{
9+
10+
Image::Image(int iw, int ih): width{iw}, height{ih}{
11+
channels = 4;
12+
data = (stbi_uc*)malloc(static_cast<size_t>(width) * static_cast<size_t>(height) * channels);
13+
}
14+
15+
Image::~Image(){
16+
stbi_image_free(data);
17+
}
18+
19+
std::string Image::get_png_data(){
20+
int len;
21+
unsigned char* d = stbi_write_png_to_mem((const unsigned char*) data, width * channels, width, height, channels, &len);
22+
std::string str_data(reinterpret_cast<const char*>(d), len);
23+
stbi_image_free(d);
24+
return str_data;
25+
}
26+
27+
void Image::get_pixel(size_t x, size_t y, stbi_uc* r, stbi_uc* g, stbi_uc* b, stbi_uc* a){
28+
*r = data[4 * (y * width + x) + 0];
29+
*g = data[4 * (y * width + x) + 1];
30+
*b = data[4 * (y * width + x) + 2];
31+
*a = data[4 * (y * width + x) + 3];
32+
}
33+
34+
void Image::write_pixel(size_t x, size_t y, stbi_uc r, stbi_uc g, stbi_uc b, stbi_uc a){
35+
data[4 * (y * width + x) + 0] = r;
36+
data[4 * (y * width + x) + 1] = g;
37+
data[4 * (y * width + x) + 2] = b;
38+
data[4 * (y * width + x) + 3] = a;
39+
}
40+
41+
void Image::save_image(const char* output){
42+
stbi_write_png(output, width, height, channels, data, width * channels);
43+
}
44+
}

src/image.hpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
3+
#include <stb_image.h>
4+
#include <string>
5+
6+
namespace mapmaker{
7+
class Image{
8+
public:
9+
Image(int width, int height);
10+
~Image();
11+
12+
Image(const Image&) = delete;
13+
Image &operator=(const Image&) = delete;
14+
Image(Image&&) = delete;
15+
Image &operator=(Image&&) = delete;
16+
17+
int get_width(){
18+
return width;
19+
}
20+
int get_height(){
21+
return height;
22+
}
23+
int get_channels(){
24+
return channels;
25+
}
26+
stbi_uc* get_data(){
27+
return data;
28+
}
29+
std::string get_png_data();
30+
void get_pixel(size_t x, size_t y, stbi_uc* r, stbi_uc* g, stbi_uc* b, stbi_uc* a);
31+
void write_pixel(size_t x, size_t y, stbi_uc r, stbi_uc g, stbi_uc b, stbi_uc a);
32+
void save_image(const char* output);
33+
34+
private:
35+
int width,height,channels;
36+
stbi_uc* data;
37+
};
38+
}

src/main.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "map_maker.hpp"
2+
3+
#include <cstdlib>
4+
#include <filesystem>
5+
#include <iostream>
6+
#include <stdexcept>
7+
8+
int main(){
9+
std::filesystem::create_directory("output");
10+
mapmaker::MapMaker mapmaker{};
11+
try{
12+
mapmaker.run();
13+
}catch(const std::exception& e){
14+
std::cerr << e.what() << '\n';
15+
return EXIT_FAILURE;
16+
}
17+
return EXIT_SUCCESS;
18+
}

0 commit comments

Comments
 (0)