From eb4922fc429764504a7e94e8c712c368c51685f2 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 23 Nov 2022 15:33:38 +0100 Subject: scenery: add table --- anim-crop-tool/main.cpp | 6 ++++-- anim/table.json | 44 ++++++++++++++++++++++++++++++++++++++++++++ anim/table.tga | Bin 0 -> 175134 bytes anim/table/table.blend | Bin 0 -> 1195856 bytes anim/table/table_rou.png | Bin 0 -> 1219363 bytes anim/table/wood.png | Bin 0 -> 1484466 bytes editor/app.cpp | 3 ++- editor/app.hpp | 2 +- editor/update.cpp | 1 + loader/atlas.cpp | 2 +- src/anim-atlas.cpp | 4 ++-- src/anim-atlas.hpp | 2 +- src/scenery.cpp | 8 ++++---- src/scenery.hpp | 4 ++-- 14 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 anim/table.json create mode 100644 anim/table.tga create mode 100644 anim/table/table.blend create mode 100644 anim/table/table_rou.png create mode 100644 anim/table/wood.png diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp index 1b3b4b59..ec08b257 100644 --- a/anim-crop-tool/main.cpp +++ b/anim-crop-tool/main.cpp @@ -256,7 +256,7 @@ int main(int argc, char** argv) return EX_DATAERR; } - if (!check_atlas_name(anim_info.anim_name)) + if (!anim_info.anim_name.isEmpty() && !check_atlas_name(anim_info.anim_name)) { Error{} << "error: atlas animation name" << anim_info.object_name << "is invalid"; return EX_DATAERR; @@ -283,7 +283,9 @@ int main(int argc, char** argv) if (!Path::make(opts.output_dir)) return EX_CANTCREAT; - const String base_name = anim_info.object_name + "-" + anim_info.anim_name; + const String base_name = !anim_info.anim_name.isEmpty() + ? anim_info.object_name + "-" + anim_info.anim_name + : anim_info.object_name; if (auto pathname = Path::join(opts.output_dir, (base_name + ".png")); !atlas.dump(pathname)) { Error{} << "error: failed writing image to" << pathname << ":" diff --git a/anim/table.json b/anim/table.json new file mode 100644 index 00000000..3b15dbc0 --- /dev/null +++ b/anim/table.json @@ -0,0 +1,44 @@ +{ + "actionframe": 0, + "anim_name": "", + "fps": 24, + "groups": [ + { + "frames": [ + { + "ground": "90 x 88", + "offset": "0 x 0", + "size": "180 x 164" + } + ], + "ground": "959 x 712", + "name": "n", + "offset": [ + 0, + 0, + 0 + ] + }, + { + "frames": [ + { + "ground": "90 x 88", + "offset": "0 x 164", + "size": "180 x 164" + } + ], + "ground": "959 x 712", + "name": "w", + "offset": [ + 0, + 0, + 0 + ] + } + ], + "height": 0, + "nframes": 1, + "object_name": "table", + "pixel_size": "180 x 328", + "width": 180 +} diff --git a/anim/table.tga b/anim/table.tga new file mode 100644 index 00000000..a3c6aed6 Binary files /dev/null and b/anim/table.tga differ diff --git a/anim/table/table.blend b/anim/table/table.blend new file mode 100644 index 00000000..dddaf9c5 Binary files /dev/null and b/anim/table/table.blend differ diff --git a/anim/table/table_rou.png b/anim/table/table_rou.png new file mode 100644 index 00000000..2f7d0048 Binary files /dev/null and b/anim/table/table_rou.png differ diff --git a/anim/table/wood.png b/anim/table/wood.png new file mode 100644 index 00000000..2bdb07db Binary files /dev/null and b/anim/table/wood.png differ diff --git a/editor/app.cpp b/editor/app.cpp index 9f8914f0..4fcc051b 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -16,7 +16,8 @@ app::app(fm_settings&& opts) : _floor2{loader.tile_atlas("metal1", {2, 2})}, _wall1{loader.tile_atlas("wood2", {2, 1})}, _wall2{loader.tile_atlas("wood1", {2, 1})}, - _door{loader.anim_atlas("door-close")} + _door{loader.anim_atlas("door-close")}, + _table{loader.anim_atlas("table")} { world& w = M->world(); chunk_coords coord{0 ,0}; diff --git a/editor/app.hpp b/editor/app.hpp index 7a1bf89d..aac86d76 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -114,7 +114,7 @@ private: Containers::Pointer M; ImGuiIntegration::Context _imgui{NoCreate}; std::shared_ptr _floor1, _floor2, _wall1, _wall2; - std::shared_ptr _door; + std::shared_ptr _door, _table; GL::Texture2D _wireframe_texture = wireframe::make_constant_texture(); wireframe_mesh _wireframe_quad {_wireframe_texture}; wireframe_mesh _wireframe_wall_n {_wireframe_texture}; diff --git a/editor/update.cpp b/editor/update.cpp index a253c3c4..9f347f0d 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -31,6 +31,7 @@ void app::maybe_initialize_chunk_(const chunk_coords& pos, chunk& c) c[{K, K+1}].wall_north() = { _wall1, 0 }; c[{K+1, K }].wall_west() = { _wall2, 0 }; c[{K+3, K+1}].scenery() = { scenery::door, rotation::N, _door, false }; + c[{ 3, 4 }].scenery() = { scenery::generic, rotation::N, _table }; c.mark_modified(); } diff --git a/loader/atlas.cpp b/loader/atlas.cpp index ab289647..1aaa4e31 100644 --- a/loader/atlas.cpp +++ b/loader/atlas.cpp @@ -36,7 +36,7 @@ std::shared_ptr loader_impl::anim_atlas(StringView name) auto anim_info = deserialize_anim(path + ".json"); auto tex = texture("", path); - fm_assert(!anim_info.anim_name.isEmpty() && !anim_info.object_name.isEmpty()); + fm_assert(!anim_info.object_name.isEmpty()); fm_assert(anim_info.pixel_size.product() > 0); fm_assert(!anim_info.groups.empty()); fm_assert(anim_info.nframes > 0); diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp index 841c66d8..33b107df 100644 --- a/src/anim-atlas.cpp +++ b/src/anim-atlas.cpp @@ -33,7 +33,7 @@ decltype(anim_atlas::_group_indices) anim_atlas::make_group_indices(const anim_d anim_atlas::anim_atlas() noexcept = default; anim_atlas::anim_atlas(StringView name, const ImageView2D& image, anim_def info) noexcept : - _name{name}, _bitmask{make_bit_array(image)}, + _name{name}, _bitmask{ make_bitmask(image)}, _info{std::move(info)}, _group_indices{make_group_indices(_info)} { const Size<3>& size = image.pixels().size(); @@ -104,7 +104,7 @@ auto anim_atlas::frame_quad(const Vector3& center, rotation r, std::size_t i) co }}; } -BitArray anim_atlas::make_bit_array(const ImageView2D& tex) +BitArray anim_atlas::make_bitmask(const ImageView2D& tex) { const auto pixels = tex.pixels(); const auto size = pixels.size(); diff --git a/src/anim-atlas.hpp b/src/anim-atlas.hpp index ce0e6176..5b79ca19 100644 --- a/src/anim-atlas.hpp +++ b/src/anim-atlas.hpp @@ -48,7 +48,7 @@ private: static decltype(_group_indices) make_group_indices(const anim_def& anim) noexcept; static std::uint8_t rotation_to_index(const anim_def& a, rotation r) noexcept; - static BitArray make_bit_array(const ImageView2D& tex); + static BitArray make_bitmask(const ImageView2D& tex); }; } // namespace floormat diff --git a/src/scenery.cpp b/src/scenery.cpp index 86561a13..4eed262f 100644 --- a/src/scenery.cpp +++ b/src/scenery.cpp @@ -11,8 +11,8 @@ scenery_proto::scenery_proto(const std::shared_ptr& atlas, const sce atlas{atlas}, frame{frame} {} -scenery_proto::scenery_proto(scenery::generic_tag_t, rotation r, const std::shared_ptr& atlas, scenery::frame_t frame) : - atlas{atlas}, frame{scenery::generic, r, *atlas, frame} +scenery_proto::scenery_proto(scenery::generic_tag_t, rotation r, const std::shared_ptr& atlas, bool passable, scenery::frame_t frame) : + atlas{atlas}, frame{scenery::generic, r, *atlas, passable, frame} {} scenery_proto::scenery_proto(scenery::door_tag_t, rotation r, const std::shared_ptr& atlas, bool is_open) : @@ -39,8 +39,8 @@ scenery_ref::operator bool() const noexcept { return atlas != nullptr; } scenery::scenery() noexcept : scenery{none_tag_t{}} {} scenery::scenery(none_tag_t) noexcept : passable{true} {} -scenery::scenery(generic_tag_t, rotation r, const anim_atlas& atlas, frame_t frame) : - frame{frame}, r{r}, type{scenery_type::generic} +scenery::scenery(generic_tag_t, rotation r, const anim_atlas& atlas, bool passable, frame_t frame) : + frame{frame}, r{r}, passable{passable}, type{scenery_type::generic} { fm_assert(frame < atlas.group(r).frames.size()); } diff --git a/src/scenery.hpp b/src/scenery.hpp index 68bb084a..b6468ebe 100644 --- a/src/scenery.hpp +++ b/src/scenery.hpp @@ -39,7 +39,7 @@ struct scenery final scenery() noexcept; scenery(none_tag_t) noexcept; - scenery(generic_tag_t, rotation r, const anim_atlas& atlas, frame_t frame = 0); + scenery(generic_tag_t, rotation r, const anim_atlas& atlas, bool passable = false, frame_t frame = 0); scenery(door_tag_t, rotation r, const anim_atlas& atlas, bool is_open = false); scenery(float dt, frame_t frame, rotation r, bool passable, scenery_type type); @@ -54,7 +54,7 @@ struct scenery_proto final { scenery_proto() noexcept; explicit scenery_proto(scenery::none_tag_t) noexcept; scenery_proto(const std::shared_ptr& atlas, const scenery& frame); - scenery_proto(scenery::generic_tag_t, rotation r, const std::shared_ptr& atlas, scenery::frame_t frame = 0); + scenery_proto(scenery::generic_tag_t, rotation r, const std::shared_ptr& atlas, bool passable = false, scenery::frame_t frame = 0); scenery_proto(scenery::door_tag_t, rotation r, const std::shared_ptr& atlas, bool is_open = false); scenery_proto& operator=(const scenery_proto&) noexcept; -- cgit v1.2.3