Add prop uv rect query into the library, and make add_mesh_data_resource use it.

This commit is contained in:
Relintai 2020-06-28 21:31:26 +02:00
parent 1996f60f0f
commit 9e2d71169b
6 changed files with 29 additions and 5 deletions

View File

@ -222,6 +222,10 @@ int VoxelmanLibrary::get_num_props() const {
}
void VoxelmanLibrary::clear_props() {
}
Rect2 VoxelmanLibrary::get_prop_uv_rect(const Ref<Texture> &texture) {
return Rect2(0, 0, 1, 1);
}
#endif
//Rects

View File

@ -101,6 +101,8 @@ public:
virtual void remove_prop(const int id);
virtual int get_num_props() const;
virtual void clear_props();
virtual Rect2 get_prop_uv_rect(const Ref<Texture> &texture);
#endif
virtual void refresh_rects();

View File

@ -180,6 +180,18 @@ Vector<Variant> VoxelmanLibraryMerger::get_props() {
void VoxelmanLibraryMerger::set_props(const Vector<Variant> &props) {
VARIANT_ARRAY_SET(props, _props, PropData);
}
Rect2 VoxelmanLibraryMerger::get_prop_uv_rect(const Ref<Texture> &texture) {
if (!texture.is_valid())
return Rect2(0, 0, 1, 1);
Ref<AtlasTexture> at = _prop_packer->get_texture(texture);
if (!at.is_valid())
return Rect2(0, 0, 1, 1);
return at->get_region();
}
#endif
void VoxelmanLibraryMerger::refresh_rects() {

View File

@ -75,6 +75,8 @@ public:
Vector<Variant> get_props();
void set_props(const Vector<Variant> &props);
Rect2 get_prop_uv_rect(const Ref<Texture> &texture);
#endif
void refresh_rects();

View File

@ -711,17 +711,21 @@ void VoxelChunk::clear_props() {
}
#if MESH_DATA_RESOURCE_PRESENT
int VoxelChunk::add_mesh_data_resource(const Transform &transform, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture, const Rect2 &uv_rect, const Color &color) {
int VoxelChunk::add_mesh_data_resource(const Transform &local_transform, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture, const Color &color) {
ERR_FAIL_COND_V(!mesh.is_valid(), 0);
int index = _mesh_data_resources.size();
MeshDataResourceEntry e;
e.transform = transform;
e.transform = local_transform;
e.mesh = mesh;
e.texture = texture;
e.color = color;
e.uv_rect = uv_rect;
if (get_library().is_valid() && texture.is_valid())
e.uv_rect = get_library()->get_prop_uv_rect(texture);
else
e.uv_rect = Rect2(0, 0, 1, 1);
_mesh_data_resources.push_back(e);
@ -1133,7 +1137,7 @@ void VoxelChunk::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear_props"), &VoxelChunk::clear_props);
#if MESH_DATA_RESOURCE_PRESENT
ClassDB::bind_method(D_METHOD("add_mesh_data_resource", "transform", "mesh", "texture", "uv_rect", "color"), &VoxelChunk::add_mesh_data_resource, DEFVAL(Ref<Texture>()), DEFVAL(Rect2(0, 0, 1, 1)), DEFVAL(Color(1, 1, 1, 1)));
ClassDB::bind_method(D_METHOD("add_mesh_data_resource", "local_transform", "mesh", "texture", "color"), &VoxelChunk::add_mesh_data_resource, DEFVAL(Ref<Texture>()), DEFVAL(Color(1, 1, 1, 1)));
ClassDB::bind_method(D_METHOD("get_mesh_data_resource", "index"), &VoxelChunk::get_mesh_data_resource);
ClassDB::bind_method(D_METHOD("set_mesh_data_resource", "index", "mesh"), &VoxelChunk::set_mesh_data_resource);

View File

@ -200,7 +200,7 @@ public:
void clear_props();
#if MESH_DATA_RESOURCE_PRESENT
int add_mesh_data_resource(const Transform &transform, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture = Ref<Texture>(), const Rect2 &uv_rect = Rect2(0, 0, 1, 1), const Color &color = Color(1, 1, 1, 1));
int add_mesh_data_resource(const Transform &local_transform, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture = Ref<Texture>(), const Color &color = Color(1, 1, 1, 1));
Ref<MeshDataResource> get_mesh_data_resource(const int index);
void set_mesh_data_resource(const int index, const Ref<MeshDataResource> &mesh);