2021-11-22 22:00:45 +01:00
|
|
|
/*
|
2022-02-22 10:33:06 +01:00
|
|
|
Copyright (c) 2019-2022 Péter Magyar
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2022-02-22 11:09:36 +01:00
|
|
|
#include "terrain_2d_library_merger.h"
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
#include "scene/resources/packed_scene.h"
|
|
|
|
#include "scene/resources/texture.h"
|
|
|
|
|
2022-02-22 13:29:31 +01:00
|
|
|
#ifdef PROPS_2D_PRESENT
|
|
|
|
#include "../../props_2d/props/prop_2d_data.h"
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 13:29:31 +01:00
|
|
|
#include "../../props_2d/props/prop_2d_data_prop.h"
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
#if MESH_DATA_RESOURCE_PRESENT
|
2022-02-22 13:29:31 +01:00
|
|
|
#include "../../mesh_data_resource/props_2d/prop_2d_data_mesh_data.h"
|
2021-11-22 22:00:45 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../defines.h"
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DLibraryMerger::get_texture_flags() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _packer->get_texture_flags();
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::set_texture_flags(const int flags) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_packer->set_texture_flags(flags);
|
|
|
|
_prop_packer->set_texture_flags(flags);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DLibraryMerger::get_max_atlas_size() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _packer->get_max_atlas_size();
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::set_max_atlas_size(const int size) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_packer->set_max_atlas_size(size);
|
|
|
|
_prop_packer->set_max_atlas_size(size);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
bool Terrain2DLibraryMerger::get_keep_original_atlases() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _packer->get_keep_original_atlases();
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::set_keep_original_atlases(const bool value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_packer->set_keep_original_atlases(value);
|
|
|
|
_prop_packer->set_keep_original_atlases(value);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Color Terrain2DLibraryMerger::get_background_color() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _packer->get_background_color();
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::set_background_color(const Color &color) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_packer->set_background_color(color);
|
|
|
|
_prop_packer->set_background_color(color);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DLibraryMerger::get_margin() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _packer->get_margin();
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::set_margin(const int margin) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_packer->set_margin(margin);
|
|
|
|
_prop_packer->set_margin(margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Surfaces
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DSurface> Terrain2DLibraryMerger::terra_surface_get(const int index) {
|
|
|
|
ERR_FAIL_INDEX_V(index, _terra_surfaces.size(), Ref<Terrain2DSurface>(NULL));
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
return _terra_surfaces[index];
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::terra_surface_add(Ref<Terrain2DSurface> value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_COND(!value.is_valid());
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
value->set_library(Ref<Terrain2DLibraryMerger>(this));
|
2022-02-22 10:33:06 +01:00
|
|
|
value->set_id(_terra_surfaces.size());
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
_terra_surfaces.push_back(value);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::terra_surface_set(const int index, Ref<Terrain2DSurface> value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_COND(index < 0);
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
if (_terra_surfaces.size() < index) {
|
|
|
|
_terra_surfaces.resize(index + 1);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
if (_terra_surfaces[index].is_valid()) {
|
2022-02-22 11:42:28 +01:00
|
|
|
_terra_surfaces.get(index)->set_library(Ref<Terrain2DLibraryMerger>(NULL));
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (value.is_valid()) {
|
2022-02-22 11:42:28 +01:00
|
|
|
value->set_library(Ref<Terrain2DLibraryMerger>(this));
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
_terra_surfaces.set(index, value);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::terra_surface_remove(const int index) {
|
2022-02-22 10:33:06 +01:00
|
|
|
_terra_surfaces.remove(index);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DLibraryMerger::terra_surface_get_num() const {
|
2022-02-22 10:33:06 +01:00
|
|
|
return _terra_surfaces.size();
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::terra_surfaces_clear() {
|
2021-11-22 22:00:45 +01:00
|
|
|
_packer->clear();
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
for (int i = 0; i < _terra_surfaces.size(); i++) {
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DSurfaceMerger> surface = _terra_surfaces[i];
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
if (surface.is_valid()) {
|
|
|
|
surface->set_library(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
_terra_surfaces.clear();
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Vector<Variant> Terrain2DLibraryMerger::get_terra_surfaces() {
|
2022-02-22 10:33:06 +01:00
|
|
|
VARIANT_ARRAY_GET(_terra_surfaces);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::set_terra_surfaces(const Vector<Variant> &surfaces) {
|
2022-02-22 10:33:06 +01:00
|
|
|
_terra_surfaces.clear();
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < surfaces.size(); i++) {
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DSurfaceMerger> surface = Ref<Terrain2DSurfaceMerger>(surfaces[i]);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
if (surface.is_valid()) {
|
2022-02-22 11:42:28 +01:00
|
|
|
surface->set_library(Ref<Terrain2DLibraryMerger>(this));
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
_terra_surfaces.push_back(surface);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 13:29:31 +01:00
|
|
|
#ifdef PROPS_2D_PRESENT
|
|
|
|
Ref<Prop2DData> Terrain2DLibraryMerger::get_prop(const int index) {
|
|
|
|
ERR_FAIL_INDEX_V(index, _props.size(), Ref<Prop2DData>());
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
return _props[index];
|
|
|
|
}
|
2022-02-22 13:29:31 +01:00
|
|
|
void Terrain2DLibraryMerger::add_prop(Ref<Prop2DData> value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
_props.push_back(value);
|
|
|
|
}
|
2022-02-22 13:29:31 +01:00
|
|
|
bool Terrain2DLibraryMerger::has_prop(const Ref<Prop2DData> &value) const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _props.find(value) != -1;
|
|
|
|
}
|
2022-02-22 13:29:31 +01:00
|
|
|
void Terrain2DLibraryMerger::set_prop(const int index, const Ref<Prop2DData> &value) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _props.size());
|
|
|
|
|
|
|
|
_props.write[index] = value;
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::remove_prop(const int index) {
|
2021-11-22 22:00:45 +01:00
|
|
|
ERR_FAIL_INDEX(index, _props.size());
|
|
|
|
|
|
|
|
_props.remove(index);
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
int Terrain2DLibraryMerger::get_num_props() const {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _props.size();
|
|
|
|
}
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::clear_props() {
|
2021-11-22 22:00:45 +01:00
|
|
|
_props.clear();
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Vector<Variant> Terrain2DLibraryMerger::get_props() {
|
2021-11-22 22:00:45 +01:00
|
|
|
VARIANT_ARRAY_GET(_props);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::set_props(const Vector<Variant> &props) {
|
2022-02-22 13:29:31 +01:00
|
|
|
VARIANT_ARRAY_SET(props, _props, Prop2DData);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Rect2 Terrain2DLibraryMerger::get_prop_uv_rect(const Ref<Texture> &texture) {
|
2021-11-22 22:00:45 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect2 region = at->get_region();
|
|
|
|
|
|
|
|
Ref<Texture> tex = at->get_atlas();
|
|
|
|
|
|
|
|
if (!tex.is_valid()) {
|
|
|
|
return Rect2(0, 0, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Image> image = tex->get_data();
|
|
|
|
|
|
|
|
if (!image.is_valid()) {
|
|
|
|
return Rect2(0, 0, 1, 1);
|
|
|
|
}
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
float w = tex->get_width();
|
|
|
|
float h = tex->get_height();
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
region.position = Size2(region.position.x / w, region.position.y / h);
|
|
|
|
region.size = Size2(region.size.x / w, region.size.y / h);
|
|
|
|
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<TexturePacker> Terrain2DLibraryMerger::get_prop_packer() {
|
2021-11-22 22:00:45 +01:00
|
|
|
return _prop_packer;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::refresh_rects() {
|
2021-11-22 22:00:45 +01:00
|
|
|
bool texture_added = false;
|
2022-02-22 10:33:06 +01:00
|
|
|
for (int i = 0; i < _terra_surfaces.size(); i++) {
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DSurfaceMerger> surface = Ref<Terrain2DSurfaceMerger>(_terra_surfaces[i]);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
if (surface.is_valid()) {
|
2022-02-24 17:30:04 +01:00
|
|
|
Ref<Texture> tex = surface->get_texture();
|
|
|
|
|
|
|
|
if (!tex.is_valid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!_packer->contains_texture(tex)) {
|
|
|
|
texture_added = true;
|
|
|
|
surface->set_region(_packer->add_texture(tex));
|
|
|
|
} else {
|
|
|
|
surface->set_region(_packer->get_texture(tex));
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texture_added) {
|
|
|
|
_packer->merge();
|
|
|
|
|
|
|
|
ERR_FAIL_COND(_packer->get_texture_count() == 0);
|
|
|
|
|
|
|
|
Ref<Texture> tex = _packer->get_generated_texture(0);
|
|
|
|
|
2022-02-24 10:16:02 +01:00
|
|
|
texture_set(tex);
|
|
|
|
liquid_texture_set(tex);
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
setup_material_albedo(MATERIAL_INDEX_TERRAIN, tex);
|
2021-11-22 22:00:45 +01:00
|
|
|
setup_material_albedo(MATERIAL_INDEX_LIQUID, tex);
|
|
|
|
}
|
|
|
|
|
2022-02-22 13:29:31 +01:00
|
|
|
#ifdef PROPS_2D_PRESENT
|
2021-11-22 22:00:45 +01:00
|
|
|
//todo add this back
|
|
|
|
//texture_added = false;
|
|
|
|
for (int i = 0; i < _props.size(); i++) {
|
2022-02-22 13:29:31 +01:00
|
|
|
Ref<Prop2DData> prop = _props.get(i);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
if (prop.is_valid()) {
|
|
|
|
if (process_prop_textures(prop))
|
|
|
|
texture_added = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//if (texture_added) {
|
|
|
|
if (_prop_packer->get_texture_count() > 0) {
|
|
|
|
_prop_packer->merge();
|
|
|
|
|
|
|
|
//ERR_FAIL_COND(_prop_packer->get_texture_count() == 0);
|
|
|
|
|
|
|
|
Ref<Texture> tex = _prop_packer->get_generated_texture(0);
|
|
|
|
|
2022-02-24 10:16:02 +01:00
|
|
|
prop_texture_set(tex);
|
|
|
|
|
2021-11-22 22:00:45 +01:00
|
|
|
setup_material_albedo(MATERIAL_INDEX_PROP, tex);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
for (int i = 0; i < _terra_surfaces.size(); i++) {
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DSurfaceMerger> surface = _terra_surfaces[i];
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
if (surface.is_valid()) {
|
|
|
|
surface->refresh_rects();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set_initialized(true);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::_setup_material_albedo(const int material_index, const Ref<Texture> &texture) {
|
2022-02-23 23:20:41 +01:00
|
|
|
Ref<ShaderMaterial> shmat;
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
switch (material_index) {
|
2022-02-22 10:33:06 +01:00
|
|
|
case MATERIAL_INDEX_TERRAIN:
|
2022-02-23 23:20:41 +01:00
|
|
|
shmat = material_get();
|
2021-11-22 22:00:45 +01:00
|
|
|
break;
|
|
|
|
case MATERIAL_INDEX_LIQUID:
|
2022-02-23 23:20:41 +01:00
|
|
|
shmat = liquid_material_get();
|
2021-11-22 22:00:45 +01:00
|
|
|
break;
|
|
|
|
case MATERIAL_INDEX_PROP:
|
2022-02-23 23:20:41 +01:00
|
|
|
shmat = prop_material_get();
|
2021-11-22 22:00:45 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-02-23 23:20:41 +01:00
|
|
|
if (shmat.is_valid()) {
|
|
|
|
shmat->set_shader_param("texture_albedo", texture);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Terrain2DLibraryMerger::Terrain2DLibraryMerger() {
|
2021-11-22 22:00:45 +01:00
|
|
|
_packer.instance();
|
|
|
|
|
|
|
|
#if GODOT4
|
|
|
|
#warning implement
|
|
|
|
#else
|
|
|
|
_packer->set_texture_flags(Texture::FLAG_MIPMAPS | Texture::FLAG_FILTER);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_packer->set_max_atlas_size(1024);
|
|
|
|
_packer->set_keep_original_atlases(false);
|
|
|
|
_packer->set_margin(0);
|
|
|
|
|
|
|
|
_prop_packer.instance();
|
|
|
|
|
|
|
|
#if GODOT4
|
|
|
|
#warning implement
|
|
|
|
#else
|
|
|
|
_prop_packer->set_texture_flags(Texture::FLAG_MIPMAPS | Texture::FLAG_FILTER);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_prop_packer->set_max_atlas_size(1024);
|
|
|
|
_prop_packer->set_keep_original_atlases(false);
|
|
|
|
_prop_packer->set_margin(0);
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
Terrain2DLibraryMerger::~Terrain2DLibraryMerger() {
|
2022-02-22 10:33:06 +01:00
|
|
|
for (int i = 0; i < _terra_surfaces.size(); ++i) {
|
2022-02-22 11:42:28 +01:00
|
|
|
Ref<Terrain2DSurface> surface = _terra_surfaces[i];
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
if (surface.is_valid()) {
|
2022-02-22 11:42:28 +01:00
|
|
|
surface->set_library(Ref<Terrain2DLibraryMerger>());
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 10:33:06 +01:00
|
|
|
_terra_surfaces.clear();
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
_packer->clear();
|
|
|
|
_packer.unref();
|
|
|
|
|
|
|
|
_prop_packer->clear();
|
|
|
|
_prop_packer.unref();
|
|
|
|
}
|
|
|
|
|
2022-02-22 13:29:31 +01:00
|
|
|
#ifdef PROPS_2D_PRESENT
|
|
|
|
bool Terrain2DLibraryMerger::process_prop_textures(Ref<Prop2DData> prop) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (!prop.is_valid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool texture_added = false;
|
|
|
|
|
|
|
|
for (int i = 0; i < prop->get_prop_count(); ++i) {
|
|
|
|
#if MESH_DATA_RESOURCE_PRESENT
|
2022-02-22 13:29:31 +01:00
|
|
|
Ref<Prop2DDataMeshData> pdm = prop->get_prop(i);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
if (pdm.is_valid()) {
|
|
|
|
Ref<Texture> tex = pdm->get_texture();
|
|
|
|
|
|
|
|
if (!tex.is_valid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!_prop_packer->contains_texture(tex)) {
|
|
|
|
_prop_packer->add_texture(tex);
|
|
|
|
texture_added = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-02-22 13:29:31 +01:00
|
|
|
Ref<Prop2DDataProp2D> pdp = prop->get_prop(i);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
if (pdp.is_valid()) {
|
|
|
|
if (process_prop_textures(pdp))
|
|
|
|
texture_added = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return texture_added;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
void Terrain2DLibraryMerger::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture_flags"), &Terrain2DLibraryMerger::get_texture_flags);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_texture_flags", "flags"), &Terrain2DLibraryMerger::set_texture_flags);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_flags", PROPERTY_HINT_FLAGS, "Mipmaps,Repeat,Filter,Anisotropic Linear,Convert to Linear,Mirrored Repeat,Video Surface"), "set_texture_flags", "get_texture_flags");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_max_atlas_size"), &Terrain2DLibraryMerger::get_max_atlas_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_max_atlas_size", "size"), &Terrain2DLibraryMerger::set_max_atlas_size);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_atlas_size"), "set_max_atlas_size", "get_max_atlas_size");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_keep_original_atlases"), &Terrain2DLibraryMerger::get_keep_original_atlases);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_keep_original_atlases", "value"), &Terrain2DLibraryMerger::set_keep_original_atlases);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_original_atlases"), "set_keep_original_atlases", "get_keep_original_atlases");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_background_color"), &Terrain2DLibraryMerger::get_background_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_background_color", "color"), &Terrain2DLibraryMerger::set_background_color);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "background_color"), "set_background_color", "get_background_color");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_margin"), &Terrain2DLibraryMerger::get_margin);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_margin", "size"), &Terrain2DLibraryMerger::set_margin);
|
2021-11-22 22:00:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "margin"), "set_margin", "get_margin");
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_terra_surfaces"), &Terrain2DLibraryMerger::get_terra_surfaces);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_terra_surfaces"), &Terrain2DLibraryMerger::set_terra_surfaces);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "terra_surfaces", PROPERTY_HINT_NONE, "17/17:Terrain2DSurfaceMerger", PROPERTY_USAGE_DEFAULT, "Terrain2DSurfaceMerger"), "set_terra_surfaces", "get_terra_surfaces");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 13:29:31 +01:00
|
|
|
#ifdef PROPS_2D_PRESENT
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_props"), &Terrain2DLibraryMerger::get_props);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_props"), &Terrain2DLibraryMerger::set_props);
|
2022-02-22 13:29:31 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "props", PROPERTY_HINT_NONE, "17/17:Prop2DData", PROPERTY_USAGE_DEFAULT, "Prop2DData"), "set_props", "get_props");
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_prop_uv_rect", "texture"), &Terrain2DLibraryMerger::get_prop_uv_rect);
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_prop_packer"), &Terrain2DLibraryMerger::get_prop_packer);
|
2021-11-22 22:00:45 +01:00
|
|
|
#endif
|
|
|
|
|
2022-02-22 11:42:28 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_setup_material_albedo", "material_index", "texture"), &Terrain2DLibraryMerger::_setup_material_albedo);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|