diff options
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/instance_placeholder.cpp | 74 | ||||
-rw-r--r-- | scene/main/instance_placeholder.h | 37 | ||||
-rw-r--r-- | scene/main/node.cpp | 202 | ||||
-rw-r--r-- | scene/main/node.h | 44 | ||||
-rw-r--r-- | scene/main/scene_main_loop.cpp | 589 | ||||
-rw-r--r-- | scene/main/scene_main_loop.h | 94 | ||||
-rw-r--r-- | scene/main/timer.cpp | 5 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 78 | ||||
-rw-r--r-- | scene/main/viewport.h | 5 |
9 files changed, 1093 insertions, 35 deletions
diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp new file mode 100644 index 0000000000..370eb1e74a --- /dev/null +++ b/scene/main/instance_placeholder.cpp @@ -0,0 +1,74 @@ +#include "instance_placeholder.h" + +#include "scene/resources/packed_scene.h" +#include "io/resource_loader.h" + +bool InstancePlaceholder::_set(const StringName& p_name, const Variant& p_value) { + + PropSet ps; + ps.name=p_name; + ps.value=p_value; + stored_values.push_back(ps); + return true; +} + +bool InstancePlaceholder::_get(const StringName& p_name,Variant &r_ret) const{ + + return false; +} +void InstancePlaceholder::_get_property_list( List<PropertyInfo> *p_list) const{ + + +} + + +void InstancePlaceholder::set_path(const String& p_name) { + + path=p_name; +} + +String InstancePlaceholder::get_path() const { + + return path; +} +void InstancePlaceholder::replace_by_instance(const Ref<PackedScene> &p_custom_scene){ + + ERR_FAIL_COND(!is_inside_tree()); + + Node *base = get_parent(); + if (!base) + return; + + Ref<PackedScene> ps; + if (p_custom_scene.is_valid()) + ps = p_custom_scene; + else + ps = ResourceLoader::load(path,"PackedScene"); + + if (!ps.is_valid()) + return; + Node *scene = ps->instance(); + scene->set_name(get_name()); + int pos = get_position_in_parent(); + + for(List<PropSet>::Element *E=stored_values.front();E;E=E->next()) { + scene->set(E->get().name,E->get().value); + } + + queue_delete(); + + base->remove_child(this); + base->add_child(scene); + base->move_child(scene,pos); + +} + +void InstancePlaceholder::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("replace_by_instance","custom_scene:PackedScene"),&InstancePlaceholder::replace_by_instance,DEFVAL(Variant())); +} + +InstancePlaceholder::InstancePlaceholder() { + + +} diff --git a/scene/main/instance_placeholder.h b/scene/main/instance_placeholder.h new file mode 100644 index 0000000000..e9e76e7a2d --- /dev/null +++ b/scene/main/instance_placeholder.h @@ -0,0 +1,37 @@ +#ifndef INSTANCE_PLACEHOLDER_H +#define INSTANCE_PLACEHOLDER_H + +#include "scene/main/node.h" + +class PackedScene; + +class InstancePlaceholder : public Node { + + OBJ_TYPE(InstancePlaceholder,Node); + + String path; + struct PropSet { + StringName name; + Variant value; + }; + + List<PropSet> stored_values; + +protected: + bool _set(const StringName& p_name, const Variant& p_value); + bool _get(const StringName& p_name,Variant &r_ret) const; + void _get_property_list( List<PropertyInfo> *p_list) const; + + static void _bind_methods(); + +public: + + void set_path(const String& p_name); + String get_path() const; + + void replace_by_instance(const Ref<PackedScene>& p_custom_scene=Ref<PackedScene>()); + + InstancePlaceholder(); +}; + +#endif // INSTANCE_PLACEHOLDER_H diff --git a/scene/main/node.cpp b/scene/main/node.cpp index ab530866bb..631dc8dcc7 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -196,6 +196,14 @@ void Node::_propagate_enter_tree() { } data.blocked--; + +#ifdef DEBUG_ENABLED + + if (ScriptDebugger::get_singleton() && data.filename!=String()) { + //used for live edit + data.tree->live_scene_edit_cache[data.filename].insert(this); + } +#endif // enter groups } @@ -205,6 +213,28 @@ void Node::_propagate_exit_tree() { //block while removing children +#ifdef DEBUG_ENABLED + + if (ScriptDebugger::get_singleton() && data.filename!=String()) { + //used for live edit + Map<String,Set<Node*> >::Element *E=data.tree->live_scene_edit_cache.find(data.filename); + if (E) { + E->get().erase(this); + if (E->get().size()==0) { + data.tree->live_scene_edit_cache.erase(E); + } + } + + Map<Node*,Map<ObjectID,Node*> >::Element *F=data.tree->live_edit_remove_list.find(this); + if (F) { + for (Map<ObjectID,Node*>::Element*G=F->get().front();G;G=G->next()) { + + memdelete(G->get()); + } + data.tree->live_edit_remove_list.erase(F); + } + } +#endif data.blocked++; for (int i=data.children.size()-1;i>=0;i--) { @@ -552,6 +582,52 @@ void Node::set_human_readable_collision_renaming(bool p_enabled) { } + +String Node::validate_child_name(const String& p_name) const { + + //this approach to autoset node names is human readable but very slow + //it's turned on while running in the editor + + String basename = p_name; + + if (basename==String()) { + + return String(); + } + + int val=1; + + for(;;) { + + String attempted = val > 1 ? (basename + " " +itos(val) ) : basename; + + bool found=false; + + for (int i=0;i<data.children.size();i++) { + + //if (data.children[i]==p_child) + // continue; + if (data.children[i]->get_name() == attempted) { + found=true; + break; + } + + } + + if (found) { + + val++; + continue; + } + + return attempted; + break; + } + + return basename; + +} + void Node::_validate_child_name(Node *p_child) { /* Make sure the name is unique */ @@ -641,6 +717,7 @@ void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) { p_child->data.pos=data.children.size(); data.children.push_back( p_child ); p_child->data.parent=this; + p_child->notification(NOTIFICATION_PARENTED); if (data.tree) { p_child->_set_tree(data.tree); @@ -649,7 +726,6 @@ void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) { /* Notify */ //recognize childs created in this node constructor p_child->data.parent_owned=data.in_constructor; - p_child->notification(NOTIFICATION_PARENTED); add_child_notify(p_child); @@ -765,6 +841,20 @@ Node *Node::get_child(int p_index) const { return data.children[p_index]; } + +Node *Node::_get_child_by_name(const StringName& p_name) const { + + int cc=data.children.size(); + Node* const* cd=data.children.ptr(); + + for(int i=0;i<cc;i++){ + if (cd[i]->data.name==p_name) + return cd[i]; + } + + return NULL; +} + Node *Node::_get_node(const NodePath& p_path) const { ERR_FAIL_COND_V( !data.inside_tree && p_path.is_absolute(), NULL ); @@ -830,8 +920,10 @@ Node *Node::_get_node(const NodePath& p_path) const { Node *Node::get_node(const NodePath& p_path) const { Node *node = _get_node(p_path); - ERR_EXPLAIN("Node not found: "+p_path); - ERR_FAIL_COND_V(!node,NULL); + if (!node) { + ERR_EXPLAIN("Node not found: "+p_path); + ERR_FAIL_COND_V(!node,NULL); + } return node; } @@ -960,6 +1052,7 @@ void Node::get_owned_by(Node *p_by,List<Node*> *p_owned) { void Node::_set_owner_nocheck(Node* p_owner) { + ERR_FAIL_COND(data.owner); data.owner=p_owner; data.owner->data.owned.push_back( this ); data.OW = data.owner->data.owned.back(); @@ -1256,7 +1349,29 @@ String Node::get_filename() const { return data.filename; } +void Node::set_editable_instance(Node* p_node,bool p_editable) { + + ERR_FAIL_NULL(p_node); + ERR_FAIL_COND(!is_a_parent_of(p_node)); + NodePath p = get_path_to(p_node); + if (!p_editable) + data.editable_instances.erase(p); + else + data.editable_instances[p]=true; + +} + +bool Node::is_editable_instance(Node *p_node) const { + + if (!p_node) + return false; //easier, null is never editable :) + ERR_FAIL_COND_V(!is_a_parent_of(p_node),false); + NodePath p = get_path_to(p_node); + return data.editable_instances.has(p); +} + +#if 0 void Node::generate_instance_state() { @@ -1307,13 +1422,36 @@ Dictionary Node::get_instance_state() const { return data.instance_state; } -Vector<StringName> Node::get_instance_groups() const { +#endif + +void Node::set_scene_instance_state(const Ref<SceneState>& p_state) { - return data.instance_groups; + data.instance_state=p_state; } -Vector<Node::Connection> Node::get_instance_connections() const{ - return data.instance_connections; +Ref<SceneState> Node::get_scene_instance_state() const{ + + return data.instance_state; +} + +void Node::set_scene_inherited_state(const Ref<SceneState>& p_state) { + + data.inherited_state=p_state; +} + +Ref<SceneState> Node::get_scene_inherited_state() const{ + + return data.inherited_state; +} + +void Node::set_scene_instance_load_placeholder(bool p_enable) { + + data.use_placeholder=p_enable; +} + +bool Node::get_scene_instance_load_placeholder() const{ + + return data.use_placeholder; } int Node::get_position_in_parent() const { @@ -1323,18 +1461,31 @@ int Node::get_position_in_parent() const { -Node *Node::duplicate() const { +Node *Node::duplicate(bool p_use_instancing) const { Node *node=NULL; - Object *obj = ObjectTypeDB::instance(get_type()); - ERR_FAIL_COND_V(!obj,NULL); - node = obj->cast_to<Node>(); - if (!node) - memdelete(obj); - ERR_FAIL_COND_V(!node,NULL); + bool instanced=false; + + if (p_use_instancing && get_filename()!=String()) { + + Ref<PackedScene> res = ResourceLoader::load(get_filename()); + ERR_FAIL_COND_V(res.is_null(),NULL); + node=res->instance(); + ERR_FAIL_COND_V(!node,NULL); + + instanced=true; + + } else { + Object *obj = ObjectTypeDB::instance(get_type()); + ERR_FAIL_COND_V(!obj,NULL); + node = obj->cast_to<Node>(); + if (!node) + memdelete(obj); + ERR_FAIL_COND_V(!node,NULL); + } if (get_filename()!="") { //an instance @@ -1360,7 +1511,10 @@ Node *Node::duplicate() const { if (get_child(i)->data.parent_owned) continue; - Node *dup = get_child(i)->duplicate(); + if (instanced && get_child(i)->data.owner==this) + continue; //part of instance + + Node *dup = get_child(i)->duplicate(p_use_instancing); if (!dup) { memdelete(node); @@ -1816,6 +1970,16 @@ void Node::get_argument_options(const StringName& p_function,int p_idx,List<Stri Object::get_argument_options(p_function,p_idx,r_options); } + +void Node::clear_internal_tree_resource_paths() { + + clear_internal_resource_paths(); + for(int i=0;i<data.children.size();i++) { + data.children[i]->clear_internal_tree_resource_paths(); + } + +} + void Node::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_name","name"),&Node::set_name); @@ -1829,7 +1993,7 @@ void Node::_bind_methods() { ObjectTypeDB::bind_method(_MD("has_node","path"),&Node::has_node); ObjectTypeDB::bind_method(_MD("get_node:Node","path"),&Node::get_node); ObjectTypeDB::bind_method(_MD("get_parent:Parent"),&Node::get_parent); - ObjectTypeDB::bind_method(_MD("find_node:Node","mask","recursive","owned"),&Node::get_node,DEFVAL(true),DEFVAL(true)); + ObjectTypeDB::bind_method(_MD("find_node:Node","mask","recursive","owned"),&Node::find_node,DEFVAL(true),DEFVAL(true)); ObjectTypeDB::bind_method(_MD("has_node_and_resource","path"),&Node::has_node_and_resource); ObjectTypeDB::bind_method(_MD("get_node_and_resource","path"),&Node::_get_node_and_resource); @@ -1872,7 +2036,7 @@ void Node::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_tree:SceneTree"),&Node::get_tree); - ObjectTypeDB::bind_method(_MD("duplicate:Node"),&Node::duplicate); + ObjectTypeDB::bind_method(_MD("duplicate:Node","use_instancing"),&Node::duplicate,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("replace_by","node:Node","keep_data"),&Node::replace_by,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("get_viewport"),&Node::get_viewport); @@ -1881,7 +2045,7 @@ void Node::_bind_methods() { #ifdef TOOLS_ENABLED ObjectTypeDB::bind_method(_MD("_set_import_path","import_path"),&Node::set_import_path); ObjectTypeDB::bind_method(_MD("_get_import_path"),&Node::get_import_path); - ADD_PROPERTY( PropertyInfo(Variant::NODE_PATH,"_import_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_import_path"),_SCS("_get_import_path")); + ADD_PROPERTYNZ( PropertyInfo(Variant::NODE_PATH,"_import_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_import_path"),_SCS("_get_import_path")); #endif @@ -1947,6 +2111,7 @@ Node::Node() { data.parent_owned=false; data.in_constructor=true; data.viewport=NULL; + data.use_placeholder=false; } Node::~Node() { @@ -1963,3 +2128,4 @@ Node::~Node() { } +//////////////////////////////// diff --git a/scene/main/node.h b/scene/main/node.h index a89a6abf33..87fa4dd6ca 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -38,6 +38,7 @@ class Viewport; +class SceneState; class Node : public Object { OBJ_TYPE( Node, Object ); @@ -69,9 +70,10 @@ private: struct Data { String filename; - Dictionary instance_state; - Vector<StringName> instance_groups; - Vector<Connection> instance_connections; + Ref<SceneState> instance_state; + Ref<SceneState> inherited_state; + + HashMap<NodePath,int> editable_instances; Node *parent; Node *owner; @@ -96,6 +98,7 @@ private: PauseMode pause_mode; Node *pause_owner; // variables used to properly sort the node when processing, ignored otherwise + //should move all the stuff below to bits bool fixed_process; bool idle_process; @@ -105,6 +108,9 @@ private: bool parent_owned; bool in_constructor; + bool use_placeholder; + + } data; @@ -112,6 +118,7 @@ private: virtual bool _use_builtin_script() const { return true; } Node *_get_node(const NodePath& p_path) const; + Node *_get_child_by_name(const StringName& p_name) const; @@ -151,7 +158,7 @@ protected: static void _bind_methods(); -friend class PackedScene; +friend class SceneState; void _add_child_nocheck(Node* p_child,const StringName& p_name); void _set_owner_nocheck(Node* p_owner); @@ -208,7 +215,7 @@ public: struct GroupInfo { - String name; + StringName name; bool persistent; }; @@ -229,7 +236,11 @@ public: void set_filename(const String& p_filename); String get_filename() const; - + + void set_editable_instance(Node* p_node,bool p_editable); + bool is_editable_instance(Node* p_node) const; + + /* NOTIFICATIONS */ void propagate_notification(int p_notification); @@ -255,15 +266,20 @@ public: int get_position_in_parent() const; - Node *duplicate() const; + Node *duplicate(bool p_use_instancing=false) const; Node *duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const; + //Node *clone_tree() const; // used by editors, to save what has changed only - void generate_instance_state(); - Dictionary get_instance_state() const; - Vector<StringName> get_instance_groups() const; - Vector<Connection> get_instance_connections() const; + void set_scene_instance_state(const Ref<SceneState>& p_state); + Ref<SceneState> get_scene_instance_state() const; + + void set_scene_inherited_state(const Ref<SceneState>& p_state); + Ref<SceneState> get_scene_inherited_state() const; + + void set_scene_instance_load_placeholder(bool p_enable); + bool get_scene_instance_load_placeholder() const; static Vector<Variant> make_binds(VARIANT_ARG_LIST); @@ -275,6 +291,8 @@ public: static void print_stray_nodes(); + String validate_child_name(const String& p_name) const; + void queue_delete(); //shitty hacks for speed @@ -290,6 +308,8 @@ public: void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const; + void clear_internal_tree_resource_paths(); + _FORCE_INLINE_ Viewport *get_viewport() const { return data.viewport; } /* CANVAS */ @@ -302,6 +322,4 @@ public: typedef Set<Node*,Node::Comparator> NodeSet; - - #endif diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 584b40337f..adf053f5c9 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -42,6 +42,8 @@ #include "io/resource_loader.h" #include "viewport.h" #include "scene/resources/packed_scene.h" +#include "scene/resources/material.h" +#include "scene/resources/mesh.h" void SceneTree::tree_changed() { @@ -470,7 +472,6 @@ void SceneTree::init() { input_handled=false; - editor_hint=false; pause=false; root->_set_tree(this); @@ -624,6 +625,175 @@ bool SceneTree::is_editor_hint() const { return editor_hint; } +void SceneTree::set_debug_collisions_hint(bool p_enabled) { + + debug_collisions_hint=p_enabled; +} + +bool SceneTree::is_debugging_collisions_hint() const { + + return debug_collisions_hint; +} + +void SceneTree::set_debug_navigation_hint(bool p_enabled) { + + debug_navigation_hint=p_enabled; +} + +bool SceneTree::is_debugging_navigation_hint() const { + + return debug_navigation_hint; +} + +void SceneTree::set_debug_collisions_color(const Color& p_color) { + + debug_collisions_color=p_color; +} + +Color SceneTree::get_debug_collisions_color() const { + + return debug_collisions_color; +} + +void SceneTree::set_debug_collision_contact_color(const Color& p_color) { + + debug_collision_contact_color=p_color; +} + +Color SceneTree::get_debug_collision_contact_color() const { + + return debug_collision_contact_color; +} + +void SceneTree::set_debug_navigation_color(const Color& p_color) { + + debug_navigation_color=p_color; +} + +Color SceneTree::get_debug_navigation_color() const { + + return debug_navigation_color; +} + +void SceneTree::set_debug_navigation_disabled_color(const Color& p_color) { + + debug_navigation_disabled_color=p_color; +} + +Color SceneTree::get_debug_navigation_disabled_color() const { + + return debug_navigation_disabled_color; +} + +Ref<Material> SceneTree::get_debug_navigation_material() { + + if (navigation_material.is_valid()) + return navigation_material; + + Ref<FixedMaterial> line_material = Ref<FixedMaterial>( memnew( FixedMaterial )); + line_material->set_flag(Material::FLAG_UNSHADED, true); + line_material->set_line_width(3.0); + line_material->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true); + line_material->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY, true); + line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_navigation_color()); + + navigation_material=line_material; + + return navigation_material; + +} + +Ref<Material> SceneTree::get_debug_navigation_disabled_material(){ + + if (navigation_disabled_material.is_valid()) + return navigation_disabled_material; + + Ref<FixedMaterial> line_material = Ref<FixedMaterial>( memnew( FixedMaterial )); + line_material->set_flag(Material::FLAG_UNSHADED, true); + line_material->set_line_width(3.0); + line_material->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true); + line_material->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY, true); + line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_navigation_disabled_color()); + + navigation_disabled_material=line_material; + + return navigation_disabled_material; + +} +Ref<Material> SceneTree::get_debug_collision_material() { + + if (collision_material.is_valid()) + return collision_material; + + + Ref<FixedMaterial> line_material = Ref<FixedMaterial>( memnew( FixedMaterial )); + line_material->set_flag(Material::FLAG_UNSHADED, true); + line_material->set_line_width(3.0); + line_material->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true); + line_material->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY, true); + line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_collisions_color()); + + collision_material=line_material; + + return collision_material; +} + +Ref<Mesh> SceneTree::get_debug_contact_mesh() { + + if (debug_contact_mesh.is_valid()) + return debug_contact_mesh; + + debug_contact_mesh = Ref<Mesh>( memnew( Mesh ) ); + + Ref<FixedMaterial> mat = memnew( FixedMaterial ); + mat->set_flag(Material::FLAG_UNSHADED,true); + mat->set_flag(Material::FLAG_DOUBLE_SIDED,true); + mat->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true); + mat->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_collision_contact_color()); + + Vector3 diamond[6]={ + Vector3(-1, 0, 0), + Vector3( 1, 0, 0), + Vector3( 0, -1, 0), + Vector3( 0, 1, 0), + Vector3( 0, 0, -1), + Vector3( 0, 0, 1) + }; + + int diamond_faces[8*3]={ + 0,2,4, + 0,3,4, + 1,2,4, + 1,3,4, + 0,2,5, + 0,3,5, + 1,2,5, + 1,3,5, + }; + + DVector<int> indices; + for(int i=0;i<8*3;i++) + indices.push_back(diamond_faces[i]); + + DVector<Vector3> vertices; + for(int i=0;i<6;i++) + vertices.push_back(diamond[i]*0.1); + + Array arr; + arr.resize(Mesh::ARRAY_MAX); + arr[Mesh::ARRAY_VERTEX]=vertices; + arr[Mesh::ARRAY_INDEX]=indices; + + + debug_contact_mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES,arr); + debug_contact_mesh->surface_set_material(0,mat); + + return debug_contact_mesh; + +} + + + void SceneTree::set_pause(bool p_enabled) { if (p_enabled==pause) @@ -1044,7 +1214,371 @@ void SceneTree::add_current_scene(Node * p_current) { current_scene=p_current; root->add_child(p_current); } +#ifdef DEBUG_ENABLED + +void SceneTree::_live_edit_node_path_func(const NodePath &p_path,int p_id) { + + live_edit_node_path_cache[p_id]=p_path; +} + +void SceneTree::_live_edit_res_path_func(const String &p_path,int p_id) { + + live_edit_resource_cache[p_id]=p_path; +} + +void SceneTree::_live_edit_node_set_func(int p_id,const StringName& p_prop,const Variant& p_value) { + + if (!live_edit_node_path_cache.has(p_id)) + return; + + NodePath np = live_edit_node_path_cache[p_id]; + Node *base = NULL; + if (root->has_node(live_edit_root)) + base = root->get_node(live_edit_root); + + Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + if (!E) + return; //scene not editable + + for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + + Node *n=F->get(); + + if (base && !base->is_a_parent_of(n)) + continue; + + if (!n->has_node(np)) + continue; + Node *n2 = n->get_node(np); + + n2->set(p_prop,p_value); + } + +} + +void SceneTree::_live_edit_node_set_res_func(int p_id,const StringName& p_prop,const String& p_value) { + + RES r = ResourceLoader::load(p_value); + if (!r.is_valid()) + return; + _live_edit_node_set_func(p_id,p_prop,r); + +} +void SceneTree::_live_edit_node_call_func(int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) { + + if (!live_edit_node_path_cache.has(p_id)) + return; + + NodePath np = live_edit_node_path_cache[p_id]; + Node *base = NULL; + if (root->has_node(live_edit_root)) + base = root->get_node(live_edit_root); + + Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + if (!E) + return; //scene not editable + + for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + + Node *n=F->get(); + + if (base && !base->is_a_parent_of(n)) + continue; + + if (!n->has_node(np)) + continue; + Node *n2 = n->get_node(np); + + n2->call(p_method,VARIANT_ARG_PASS); + } +} +void SceneTree::_live_edit_res_set_func(int p_id,const StringName& p_prop,const Variant& p_value) { + + if (!live_edit_resource_cache.has(p_id)) + return; + + String resp = live_edit_resource_cache[p_id]; + + if (!ResourceCache::has(resp)) + return; + + RES r = ResourceCache::get(resp); + if (!r.is_valid()) + return; + + r->set(p_prop,p_value); +} +void SceneTree::_live_edit_res_set_res_func(int p_id,const StringName& p_prop,const String& p_value) { + + RES r = ResourceLoader::load(p_value); + if (!r.is_valid()) + return; + _live_edit_res_set_func(p_id,p_prop,r); + +} +void SceneTree::_live_edit_res_call_func(int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) { + + if (!live_edit_resource_cache.has(p_id)) + return; + + String resp = live_edit_resource_cache[p_id]; + + if (!ResourceCache::has(resp)) + return; + + RES r = ResourceCache::get(resp); + if (!r.is_valid()) + return; + + r->call(p_method,VARIANT_ARG_PASS); +} + +void SceneTree::_live_edit_root_func(const NodePath& p_scene_path,const String& p_scene_from) { + + live_edit_root=p_scene_path; + live_edit_scene=p_scene_from; +} + +void SceneTree::_live_edit_create_node_func(const NodePath& p_parent,const String& p_type,const String& p_name) { + + Node *base = NULL; + if (root->has_node(live_edit_root)) + base = root->get_node(live_edit_root); + + Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + if (!E) + return; //scene not editable + + for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + + Node *n=F->get(); + + if (base && !base->is_a_parent_of(n)) + continue; + + if (!n->has_node(p_parent)) + continue; + Node *n2 = n->get_node(p_parent); + + Object *o = ObjectTypeDB::instance(p_type); + if (!o) + continue; + Node *no=o->cast_to<Node>(); + no->set_name(p_name); + + n2->add_child(no); + } +} +void SceneTree::_live_edit_instance_node_func(const NodePath& p_parent,const String& p_path,const String& p_name){ + + Ref<PackedScene> ps = ResourceLoader::load(p_path); + + if (!ps.is_valid()) + return; + + Node *base = NULL; + if (root->has_node(live_edit_root)) + base = root->get_node(live_edit_root); + + Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + if (!E) + return; //scene not editable + + for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + + Node *n=F->get(); + + if (base && !base->is_a_parent_of(n)) + continue; + + if (!n->has_node(p_parent)) + continue; + Node *n2 = n->get_node(p_parent); + + + + Node *no=ps->instance(); + no->set_name(p_name); + + n2->add_child(no); + } +} +void SceneTree::_live_edit_remove_node_func(const NodePath& p_at){ + + Node *base = NULL; + if (root->has_node(live_edit_root)) + base = root->get_node(live_edit_root); + + Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + if (!E) + return; //scene not editable + + for(Set<Node*>::Element *F=E->get().front();F;) { + + Set<Node*>::Element *N=F->next(); + + Node *n=F->get(); + + if (base && !base->is_a_parent_of(n)) + continue; + + if (!n->has_node(p_at)) + continue; + Node *n2 = n->get_node(p_at); + + memdelete(n2); + + F=N; + + } +} +void SceneTree::_live_edit_remove_and_keep_node_func(const NodePath& p_at,ObjectID p_keep_id){ + + Node *base = NULL; + if (root->has_node(live_edit_root)) + base = root->get_node(live_edit_root); + + Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + if (!E) + return; //scene not editable + + + for(Set<Node*>::Element *F=E->get().front();F;) { + + Set<Node*>::Element *N=F->next(); + + Node *n=F->get(); + + if (base && !base->is_a_parent_of(n)) + continue; + + if (!n->has_node(p_at)) + continue; + + Node *n2 = n->get_node(p_at); + + n2->get_parent()->remove_child(n2); + + live_edit_remove_list[n][p_keep_id]=n2; + + F=N; + + } +} +void SceneTree::_live_edit_restore_node_func(ObjectID p_id,const NodePath& p_at,int p_at_pos){ + + + Node *base = NULL; + if (root->has_node(live_edit_root)) + base = root->get_node(live_edit_root); + + Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + if (!E) + return; //scene not editable + + for(Set<Node*>::Element *F=E->get().front();F;) { + + Set<Node*>::Element *N=F->next(); + + Node *n=F->get(); + + if (base && !base->is_a_parent_of(n)) + continue; + + if (!n->has_node(p_at)) + continue; + Node *n2 = n->get_node(p_at); + + Map<Node*,Map<ObjectID,Node*> >::Element *EN=live_edit_remove_list.find(n); + + if (!EN) + continue; + + Map<ObjectID,Node*>::Element *FN=EN->get().find(p_id); + + if (!FN) + continue; + n2->add_child(FN->get()); + + EN->get().erase(FN); + + if (EN->get().size()==0) { + live_edit_remove_list.erase(EN); + } + + F=N; + + } +} +void SceneTree::_live_edit_duplicate_node_func(const NodePath& p_at,const String& p_new_name){ + + Node *base = NULL; + if (root->has_node(live_edit_root)) + base = root->get_node(live_edit_root); + + Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + if (!E) + return; //scene not editable + + for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + + Node *n=F->get(); + + if (base && !base->is_a_parent_of(n)) + continue; + + if (!n->has_node(p_at)) + continue; + Node *n2 = n->get_node(p_at); + + Node *dup = n2->duplicate(true); + + if (!dup) + continue; + + dup->set_name(p_new_name); + n2->get_parent()->add_child(dup); + + } +} +void SceneTree::_live_edit_reparent_node_func(const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name,int p_at_pos){ + + Node *base = NULL; + if (root->has_node(live_edit_root)) + base = root->get_node(live_edit_root); + + Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + if (!E) + return; //scene not editable + + for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + + Node *n=F->get(); + + if (base && !base->is_a_parent_of(n)) + continue; + + if (!n->has_node(p_at)) + continue; + Node *nfrom = n->get_node(p_at); + + if (!n->has_node(p_new_place)) + continue; + Node *nto = n->get_node(p_new_place); + + nfrom->get_parent()->remove_child(nfrom); + nfrom->set_name(p_new_name); + + nto->add_child(nfrom); + if (p_at_pos>=0) + nto->move_child(nfrom,p_at_pos); + + } +} + + +#endif void SceneTree::_bind_methods() { @@ -1060,6 +1594,11 @@ void SceneTree::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_editor_hint","enable"),&SceneTree::set_editor_hint); ObjectTypeDB::bind_method(_MD("is_editor_hint"),&SceneTree::is_editor_hint); + ObjectTypeDB::bind_method(_MD("set_debug_collisions_hint","enable"),&SceneTree::set_debug_collisions_hint); + ObjectTypeDB::bind_method(_MD("is_debugging_collisions_hint"),&SceneTree::is_debugging_collisions_hint); + ObjectTypeDB::bind_method(_MD("set_debug_navigation_hint","enable"),&SceneTree::set_debug_navigation_hint); + ObjectTypeDB::bind_method(_MD("is_debugging_navigation_hint"),&SceneTree::is_debugging_navigation_hint); + #ifdef TOOLS_ENABLED ObjectTypeDB::bind_method(_MD("set_edited_scene_root","scene"),&SceneTree::set_edited_scene_root); ObjectTypeDB::bind_method(_MD("get_edited_scene_root"),&SceneTree::get_edited_scene_root); @@ -1108,6 +1647,9 @@ void SceneTree::_bind_methods() { ADD_SIGNAL( MethodInfo("node_removed",PropertyInfo( Variant::OBJECT, "node") ) ); ADD_SIGNAL( MethodInfo("screen_resized") ); + ADD_SIGNAL( MethodInfo("idle_frame")); + ADD_SIGNAL( MethodInfo("fixed_frame")); + BIND_CONSTANT( GROUP_CALL_DEFAULT ); BIND_CONSTANT( GROUP_CALL_REVERSE ); BIND_CONSTANT( GROUP_CALL_REALTIME ); @@ -1123,10 +1665,23 @@ void SceneTree::_bind_methods() { } +SceneTree *SceneTree::singleton=NULL; + SceneTree::SceneTree() { + singleton=this; _quit=false; initialized=false; + editor_hint=false; + debug_collisions_hint=false; + debug_navigation_hint=false; + debug_collisions_color=GLOBAL_DEF("debug/collision_shape_color",Color(0.0,0.6,0.7,0.5)); + debug_collision_contact_color=GLOBAL_DEF("debug/collision_contact_color",Color(1.0,0.2,0.1,0.8)); + debug_navigation_color=GLOBAL_DEF("debug/navigation_geometry_color",Color(0.1,1.0,0.7,0.4)); + debug_navigation_disabled_color=GLOBAL_DEF("debug/navigation_disabled_geometry_color",Color(1.0,0.7,0.1,0.4)); + collision_debug_contacts=GLOBAL_DEF("debug/collision_max_contacts_displayed",10000); + + tree_version=1; fixed_process_time=1; idle_process_time=1; @@ -1166,8 +1721,36 @@ SceneTree::SceneTree() { edited_scene_root=NULL; #endif - ADD_SIGNAL( MethodInfo("idle_frame")); - ADD_SIGNAL( MethodInfo("fixed_frame")); +#ifdef DEBUG_ENABLED + + + live_edit_funcs.udata=this; + live_edit_funcs.node_path_func=_live_edit_node_path_funcs; + live_edit_funcs.res_path_func=_live_edit_res_path_funcs; + live_edit_funcs.node_set_func=_live_edit_node_set_funcs; + live_edit_funcs.node_set_res_func=_live_edit_node_set_res_funcs; + live_edit_funcs.node_call_func=_live_edit_node_call_funcs; + live_edit_funcs.res_set_func=_live_edit_res_set_funcs; + live_edit_funcs.res_set_res_func=_live_edit_res_set_res_funcs; + live_edit_funcs.res_call_func=_live_edit_res_call_funcs; + live_edit_funcs.root_func=_live_edit_root_funcs; + + live_edit_funcs.tree_create_node_func=_live_edit_create_node_funcs; + live_edit_funcs.tree_instance_node_func=_live_edit_instance_node_funcs; + live_edit_funcs.tree_remove_node_func=_live_edit_remove_node_funcs; + live_edit_funcs.tree_remove_and_keep_node_func=_live_edit_remove_and_keep_node_funcs; + live_edit_funcs.tree_restore_node_func=_live_edit_restore_node_funcs; + live_edit_funcs.tree_duplicate_node_func=_live_edit_duplicate_node_funcs; + live_edit_funcs.tree_reparent_node_func=_live_edit_reparent_node_funcs; + + if (ScriptDebugger::get_singleton()) { + ScriptDebugger::get_singleton()->set_live_edit_funcs(&live_edit_funcs); + } + + live_edit_root=NodePath("/root"); + +#endif + } diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h index e49c150fbf..8d9021d24e 100644 --- a/scene/main/scene_main_loop.h +++ b/scene/main/scene_main_loop.h @@ -45,6 +45,8 @@ class SceneTree; class PackedScene; class Node; class Viewport; +class Material; +class Mesh; class SceneTree : public MainLoop { @@ -87,6 +89,8 @@ private: uint32_t last_id; bool editor_hint; + bool debug_collisions_hint; + bool debug_navigation_hint; bool pause; int root_lock; @@ -138,9 +142,20 @@ private: Node *current_scene; + Color debug_collisions_color; + Color debug_collision_contact_color; + Color debug_navigation_color; + Color debug_navigation_disabled_color; + Ref<Mesh> debug_contact_mesh; + Ref<Material> navigation_material; + Ref<Material> navigation_disabled_material; + Ref<Material> collision_material; + int collision_debug_contacts; + void _change_scene(Node* p_to); //void _call_group(uint32_t p_call_flags,const StringName& p_group,const StringName& p_function,const Variant& p_arg1,const Variant& p_arg2); + static SceneTree *singleton; friend class Node; void tree_changed(); @@ -164,6 +179,58 @@ friend class Viewport; SelfList<Node>::List xform_change_list; +#ifdef DEBUG_ENABLED + + Map<int,NodePath> live_edit_node_path_cache; + Map<int,String> live_edit_resource_cache; + + NodePath live_edit_root; + String live_edit_scene; + + Map<String,Set<Node*> > live_scene_edit_cache; + Map<Node*,Map<ObjectID,Node*> > live_edit_remove_list; + + ScriptDebugger::LiveEditFuncs live_edit_funcs; + + void _live_edit_node_path_func(const NodePath &p_path,int p_id) ; + void _live_edit_res_path_func(const String &p_path,int p_id) ; + + void _live_edit_node_set_func(int p_id,const StringName& p_prop,const Variant& p_value) ; + void _live_edit_node_set_res_func(int p_id,const StringName& p_prop,const String& p_value) ; + void _live_edit_node_call_func(int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) ; + void _live_edit_res_set_func(int p_id,const StringName& p_prop,const Variant& p_value) ; + void _live_edit_res_set_res_func(int p_id,const StringName& p_prop,const String& p_value) ; + void _live_edit_res_call_func(int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) ; + void _live_edit_root_func(const NodePath& p_scene_path,const String& p_scene_from) ; + + void _live_edit_create_node_func(const NodePath& p_parent,const String& p_type,const String& p_name); + void _live_edit_instance_node_func(const NodePath& p_parent,const String& p_path,const String& p_name); + void _live_edit_remove_node_func(const NodePath& p_at); + void _live_edit_remove_and_keep_node_func(const NodePath& p_at,ObjectID p_keep_id); + void _live_edit_restore_node_func(ObjectID p_id,const NodePath& p_at,int p_at_pos); + void _live_edit_duplicate_node_func(const NodePath& p_at,const String& p_new_name); + void _live_edit_reparent_node_func(const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name,int p_at_pos); + + static void _live_edit_node_path_funcs(void *self,const NodePath &p_path,int p_id) { reinterpret_cast<SceneTree*>(self)->_live_edit_node_path_func(p_path,p_id); } + static void _live_edit_res_path_funcs(void *self,const String &p_path,int p_id) { reinterpret_cast<SceneTree*>(self)->_live_edit_res_path_func(p_path,p_id); } + + static void _live_edit_node_set_funcs(void *self,int p_id,const StringName& p_prop,const Variant& p_value) { reinterpret_cast<SceneTree*>(self)->_live_edit_node_set_func(p_id,p_prop,p_value); } + static void _live_edit_node_set_res_funcs(void *self,int p_id,const StringName& p_prop,const String& p_value) { reinterpret_cast<SceneTree*>(self)->_live_edit_node_set_res_func(p_id,p_prop,p_value); } + static void _live_edit_node_call_funcs(void *self,int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) { reinterpret_cast<SceneTree*>(self)->_live_edit_node_call_func(p_id,p_method,VARIANT_ARG_PASS); } + static void _live_edit_res_set_funcs(void *self,int p_id,const StringName& p_prop,const Variant& p_value) { reinterpret_cast<SceneTree*>(self)->_live_edit_res_set_func(p_id,p_prop,p_value); } + static void _live_edit_res_set_res_funcs(void *self,int p_id,const StringName& p_prop,const String& p_value) { reinterpret_cast<SceneTree*>(self)->_live_edit_res_set_res_func(p_id,p_prop,p_value); } + static void _live_edit_res_call_funcs(void *self,int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) { reinterpret_cast<SceneTree*>(self)->_live_edit_res_call_func(p_id,p_method,VARIANT_ARG_PASS); } + static void _live_edit_root_funcs(void *self, const NodePath& p_scene_path,const String& p_scene_from) { reinterpret_cast<SceneTree*>(self)->_live_edit_root_func(p_scene_path,p_scene_from); } + + static void _live_edit_create_node_funcs(void* self,const NodePath& p_parent,const String& p_type,const String& p_name) { reinterpret_cast<SceneTree*>(self)->_live_edit_create_node_func(p_parent,p_type,p_name); } + static void _live_edit_instance_node_funcs(void* self,const NodePath& p_parent,const String& p_path,const String& p_name) { reinterpret_cast<SceneTree*>(self)->_live_edit_instance_node_func(p_parent,p_path,p_name); } + static void _live_edit_remove_node_funcs(void* self,const NodePath& p_at) { reinterpret_cast<SceneTree*>(self)->_live_edit_remove_node_func(p_at); } + static void _live_edit_remove_and_keep_node_funcs(void* self,const NodePath& p_at,ObjectID p_keep_id) { reinterpret_cast<SceneTree*>(self)->_live_edit_remove_and_keep_node_func(p_at,p_keep_id); } + static void _live_edit_restore_node_funcs(void* self,ObjectID p_id,const NodePath& p_at,int p_at_pos) { reinterpret_cast<SceneTree*>(self)->_live_edit_restore_node_func(p_id,p_at,p_at_pos); } + static void _live_edit_duplicate_node_funcs(void* self,const NodePath& p_at,const String& p_new_name) { reinterpret_cast<SceneTree*>(self)->_live_edit_duplicate_node_func(p_at,p_new_name); } + static void _live_edit_reparent_node_funcs(void* self,const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name,int p_at_pos) { reinterpret_cast<SceneTree*>(self)->_live_edit_reparent_node_func(p_at,p_new_place,p_new_name,p_at_pos); } + +#endif protected: void _notification(int p_notification); @@ -218,6 +285,32 @@ public: void set_camera(const RID& p_camera); RID get_camera() const; + void set_debug_collisions_hint(bool p_enabled); + bool is_debugging_collisions_hint() const; + + void set_debug_navigation_hint(bool p_enabled); + bool is_debugging_navigation_hint() const; + + void set_debug_collisions_color(const Color& p_color); + Color get_debug_collisions_color() const; + + void set_debug_collision_contact_color(const Color& p_color); + Color get_debug_collision_contact_color() const; + + void set_debug_navigation_color(const Color& p_color); + Color get_debug_navigation_color() const; + + void set_debug_navigation_disabled_color(const Color& p_color); + Color get_debug_navigation_disabled_color() const; + + + Ref<Material> get_debug_navigation_material(); + Ref<Material> get_debug_navigation_disabled_material(); + Ref<Material> get_debug_collision_material(); + Ref<Mesh> get_debug_contact_mesh(); + + int get_collision_debug_contact_count() { return collision_debug_contacts; } + int64_t get_frame() const; int get_node_count() const; @@ -245,6 +338,7 @@ public: //used by Main::start, don't use otherwise void add_current_scene(Node * p_current); + static SceneTree* get_singleton() { return singleton; } SceneTree(); diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index 3a80382a40..1bd22a9db1 100644 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -182,11 +182,14 @@ void Timer::_bind_methods() { ADD_SIGNAL( MethodInfo("timeout") ); - ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_timer_process_mode"), _SCS("get_timer_process_mode")); + ADD_PROPERTY( PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_timer_process_mode"), _SCS("get_timer_process_mode") ); ADD_PROPERTY( PropertyInfo(Variant::REAL, "wait_time", PROPERTY_HINT_EXP_RANGE, "0.01,4096,0.01" ), _SCS("set_wait_time"), _SCS("get_wait_time") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL, "one_shot" ), _SCS("set_one_shot"), _SCS("is_one_shot") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL, "autostart" ), _SCS("set_autostart"), _SCS("has_autostart") ); + BIND_CONSTANT( TIMER_PROCESS_FIXED ); + BIND_CONSTANT( TIMER_PROCESS_IDLE ); + } Timer::Timer() { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 3bb64e54c6..d19b5767c2 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -37,6 +37,7 @@ #include "servers/spatial_sound_2d_server.h" #include "scene/gui/control.h" #include "scene/3d/camera.h" +#include "scene/resources/mesh.h" #include "scene/3d/spatial_indexer.h" #include "scene/3d/collision_object.h" @@ -319,6 +320,23 @@ void Viewport::_notification(int p_what) { } add_to_group("_viewports"); + if (get_tree()->is_debugging_collisions_hint()) { + //2D + Physics2DServer::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(),get_tree()->get_collision_debug_contact_count()); + contact_2d_debug=VisualServer::get_singleton()->canvas_item_create(); + VisualServer::get_singleton()->canvas_item_set_parent(contact_2d_debug,find_world_2d()->get_canvas()); + //3D + PhysicsServer::get_singleton()->space_set_debug_contacts(find_world()->get_space(),get_tree()->get_collision_debug_contact_count()); + contact_3d_debug_multimesh=VisualServer::get_singleton()->multimesh_create(); + VisualServer::get_singleton()->multimesh_set_instance_count(contact_3d_debug_multimesh,get_tree()->get_collision_debug_contact_count()); + VisualServer::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh,0); + VisualServer::get_singleton()->multimesh_set_mesh(contact_3d_debug_multimesh,get_tree()->get_debug_contact_mesh()->get_rid()); + contact_3d_debug_instance=VisualServer::get_singleton()->instance_create(); + VisualServer::get_singleton()->instance_set_base(contact_3d_debug_instance,contact_3d_debug_multimesh); + VisualServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance,find_world()->get_scenario()); + VisualServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance,VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS,true); + + } } break; case NOTIFICATION_READY: { @@ -351,11 +369,69 @@ void Viewport::_notification(int p_what) { VisualServer::get_singleton()->viewport_set_scenario(viewport,RID()); SpatialSoundServer::get_singleton()->listener_set_space(listener,RID()); VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas); + if (contact_2d_debug.is_valid()) { + VisualServer::get_singleton()->free(contact_2d_debug); + contact_2d_debug=RID(); + } + + if (contact_3d_debug_multimesh.is_valid()) { + VisualServer::get_singleton()->free(contact_3d_debug_multimesh); + VisualServer::get_singleton()->free(contact_3d_debug_instance); + contact_3d_debug_instance=RID(); + contact_3d_debug_multimesh=RID(); + } + remove_from_group("_viewports"); } break; case NOTIFICATION_FIXED_PROCESS: { + + if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) { + + VisualServer::get_singleton()->canvas_item_clear(contact_2d_debug); + VisualServer::get_singleton()->canvas_item_raise(contact_2d_debug); + + Vector<Vector2> points = Physics2DServer::get_singleton()->space_get_contacts(find_world_2d()->get_space()); + int point_count = Physics2DServer::get_singleton()->space_get_contact_count(find_world_2d()->get_space()); + Color ccol = get_tree()->get_debug_collision_contact_color(); + + + for(int i=0;i<point_count;i++) { + + VisualServer::get_singleton()->canvas_item_add_rect(contact_2d_debug,Rect2(points[i]-Vector2(2,2),Vector2(5,5)),ccol); + } + } + + if (get_tree()->is_debugging_collisions_hint() && contact_3d_debug_multimesh.is_valid()) { + + + Vector<Vector3> points = PhysicsServer::get_singleton()->space_get_contacts(find_world()->get_space()); + int point_count = PhysicsServer::get_singleton()->space_get_contact_count(find_world()->get_space()); + + + VS::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh,point_count); + + if (point_count>0) { + AABB aabb; + + Transform t; + for(int i=0;i<point_count;i++) { + + if (i==0) + aabb.pos=points[i]; + else + aabb.expand_to(points[i]); + t.origin=points[i]; + VisualServer::get_singleton()->multimesh_instance_set_transform(contact_3d_debug_multimesh,i,t); + } + aabb.grow(aabb.get_longest_axis_size()*0.01); + VisualServer::get_singleton()->multimesh_set_aabb(contact_3d_debug_multimesh,aabb); + } + } + + + if (physics_object_picking) { Vector2 last_pos(1e20,1e20); @@ -1449,6 +1525,8 @@ Viewport::Viewport() { unhandled_key_input_group = "_vp_unhandled_key_input"+id; + + } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index c3c339ac5d..843a1fd9b7 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -104,6 +104,11 @@ friend class RenderTargetTexture; Rect2 rect; Rect2 to_screen_rect; + RID contact_2d_debug; + RID contact_3d_debug_multimesh; + RID contact_3d_debug_instance; + + bool size_override; bool size_override_stretch; |