From 82f84f4c2f15b6715d0c8561a2cf8e85469fec76 Mon Sep 17 00:00:00 2001 From: Jakub Grzesik Date: Thu, 14 Jul 2016 15:23:02 +0200 Subject: [PATCH] Remote transform node (for 3d) It's code is based on RemoteTransform2D node. --- scene/3d/remote_transform.cpp | 132 ++++++++++++++++++ scene/3d/remote_transform.h | 30 ++++ scene/register_scene_types.cpp | 2 + .../editor/icons/2x/icon_remote_transform.png | Bin 0 -> 1435 bytes tools/editor/icons/icon_remote_transform.png | Bin 0 -> 680 bytes .../icons/source/icon_remote_transform.svg | 124 ++++++++++++++++ 6 files changed, 288 insertions(+) create mode 100644 scene/3d/remote_transform.cpp create mode 100644 scene/3d/remote_transform.h create mode 100644 tools/editor/icons/2x/icon_remote_transform.png create mode 100644 tools/editor/icons/icon_remote_transform.png create mode 100644 tools/editor/icons/source/icon_remote_transform.svg diff --git a/scene/3d/remote_transform.cpp b/scene/3d/remote_transform.cpp new file mode 100644 index 00000000000..d43870417a2 --- /dev/null +++ b/scene/3d/remote_transform.cpp @@ -0,0 +1,132 @@ + +/*************************************************************************/ +/* remote_transform.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 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. */ +/*************************************************************************/ + +#include "remote_transform.h" + +void RemoteTransform::_update_cache() { + cache=0; + if (has_node(remote_node)) { + Node *node = get_node(remote_node); + if (!node || this==node || node->is_a_parent_of(this) || this->is_a_parent_of(node)) { + return; + } + + cache=node->get_instance_ID(); + } +} + +void RemoteTransform::_update_remote() { + + + if (!is_inside_tree()) + return; + + if (!cache) + return; + + Object *obj = ObjectDB::get_instance(cache); + if (!obj) + return; + + Spatial *n = obj->cast_to(); + if (!n) + return; + + if (!n->is_inside_tree()) + return; + + //todo make faster + n->set_global_transform(get_global_transform()); + +} + +void RemoteTransform::_notification(int p_what) { + + switch(p_what) { + + case NOTIFICATION_READY: { + + _update_cache(); + + } break; + case NOTIFICATION_TRANSFORM_CHANGED: { + if (!is_inside_tree()) + break; + + if (cache) { + + _update_remote(); + + } + + } break; + + } +} + + +void RemoteTransform::set_remote_node(const NodePath& p_remote_node) { + + remote_node=p_remote_node; + if (is_inside_tree()) + _update_cache(); + + update_configuration_warning(); +} + +NodePath RemoteTransform::get_remote_node() const{ + + return remote_node; +} + + +String RemoteTransform::get_configuration_warning() const { + + if (!has_node(remote_node) || !get_node(remote_node) || !get_node(remote_node)->cast_to()) { + return TTR("Path property must point to a valid Spatial node to work."); + } + + return String(); +} + +void RemoteTransform::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("set_remote_node","path"),&RemoteTransform::set_remote_node); + ObjectTypeDB::bind_method(_MD("get_remote_node"),&RemoteTransform::get_remote_node); + + ADD_PROPERTY( PropertyInfo(Variant::NODE_PATH,"remote_path"),_SCS("set_remote_node"),_SCS("get_remote_node")); +} + +RemoteTransform::RemoteTransform() { + + cache=0; + +} + diff --git a/scene/3d/remote_transform.h b/scene/3d/remote_transform.h new file mode 100644 index 00000000000..78f0fec1e96 --- /dev/null +++ b/scene/3d/remote_transform.h @@ -0,0 +1,30 @@ +#ifndef REMOTETRANSFORM_H +#define REMOTETRANSFORM_H + +#include "scene/3d/spatial.h" + +class RemoteTransform : public Spatial +{ + OBJ_TYPE(RemoteTransform,Spatial); + + NodePath remote_node; + + ObjectID cache; + + void _update_remote(); + void _update_cache(); + +protected: + static void _bind_methods(); + void _notification(int p_what); +public: + void set_remote_node(const NodePath& p_remote_node); + NodePath get_remote_node() const; + + virtual String get_configuration_warning() const; + + RemoteTransform(); + +}; + +#endif // REMOTETRANSFORM_H diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index c83ab88c736..56e40679b26 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -182,6 +182,7 @@ #include "scene/3d/spatial.h" +#include "scene/3d/remote_transform.h" #include "scene/3d/skeleton.h" #include "scene/3d/bone_attachment.h" #include "scene/3d/room_instance.h" @@ -453,6 +454,7 @@ void register_scene_types() { ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); + ObjectTypeDB::register_type(); ObjectTypeDB::register_virtual_type(); ObjectTypeDB::register_type(); diff --git a/tools/editor/icons/2x/icon_remote_transform.png b/tools/editor/icons/2x/icon_remote_transform.png new file mode 100644 index 0000000000000000000000000000000000000000..9ee66bc70cff2ff0aeb7e104436afbab837b0b29 GIT binary patch literal 1435 zcmV;M1!Ve(P)TxS)>fB$>$WV6ujrbW96#Wjru)6frXDG7ov z5Dm48Aik`o^~<_@vrM4<5K$q;ve9aN!No;mA_ql&R`Zn->G?8qpL@>v|K>U8IromZ0&}f4+Ki%iN79|Lw^-VU zeHGFRz~2Q=7Vth4 zkBif%KWBR%Qd}lK4gAdTq+k*0Y++v)OQVK6uy1RFJYi{fWn$uqz5zTpw;_aZ47j5V zIBqx)4-FmD*x325arOG^3u(XYaUcPf3w!UnG@a`YAj?Jyc+Ao^!AvwX^of?RYqd%q z$J=G!P}qZ!bh4S}&kR^T{J?M{Kw(d`L#(X?SvC@+w+@Z z_T5MuF7+2I7`_-k|NM6}JzeFP5q;r zU!G;Vfg?!kv40ge8oM+-U4(l5n}$j37vgj0M*9X>0dw%+Rr$ccJ%T%BU+XA(&h|r< z$;rn6@_PL);OGTs-<_oCv2%wHZ>}WCUy)?#oqd(yQVRnEvx3h8Z??1z`~8BSH?!0Ks%K%XR`-`Z|E& z7T0Q{W$2^j+K#ROd6w-i^86`h*+@4ZrRiccJbY_BG4avLo;?plLqppI3rG@70VH|; z8|?D{LAnJX6vc@$#imsOJUjb3q=zhRE2LlcgcutOZQsuq_V>$OxCua0Q%ztIpnws8 zsJsS7Rs|@E;y%iAZn)`k5G#PBHn!e`3s)(kn*0pPj0^@iOm*47B&`T1D( zZDq_O086v8TYzDJLOKp$X(NE_e|f*mEupF02yH+CBimfi?#1#Ico1ZIKT+kKR# zi@=8feE9J7LE2Y}9@X@8?wOf^0Pg@O;HRBEP!zq6p4vZcZ|UJns8l|Wv;q5cWIqVd z931=z7e=`&&1NS+1gCoBH1I<>l+>_0_Ga{J}}3$$D3B&^jcA%yP& z8(G=)m$U!a{&YX$aN%`%g%xr94d5*o7o--!>gBNiEjSwG`4?2JHu@3o061T-PZ{=f z@pZ5th+(0CYa>{){g-5E>G!(#-sOIUI{=zTj=V|s*Lpb%PPNYTD`gQ}Xgb;Rz`!e+ pd`$ptO?UmPEe;TMG~KIg{{y|!TRNV^)>Hrh002ovPDHLkV1oG~wcP*! literal 0 HcmV?d00001 diff --git a/tools/editor/icons/icon_remote_transform.png b/tools/editor/icons/icon_remote_transform.png new file mode 100644 index 0000000000000000000000000000000000000000..deff925b531ad89a044700ef03aec9d8f420dde8 GIT binary patch literal 680 zcmV;Z0$2TsP)>mgP zskV+%v=gFL_*#o-sX^d4ljN!oiXsCE`k=^7izKK(DhhPdA`onvkN0^_3uj)+u2jwt7yz&jKnuyQ02T}|$z1MRW7ljKS7&Apx=Q7P0Zx11ruV+z zk-hT%qJUja`dH29NB#+*F>L~-O&A^q;EXY2R=Omh%Sz{D%n3tYZ9v%cg(xyE3}2D# z1aKeZx}@Wfx@F8DfHb{-V7=el6aWC#eEvYXqvMlXTRQ@>!v?{8Tq>OX(1!_SksL`+Q3 zhvAZdD>P=0fNtmgWlJt5Cc13)B!E6jk7~u@vBXqT7#|matfU{1+TeYOQU*X}GX<%? z-eu|ie63LU9v2D^8;}?nNLjlmU;yMZ06hTSZ;dh7%#y7Hb^_>aj4~r5?`qEN2C!mF zrCZjRQSbe|1R&sT{Srdr#t3a&-)R{gU9u}HN8=zkFQ7fWzMfA2sW`qN=_g2liMOqP zc@jk)*1q=64RUPkSF%|v77tN+0ib2`sKlR_c6GIXYs3i<05m(>>7085Agn8wx$#mN z(o@^seuqOt)$L*cNNIXH?VP*a5Z9@nQ@Px!W`gZyytUT=^!?9rv-%BHNck^l%)E{O O0000 + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + +