mirror of
https://github.com/Relintai/props.git
synced 2024-11-12 10:15:25 +01:00
A stab at generating room points. This might need to be thrown out. Committing for fututre reference. Also fixed the other tools menu options.
This commit is contained in:
parent
0b42390563
commit
66f4a662c6
@ -81,6 +81,18 @@ void PropEditorPlugin::convert_scene(Node *root, const String &path) {
|
||||
}
|
||||
}
|
||||
|
||||
void PropEditorPlugin::find_room_points(Variant param) {
|
||||
SceneTree *st = SceneTree::get_singleton();
|
||||
|
||||
if (st) {
|
||||
Node *scene = st->get_edited_scene_root();
|
||||
|
||||
if (scene) {
|
||||
PropUtils::get_singleton()->generate_room_points_node(scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PropEditorPlugin::_quick_convert_button_pressed() {
|
||||
convert_active_scene_to_prop_data();
|
||||
}
|
||||
@ -98,6 +110,7 @@ PropEditorPlugin::PropEditorPlugin(EditorNode *p_node) {
|
||||
#if VERSION_MAJOR < 4
|
||||
editor->add_tool_menu_item("Convert active scene to PropData", this, "convert_active_scene_to_prop_data");
|
||||
editor->add_tool_menu_item("Convert selected scene(s) to PropData", this, "convert_selected_scene_to_prop_data");
|
||||
editor->add_tool_menu_item("(Prop) Find room points.", this, "find_room_points");
|
||||
#else
|
||||
#endif
|
||||
|
||||
@ -120,8 +133,10 @@ PropEditorPlugin::~PropEditorPlugin() {
|
||||
}
|
||||
|
||||
void PropEditorPlugin::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("convert_active_scene_to_prop_data"), &PropEditorPlugin::convert_active_scene_to_prop_data);
|
||||
ClassDB::bind_method(D_METHOD("convert_selected_scene_to_prop_data"), &PropEditorPlugin::convert_selected_scene_to_prop_data);
|
||||
ClassDB::bind_method(D_METHOD("convert_active_scene_to_prop_data"), &PropEditorPlugin::_convert_active_scene_to_prop_data);
|
||||
ClassDB::bind_method(D_METHOD("convert_selected_scene_to_prop_data"), &PropEditorPlugin::_convert_active_scene_to_prop_data);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("find_room_points"), &PropEditorPlugin::find_room_points);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_quick_convert_button_pressed"), &PropEditorPlugin::_quick_convert_button_pressed);
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ public:
|
||||
void convert_selected_scene_to_prop_data();
|
||||
void convert_scene(Node *root, const String &path);
|
||||
|
||||
void find_room_points(Variant param);
|
||||
|
||||
void _convert_active_scene_to_prop_data(Variant param);
|
||||
void _convert_selected_scene_to_prop_data(Variant param);
|
||||
void _quick_convert_button_pressed();
|
||||
|
@ -28,6 +28,8 @@ SOFTWARE.
|
||||
#include "scene/3d/room.h"
|
||||
|
||||
#include "core/version.h"
|
||||
#include "scene/3d/room.h"
|
||||
#include "scene/3d/room_manager.h"
|
||||
|
||||
#if VERSION_MAJOR > 3
|
||||
#include "core/config/engine.h"
|
||||
@ -105,10 +107,6 @@ void PropUtils::_convert_tree(Ref<PropData> prop_data, Node *node, const Transfo
|
||||
|
||||
PoolVector3Array points = r->get_points();
|
||||
|
||||
if (points.size() == 0) {
|
||||
//TODO generate points
|
||||
}
|
||||
|
||||
prop_data->set_room_bounds(points);
|
||||
}
|
||||
}
|
||||
@ -128,6 +126,92 @@ void PropUtils::_convert_tree(Ref<PropData> prop_data, Node *node, const Transfo
|
||||
}
|
||||
}
|
||||
|
||||
bool PropUtils::generate_room_points_node(Node *node) {
|
||||
ERR_FAIL_COND_V(!ObjectDB::instance_validate(node), false);
|
||||
|
||||
Room *r = Object::cast_to<Room>(node);
|
||||
|
||||
if (r) {
|
||||
generate_room_points(r);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < node->get_child_count(); ++i) {
|
||||
if (generate_room_points_node(node->get_child(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void PropUtils::generate_room_points(Room *room) {
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(room));
|
||||
|
||||
Node *rn = room->duplicate();
|
||||
|
||||
rn = substitute_prop_classes(rn);
|
||||
|
||||
Room *r = Object::cast_to<Room>(rn);
|
||||
r->set_name("room");
|
||||
|
||||
RoomManager *rm = memnew(RoomManager);
|
||||
rm->set_merge_meshes(false);
|
||||
rm->add_child(r);
|
||||
rm->set_roomlist_path(NodePath("./room"));
|
||||
|
||||
//don't set owner, so it won't show up in the editor
|
||||
room->add_child(rm);
|
||||
|
||||
r->generate_points();
|
||||
|
||||
print_error(String::num(r->get_points().size()));
|
||||
|
||||
room->remove_child(rm);
|
||||
|
||||
room->set_points(r->get_points());
|
||||
|
||||
memdelete(rm);
|
||||
}
|
||||
|
||||
Node *PropUtils::substitute_prop_classes(Node *node) {
|
||||
ERR_FAIL_COND_V(!ObjectDB::instance_validate(node), nullptr);
|
||||
|
||||
//start with children
|
||||
for (int i = 0; i < node->get_child_count(); ++i) {
|
||||
substitute_prop_classes(node->get_child(i));
|
||||
}
|
||||
|
||||
Node *n = get_substitute_prop_class(node);
|
||||
|
||||
if (n) {
|
||||
for (int i = 0; i < node->get_child_count();) {
|
||||
Node *c = node->get_child(i);
|
||||
|
||||
node->remove_child(c);
|
||||
|
||||
n->add_child(c);
|
||||
}
|
||||
|
||||
memdelete(node);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
Node *PropUtils::get_substitute_prop_class(Node *node) {
|
||||
if (node->has_method("get_substitute_for_room")) {
|
||||
Node *n = node->call("get_substitute_for_room");
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int PropUtils::add_processor(const Ref<PropDataEntry> &processor) {
|
||||
ERR_FAIL_COND_V(!processor.is_valid(), 0);
|
||||
|
||||
|
@ -41,6 +41,7 @@ SOFTWARE.
|
||||
|
||||
class PropData;
|
||||
class PropDataEntry;
|
||||
class Room;
|
||||
|
||||
class PropUtils : public Object {
|
||||
GDCLASS(PropUtils, Object);
|
||||
@ -51,6 +52,11 @@ public:
|
||||
Ref<PropData> convert_tree(Node *root);
|
||||
void _convert_tree(Ref<PropData> prop_data, Node *node, const Transform &transform);
|
||||
|
||||
bool generate_room_points_node(Node *node);
|
||||
void generate_room_points(Room *room);
|
||||
Node *substitute_prop_classes(Node *node);
|
||||
Node *get_substitute_prop_class(Node *node);
|
||||
|
||||
static int add_processor(const Ref<PropDataEntry> &processor);
|
||||
static Ref<PropDataEntry> get_processor(const int index);
|
||||
static void swap_processors(const int index1, const int index2);
|
||||
|
Loading…
Reference in New Issue
Block a user