Added PropDataPortal. It can be used to save Portal data into props.

This commit is contained in:
Relintai 2021-08-14 19:01:47 +02:00
parent 6518bba651
commit 2c7ce2fc07
5 changed files with 204 additions and 0 deletions

1
SCsub
View File

@ -34,6 +34,7 @@ sources = [
"props/prop_data_scene.cpp",
"props/prop_data_light.cpp",
"props/prop_data_prop.cpp",
"props/prop_data_portal.cpp",
"clutter/ground_clutter.cpp",
"clutter/ground_clutter_foliage.cpp",

View File

@ -14,6 +14,7 @@ def get_doc_classes():
"PropDataLight",
"PropDataProp",
"PropDataScene",
"PropDataPortal",
"PropData",
"PropDataProcessor",

130
props/prop_data_portal.cpp Normal file
View File

@ -0,0 +1,130 @@
/*
Copyright (c) 2019-2021 Péter Magyar
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.
*/
#include "prop_data_portal.h"
#include "prop_data.h"
#include "scene/3d/portal.h"
bool PropDataPortal::get_is_active() const {
return _is_active;
}
void PropDataPortal::set_is_active(bool p_active) {
_is_active = p_active;
}
bool PropDataPortal::get_is_two_way() const {
return _is_two_way;
}
void PropDataPortal::set_is_two_way(bool p_two_way) {
_is_two_way = p_two_way;
}
bool PropDataPortal::get_use_default_margin() const {
return _use_default_margin;
}
void PropDataPortal::set_use_default_margin(bool p_use) {
_use_default_margin = p_use;
}
real_t PropDataPortal::get_portal_margin() const {
return _portal_margin;
}
void PropDataPortal::set_portal_margin(real_t p_margin) {
_portal_margin = p_margin;
}
PoolVector<Vector2> PropDataPortal::get_points() const {
return _points;
}
void PropDataPortal::set_points(const PoolVector<Vector2> &p_points) {
_points = p_points;
}
bool PropDataPortal::_processor_handles(Node *node) {
Portal *p = Object::cast_to<Portal>(node);
return p;
}
void PropDataPortal::_processor_process(Ref<PropData> prop_data, Node *node, const Transform &transform) {
Portal *p = Object::cast_to<Portal>(node);
ERR_FAIL_COND(!p);
Ref<PropDataPortal> l;
l.instance();
l->set_is_active(p->get_portal_active());
l->set_is_two_way(p->is_two_way());
l->set_use_default_margin(p->get_use_default_margin());
l->set_portal_margin(p->get_portal_margin());
l->set_points(p->get_points());
l->set_transform(transform * p->get_transform());
prop_data->add_prop(l);
}
Node *PropDataPortal::_processor_get_node_for(const Transform &transform) {
Portal *p = memnew(Portal);
p->set_portal_active(get_is_active());
p->set_two_way(get_is_two_way());
p->set_use_default_margin(get_use_default_margin());
p->set_portal_margin(get_portal_margin());
p->set_points(get_points());
p->set_transform(get_transform());
return p;
}
PropDataPortal::PropDataPortal() {
_is_active = true;
_is_two_way = true;
_use_default_margin = true;
_portal_margin = 1;
}
PropDataPortal::~PropDataPortal() {
}
void PropDataPortal::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_is_active"), &PropDataPortal::get_is_active);
ClassDB::bind_method(D_METHOD("set_is_active", "value"), &PropDataPortal::set_is_active);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_active"), "set_is_active", "get_is_active");
ClassDB::bind_method(D_METHOD("get_is_two_way"), &PropDataPortal::get_is_two_way);
ClassDB::bind_method(D_METHOD("set_is_two_way", "value"), &PropDataPortal::set_is_two_way);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_two_way"), "set_is_two_way", "get_is_two_way");
ClassDB::bind_method(D_METHOD("get_use_default_margin"), &PropDataPortal::get_use_default_margin);
ClassDB::bind_method(D_METHOD("set_use_default_margin", "value"), &PropDataPortal::set_use_default_margin);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_default_margin"), "set_use_default_margin", "get_use_default_margin");
ClassDB::bind_method(D_METHOD("get_portal_margin"), &PropDataPortal::get_portal_margin);
ClassDB::bind_method(D_METHOD("set_portal_margin", "value"), &PropDataPortal::set_portal_margin);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "portal_margin"), "set_portal_margin", "get_portal_margin");
ClassDB::bind_method(D_METHOD("get_points"), &PropDataPortal::get_points);
ClassDB::bind_method(D_METHOD("set_points", "value"), &PropDataPortal::set_points);
ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "points"), "set_points", "get_points");
}

67
props/prop_data_portal.h Normal file
View File

@ -0,0 +1,67 @@
/*
Copyright (c) 2019-2021 Péter Magyar
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.
*/
#ifndef PROP_DATA_PORTAL_H
#define PROP_DATA_PORTAL_H
#include "core/version.h"
#include "prop_data_entry.h"
class PropDataPortal : public PropDataEntry {
GDCLASS(PropDataPortal, PropDataEntry);
public:
bool get_is_active() const;
void set_is_active(bool p_active);
bool get_is_two_way() const;
void set_is_two_way(bool p_two_way);
bool get_use_default_margin() const;
void set_use_default_margin(bool p_use);
real_t get_portal_margin() const;
void set_portal_margin(real_t p_margin);
PoolVector<Vector2> get_points() const;
void set_points(const PoolVector<Vector2> &p_points);
bool _processor_handles(Node *node);
void _processor_process(Ref<PropData> prop_data, Node *node, const Transform &transform);
Node *_processor_get_node_for(const Transform &transform);
PropDataPortal();
~PropDataPortal();
protected:
static void _bind_methods();
private:
bool _is_active;
bool _is_two_way;
bool _use_default_margin;
real_t _portal_margin;
PoolVector<Vector2> _points;
};
#endif

View File

@ -33,6 +33,7 @@ SOFTWARE.
#include "props/prop_data.h"
#include "props/prop_data_entry.h"
#include "props/prop_data_light.h"
#include "props/prop_data_portal.h"
#include "props/prop_data_prop.h"
#include "props/prop_data_scene.h"
@ -77,6 +78,7 @@ void register_props_types() {
ClassDB::register_class<PropDataScene>();
ClassDB::register_class<PropDataLight>();
ClassDB::register_class<PropDataProp>();
ClassDB::register_class<PropDataPortal>();
ClassDB::register_class<GroundClutter>();
ClassDB::register_class<GroundClutterFoliage>();
@ -119,6 +121,9 @@ void register_props_types() {
Ref<PropDataScene> scene_processor = Ref<PropDataScene>(memnew(PropDataScene));
PropUtils::add_processor(scene_processor);
Ref<PropDataPortal> portal_processor = Ref<PropDataPortal>(memnew(PropDataPortal));
PropUtils::add_processor(portal_processor);
#ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<PropEditorPlugin>();
#endif