2020-01-31 19:34:47 +01:00
|
|
|
/*
|
2021-04-19 10:13:51 +02:00
|
|
|
Copyright (c) 2019-2021 Péter Magyar
|
2020-01-31 19:34:47 +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.
|
|
|
|
*/
|
|
|
|
|
2020-05-19 21:09:00 +02:00
|
|
|
#include "model_visual_entry.h"
|
2019-08-24 15:53:56 +02:00
|
|
|
|
2020-05-20 22:13:29 +02:00
|
|
|
#include "../../singletons/ess.h"
|
|
|
|
|
2020-06-16 15:53:33 +02:00
|
|
|
const String ModelVisualEntry::BINDING_STRING_MODEL_VISUAL_ENTRY_TYPES = "Bone,Attachment";
|
|
|
|
|
|
|
|
ModelVisualEntry::ModenVisualEntryType ModelVisualEntry::get_type() const {
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
void ModelVisualEntry::set_type(const ModelVisualEntry::ModenVisualEntryType type) {
|
|
|
|
_type = type;
|
|
|
|
}
|
|
|
|
|
2020-05-21 21:20:56 +02:00
|
|
|
int ModelVisualEntry::get_override_layer() const {
|
2019-10-26 15:13:04 +02:00
|
|
|
return _override_layer;
|
2019-10-24 22:06:47 +02:00
|
|
|
}
|
2020-05-21 21:20:56 +02:00
|
|
|
void ModelVisualEntry::set_override_layer(const int layer) {
|
2019-10-26 15:13:04 +02:00
|
|
|
_override_layer = layer;
|
2019-10-24 22:06:47 +02:00
|
|
|
}
|
|
|
|
|
2020-05-21 15:40:59 +02:00
|
|
|
int ModelVisualEntry::get_entity_type() const {
|
2020-05-20 22:13:29 +02:00
|
|
|
return _entity_type;
|
|
|
|
}
|
2020-05-21 15:40:59 +02:00
|
|
|
void ModelVisualEntry::set_entity_type(const int value) {
|
2020-05-20 22:13:29 +02:00
|
|
|
_entity_type = value;
|
|
|
|
}
|
|
|
|
|
2020-05-21 15:40:59 +02:00
|
|
|
int ModelVisualEntry::get_bone() const {
|
2020-05-20 22:13:29 +02:00
|
|
|
return _bone;
|
|
|
|
}
|
2020-05-21 15:40:59 +02:00
|
|
|
void ModelVisualEntry::set_bone(const int value) {
|
2020-05-20 22:13:29 +02:00
|
|
|
_bone = value;
|
|
|
|
}
|
|
|
|
|
2020-05-21 15:40:59 +02:00
|
|
|
int ModelVisualEntry::get_group() const {
|
2020-05-20 22:13:29 +02:00
|
|
|
return _group;
|
|
|
|
}
|
2020-05-21 15:40:59 +02:00
|
|
|
void ModelVisualEntry::set_group(const int value) {
|
2020-05-20 22:13:29 +02:00
|
|
|
_group = value;
|
|
|
|
}
|
|
|
|
|
2019-12-20 16:13:33 +01:00
|
|
|
#ifdef MESH_DATA_RESOURCE_PRESENT
|
2020-05-21 15:40:59 +02:00
|
|
|
Ref<MeshDataResource> ModelVisualEntry::get_mesh(const int index) {
|
|
|
|
ERR_FAIL_INDEX_V(index, _entries.size(), Ref<MeshDataResource>());
|
|
|
|
|
|
|
|
return _entries[index].mesh;
|
2019-10-24 22:06:47 +02:00
|
|
|
}
|
2020-05-21 15:40:59 +02:00
|
|
|
void ModelVisualEntry::set_mesh(const int index, const Ref<MeshDataResource> &mesh) {
|
|
|
|
ERR_FAIL_INDEX(index, _entries.size());
|
|
|
|
|
|
|
|
_entries.write[index].mesh = mesh;
|
2019-10-24 22:06:47 +02:00
|
|
|
}
|
2019-12-20 16:13:33 +01:00
|
|
|
#endif
|
2019-10-24 22:06:47 +02:00
|
|
|
|
2020-05-21 15:40:59 +02:00
|
|
|
Ref<Texture> ModelVisualEntry::get_texture(const int index) {
|
|
|
|
ERR_FAIL_INDEX_V(index, _entries.size(), Ref<Texture>());
|
|
|
|
|
|
|
|
return _entries[index].texture;
|
|
|
|
}
|
|
|
|
void ModelVisualEntry::set_texture(const int index, const Ref<Texture> &texture) {
|
|
|
|
ERR_FAIL_INDEX(index, _entries.size());
|
|
|
|
|
|
|
|
_entries.write[index].texture = texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color ModelVisualEntry::get_color(const int index) const {
|
|
|
|
ERR_FAIL_INDEX_V(index, _entries.size(), Color());
|
|
|
|
|
|
|
|
return _entries[index].color;
|
2019-10-24 22:06:47 +02:00
|
|
|
}
|
2020-05-21 15:40:59 +02:00
|
|
|
void ModelVisualEntry::set_color(const int index, const Color &color) {
|
|
|
|
ERR_FAIL_INDEX(index, _entries.size());
|
|
|
|
|
|
|
|
_entries.write[index].color = color;
|
2019-10-24 22:06:47 +02:00
|
|
|
}
|
|
|
|
|
2020-05-21 15:40:59 +02:00
|
|
|
Ref<PackedScene> ModelVisualEntry::get_attachment(const int index) {
|
|
|
|
ERR_FAIL_INDEX_V(index, _entries.size(), Ref<PackedScene>());
|
|
|
|
|
|
|
|
return _entries[index].attachment;
|
2019-10-24 22:06:47 +02:00
|
|
|
}
|
2020-05-21 15:40:59 +02:00
|
|
|
void ModelVisualEntry::set_attachment(const int index, const Ref<PackedScene> &attachment) {
|
|
|
|
ERR_FAIL_INDEX(index, _entries.size());
|
|
|
|
_entries.write[index].attachment = attachment;
|
2019-10-24 22:06:47 +02:00
|
|
|
}
|
|
|
|
|
2020-05-21 15:40:59 +02:00
|
|
|
Transform ModelVisualEntry::get_transform(const int index) const {
|
|
|
|
ERR_FAIL_INDEX_V(index, _entries.size(), Transform());
|
|
|
|
|
|
|
|
return _entries[index].transform;
|
2019-10-24 22:06:47 +02:00
|
|
|
}
|
2020-05-21 15:40:59 +02:00
|
|
|
void ModelVisualEntry::set_transform(const int index, const Transform &transform) {
|
|
|
|
ERR_FAIL_INDEX(index, _entries.size());
|
|
|
|
|
|
|
|
_entries.write[index].transform = transform;
|
2019-10-24 22:06:47 +02:00
|
|
|
}
|
2019-08-24 15:53:56 +02:00
|
|
|
|
2020-05-21 15:40:59 +02:00
|
|
|
int ModelVisualEntry::get_size() const {
|
|
|
|
return _entries.size();
|
2019-11-03 22:39:19 +01:00
|
|
|
}
|
2020-05-21 15:40:59 +02:00
|
|
|
void ModelVisualEntry::set_size(const int value) {
|
|
|
|
_entries.resize(value);
|
2019-11-03 22:39:19 +01:00
|
|
|
}
|
2019-10-24 22:06:47 +02:00
|
|
|
|
2020-05-19 21:09:00 +02:00
|
|
|
ModelVisualEntry::ModelVisualEntry() {
|
2020-06-16 15:53:33 +02:00
|
|
|
_type = MODEL_VISUAL_ENTRY_TYPE_BONE;
|
2020-05-21 21:20:56 +02:00
|
|
|
_override_layer = 0;
|
2019-10-24 22:06:47 +02:00
|
|
|
|
2020-05-20 22:13:29 +02:00
|
|
|
_entity_type = 0;
|
|
|
|
_bone = 0;
|
|
|
|
_group = 0;
|
2020-05-21 15:40:59 +02:00
|
|
|
|
|
|
|
_entries.resize(1);
|
2019-08-24 15:53:56 +02:00
|
|
|
}
|
|
|
|
|
2020-05-19 21:09:00 +02:00
|
|
|
ModelVisualEntry::~ModelVisualEntry() {
|
2020-05-21 15:40:59 +02:00
|
|
|
_entries.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModelVisualEntry::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
String name = p_name;
|
|
|
|
|
|
|
|
if (name.begins_with("entry_")) {
|
|
|
|
int index = name.get_slicec('_', 1).to_int();
|
|
|
|
|
|
|
|
if (index >= _entries.size()) {
|
|
|
|
_entries.resize(index + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringName p = name.get_slicec('/', 1);
|
|
|
|
|
|
|
|
if (p == "texture") {
|
|
|
|
_entries.write[index].texture = p_value;
|
|
|
|
|
|
|
|
return true;
|
2020-01-09 04:27:19 +01:00
|
|
|
#ifdef MESH_DATA_RESOURCE_PRESENT
|
2020-05-21 15:40:59 +02:00
|
|
|
} else if (p == "mesh") {
|
|
|
|
_entries.write[index].mesh = p_value;
|
|
|
|
|
|
|
|
return true;
|
2020-01-09 04:27:19 +01:00
|
|
|
#endif
|
2020-05-21 15:40:59 +02:00
|
|
|
} else if (p == "color") {
|
|
|
|
_entries.write[index].color = p_value;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else if (p == "attachment") {
|
|
|
|
_entries.write[index].attachment = p_value;
|
2020-01-09 04:27:19 +01:00
|
|
|
|
2020-05-21 15:40:59 +02:00
|
|
|
return true;
|
|
|
|
} else if (p == "transform") {
|
|
|
|
_entries.write[index].transform = p_value;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-03 22:39:19 +01:00
|
|
|
}
|
|
|
|
|
2020-05-21 15:40:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool ModelVisualEntry::_get(const StringName &p_name, Variant &r_ret) const {
|
|
|
|
String name = p_name;
|
|
|
|
|
|
|
|
if (name.begins_with("entry_")) {
|
|
|
|
int index = name.get_slicec('_', 1).to_int();
|
|
|
|
|
|
|
|
if (index >= _entries.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringName p = name.get_slicec('/', 1);
|
|
|
|
|
|
|
|
if (p == "texture") {
|
|
|
|
r_ret = _entries[index].texture;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
#ifdef MESH_DATA_RESOURCE_PRESENT
|
|
|
|
} else if (p == "mesh") {
|
|
|
|
r_ret = _entries[index].mesh;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
} else if (p == "color") {
|
|
|
|
r_ret = _entries[index].color;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else if (p == "attachment") {
|
|
|
|
r_ret = _entries[index].attachment;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else if (p == "transform") {
|
|
|
|
r_ret = _entries[index].transform;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void ModelVisualEntry::_get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
|
for (int i = 0; i < _entries.size(); ++i) {
|
2020-06-16 15:53:33 +02:00
|
|
|
if (_type == ModelVisualEntry::MODEL_VISUAL_ENTRY_TYPE_BONE) {
|
2020-05-21 15:40:59 +02:00
|
|
|
#ifdef MESH_DATA_RESOURCE_PRESENT
|
2020-06-16 15:53:33 +02:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
|
2020-05-21 15:40:59 +02:00
|
|
|
#endif
|
2020-06-16 15:53:33 +02:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::COLOR, "entry_" + itos(i) + "/color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
|
|
|
|
} else {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/attachment", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
|
|
|
|
}
|
|
|
|
p_list->push_back(PropertyInfo(Variant::TRANSFORM, "entry_" + itos(i) + "/transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
|
2020-05-21 15:40:59 +02:00
|
|
|
}
|
2019-08-24 15:53:56 +02:00
|
|
|
}
|
|
|
|
|
2020-05-20 22:13:29 +02:00
|
|
|
void ModelVisualEntry::_validate_property(PropertyInfo &property) const {
|
|
|
|
String name = property.name;
|
|
|
|
|
2020-06-16 15:53:33 +02:00
|
|
|
if (_type == ModelVisualEntry::MODEL_VISUAL_ENTRY_TYPE_BONE) {
|
|
|
|
if (name == "entity_type") {
|
|
|
|
property.usage = PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED;
|
|
|
|
property.hint_string = ESS::get_singleton()->entity_types_get();
|
|
|
|
} else if (name == "bone") {
|
|
|
|
if (ESS::get_singleton()->skeletons_bones_count() > _entity_type) {
|
|
|
|
property.hint_string = ESS::get_singleton()->skeletons_bones_index_get(_entity_type);
|
|
|
|
} else {
|
|
|
|
property.hint_string = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (name == "entity_type") {
|
|
|
|
property.usage = PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED;
|
|
|
|
} else if (name == "bone") {
|
|
|
|
property.hint_string = EntityEnums::BINDING_STRING_COMMON_CHARCATER_SKELETON_POINTS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-20 22:13:29 +02:00
|
|
|
if (name == "group") {
|
2020-05-23 16:29:47 +02:00
|
|
|
property.hint_string = ESS::get_singleton()->model_visual_groups_get();
|
2020-05-21 21:20:56 +02:00
|
|
|
} else if (name == "override_layer") {
|
2020-05-23 16:29:47 +02:00
|
|
|
property.hint_string = ESS::get_singleton()->texture_layers_get();
|
2020-05-20 22:13:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 21:09:00 +02:00
|
|
|
void ModelVisualEntry::_bind_methods() {
|
2020-06-16 15:53:33 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_type"), &ModelVisualEntry::get_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_type", "value"), &ModelVisualEntry::set_type);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, ModelVisualEntry::BINDING_STRING_MODEL_VISUAL_ENTRY_TYPES, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_type", "get_type");
|
|
|
|
|
2020-05-19 21:09:00 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_override_layer"), &ModelVisualEntry::get_override_layer);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_override_layer", "value"), &ModelVisualEntry::set_override_layer);
|
2020-05-21 21:20:56 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "override_layer", PROPERTY_HINT_ENUM, ""), "set_override_layer", "get_override_layer");
|
2019-10-24 22:06:47 +02:00
|
|
|
|
2020-05-20 22:13:29 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_entity_type"), &ModelVisualEntry::get_entity_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_entity_type", "value"), &ModelVisualEntry::set_entity_type);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "entity_type", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_entity_type", "get_entity_type");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bone"), &ModelVisualEntry::get_bone);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_bone", "value"), &ModelVisualEntry::set_bone);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "bone", PROPERTY_HINT_ENUM), "set_bone", "get_bone");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_group"), &ModelVisualEntry::get_group);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_group", "value"), &ModelVisualEntry::set_group);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "group", PROPERTY_HINT_ENUM), "set_group", "get_group");
|
|
|
|
|
2020-01-09 04:27:19 +01:00
|
|
|
#ifdef MESH_DATA_RESOURCE_PRESENT
|
2020-05-19 21:09:00 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_mesh", "index"), &ModelVisualEntry::get_mesh);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_mesh", "index", "value"), &ModelVisualEntry::set_mesh);
|
2020-01-09 04:27:19 +01:00
|
|
|
#endif
|
2019-10-24 22:06:47 +02:00
|
|
|
|
2020-05-19 21:09:00 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_texture", "index"), &ModelVisualEntry::get_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_texture", "index", "value"), &ModelVisualEntry::set_texture);
|
2019-10-24 22:06:47 +02:00
|
|
|
|
2020-05-19 21:09:00 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_color"), &ModelVisualEntry::get_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_color", "value"), &ModelVisualEntry::set_color);
|
2019-10-24 22:06:47 +02:00
|
|
|
|
2020-05-21 15:40:59 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_attachment"), &ModelVisualEntry::get_attachment);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_attachment", "value"), &ModelVisualEntry::set_attachment);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_transform", "index"), &ModelVisualEntry::get_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_transform", "index", "value"), &ModelVisualEntry::set_transform);
|
2019-11-03 22:39:19 +01:00
|
|
|
|
2020-05-21 15:40:59 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_size"), &ModelVisualEntry::get_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_size", "value"), &ModelVisualEntry::set_size);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_size", "get_size");
|
2020-06-16 15:53:33 +02:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(MODEL_VISUAL_ENTRY_TYPE_BONE);
|
|
|
|
BIND_ENUM_CONSTANT(MODEL_VISUAL_ENTRY_TYPE_ATTACHMENT);
|
2019-08-24 15:53:56 +02:00
|
|
|
}
|