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 0000000000..d43870417a --- /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 0000000000..78f0fec1e9 --- /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 c83ab88c73..56e40679b2 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 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4mJh`hT^KKFANL}EX7WqAsieW95oy%9SjT% zoCO|{#S9Gci$R#NOncH21_lPn64!{5;QX|b^2DN4hVt@qz0ADq;^f4FRK5J7^x5xh zq!<`jB|KdmLn2!DPS5R#Nf$j{|G)Zu%H|92mbvccJZjp@dier>t|n)bz5wsmE`@z- zmVG_Ft9rA~g1-WRibpqH%&I*+eX5G=`;_ZW2D^UnxvmM*<~SOq9ozl)0k>kw72nIN zJafv7zwfNKf8sai>>Hmlr++)v z^XB(=UtVsXUM(LKqh`Ym^%MxiOv}C*b z*F#$GtGJHDJ_-B(f67g4V}D#&nC-Omlk<}8OsA)nZ98=_T$t&} z*I(6*?TxGd`@ayM_^-QG_R=r2@A1bKYXX9Um)E?wV0v^{>3-evM=mnQqfPDhiF{Rl zH*+TA!SsgJr}^&7w{NiYynJ14^5of%-I7my^LubS^~CKii@HNwZ)I;Of4{$|LVg1C z;$$Jm)dP&8{1O#cXpfS8}UcQ&)t5r zMKBhBco6#YzyaGP>(uzy8dc}MIZr)#@;Jk%s=s;69gAD2sW(P!{!#os?qhx?o@H!j+aFO z+6_z0rxfaM)#aOdDE-vyYdn^h89{DsyQ_We8pp$*KO?^7rk+t|@ZP*Rx*@T_$%-!_ zQ@PBRebcOqy@nJ&qjKoR`;F(i(5yuAQ>1`#?KG&5sXX9dCtq z$zA`XY1c|yCuA;uS<47ehzAND$Vp87g zWZ%DfYd-fT`JT&P>>5I!J2b5S=5;ME+jddm=AYa*&nMYS@$%ol9~CdU;8KQ-PDR_+ zeTHipovyw*$x(LH^V37o%f(k)ii@S4IsBPtTW#Gn`;EP;XVLGc|G2kAKUZ0ERZFqu zJ(G0g&9Bop|G)9C#Qssi!_vxD(ZWBx4|K)FmxvvF^>o93T??tFKgC1Vn*9=d&tMV1 z-e2-t$;Z+S@*Rl_8?u!nHvOHRlKJxcuJ8Ar*0owQ%yRGBKDcWk@k!v9g3=9mOu6{1-oD!M<`69L5 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 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7Sc;uILpV4%IBGajIv5xj zI14-?iy0XBFM%-Q?@sHJ3=9mCC9V-A!TD(=<%vb94CUqJdYO6I#mR{Use1WE>9gP2 zNHH)lsd~CNhFJ9WPCV;9B~j$)`O0~c&r6v~g*o)Ma4LCfaI`XYzmex)UAe6vCV87mzhSWJGhioZ*Vne*3z6TaOlD;%`AN-ir2e6YT`CJsdp%D%!|5EC>u}>stA>#tPyEC; zECupUb}e~4VOQ!Ig$9$o^$C0L-xgtDxLWhiVb|ivlcS@pnKm6}J6IE=HCMIrAX9AL z9=`{tI6w)7Ta|(bvl`iPmGp+WLdCsWzXrf`5ir%4j(>0 zd8dny&xQ7flNz*5()t_np8rkt)>Bj4mGe!d!Op8c>*%A6M?!)mp^X2 z5Sv4)G3(0x_flW}tyvrJLr$EFUwVRsgh%9VjRb}##tgO$_wsuUZ=9L5mZgm8MQ)Fg zvhw?^b8p!;BzZ55zBVK9{olPT3J-Gs3OPMG#*rI+KT}dRc9XWY`(p(Q{ROsr_s#QX zSZT3O@uj*)L+AFj^_4=da@Y2KJI7m;^Co;#q_!A;U=`zn)Xyu9%%5IXy0t$02&Vvp ziS_N5bE=sY)@V=P`7ucHQt<72b?wg1SKlTvcw|;ty`8iBuE6z`^MiNZS((=KHg(U| i>kME1o-f+`i#OEcr+&tnJ$(!e3=E#GelF{r5}E+hJtAKK literal 0 HcmV?d00001 diff --git a/tools/editor/icons/source/icon_remote_transform.svg b/tools/editor/icons/source/icon_remote_transform.svg new file mode 100644 index 0000000000..fbbfacf629 --- /dev/null +++ b/tools/editor/icons/source/icon_remote_transform.svg @@ -0,0 +1,124 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + +