mirror of
https://github.com/Relintai/props_2d.git
synced 2024-11-12 10:25:01 +01:00
Added a Transform2D property to PropDataEntry, and also changed the processor api to use Transform2Ds. I did not yet remove the 3D transforms, as it would break too much code right now.
This commit is contained in:
parent
bb6f76dbf0
commit
828863d638
@ -89,7 +89,7 @@ void Prop2DEditorPlugin::find_room_points(Variant param) {
|
||||
Node *scene = st->get_edited_scene_root();
|
||||
|
||||
if (scene) {
|
||||
Prop2DUtils::get_singleton()->generate_room_points_node(scene);
|
||||
//Prop2DUtils::get_singleton()->generate_room_points_node(scene);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -47,6 +47,13 @@ void Prop2DDataEntry::set_transform(const Transform &value) {
|
||||
_transform = value;
|
||||
}
|
||||
|
||||
Transform2D Prop2DDataEntry::get_transform_2d() const {
|
||||
return _transform_2d;
|
||||
}
|
||||
void Prop2DDataEntry::set_transform_2d(const Transform2D &value) {
|
||||
_transform_2d = value;
|
||||
}
|
||||
|
||||
#if TEXTURE_PACKER_PRESENT
|
||||
void Prop2DDataEntry::add_textures_into(Ref<TexturePacker> texture_packer) {
|
||||
if (has_method("_add_textures_into"))
|
||||
@ -57,10 +64,10 @@ void Prop2DDataEntry::add_textures_into(Ref<TexturePacker> texture_packer) {
|
||||
bool Prop2DDataEntry::processor_handles(Node *node) {
|
||||
return call("_processor_handles", node);
|
||||
}
|
||||
void Prop2DDataEntry::processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform) {
|
||||
void Prop2DDataEntry::processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform) {
|
||||
call("_processor_process", prop_data, node, transform);
|
||||
}
|
||||
Node *Prop2DDataEntry::processor_get_node_for(const Transform &transform) {
|
||||
Node *Prop2DDataEntry::processor_get_node_for(const Transform2D &transform) {
|
||||
return call("_processor_get_node_for", transform);
|
||||
}
|
||||
bool Prop2DDataEntry::processor_evaluate_children() {
|
||||
@ -70,9 +77,9 @@ bool Prop2DDataEntry::processor_evaluate_children() {
|
||||
bool Prop2DDataEntry::_processor_handles(Node *node) {
|
||||
return false;
|
||||
}
|
||||
void Prop2DDataEntry::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform) {
|
||||
void Prop2DDataEntry::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform) {
|
||||
}
|
||||
Node *Prop2DDataEntry::_processor_get_node_for(const Transform &transform) {
|
||||
Node *Prop2DDataEntry::_processor_get_node_for(const Transform2D &transform) {
|
||||
return NULL;
|
||||
}
|
||||
bool Prop2DDataEntry::_processor_evaluate_children() {
|
||||
@ -89,6 +96,10 @@ void Prop2DDataEntry::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_transform", "value"), &Prop2DDataEntry::set_transform);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform"), "set_transform", "get_transform");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_transform_2d"), &Prop2DDataEntry::get_transform_2d);
|
||||
ClassDB::bind_method(D_METHOD("set_transform_2d", "value"), &Prop2DDataEntry::set_transform_2d);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform_2d"), "set_transform_2d", "get_transform_2d");
|
||||
|
||||
#if TEXTURE_PACKER_PRESENT
|
||||
BIND_VMETHOD(MethodInfo("_add_textures_into", PropertyInfo(Variant::OBJECT, "texture_packer", PROPERTY_HINT_RESOURCE_TYPE, "TexturePacker")));
|
||||
|
||||
@ -115,5 +126,4 @@ void Prop2DDataEntry::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_processor_process", "prop_data", "node", "transform"), &Prop2DDataEntry::_processor_process);
|
||||
ClassDB::bind_method(D_METHOD("_processor_get_node_for", "transform"), &Prop2DDataEntry::_processor_get_node_for);
|
||||
ClassDB::bind_method(D_METHOD("_processor_evaluate_children"), &Prop2DDataEntry::_processor_evaluate_children);
|
||||
|
||||
}
|
||||
|
@ -29,12 +29,13 @@ SOFTWARE.
|
||||
#include "core/io/resource.h"
|
||||
#include "core/math/transform_3d.h"
|
||||
|
||||
#ifndef Transform
|
||||
#ifndef Transform
|
||||
#define Transform Transform3D
|
||||
#endif
|
||||
#else
|
||||
#include "core/resource.h"
|
||||
#include "core/math/transform.h"
|
||||
#include "core/math/transform_2d.h"
|
||||
#include "core/resource.h"
|
||||
#endif
|
||||
|
||||
class Prop2DData;
|
||||
@ -48,20 +49,23 @@ public:
|
||||
Transform get_transform() const;
|
||||
void set_transform(const Transform &value);
|
||||
|
||||
Transform2D get_transform_2d() const;
|
||||
void set_transform_2d(const Transform2D &value);
|
||||
|
||||
#if TEXTURE_PACKER_PRESENT
|
||||
void add_textures_into(Ref<TexturePacker> texture_packer);
|
||||
#endif
|
||||
|
||||
bool processor_handles(Node *node);
|
||||
void processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform);
|
||||
Node *processor_get_node_for(const Transform &transform);
|
||||
void processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform);
|
||||
Node *processor_get_node_for(const Transform2D &transform);
|
||||
bool processor_evaluate_children();
|
||||
|
||||
virtual bool _processor_handles(Node *node);
|
||||
virtual void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform);
|
||||
virtual Node *_processor_get_node_for(const Transform &transform);
|
||||
virtual void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform);
|
||||
virtual Node *_processor_get_node_for(const Transform2D &transform);
|
||||
virtual bool _processor_evaluate_children();
|
||||
|
||||
|
||||
Prop2DDataEntry();
|
||||
~Prop2DDataEntry();
|
||||
|
||||
@ -70,6 +74,7 @@ protected:
|
||||
|
||||
private:
|
||||
Transform _transform;
|
||||
Transform2D _transform_2d;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -52,7 +52,7 @@ bool Prop2DDataLight::_processor_handles(Node *node) {
|
||||
return i;
|
||||
}
|
||||
|
||||
void Prop2DDataLight::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform) {
|
||||
void Prop2DDataLight::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform) {
|
||||
OmniLight *i = Object::cast_to<OmniLight>(node);
|
||||
|
||||
ERR_FAIL_COND(!i);
|
||||
@ -61,16 +61,16 @@ void Prop2DDataLight::_processor_process(Ref<Prop2DData> prop_data, Node *node,
|
||||
l.instance();
|
||||
l->set_light_color(i->get_color());
|
||||
l->set_light_size(i->get_param(Light::PARAM_RANGE));
|
||||
l->set_transform(transform * i->get_transform());
|
||||
//l->set_transform(transform * i->get_transform());
|
||||
prop_data->add_prop(l);
|
||||
}
|
||||
|
||||
Node *Prop2DDataLight::_processor_get_node_for(const Transform &transform) {
|
||||
Node *Prop2DDataLight::_processor_get_node_for(const Transform2D &transform) {
|
||||
OmniLight *i = memnew(OmniLight);
|
||||
|
||||
i->set_color(get_light_color());
|
||||
i->set_param(Light::PARAM_RANGE, get_light_size());
|
||||
i->set_transform(get_transform());
|
||||
//i->set_transform(get_transform());
|
||||
|
||||
return i;
|
||||
}
|
||||
|
@ -44,8 +44,8 @@ public:
|
||||
void set_light_size(const int value);
|
||||
|
||||
bool _processor_handles(Node *node);
|
||||
void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform);
|
||||
Node *_processor_get_node_for(const Transform &transform);
|
||||
void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform);
|
||||
Node *_processor_get_node_for(const Transform2D &transform);
|
||||
|
||||
Prop2DDataLight();
|
||||
~Prop2DDataLight();
|
||||
|
@ -67,7 +67,7 @@ bool Prop2DDataPortal::_processor_handles(Node *node) {
|
||||
return p;
|
||||
}
|
||||
|
||||
void Prop2DDataPortal::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform) {
|
||||
void Prop2DDataPortal::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform) {
|
||||
Portal *p = Object::cast_to<Portal>(node);
|
||||
|
||||
ERR_FAIL_COND(!p);
|
||||
@ -80,11 +80,11 @@ void Prop2DDataPortal::_processor_process(Ref<Prop2DData> prop_data, Node *node,
|
||||
l->set_portal_margin(p->get_portal_margin());
|
||||
l->set_points(p->get_points());
|
||||
|
||||
l->set_transform(transform * p->get_transform());
|
||||
//l->set_transform(transform * p->get_transform());
|
||||
prop_data->add_prop(l);
|
||||
}
|
||||
|
||||
Node *Prop2DDataPortal::_processor_get_node_for(const Transform &transform) {
|
||||
Node *Prop2DDataPortal::_processor_get_node_for(const Transform2D &transform) {
|
||||
Portal *p = memnew(Portal);
|
||||
|
||||
p->set_portal_active(get_is_active());
|
||||
@ -93,7 +93,7 @@ Node *Prop2DDataPortal::_processor_get_node_for(const Transform &transform) {
|
||||
p->set_portal_margin(get_portal_margin());
|
||||
p->set_points(get_points());
|
||||
|
||||
p->set_transform(get_transform());
|
||||
//p->set_transform(get_transform());
|
||||
|
||||
return p;
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ public:
|
||||
void set_points(const PoolVector<Vector2> &p_points);
|
||||
|
||||
bool _processor_handles(Node *node);
|
||||
void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform);
|
||||
Node *_processor_get_node_for(const Transform &transform);
|
||||
void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform);
|
||||
Node *_processor_get_node_for(const Transform2D &transform);
|
||||
|
||||
Prop2DDataPortal();
|
||||
~Prop2DDataPortal();
|
||||
|
@ -60,7 +60,7 @@ bool Prop2DDataProp2D::_processor_handles(Node *node) {
|
||||
return i;
|
||||
}
|
||||
|
||||
void Prop2DDataProp2D::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform) {
|
||||
void Prop2DDataProp2D::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform) {
|
||||
Prop2DInstance *i = Object::cast_to<Prop2DInstance>(node);
|
||||
|
||||
ERR_FAIL_COND(!i);
|
||||
@ -68,15 +68,15 @@ void Prop2DDataProp2D::_processor_process(Ref<Prop2DData> prop_data, Node *node,
|
||||
Ref<Prop2DDataProp2D> l;
|
||||
l.instance();
|
||||
l->set_prop(i->get_prop_data());
|
||||
l->set_transform(transform * i->get_transform());
|
||||
//l->set_transform(transform * i->get_transform());
|
||||
prop_data->add_prop(l);
|
||||
}
|
||||
|
||||
Node *Prop2DDataProp2D::_processor_get_node_for(const Transform &transform) {
|
||||
Node *Prop2DDataProp2D::_processor_get_node_for(const Transform2D &transform) {
|
||||
Prop2DInstance *i = memnew(Prop2DInstance);
|
||||
|
||||
i->set_prop_data(get_prop());
|
||||
i->set_transform(get_transform());
|
||||
//i->set_transform(get_transform());
|
||||
|
||||
return i;
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ public:
|
||||
#endif
|
||||
|
||||
bool _processor_handles(Node *node);
|
||||
void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform);
|
||||
Node *_processor_get_node_for(const Transform &transform);
|
||||
void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform);
|
||||
Node *_processor_get_node_for(const Transform2D &transform);
|
||||
|
||||
Prop2DDataProp2D();
|
||||
~Prop2DDataProp2D();
|
||||
|
@ -52,7 +52,7 @@ bool Prop2DDataScene::_processor_handles(Node *node) {
|
||||
return i;
|
||||
}
|
||||
|
||||
void Prop2DDataScene::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform) {
|
||||
void Prop2DDataScene::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform) {
|
||||
Prop2DSceneInstance *i = Object::cast_to<Prop2DSceneInstance>(node);
|
||||
|
||||
ERR_FAIL_COND(!i);
|
||||
@ -60,15 +60,15 @@ void Prop2DDataScene::_processor_process(Ref<Prop2DData> prop_data, Node *node,
|
||||
Ref<Prop2DDataScene> l;
|
||||
l.instance();
|
||||
l->set_scene(i->get_scene());
|
||||
l->set_transform(transform * i->get_transform());
|
||||
//l->set_transform(transform * i->get_transform());
|
||||
prop_data->add_prop(l);
|
||||
}
|
||||
|
||||
Node *Prop2DDataScene::_processor_get_node_for(const Transform &transform) {
|
||||
Node *Prop2DDataScene::_processor_get_node_for(const Transform2D &transform) {
|
||||
Prop2DSceneInstance *i = memnew(Prop2DSceneInstance);
|
||||
|
||||
i->set_scene(get_scene());
|
||||
i->set_transform(get_transform());
|
||||
//i->set_transform(get_transform());
|
||||
|
||||
return i;
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ public:
|
||||
void set_snap_axis(Vector3 value);
|
||||
|
||||
bool _processor_handles(Node *node);
|
||||
void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform);
|
||||
Node *_processor_get_node_for(const Transform &transform);
|
||||
void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform);
|
||||
Node *_processor_get_node_for(const Transform2D &transform);
|
||||
|
||||
Prop2DDataScene();
|
||||
~Prop2DDataScene();
|
||||
|
@ -61,7 +61,7 @@ bool Prop2DDataTiledWall2D::_processor_handles(Node *node) {
|
||||
return t;
|
||||
}
|
||||
|
||||
void Prop2DDataTiledWall2D::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform) {
|
||||
void Prop2DDataTiledWall2D::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform) {
|
||||
TiledWall2D *t = Object::cast_to<TiledWall2D>(node);
|
||||
|
||||
ERR_FAIL_COND(!t);
|
||||
@ -73,18 +73,18 @@ void Prop2DDataTiledWall2D::_processor_process(Ref<Prop2DData> prop_data, Node *
|
||||
tw->set_heigth(t->get_heigth());
|
||||
tw->set_data(t->get_data());
|
||||
tw->set_collision(t->get_collision());
|
||||
tw->set_transform(transform * t->get_transform());
|
||||
//tw->set_transform(transform * t->get_transform());
|
||||
prop_data->add_prop(tw);
|
||||
}
|
||||
|
||||
Node *Prop2DDataTiledWall2D::_processor_get_node_for(const Transform &transform) {
|
||||
Node *Prop2DDataTiledWall2D::_processor_get_node_for(const Transform2D &transform) {
|
||||
TiledWall2D *t = memnew(TiledWall2D);
|
||||
|
||||
t->set_width(get_width());
|
||||
t->set_heigth(get_heigth());
|
||||
t->set_collision(get_collision());
|
||||
t->set_data(get_data());
|
||||
t->set_transform(get_transform());
|
||||
//t->set_transform(get_transform());
|
||||
|
||||
return t;
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ public:
|
||||
void set_collision(const int value);
|
||||
|
||||
bool _processor_handles(Node *node);
|
||||
void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform &transform);
|
||||
Node *_processor_get_node_for(const Transform &transform);
|
||||
void _processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform);
|
||||
Node *_processor_get_node_for(const Transform2D &transform);
|
||||
|
||||
Prop2DDataTiledWall2D();
|
||||
~Prop2DDataTiledWall2D();
|
||||
|
@ -46,6 +46,8 @@ SOFTWARE.
|
||||
#include "core/engine.h"
|
||||
#endif
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
Prop2DUtils *Prop2DUtils::_instance;
|
||||
Vector<Ref<Prop2DDataEntry> > Prop2DUtils::_processors;
|
||||
|
||||
@ -60,14 +62,14 @@ Ref<Prop2DData> Prop2DUtils::convert_tree(Node *root) {
|
||||
|
||||
Ref<Prop2DData> data;
|
||||
data.instance();
|
||||
Transform t;
|
||||
Transform2D t;
|
||||
|
||||
_convert_tree(data, root, t);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void Prop2DUtils::_convert_tree(Ref<Prop2DData> prop_data, Node *node, const Transform &transform) {
|
||||
void Prop2DUtils::_convert_tree(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform) {
|
||||
#if VERSION_MAJOR < 4
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(node));
|
||||
#endif
|
||||
@ -88,11 +90,11 @@ void Prop2DUtils::_convert_tree(Ref<Prop2DData> prop_data, Node *node, const Tra
|
||||
}
|
||||
}
|
||||
|
||||
Spatial *sp = Object::cast_to<Spatial>(node);
|
||||
Node2D *n2d = Object::cast_to<Node2D>(node);
|
||||
|
||||
if (!sp) {
|
||||
if (!n2d) {
|
||||
//reset transform
|
||||
Transform t;
|
||||
Transform2D t;
|
||||
|
||||
for (int i = 0; i < node->get_child_count(); ++i) {
|
||||
Node *child = node->get_child(i);
|
||||
@ -107,20 +109,6 @@ void Prop2DUtils::_convert_tree(Ref<Prop2DData> prop_data, Node *node, const Tra
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#if VERSION_MINOR >= 4
|
||||
//only handle the first encountered room per prop
|
||||
if (!prop_data->get_is_room()) {
|
||||
Room *r = Object::cast_to<Room>(sp);
|
||||
|
||||
if (r) {
|
||||
prop_data->set_is_room(true);
|
||||
|
||||
PoolVector3Array points = r->get_points();
|
||||
|
||||
prop_data->set_room_bounds(points);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < node->get_child_count(); ++i) {
|
||||
Node *child = node->get_child(i);
|
||||
@ -128,340 +116,15 @@ void Prop2DUtils::_convert_tree(Ref<Prop2DData> prop_data, Node *node, const Tra
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
//Skip it if it's hidden from the tree
|
||||
if (child->get_owner() != NULL) {
|
||||
_convert_tree(prop_data, node->get_child(i), transform * sp->get_transform());
|
||||
_convert_tree(prop_data, node->get_child(i), transform * n2d->get_transform());
|
||||
}
|
||||
} else {
|
||||
_convert_tree(prop_data, node->get_child(i), transform * sp->get_transform());
|
||||
_convert_tree(prop_data, node->get_child(i), transform * n2d->get_transform());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if VERSION_MINOR >= 4
|
||||
bool Prop2DUtils::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 Prop2DUtils::generate_room_points(Room *room) {
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(room));
|
||||
|
||||
Vector<PoolVector<Vector3> > mesh_arrays;
|
||||
|
||||
get_mesh_arrays(room, &mesh_arrays);
|
||||
|
||||
PoolVector<Plane> planes;
|
||||
Vector<Vector3> points;
|
||||
PoolVector<Face3> faces;
|
||||
|
||||
for (int i = 0; i < mesh_arrays.size(); ++i) {
|
||||
PoolVector<Vector3> verts = mesh_arrays[i];
|
||||
|
||||
for (int j = 0; j < verts.size(); j += 3) {
|
||||
Plane p(verts[j], verts[j + 1], verts[j + 2]);
|
||||
|
||||
faces.push_back(Face3(verts[j], verts[j + 1], verts[j + 2]));
|
||||
|
||||
//points.push_back(verts[j]);
|
||||
//points.push_back(verts[j + 1]);
|
||||
//points.push_back(verts[j + 2]);
|
||||
|
||||
if (!is_plane_unique(planes, p)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
planes.push_back(p);
|
||||
|
||||
//points.push_back(verts[j]);
|
||||
//points.push_back(verts[j + 1]);
|
||||
//points.push_back(verts[j + 2]);
|
||||
}
|
||||
}
|
||||
|
||||
PoolVector<Face3> wrapped = Geometry::wrap_geometry(faces);
|
||||
|
||||
for (int i = 0; i < wrapped.size(); ++i) {
|
||||
Face3 f = wrapped[i];
|
||||
|
||||
points.push_back(f.vertex[0]);
|
||||
points.push_back(f.vertex[1]);
|
||||
points.push_back(f.vertex[2]);
|
||||
}
|
||||
|
||||
Geometry::MeshData md = Geometry::build_convex_mesh(planes);
|
||||
md.optimize_vertices();
|
||||
|
||||
QuickHull q;
|
||||
|
||||
// calculate an epsilon based on the simplify value, and use this to build the hull
|
||||
real_t s = 0.5;
|
||||
|
||||
// value between 0.3 (accurate) and 10.0 (very rough)
|
||||
// * UNIT_EPSILON
|
||||
s *= s;
|
||||
s *= 40.0;
|
||||
s += 0.3; // minimum
|
||||
s *= UNIT_EPSILON;
|
||||
|
||||
q.build(points, md, s);
|
||||
|
||||
md.optimize_vertices();
|
||||
|
||||
PoolVector<Vector3> vs;
|
||||
vs.resize(md.vertices.size());
|
||||
for (int i = 0; i < md.vertices.size(); ++i) {
|
||||
vs.set(i, md.vertices[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
//It will probably have a few unnecessary vertices still
|
||||
//let's try to get rid of those aswell
|
||||
PoolVector<int> remove_indices;
|
||||
int vssize = vs.size();
|
||||
for (int i = 0; i < vssize - 2; ++i) {
|
||||
Plane p(vs[i], vs[i + 1], vs[i + 2]);
|
||||
|
||||
for (int j = 0; j < vssize; ++j) {
|
||||
if (i == j) {
|
||||
//skip this and the next 2
|
||||
j += 3;
|
||||
|
||||
if (j >= vssize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (p.has_point(vs[j], 0.1)) {
|
||||
bool found = false;
|
||||
for (int k = 0; k < remove_indices.size(); ++k) {
|
||||
if (remove_indices[k] == j) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
remove_indices.push_back(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < remove_indices.size(); ++i) {
|
||||
int rindex = remove_indices[i];
|
||||
|
||||
vs.remove(rindex);
|
||||
|
||||
for (int j = i + 1; j < remove_indices.size(); ++j) {
|
||||
int rij = remove_indices[j];
|
||||
|
||||
if (rij > rindex) {
|
||||
remove_indices.set(j, rij - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
room->set_points(vs);
|
||||
}
|
||||
|
||||
//based on Room::SimplifyInfo::add_plane_if_unique
|
||||
bool Prop2DUtils::is_plane_unique(const PoolVector<Plane> &planes, const Plane &p) {
|
||||
for (int n = 0; n < planes.size(); n++) {
|
||||
const Plane &o = planes[n];
|
||||
|
||||
// this is a fudge factor for how close planes can be to be considered the same ...
|
||||
// to prevent ridiculous amounts of planes
|
||||
const real_t d = 0.08f; //_plane_simplify_dist; // 0.08f
|
||||
|
||||
if (Math::abs(p.d - o.d) > d) {
|
||||
continue;
|
||||
}
|
||||
|
||||
real_t dot = p.normal.dot(o.normal);
|
||||
if (dot < 0.98f) //_plane_simplify_dot) // 0.98f
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// match!
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Prop2DUtils::get_mesh_arrays(Node *node, Vector<PoolVector<Vector3> > *arrs) {
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(node));
|
||||
|
||||
for (int i = 0; i < node->get_child_count(); ++i) {
|
||||
get_mesh_arrays(node->get_child(i), arrs);
|
||||
}
|
||||
|
||||
{
|
||||
Portal *pn = Object::cast_to<Portal>(node);
|
||||
|
||||
if (pn) {
|
||||
if (!pn->get_portal_active()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pn->is_visible_in_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PoolVector<Vector2> points = pn->get_points();
|
||||
PoolVector<Vector3> v3p;
|
||||
v3p.resize(points.size());
|
||||
|
||||
for (int i = 0; i < points.size(); ++i) {
|
||||
v3p.set(i, Vector3(points[i].x, points[i].y, 0));
|
||||
}
|
||||
|
||||
Transform t = pn->get_global_transform();
|
||||
|
||||
int fvertcount = (points.size() - 2) * 3;
|
||||
|
||||
PoolVector<Vector3> tverts;
|
||||
tverts.resize(fvertcount);
|
||||
|
||||
for (int i = 0; i < points.size() - 2; ++i) {
|
||||
int sindex = i * 3;
|
||||
|
||||
tverts.set(sindex, t.xform(v3p[i]));
|
||||
tverts.set(sindex + 1, t.xform(v3p[i + 1]));
|
||||
tverts.set(sindex + 2, t.xform(v3p[i + 2]));
|
||||
}
|
||||
|
||||
//portal planes need to take precedence
|
||||
arrs->insert(0, tverts);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#if MESH_DATA_RESOURCE_PRESENT
|
||||
{
|
||||
MeshDataInstance *mdi = Object::cast_to<MeshDataInstance>(node);
|
||||
|
||||
if (mdi) {
|
||||
if (!mdi->is_visible_in_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<MeshDataResource> mdr = mdi->get_mesh_data();
|
||||
|
||||
if (!mdr.is_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Array arr = mdr->get_array();
|
||||
|
||||
if (arr.size() != Mesh::ARRAY_MAX) {
|
||||
return;
|
||||
}
|
||||
|
||||
Transform t = mdi->get_global_transform();
|
||||
|
||||
PoolVector<Vector3> verts = arr[Mesh::ARRAY_VERTEX];
|
||||
PoolVector<Vector3> tverts;
|
||||
tverts.resize(verts.size());
|
||||
|
||||
for (int i = 0; i < verts.size(); ++i) {
|
||||
tverts.set(i, t.xform(verts[i]));
|
||||
}
|
||||
|
||||
PoolVector<int> indices = arr[Mesh::ARRAY_INDEX];
|
||||
|
||||
if (indices.size() == 0) {
|
||||
arrs->push_back(tverts);
|
||||
return;
|
||||
}
|
||||
|
||||
PoolVector<Vector3> fverts;
|
||||
fverts.resize(indices.size());
|
||||
|
||||
for (int i = 0; i < indices.size(); ++i) {
|
||||
fverts.set(i, tverts[indices[i]]);
|
||||
}
|
||||
|
||||
arrs->push_back(fverts);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
MeshInstance *min = Object::cast_to<MeshInstance>(node);
|
||||
|
||||
if (min) {
|
||||
if (!min->is_visible_in_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<ArrayMesh> am = min->get_mesh();
|
||||
|
||||
if (!am.is_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Transform t = min->get_global_transform();
|
||||
|
||||
for (int si = 0; si < am->get_surface_count(); ++si) {
|
||||
Array arr = am->surface_get_arrays(si);
|
||||
|
||||
if (arr.size() != Mesh::ARRAY_MAX) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PoolVector<Vector3> verts = arr[Mesh::ARRAY_VERTEX];
|
||||
PoolVector<Vector3> tverts;
|
||||
tverts.resize(verts.size());
|
||||
|
||||
for (int i = 0; i < verts.size(); ++i) {
|
||||
tverts.set(i, t.xform(verts[i]));
|
||||
}
|
||||
|
||||
PoolVector<int> indices = arr[Mesh::ARRAY_INDEX];
|
||||
|
||||
if (indices.size() == 0) {
|
||||
arrs->push_back(tverts);
|
||||
continue;
|
||||
}
|
||||
|
||||
PoolVector<Vector3> fverts;
|
||||
fverts.resize(indices.size());
|
||||
|
||||
for (int i = 0; i < indices.size(); ++i) {
|
||||
fverts.set(i, tverts[indices[i]]);
|
||||
}
|
||||
|
||||
arrs->push_back(fverts);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int Prop2DUtils::add_processor(const Ref<Prop2DDataEntry> &processor) {
|
||||
ERR_FAIL_COND_V(!processor.is_valid(), 0);
|
||||
|
||||
|
@ -53,14 +53,7 @@ public:
|
||||
static Prop2DUtils *get_singleton();
|
||||
|
||||
Ref<Prop2DData> convert_tree(Node *root);
|
||||
void _convert_tree(Ref<Prop2DData> prop_data, Node *node, const Transform &transform);
|
||||
|
||||
#if VERSION_MINOR >= 4
|
||||
bool generate_room_points_node(Node *node);
|
||||
void generate_room_points(Room *room);
|
||||
void get_mesh_arrays(Node *node, Vector<PoolVector<Vector3>> *arrs);
|
||||
bool is_plane_unique(const PoolVector<Plane> &planes, const Plane &p);
|
||||
#endif
|
||||
void _convert_tree(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform);
|
||||
|
||||
static int add_processor(const Ref<Prop2DDataEntry> &processor);
|
||||
static Ref<Prop2DDataEntry> get_processor(const int index);
|
||||
|
Loading…
Reference in New Issue
Block a user