From 8ba8209bc243f259467003bcfa1d3d0804bd2c65 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 8 Nov 2019 09:45:21 +0100 Subject: [PATCH] Added add_textures_into method to PropData. --- props/prop_data.cpp | 24 ++++++++++++++++++++++++ props/prop_data.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/props/prop_data.cpp b/props/prop_data.cpp index 071c4c8..96af0d5 100644 --- a/props/prop_data.cpp +++ b/props/prop_data.cpp @@ -1,5 +1,7 @@ #include "prop_data.h" +#include "prop_data_prop.h" + bool PropData::get_snap_to_mesh() { return _snap_to_mesh; } @@ -53,6 +55,26 @@ void PropData::set_props(const Vector &props) { } } +void PropData::add_textures_into(Ref texture_packer) { + ERR_FAIL_COND(!texture_packer.is_valid()); + + for (int i = 0; i < _props.size(); ++i) { + Ref entry = _props.get(i); + + Ref pmesh = entry; + + if (pmesh.is_valid() && pmesh->get_texture().is_valid()) { + texture_packer->add_texture(pmesh->get_texture()); + } + + Ref pdataprop = entry; + + if (pdataprop.is_valid() && pdataprop->get_prop().is_valid()) { + pdataprop->get_prop()->add_textures_into(texture_packer); + } + } +} + PropData::PropData() { _snap_to_mesh = false; _snap_axis = Vector3(0, -1, 0); @@ -80,4 +102,6 @@ void PropData::_bind_methods() { ClassDB::bind_method(D_METHOD("get_props"), &PropData::get_props); ClassDB::bind_method(D_METHOD("set_props", "props"), &PropData::set_props); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "props", PROPERTY_HINT_NONE, "17/17:PropDataEntry", PROPERTY_USAGE_DEFAULT, "PropDataEntry"), "set_props", "get_props"); + + ClassDB::bind_method(D_METHOD("add_textures_into", "texture_packer"), &PropData::add_textures_into); } diff --git a/props/prop_data.h b/props/prop_data.h index 4000c4b..d62c00d 100644 --- a/props/prop_data.h +++ b/props/prop_data.h @@ -5,6 +5,9 @@ #include "core/vector.h" #include "prop_data_entry.h" +#include "prop_data_mesh.h" + +#include "../../texture_packer/texture_packer.h" class PropData : public Resource { GDCLASS(PropData, Resource); @@ -25,6 +28,8 @@ public: Vector get_props(); void set_props(const Vector &props); + + void add_textures_into(Ref texture_packer); PropData(); ~PropData();