feat: implemented point primitive gizmo
This commit is contained in:
parent
60865b74c7
commit
dfbe37a2e7
15 changed files with 330 additions and 60 deletions
54
modules/terrain_editor/point_primitive_node.cpp
Normal file
54
modules/terrain_editor/point_primitive_node.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include "point_primitive_node.h"
|
||||
#include "scene/3d/node_3d.h"
|
||||
#include "terrain_editor/macros.h"
|
||||
|
||||
void PointPrimitiveNode::_bind_methods() {
|
||||
BIND_GET_SET(primitive);
|
||||
ClassDB::bind_method(D_METHOD("push_transform_changes"), &self_type::push_transform_changes);
|
||||
}
|
||||
|
||||
void PointPrimitiveNode::on_underlying_changed() {
|
||||
if (!this->pushing_change && this->is_inside_tree()) {
|
||||
this->pushing_change = true;
|
||||
Vector2 const center{ this->primitive->get_center() };
|
||||
set_global_position({ center.x, this->primitive->get_height(), center.y });
|
||||
this->pushing_change = false;
|
||||
}
|
||||
}
|
||||
|
||||
void PointPrimitiveNode::_notification(int what) {
|
||||
switch (what) {
|
||||
default:
|
||||
return;
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
if (this->primitive.is_valid()) {
|
||||
on_underlying_changed();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void PointPrimitiveNode::push_transform_changes() {
|
||||
if (this->primitive.is_valid()) {
|
||||
this->pushing_change = true;
|
||||
Vector3 const position{ get_global_position() };
|
||||
this->primitive->set_center({ position.x, position.z });
|
||||
this->primitive->set_height(position.y);
|
||||
this->pushing_change = false;
|
||||
}
|
||||
}
|
||||
|
||||
void PointPrimitiveNode::set_primitive(Ref<PointPrimitive> primitive) {
|
||||
if (this->primitive.is_valid()) {
|
||||
this->primitive->disconnect_changed(underlying_changed_callable);
|
||||
}
|
||||
this->primitive = primitive;
|
||||
if (this->primitive.is_valid()) {
|
||||
primitive->connect_changed(underlying_changed_callable);
|
||||
on_underlying_changed();
|
||||
}
|
||||
}
|
||||
|
||||
Ref<PointPrimitive> PointPrimitiveNode::get_primitive() const {
|
||||
return this->primitive;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue