Browse Source

Merge pull request #5692 from kubecz3k/remoteTransform

Remote transform node (for 3d)
Juan Linietsky 9 years ago
parent
commit
4d664c9289

+ 132 - 0
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;
+
+}
+

+ 30 - 0
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

+ 2 - 0
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>();

BIN
tools/editor/icons/2x/icon_remote_transform.png


BIN
tools/editor/icons/icon_remote_transform.png


+ 124 - 0
tools/editor/icons/source/icon_remote_transform.svg

@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="16"
+   height="16"
+   viewBox="0 0 16 16"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.91 r13725"
+   inkscape:export-filename="/home/djrm/Projects/godot/tools/editor/icons/icon_node_2d.png"
+   inkscape:export-xdpi="90"
+   inkscape:export-ydpi="90"
+   sodipodi:docname="icon_remote_transform.svg">
+  <defs
+     id="defs4" />
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="16"
+     inkscape:cx="7.0691739"
+     inkscape:cy="9.3738931"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="true"
+     units="px"
+     inkscape:snap-bbox="true"
+     inkscape:bbox-paths="true"
+     inkscape:bbox-nodes="true"
+     inkscape:snap-bbox-edge-midpoints="true"
+     inkscape:snap-bbox-midpoints="true"
+     inkscape:snap-object-midpoints="true"
+     inkscape:snap-center="true"
+     inkscape:window-width="1680"
+     inkscape:window-height="1050"
+     inkscape:window-x="1366"
+     inkscape:window-y="0"
+     inkscape:window-maximized="1"
+     inkscape:object-paths="true"
+     inkscape:snap-intersection-paths="true"
+     inkscape:object-nodes="true"
+     inkscape:snap-smooth-nodes="true">
+    <inkscape:grid
+       type="xygrid"
+       id="grid3336"
+       empspacing="4" />
+  </sodipodi:namedview>
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer"
+     id="layer1"
+     transform="translate(0,-1036.3622)">
+    <path
+       style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       id="path4155"
+       sodipodi:type="arc"
+       sodipodi:cx="744.13245"
+       sodipodi:cy="734.23291"
+       sodipodi:rx="4"
+       sodipodi:ry="4"
+       sodipodi:start="0"
+       sodipodi:end="3.1415927"
+       d="m 748.13245,734.23291 a 4,4 0 0 1 -2,3.4641 4,4 0 0 1 -4,0 4,4 0 0 1 -2,-3.4641 l 4,0 z"
+       inkscape:transform-center-y="0.58575321"
+       transform="matrix(0.70710678,0.70710678,-0.70710678,0.70710678,0,0)"
+       inkscape:transform-center-x="0.58575732" />
+    <circle
+       style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       id="path4159"
+       cx="7"
+       cy="1045.3622"
+       r="1" />
+    <path
+       style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       d="m 13.242641,1039.1196 a 6.0000172,6.0000172 0 0 0 -8.4852817,0 l 0.7071068,0.7071 a 5.0000172,5.0000172 0 0 1 7.0710679,0 5.0000172,5.0000172 0 0 1 0,7.071 l 0.707107,0.7071 a 6.0000172,6.0000172 0 0 0 0,-8.4852 z"
+       id="circle4163"
+       inkscape:connector-curvature="0"
+       inkscape:transform-center-y="-0.87867618"
+       inkscape:transform-center-x="-0.8786559" />
+    <path
+       style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       d="m 11.828427,1040.5338 a 4.0000172,4.0000172 0 0 0 -5.6568541,0 l 0.7071068,0.7071 a 3.0000174,3.0000174 0 0 1 4.2426403,0 3.0000174,3.0000174 0 0 1 0,4.2426 l 0.707107,0.7071 a 4.0000172,4.0000172 0 0 0 0,-5.6568 z"
+       id="circle4168"
+       inkscape:connector-curvature="0"
+       inkscape:transform-center-y="-0.58578284"
+       inkscape:transform-center-x="-0.58576926" />
+    <path
+       style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       d="m 10.414214,1041.948 a 2,2 0 0 0 -2.8284276,0 l 0.7071068,0.7071 a 1.0000174,1.0000174 0 0 1 1.4142136,0 1.0000174,1.0000174 0 0 1 0,1.4142 l 0.7071072,0.7071 a 2,2 0 0 0 0,-2.8284 z"
+       id="circle4172"
+       inkscape:connector-curvature="0"
+       inkscape:transform-center-y="-0.29289334"
+       inkscape:transform-center-x="-0.29288664" />
+    <path
+       style="fill:#fc9c9c;fill-opacity:0.99607843;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       d="m 1,1051.3622 4,-5 1,0 0,5 z"
+       id="path4181"
+       inkscape:connector-curvature="0"
+       sodipodi:nodetypes="ccccc" />
+  </g>
+</svg>