diff options
-rw-r--r-- | blender/concrete-wall1/n/corner/0001.png | bin | 1665 -> 1354 bytes | |||
-rw-r--r-- | blender/concrete-wall1/n/top/0001.png | bin | 2145 -> 410 bytes | |||
-rw-r--r-- | blender/test-wall1/n/top/0001.png | bin | 161 -> 149 bytes | |||
-rw-r--r-- | blender/test-wall1/test1.tpl.json (renamed from blender/test-wall1/test11.tpl.json) | 0 | ||||
-rw-r--r-- | doc/saves/quicksave - Copy (44).dat | bin | 4137 -> 4169 bytes | |||
-rw-r--r-- | doc/saves/quicksave - Copy (45).dat | bin | 4832 -> 0 bytes | |||
-rw-r--r-- | doc/saves/quicksave - Copy (46).dat | bin | 4116 -> 0 bytes | |||
-rw-r--r-- | editor/imgui-editors.cpp | 2 | ||||
-rw-r--r-- | src/chunk-walls.cpp | 6 | ||||
-rw-r--r-- | src/wall-atlas.cpp | 1 | ||||
-rw-r--r-- | test/save/quicksave - Copy (0029).dat | bin | 0 -> 4169 bytes | |||
-rw-r--r-- | test/wall-atlas.cpp | 2 | ||||
-rw-r--r-- | wall-tileset-tool/main.cpp | 121 | ||||
-rw-r--r-- | wall-tileset-tool/main.hpp | 13 | ||||
-rw-r--r-- | walls/concrete1.json | 4 | ||||
-rw-r--r-- | walls/concrete1.png | bin | 73754 -> 71209 bytes | |||
-rw-r--r-- | walls/test1.json | 4 | ||||
-rw-r--r-- | walls/test1.png | bin | 6228 -> 6287 bytes |
18 files changed, 103 insertions, 50 deletions
diff --git a/blender/concrete-wall1/n/corner/0001.png b/blender/concrete-wall1/n/corner/0001.png Binary files differindex a84f99eb..91404575 100644 --- a/blender/concrete-wall1/n/corner/0001.png +++ b/blender/concrete-wall1/n/corner/0001.png diff --git a/blender/concrete-wall1/n/top/0001.png b/blender/concrete-wall1/n/top/0001.png Binary files differindex 495a2e48..7e132135 100644 --- a/blender/concrete-wall1/n/top/0001.png +++ b/blender/concrete-wall1/n/top/0001.png diff --git a/blender/test-wall1/n/top/0001.png b/blender/test-wall1/n/top/0001.png Binary files differindex 3d98e728..b6612ca7 100644 --- a/blender/test-wall1/n/top/0001.png +++ b/blender/test-wall1/n/top/0001.png diff --git a/blender/test-wall1/test11.tpl.json b/blender/test-wall1/test1.tpl.json index f1d7c050..f1d7c050 100644 --- a/blender/test-wall1/test11.tpl.json +++ b/blender/test-wall1/test1.tpl.json diff --git a/doc/saves/quicksave - Copy (44).dat b/doc/saves/quicksave - Copy (44).dat Binary files differindex a0fc36bd..55f76ce5 100644 --- a/doc/saves/quicksave - Copy (44).dat +++ b/doc/saves/quicksave - Copy (44).dat diff --git a/doc/saves/quicksave - Copy (45).dat b/doc/saves/quicksave - Copy (45).dat Binary files differdeleted file mode 100644 index e06b36c3..00000000 --- a/doc/saves/quicksave - Copy (45).dat +++ /dev/null diff --git a/doc/saves/quicksave - Copy (46).dat b/doc/saves/quicksave - Copy (46).dat Binary files differdeleted file mode 100644 index de8b5543..00000000 --- a/doc/saves/quicksave - Copy (46).dat +++ /dev/null diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp index 7dbef176..f4b546f1 100644 --- a/editor/imgui-editors.cpp +++ b/editor/imgui-editors.cpp @@ -34,7 +34,7 @@ StringView scenery_type_to_string(const scenery_& sc) } StringView scenery_path(const wall_info* wa) { return wa->atlas->name(); } -StringView scenery_name(StringView name, const scenery_& sc) { return sc.descr; } +StringView scenery_name(StringView, const scenery_& sc) { return sc.descr; } StringView scenery_name(StringView, const vobj_& vobj) { return vobj.descr; } StringView scenery_name(StringView, const wall_info* w) { return w->descr; } std::shared_ptr<anim_atlas> get_atlas(const scenery_& sc) { return sc.proto.atlas; } diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp index 83e33b62..6720bec9 100644 --- a/src/chunk-walls.cpp +++ b/src/chunk-walls.cpp @@ -93,10 +93,10 @@ constexpr Quads::quad get_quad(Direction_ D, Group_ G, float depth) else { return {{ - { -X - depth, Y, Z }, - { -X, Y, Z }, - { -X - depth, -Y, Z }, { -X, -Y, Z }, + { -X, Y, Z }, + { -X - depth, -Y, Z }, + { -X - depth, Y, Z }, }}; } case corner: diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp index 9461431c..11bf5f15 100644 --- a/src/wall-atlas.cpp +++ b/src/wall-atlas.cpp @@ -92,6 +92,7 @@ Vector2ui wall_atlas::expected_size(unsigned depth, Group_ group) case wall: return { size.x(), size.z() }; case top: + return { depth, size.x() }; case side: case corner: return { depth, size.z() }; diff --git a/test/save/quicksave - Copy (0029).dat b/test/save/quicksave - Copy (0029).dat Binary files differnew file mode 100644 index 00000000..55f76ce5 --- /dev/null +++ b/test/save/quicksave - Copy (0029).dat diff --git a/test/wall-atlas.cpp b/test/wall-atlas.cpp index eec4ecee..1f71d10f 100644 --- a/test/wall-atlas.cpp +++ b/test/wall-atlas.cpp @@ -123,7 +123,7 @@ void test_expected_size() fm_assert_equal(Vector2ui{64, 192}, wall_atlas::expected_size(42, Group_::wall)); fm_assert_equal(Vector2ui{42, 192}, wall_atlas::expected_size(42, Group_::side)); // swapped in atlas.json during reading and writing, rotated counter-clockwise in atlas image file - fm_assert_equal(Vector2ui{42, 192}, wall_atlas::expected_size(42, Group_::top)); + fm_assert_equal(Vector2ui{42, 64}, wall_atlas::expected_size(42, Group_::top)); } } // namespace diff --git a/wall-tileset-tool/main.cpp b/wall-tileset-tool/main.cpp index 38697d9c..c9bb3a72 100644 --- a/wall-tileset-tool/main.cpp +++ b/wall-tileset-tool/main.cpp @@ -5,6 +5,7 @@ #include "compat/format.hpp" #include "compat/debug.hpp" #include "src/wall-atlas.hpp" +#include "src/tile-defs.hpp" #include "serialize/wall-atlas.hpp" //#include "serialize/json-helper.hpp" #include "loader/loader.hpp" @@ -40,11 +41,6 @@ const Direction& get_direction(const wall_atlas_def& atlas, size_t i) return atlas.direction_array[idx.val]; } -Direction& get_direction(wall_atlas_def& atlas, size_t i) -{ - return const_cast<Direction&>(get_direction(const_cast<const wall_atlas_def&>(atlas), i)); -} - template<typename Fmt, typename... Xs> auto asformat(Fmt&& fmt, Xs&&... args) { @@ -90,40 +86,62 @@ bool convert_to_bgra32(const cv::Mat& src, cv::Mat4b& dest) } } -Vector2ui mat_size(const cv::Mat& mat) -{ - return { (unsigned)mat.cols, (unsigned)mat.rows }; -} - bool save_image(state st) { - const auto count = st.frames.size(); - fm_assert(count); - - for (auto i = 1uz; i < count; i++) - fm_assert(mat_size(st.frames[i].mat).y() == mat_size(st.frames[0].mat).y()); + fm_assert(st.new_atlas.frames.empty()); + uint32_t max_height = 0; + for (const auto& group : st.groups) + { + const auto expected_size = wall_atlas::expected_size(st.new_atlas.header.depth, group.G); + max_height = std::max(max_height, expected_size.y()); + } + fm_assert(max_height > 0); + fm_assert(max_height == (uint32_t)iTILE_SIZE.z()); // todo? - size_t total_width = 0; - for (const auto& x : st.frames) - total_width += mat_size(x.mat).x(); - size_t num_rows = (total_width + max_image_dimension - 1) / max_image_dimension; - fm_assert(num_rows > 0); - fm_assert(num_rows == 1); // todo + uint32_t xpos = 0; + Vector2ui max; + for (auto& group : st.groups) + { + const auto size = wall_atlas::expected_size(st.new_atlas.header.depth, group.G); + const auto width = size.x(), height = size.y(); + uint32_t ypos = 0; + bool started = false; + for (auto& frame : group.frames) + { + frame.offset = {xpos, ypos}; + max = Math::max(max, frame.offset + size); + started = true; + fm_assert(max <= Vector2ui{(unsigned)max_image_dimension}); + fm_assert(frame.size == size); + if (ypos + height*2 <= max_height) + ypos += height; + else + { + ypos = 0; + xpos += width; + started = false; + } + } + if (started) + xpos += width; + } + fm_assert(max.product() > 0); - st.dest.create((int)mat_size(st.frames[0].mat).y(), (int)total_width); - st.dest.setTo(cv::Scalar{0, 0, 0, 0}); + st.dest.create((int)max.y(), (int)max.x()); + st.dest.setTo(cv::Scalar{255, 0, 255, 0}); - unsigned xpos = 0; - for (auto& x : st.frames) + for (const auto& group : st.groups) { - const auto& src = x.mat; - x.size = mat_size(src); - x.offset = {(unsigned)xpos, 0}; - auto rect = cv::Rect{(int)xpos, 0, (int)x.size.x(), (int)x.size.y()}; - xpos += x.size.x(); - src.copyTo(st.dest(rect)); - st.new_atlas.frames.push_back({.offset = x.offset, .size = x.size}); + for (const auto& frame : group.frames) + { + //Debug{} << "g" << (int)group.G << frame.offset << frame.size; + auto rect = cv::Rect{(int)frame.offset.x(), (int)frame.offset.y(), + (int)frame.size.x(), (int)frame.size.y()}; + frame.mat.copyTo(st.dest(rect)); + st.new_atlas.frames.push_back({.offset = frame.offset, .size = frame.size}); + } } + auto filename = ""_s.join({Path::join(st.opts.output_dir, st.new_atlas.header.name), ".png"_s}); if (!st.opts.use_alpha) { @@ -139,6 +157,8 @@ bool save_image(state st) bool save_json(state st) { using namespace floormat::Wall::detail; + fm_assert(!st.new_atlas.frames.empty()); + fm_assert(st.new_atlas.header.depth > 0); auto filename = ""_s.join({Path::join(st.opts.output_dir, st.new_atlas.header.name), ".json"_s}); st.new_atlas.serialize(filename); return true; @@ -160,8 +180,16 @@ bool do_group(state st, size_t i, size_t j, Group& new_group) DBG << " group" << quoted2(group_name); fm_debug_assert(expected_size > Vector2ui{0}); fm_assert(Math::max(expected_size.x(), expected_size.y()) < max_image_dimension); + fm_assert((size_t)st.groups.at(j).G == j); + + auto& frames = [&] -> auto&& { + for (auto& g : st.groups) + if ((size_t)g.G == j) + return g.frames; + fm_abort("can't find ground '%d'", (int)j); + }(); - uint32_t count = 0, start = (uint32_t)st.frames.size(); + auto count = 0uz, start = st.n_frames; new_group = old_group; new_group.is_defined = true; new_group.pixel_size = Vector2ui(expected_size); @@ -171,13 +199,15 @@ bool do_group(state st, size_t i, size_t j, Group& new_group) auto filename = asformat("{}/{:04}.png"_cf, path, count+1); if (!Path::exists(filename)) break; - count++; if (Path::isDirectory(filename)) [[unlikely]] { ERR << "fatal: path" << quoted(filename) << "is a directory!"; return false; } + count++; + st.n_frames++; + cv::Mat mat = cv::imread(filename, cv::IMREAD_ANYCOLOR), mat2; if ((Group_)j == Group_::top) { @@ -210,7 +240,10 @@ bool do_group(state st, size_t i, size_t j, Group& new_group) return false; } - st.frames.push_back({.mat = std::move(buf)}); + frames.push_back({ + .mat = std::move(buf), + .size = {(unsigned)mat.cols, (unsigned)mat.rows}, + }); } if (count == 0) @@ -221,7 +254,7 @@ bool do_group(state st, size_t i, size_t j, Group& new_group) DBG << " " << Debug::nospace << count << (count == 1 ? "frame" : "frames"); - fm_assert(start + count == st.frames.size()); + fm_assert(start + count == st.n_frames); new_group.count = count; new_group.index = start; @@ -363,15 +396,27 @@ int main(int argc, char** argv) auto old_atlas = wall_atlas_def::deserialize(opts.input_file); auto new_atlas = wall_atlas_def{}; - auto frames = std::vector<frame>{}; frames.reserve(64); auto dest = cv::Mat4b{}; auto error = EX_DATAERR; + size_t n_frames = 0; + + auto groups = std::vector<group>{}; + groups.reserve(std::size(Wall::Direction::groups)); + + for (auto [name, ptr, val] : Wall::Direction::groups) + { + groups.push_back({ + .frames = std::vector<frame>{}, + .G = val, + }); + } auto st = state { .opts = opts, .old_atlas = old_atlas, .new_atlas = new_atlas, - .frames = frames, + .groups = groups, + .n_frames = n_frames, .dest = dest, .error = error, }; diff --git a/wall-tileset-tool/main.hpp b/wall-tileset-tool/main.hpp index b7bc54e2..942ecf6c 100644 --- a/wall-tileset-tool/main.hpp +++ b/wall-tileset-tool/main.hpp @@ -13,8 +13,14 @@ struct options struct frame { - cv::Mat4b mat{}; - Vector2ui offset{}, size{}; + cv::Mat4b mat; + Vector2ui offset{}, size; +}; + +struct group +{ + std::vector<frame> frames; + Wall::Group_ G; }; struct state @@ -22,7 +28,8 @@ struct state options& opts; const wall_atlas_def& old_atlas; wall_atlas_def& new_atlas; - std::vector<frame>& frames; + std::vector<group>& groups; + size_t& n_frames; cv::Mat4b& dest; int& error; }; diff --git a/walls/concrete1.json b/walls/concrete1.json index 91c5069a..a00be145 100644 --- a/walls/concrete1.json +++ b/walls/concrete1.json @@ -19,7 +19,7 @@ },
{
"offset": "212 x 0",
- "size": "20 x 192"
+ "size": "20 x 64"
},
{
"offset": "232 x 0",
@@ -43,7 +43,7 @@ "count": 1,
"mirrored": false,
"offset": 4,
- "pixel-size": "192 x 20"
+ "pixel-size": "64 x 20"
},
"wall": {
"count": 3,
diff --git a/walls/concrete1.png b/walls/concrete1.png Binary files differindex e0e9c4f4..03e070ad 100644 --- a/walls/concrete1.png +++ b/walls/concrete1.png diff --git a/walls/test1.json b/walls/test1.json index 04b4aaeb..b8c61817 100644 --- a/walls/test1.json +++ b/walls/test1.json @@ -19,7 +19,7 @@ },
{
"offset": "192 x 0",
- "size": "32 x 192"
+ "size": "32 x 64"
},
{
"offset": "224 x 0",
@@ -47,7 +47,7 @@ "count": 1,
"mirrored": false,
"offset": 4,
- "pixel-size": "192 x 32"
+ "pixel-size": "64 x 32"
},
"wall": {
"count": 2,
diff --git a/walls/test1.png b/walls/test1.png Binary files differindex c72bde3e..bf43e4ba 100644 --- a/walls/test1.png +++ b/walls/test1.png |