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); }
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; }
BehaviorNode::Status BehaviorNode::_traversal_children(const Variant& target, Dictionary& env) { int t = get_child_count(); Status res = STATUS_FAILURE; BehaviorNode *checked = NULL; do { if (_behavior_node_type == TYPE_CONDITION && _focus_node_path != String("") && has_node(_focus_node_path)) { BehaviorNode *child = get_node(_focus_node_path)->cast_to<BehaviorNode>(); if (child && child != this) { if (!child->get_will_focus()) _focus_node_path = NodePath(); NodePath old_path = _focus_node_path; int ret = (int)child->call("step", target, env); if (ret == STATUS_CONTINUE) { continue; }else if (ret == STATUS_RUNNING) { return STATUS_RUNNING; }else { checked = child; if (old_path == _focus_node_path) _focus_node_path = NodePath(); else continue; } } } for (int i = 0; i < t; ++i) { BehaviorNode * child = get_child(i)->cast_to<BehaviorNode>(); if (child == checked) continue; bool is_focus; if (child) { if ((int)child->call("step", target, env) == STATUS_RUNNING) { res = STATUS_RUNNING; is_focus = child->get_will_focus(); if (_behavior_node_type == TYPE_CONDITION) { if (is_focus) { _focus_node_path = get_path_to(child); } return res; } } } } if (_behavior_node_type == TYPE_CONDITION) { _focus_node_path = NodePath(); } return res; }while(true); }
bool Skeleton::_get(const StringName& p_name,Variant &r_ret) const { String path=p_name; if (!path.begins_with("bones/")) return false; int which=path.get_slicec('/',1).to_int(); String what=path.get_slicec('/',2); ERR_FAIL_INDEX_V( which, bones.size(), false ); if (what=="name") r_ret=get_bone_name(which); else if (what=="parent") r_ret=get_bone_parent(which); else if (what=="rest") r_ret=get_bone_rest(which); else if (what=="enabled") r_ret=is_bone_enabled(which); else if (what=="pose") r_ret=get_bone_pose(which); else if (what=="bound_childs") { Array children; for (const List<uint32_t>::Element *E=bones[which].nodes_bound.front();E;E=E->next()) { Object *obj=ObjectDB::get_instance(E->get()); ERR_CONTINUE(!obj); Node *node=obj->cast_to<Node>(); ERR_CONTINUE(!node); NodePath path=get_path_to(node); children.push_back(path); } r_ret=children; } else return false; return true; }
void InterpolatedCamera::set_target(const Spatial *p_target) { ERR_FAIL_NULL(p_target); target = get_path_to(p_target); }
void Node::_duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const { if (get_owner()!=get_parent()->get_owner()) return; Node *node=NULL; if (get_filename()!="") { Ref<PackedScene> res = ResourceLoader::load(get_filename()); ERR_FAIL_COND(res.is_null()); node=res->instance(); ERR_FAIL_COND(!node); } else { Object *obj = ObjectTypeDB::instance(get_type()); if (!obj) { print_line("could not duplicate: "+String(get_type())); } ERR_FAIL_COND(!obj); node = obj->cast_to<Node>(); if (!node) memdelete(obj); } List<PropertyInfo> plist; get_property_list(&plist); for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) { if (!(E->get().usage&PROPERTY_USAGE_STORAGE)) continue; String name = E->get().name; node->set( name, get(name) ); } node->set_name(get_name()); p_new_parent->add_child(node); Node *owner=get_owner(); if (p_reown_map.has(owner)) owner=p_reown_map[owner]; if (owner) { NodePath p = get_path_to(owner); if (owner!=this) { Node *new_owner = node->get_node(p); if (new_owner) { node->set_owner(new_owner); } } } for(int i=0;i<get_child_count();i++) { get_child(i)->_duplicate_and_reown(node,p_reown_map); } }
void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, List<PlotMesh> &plot_meshes, List<PlotLight> &plot_lights) { MeshInstance *mi = Object::cast_to<MeshInstance>(p_at_node); if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT) && mi->is_visible_in_tree()) { Ref<Mesh> mesh = mi->get_mesh(); if (mesh.is_valid()) { bool all_have_uv2 = true; for (int i = 0; i < mesh->get_surface_count(); i++) { if (!(mesh->surface_get_format(i) & Mesh::ARRAY_FORMAT_TEX_UV2)) { all_have_uv2 = false; break; } } if (all_have_uv2 && mesh->get_lightmap_size_hint() != Size2()) { //READY TO BAKE! size hint could be computed if not found, actually.. AABB aabb = mesh->get_aabb(); Transform xf = get_global_transform().affine_inverse() * mi->get_global_transform(); if (AABB(-extents, extents * 2).intersects(xf.xform(aabb))) { PlotMesh pm; pm.local_xform = xf; pm.mesh = mesh; pm.path = get_path_to(mi); pm.instance_idx = -1; for (int i = 0; i < mesh->get_surface_count(); i++) { pm.instance_materials.push_back(mi->get_surface_material(i)); } pm.override_material = mi->get_material_override(); plot_meshes.push_back(pm); } } } } Spatial *s = Object::cast_to<Spatial>(p_at_node); if (!mi && s) { Array meshes = p_at_node->call("get_bake_meshes"); if (meshes.size() && (meshes.size() & 1) == 0) { Transform xf = get_global_transform().affine_inverse() * s->get_global_transform(); for (int i = 0; i < meshes.size(); i += 2) { PlotMesh pm; Transform mesh_xf = meshes[i + 1]; pm.local_xform = xf * mesh_xf; pm.mesh = meshes[i]; pm.instance_idx = i / 2; if (!pm.mesh.is_valid()) continue; pm.path = get_path_to(s); plot_meshes.push_back(pm); } } } Light *light = Object::cast_to<Light>(p_at_node); if (light && light->get_bake_mode() != Light::BAKE_DISABLED) { PlotLight pl; Transform xf = get_global_transform().affine_inverse() * light->get_global_transform(); pl.local_xform = xf; pl.light = light; plot_lights.push_back(pl); } for (int i = 0; i < p_at_node->get_child_count(); i++) { Node *child = p_at_node->get_child(i); if (!child->get_owner()) continue; //maybe a helper _find_meshes_and_lights(child, plot_meshes, plot_lights); } }