summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/remote_transform.cpp132
-rw-r--r--scene/3d/remote_transform.h30
-rw-r--r--scene/register_scene_types.cpp2
3 files changed, 164 insertions, 0 deletions
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<Spatial>();
+ 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<Spatial>()) {
+ 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 be2c12d63a..d22c3bad14 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<BakedLightInstance>();
ObjectTypeDB::register_type<BakedLightSampler>();
ObjectTypeDB::register_type<WorldEnvironment>();
+ ObjectTypeDB::register_type<RemoteTransform>();
ObjectTypeDB::register_virtual_type<Joint>();
ObjectTypeDB::register_type<PinJoint>();