2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* mesh_library.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "mesh_library.h"
|
|
|
|
|
2022-01-18 07:05:31 +01:00
|
|
|
#include "box_shape_3d.h"
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
|
2022-09-29 11:53:28 +02:00
|
|
|
String prop_name = p_name;
|
|
|
|
if (prop_name.begins_with("item/")) {
|
|
|
|
int idx = prop_name.get_slicec('/', 1).to_int();
|
|
|
|
String what = prop_name.get_slicec('/', 2);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!item_map.has(idx)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
create_item(idx);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (what == "name") {
|
2017-03-05 16:44:50 +01:00
|
|
|
set_item_name(idx, p_value);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "mesh") {
|
2017-03-05 16:44:50 +01:00
|
|
|
set_item_mesh(idx, p_value);
|
2021-09-01 01:17:33 +02:00
|
|
|
} else if (what == "mesh_transform") {
|
|
|
|
set_item_mesh_transform(idx, p_value);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "shape") {
|
2017-08-27 21:00:59 +02:00
|
|
|
Vector<ShapeData> shapes;
|
|
|
|
ShapeData sd;
|
|
|
|
sd.shape = p_value;
|
|
|
|
shapes.push_back(sd);
|
|
|
|
set_item_shapes(idx, shapes);
|
|
|
|
} else if (what == "shapes") {
|
|
|
|
_set_item_shapes(idx, p_value);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "preview") {
|
2017-03-05 16:44:50 +01:00
|
|
|
set_item_preview(idx, p_value);
|
2022-12-11 18:02:35 +01:00
|
|
|
} else if (what == "navigation_mesh") {
|
|
|
|
set_item_navigation_mesh(idx, p_value);
|
|
|
|
} else if (what == "navigation_mesh_transform") {
|
|
|
|
set_item_navigation_mesh_transform(idx, p_value);
|
2022-12-18 05:07:10 +01:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
} else if (what == "navmesh") { // Renamed in 4.0 beta 9.
|
|
|
|
set_item_navigation_mesh(idx, p_value);
|
|
|
|
} else if (what == "navmesh_transform") { // Renamed in 4.0 beta 9.
|
|
|
|
set_item_navigation_mesh_transform(idx, p_value);
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2022-11-29 20:01:31 +01:00
|
|
|
} else if (what == "navigation_layers") {
|
|
|
|
set_item_navigation_layers(idx, p_value);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const {
|
2022-09-29 11:53:28 +02:00
|
|
|
String prop_name = p_name;
|
|
|
|
int idx = prop_name.get_slicec('/', 1).to_int();
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!item_map.has(idx), false);
|
2022-09-29 11:53:28 +02:00
|
|
|
String what = prop_name.get_slicec('/', 2);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (what == "name") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = get_item_name(idx);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "mesh") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = get_item_mesh(idx);
|
2021-09-01 01:17:33 +02:00
|
|
|
} else if (what == "mesh_transform") {
|
|
|
|
r_ret = get_item_mesh_transform(idx);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "shapes") {
|
2017-08-27 21:00:59 +02:00
|
|
|
r_ret = _get_item_shapes(idx);
|
2022-12-11 18:02:35 +01:00
|
|
|
} else if (what == "navigation_mesh") {
|
|
|
|
r_ret = get_item_navigation_mesh(idx);
|
|
|
|
} else if (what == "navigation_mesh_transform") {
|
|
|
|
r_ret = get_item_navigation_mesh_transform(idx);
|
2022-12-18 05:07:10 +01:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
} else if (what == "navmesh") { // Renamed in 4.0 beta 9.
|
|
|
|
r_ret = get_item_navigation_mesh(idx);
|
|
|
|
} else if (what == "navmesh_transform") { // Renamed in 4.0 beta 9.
|
|
|
|
r_ret = get_item_navigation_mesh_transform(idx);
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2022-11-29 20:01:31 +01:00
|
|
|
} else if (what == "navigation_layers") {
|
|
|
|
r_ret = get_item_navigation_layers(idx);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (what == "preview") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = get_item_preview(idx);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void MeshLibrary::_get_property_list(List<PropertyInfo> *p_list) const {
|
2021-08-09 22:13:42 +02:00
|
|
|
for (const KeyValue<int, Item> &E : item_map) {
|
2022-09-29 11:53:28 +02:00
|
|
|
String prop_name = vformat("%s/%d/", PNAME("item"), E.key);
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, prop_name + PNAME("name")));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, prop_name + PNAME("mesh"), PROPERTY_HINT_RESOURCE_TYPE, "Mesh"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::TRANSFORM3D, prop_name + PNAME("mesh_transform"), PROPERTY_HINT_NONE, "suffix:m"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, prop_name + PNAME("shapes")));
|
2022-12-11 18:02:35 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, prop_name + PNAME("navigation_mesh"), PROPERTY_HINT_RESOURCE_TYPE, "NavigationMesh"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::TRANSFORM3D, prop_name + PNAME("navigation_mesh_transform"), PROPERTY_HINT_NONE, "suffix:m"));
|
2022-11-29 20:01:31 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, prop_name + PNAME("navigation_layers"), PROPERTY_HINT_LAYERS_3D_NAVIGATION));
|
2022-09-29 11:53:28 +02:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, prop_name + PNAME("preview"), PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_DEFAULT));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MeshLibrary::create_item(int p_item) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(p_item < 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(item_map.has(p_item));
|
2017-03-05 16:44:50 +01:00
|
|
|
item_map[p_item] = Item();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void MeshLibrary::set_item_name(int p_item, const String &p_name) {
|
2019-09-25 10:28:50 +02:00
|
|
|
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2017-03-05 16:44:50 +01:00
|
|
|
item_map[p_item].name = p_name;
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
|
|
|
}
|
2019-02-26 14:38:23 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void MeshLibrary::set_item_mesh(int p_item, const Ref<Mesh> &p_mesh) {
|
2019-09-25 10:28:50 +02:00
|
|
|
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2017-03-05 16:44:50 +01:00
|
|
|
item_map[p_item].mesh = p_mesh;
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2021-09-01 01:17:33 +02:00
|
|
|
void MeshLibrary::set_item_mesh_transform(int p_item, const Transform3D &p_transform) {
|
|
|
|
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
|
|
|
item_map[p_item].mesh_transform = p_transform;
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-08-27 21:00:59 +02:00
|
|
|
void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes) {
|
2019-09-25 10:28:50 +02:00
|
|
|
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2017-08-27 21:00:59 +02:00
|
|
|
item_map[p_item].shapes = p_shapes;
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-12-11 18:02:35 +01:00
|
|
|
void MeshLibrary::set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh) {
|
2019-09-25 10:28:50 +02:00
|
|
|
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2022-12-11 18:02:35 +01:00
|
|
|
item_map[p_item].navigation_mesh = p_navigation_mesh;
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-04-20 20:19:05 +02:00
|
|
|
emit_changed();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-04-20 20:19:05 +02:00
|
|
|
}
|
|
|
|
|
2022-12-11 18:02:35 +01:00
|
|
|
void MeshLibrary::set_item_navigation_mesh_transform(int p_item, const Transform3D &p_transform) {
|
2019-09-25 10:28:50 +02:00
|
|
|
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2022-12-11 18:02:35 +01:00
|
|
|
item_map[p_item].navigation_mesh_transform = p_transform;
|
2019-02-26 14:38:23 +01:00
|
|
|
emit_changed();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-02-26 14:38:23 +01:00
|
|
|
}
|
|
|
|
|
2022-11-29 20:01:31 +01:00
|
|
|
void MeshLibrary::set_item_navigation_layers(int p_item, uint32_t p_navigation_layers) {
|
|
|
|
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
|
|
|
item_map[p_item].navigation_layers = p_navigation_layers;
|
|
|
|
notify_property_list_changed();
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
void MeshLibrary::set_item_preview(int p_item, const Ref<Texture2D> &p_preview) {
|
2019-09-25 10:28:50 +02:00
|
|
|
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2017-03-05 16:44:50 +01:00
|
|
|
item_map[p_item].preview = p_preview;
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2019-02-26 14:38:23 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String MeshLibrary::get_item_name(int p_item) const {
|
2019-09-25 10:28:50 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), "", "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2014-02-10 02:10:30 +01:00
|
|
|
return item_map[p_item].name;
|
|
|
|
}
|
2019-02-26 14:38:23 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Ref<Mesh> MeshLibrary::get_item_mesh(int p_item) const {
|
2019-09-25 10:28:50 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<Mesh>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2014-02-10 02:10:30 +01:00
|
|
|
return item_map[p_item].mesh;
|
|
|
|
}
|
|
|
|
|
2021-09-01 01:17:33 +02:00
|
|
|
Transform3D MeshLibrary::get_item_mesh_transform(int p_item) const {
|
|
|
|
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Transform3D(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
|
|
|
return item_map[p_item].mesh_transform;
|
|
|
|
}
|
|
|
|
|
2017-08-27 21:00:59 +02:00
|
|
|
Vector<MeshLibrary::ShapeData> MeshLibrary::get_item_shapes(int p_item) const {
|
2019-09-25 10:28:50 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Vector<ShapeData>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2017-08-27 21:00:59 +02:00
|
|
|
return item_map[p_item].shapes;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-12-11 18:02:35 +01:00
|
|
|
Ref<NavigationMesh> MeshLibrary::get_item_navigation_mesh(int p_item) const {
|
2019-09-25 10:28:50 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<NavigationMesh>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2022-12-11 18:02:35 +01:00
|
|
|
return item_map[p_item].navigation_mesh;
|
2016-04-20 20:19:05 +02:00
|
|
|
}
|
|
|
|
|
2022-12-11 18:02:35 +01:00
|
|
|
Transform3D MeshLibrary::get_item_navigation_mesh_transform(int p_item) const {
|
2020-10-17 07:08:21 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Transform3D(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2022-12-11 18:02:35 +01:00
|
|
|
return item_map[p_item].navigation_mesh_transform;
|
2019-02-26 14:38:23 +01:00
|
|
|
}
|
|
|
|
|
2022-11-29 20:01:31 +01:00
|
|
|
uint32_t MeshLibrary::get_item_navigation_layers(int p_item) const {
|
|
|
|
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), 0, "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
|
|
|
return item_map[p_item].navigation_layers;
|
|
|
|
}
|
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
Ref<Texture2D> MeshLibrary::get_item_preview(int p_item) const {
|
|
|
|
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<Texture2D>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2014-02-10 02:10:30 +01:00
|
|
|
return item_map[p_item].preview;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MeshLibrary::has_item(int p_item) const {
|
2017-03-05 16:44:50 +01:00
|
|
|
return item_map.has(p_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void MeshLibrary::remove_item(int p_item) {
|
2019-09-25 10:28:50 +02:00
|
|
|
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
2014-02-10 02:10:30 +01:00
|
|
|
item_map.erase(p_item);
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MeshLibrary::clear() {
|
|
|
|
item_map.clear();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<int> MeshLibrary::get_item_list() const {
|
|
|
|
Vector<int> ret;
|
|
|
|
ret.resize(item_map.size());
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = 0;
|
2021-08-09 22:13:42 +02:00
|
|
|
for (const KeyValue<int, Item> &E : item_map) {
|
|
|
|
ret.write[idx++] = E.key;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-03 19:53:17 +02:00
|
|
|
int MeshLibrary::find_item_by_name(const String &p_name) const {
|
2021-08-09 22:13:42 +02:00
|
|
|
for (const KeyValue<int, Item> &E : item_map) {
|
|
|
|
if (E.value.name == p_name) {
|
|
|
|
return E.key;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MeshLibrary::get_last_unused_item_id() const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!item_map.size()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return 0;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
return item_map.back()->key() + 1;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-08-27 21:00:59 +02:00
|
|
|
void MeshLibrary::_set_item_shapes(int p_item, const Array &p_shapes) {
|
2022-01-18 07:05:31 +01:00
|
|
|
Array arr_shapes = p_shapes;
|
|
|
|
int size = p_shapes.size();
|
|
|
|
if (size & 1) {
|
|
|
|
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
|
|
|
|
int prev_size = item_map[p_item].shapes.size() * 2;
|
|
|
|
|
|
|
|
if (prev_size < size) {
|
|
|
|
// Check if last element is a shape.
|
|
|
|
Ref<Shape3D> shape = arr_shapes[size - 1];
|
|
|
|
if (shape.is_null()) {
|
|
|
|
Ref<BoxShape3D> box_shape;
|
|
|
|
box_shape.instantiate();
|
|
|
|
arr_shapes[size - 1] = box_shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the added element is a Transform3D.
|
|
|
|
arr_shapes.push_back(Transform3D());
|
|
|
|
size++;
|
|
|
|
} else {
|
|
|
|
size--;
|
|
|
|
arr_shapes.resize(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-27 21:00:59 +02:00
|
|
|
Vector<ShapeData> shapes;
|
2022-01-18 07:05:31 +01:00
|
|
|
for (int i = 0; i < size; i += 2) {
|
2017-08-27 21:00:59 +02:00
|
|
|
ShapeData sd;
|
2022-01-18 07:05:31 +01:00
|
|
|
sd.shape = arr_shapes[i + 0];
|
|
|
|
sd.local_transform = arr_shapes[i + 1];
|
2017-08-27 21:00:59 +02:00
|
|
|
|
|
|
|
if (sd.shape.is_valid()) {
|
|
|
|
shapes.push_back(sd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set_item_shapes(p_item, shapes);
|
|
|
|
}
|
|
|
|
|
|
|
|
Array MeshLibrary::_get_item_shapes(int p_item) const {
|
|
|
|
Vector<ShapeData> shapes = get_item_shapes(p_item);
|
|
|
|
Array ret;
|
|
|
|
for (int i = 0; i < shapes.size(); i++) {
|
|
|
|
ret.push_back(shapes[i].shape);
|
|
|
|
ret.push_back(shapes[i].local_transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-02-11 18:18:45 +01:00
|
|
|
void MeshLibrary::reset_state() {
|
|
|
|
clear();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
void MeshLibrary::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("create_item", "id"), &MeshLibrary::create_item);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_item_name", "id", "name"), &MeshLibrary::set_item_name);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_item_mesh", "id", "mesh"), &MeshLibrary::set_item_mesh);
|
2021-09-01 01:17:33 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_item_mesh_transform", "id", "mesh_transform"), &MeshLibrary::set_item_mesh_transform);
|
2022-12-11 18:02:35 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_item_navigation_mesh", "id", "navigation_mesh"), &MeshLibrary::set_item_navigation_mesh);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_item_navigation_mesh_transform", "id", "navigation_mesh"), &MeshLibrary::set_item_navigation_mesh_transform);
|
2022-11-29 20:01:31 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_item_navigation_layers", "id", "navigation_layers"), &MeshLibrary::set_item_navigation_layers);
|
2017-08-27 21:00:59 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_item_shapes", "id", "shapes"), &MeshLibrary::_set_item_shapes);
|
2017-08-28 05:03:34 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_item_preview", "id", "texture"), &MeshLibrary::set_item_preview);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_item_name", "id"), &MeshLibrary::get_item_name);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_item_mesh", "id"), &MeshLibrary::get_item_mesh);
|
2021-09-01 01:17:33 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_item_mesh_transform", "id"), &MeshLibrary::get_item_mesh_transform);
|
2022-12-11 18:02:35 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_item_navigation_mesh", "id"), &MeshLibrary::get_item_navigation_mesh);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_item_navigation_mesh_transform", "id"), &MeshLibrary::get_item_navigation_mesh_transform);
|
2022-11-29 20:01:31 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_item_navigation_layers", "id"), &MeshLibrary::get_item_navigation_layers);
|
2017-08-27 21:00:59 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_item_shapes", "id"), &MeshLibrary::_get_item_shapes);
|
2017-08-28 05:03:34 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_item_preview", "id"), &MeshLibrary::get_item_preview);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("remove_item", "id"), &MeshLibrary::remove_item);
|
2017-09-03 19:53:17 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("find_item_by_name", "name"), &MeshLibrary::find_item_by_name);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("clear"), &MeshLibrary::clear);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_item_list"), &MeshLibrary::get_item_list);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_last_unused_item_id"), &MeshLibrary::get_last_unused_item_id);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MeshLibrary::MeshLibrary() {
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
MeshLibrary::~MeshLibrary() {
|
|
|
|
}
|