summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/input/input.cpp2
-rw-r--r--core/math/dynamic_bvh.cpp68
-rw-r--r--core/math/dynamic_bvh.h28
-rw-r--r--core/variant/array.cpp2
-rw-r--r--doc/classes/RenderingServer.xml8
-rwxr-xr-xmisc/scripts/codespell.sh7
-rw-r--r--modules/gdscript/gdscript_disassembler.cpp6
-rw-r--r--modules/gltf/editor/editor_import_blend_runner.cpp314
-rw-r--r--modules/gltf/editor/editor_import_blend_runner.h69
-rw-r--r--modules/gltf/editor/editor_scene_importer_blend.cpp131
-rw-r--r--modules/gltf/register_types.cpp11
-rw-r--r--platform/linuxbsd/x11/display_server_x11.cpp19
-rw-r--r--platform/macos/display_server_macos.mm17
-rw-r--r--platform/windows/display_server_windows.cpp19
-rw-r--r--scene/gui/popup_menu.cpp3
-rw-r--r--scene/main/canvas_item.cpp4
-rw-r--r--scene/main/viewport.cpp5
17 files changed, 572 insertions, 141 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index aa89facdd7..2e886f9093 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -904,7 +904,7 @@ void Input::parse_input_event(const Ref<InputEvent> &p_event) {
// - If platform doesn't use buffering and event accumulation is disabled.
// - If platform doesn't use buffering and the event type is not accumulable.
// However, it wouldn't be reasonable to ask users to remember the full ruleset and be aware at all times
- // of the possibilites of the target platform, project settings and engine internals, which may change
+ // of the possibilities of the target platform, project settings and engine internals, which may change
// without prior notice.
// Therefore, the guideline is, "don't send the same event object more than once per frame".
WARN_PRINT_ONCE(
diff --git a/core/math/dynamic_bvh.cpp b/core/math/dynamic_bvh.cpp
index 4452445241..e1315d1c64 100644
--- a/core/math/dynamic_bvh.cpp
+++ b/core/math/dynamic_bvh.cpp
@@ -36,8 +36,8 @@ void DynamicBVH::_delete_node(Node *p_node) {
void DynamicBVH::_recurse_delete_node(Node *p_node) {
if (!p_node->is_leaf()) {
- _recurse_delete_node(p_node->childs[0]);
- _recurse_delete_node(p_node->childs[1]);
+ _recurse_delete_node(p_node->children[0]);
+ _recurse_delete_node(p_node->children[1]);
}
if (p_node == bvh_root) {
bvh_root = nullptr;
@@ -65,31 +65,31 @@ void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) {
} else {
if (!p_root->is_leaf()) {
do {
- p_root = p_root->childs[p_leaf->volume.select_by_proximity(
- p_root->childs[0]->volume,
- p_root->childs[1]->volume)];
+ p_root = p_root->children[p_leaf->volume.select_by_proximity(
+ p_root->children[0]->volume,
+ p_root->children[1]->volume)];
} while (!p_root->is_leaf());
}
Node *prev = p_root->parent;
Node *node = _create_node_with_volume(prev, p_leaf->volume.merge(p_root->volume), nullptr);
if (prev) {
- prev->childs[p_root->get_index_in_parent()] = node;
- node->childs[0] = p_root;
+ prev->children[p_root->get_index_in_parent()] = node;
+ node->children[0] = p_root;
p_root->parent = node;
- node->childs[1] = p_leaf;
+ node->children[1] = p_leaf;
p_leaf->parent = node;
do {
if (!prev->volume.contains(node->volume)) {
- prev->volume = prev->childs[0]->volume.merge(prev->childs[1]->volume);
+ prev->volume = prev->children[0]->volume.merge(prev->children[1]->volume);
} else {
break;
}
node = prev;
} while (nullptr != (prev = node->parent));
} else {
- node->childs[0] = p_root;
+ node->children[0] = p_root;
p_root->parent = node;
- node->childs[1] = p_leaf;
+ node->children[1] = p_leaf;
p_leaf->parent = node;
bvh_root = node;
}
@@ -103,14 +103,14 @@ DynamicBVH::Node *DynamicBVH::_remove_leaf(Node *leaf) {
} else {
Node *parent = leaf->parent;
Node *prev = parent->parent;
- Node *sibling = parent->childs[1 - leaf->get_index_in_parent()];
+ Node *sibling = parent->children[1 - leaf->get_index_in_parent()];
if (prev) {
- prev->childs[parent->get_index_in_parent()] = sibling;
+ prev->children[parent->get_index_in_parent()] = sibling;
sibling->parent = prev;
_delete_node(parent);
while (prev) {
const Volume pb = prev->volume;
- prev->volume = prev->childs[0]->volume.merge(prev->childs[1]->volume);
+ prev->volume = prev->children[0]->volume.merge(prev->children[1]->volume);
if (pb.is_not_equal_to(prev->volume)) {
prev = prev->parent;
} else {
@@ -129,8 +129,8 @@ DynamicBVH::Node *DynamicBVH::_remove_leaf(Node *leaf) {
void DynamicBVH::_fetch_leaves(Node *p_root, LocalVector<Node *> &r_leaves, int p_depth) {
if (p_root->is_internal() && p_depth) {
- _fetch_leaves(p_root->childs[0], r_leaves, p_depth - 1);
- _fetch_leaves(p_root->childs[1], r_leaves, p_depth - 1);
+ _fetch_leaves(p_root->children[0], r_leaves, p_depth - 1);
+ _fetch_leaves(p_root->children[1], r_leaves, p_depth - 1);
_delete_node(p_root);
} else {
r_leaves.push_back(p_root);
@@ -195,8 +195,8 @@ void DynamicBVH::_bottom_up(Node **leaves, int p_count) {
}
Node *n[] = { leaves[minidx[0]], leaves[minidx[1]] };
Node *p = _create_node_with_volume(nullptr, n[0]->volume.merge(n[1]->volume), nullptr);
- p->childs[0] = n[0];
- p->childs[1] = n[1];
+ p->children[0] = n[0];
+ p->children[1] = n[1];
n[0]->parent = p;
n[1]->parent = p;
leaves[minidx[0]] = p;
@@ -241,10 +241,10 @@ DynamicBVH::Node *DynamicBVH::_top_down(Node **leaves, int p_count, int p_bu_thr
}
Node *node = _create_node_with_volume(nullptr, vol, nullptr);
- node->childs[0] = _top_down(&leaves[0], partition, p_bu_threshold);
- node->childs[1] = _top_down(&leaves[partition], p_count - partition, p_bu_threshold);
- node->childs[0]->parent = node;
- node->childs[1]->parent = node;
+ node->children[0] = _top_down(&leaves[0], partition, p_bu_threshold);
+ node->children[1] = _top_down(&leaves[partition], p_count - partition, p_bu_threshold);
+ node->children[0]->parent = node;
+ node->children[1]->parent = node;
return (node);
} else {
_bottom_up(leaves, p_count);
@@ -260,23 +260,23 @@ DynamicBVH::Node *DynamicBVH::_node_sort(Node *n, Node *&r) {
if (p > n) {
const int i = n->get_index_in_parent();
const int j = 1 - i;
- Node *s = p->childs[j];
+ Node *s = p->children[j];
Node *q = p->parent;
- ERR_FAIL_COND_V(n != p->childs[i], nullptr);
+ ERR_FAIL_COND_V(n != p->children[i], nullptr);
if (q) {
- q->childs[p->get_index_in_parent()] = n;
+ q->children[p->get_index_in_parent()] = n;
} else {
r = n;
}
s->parent = n;
p->parent = n;
n->parent = q;
- p->childs[0] = n->childs[0];
- p->childs[1] = n->childs[1];
- n->childs[0]->parent = p;
- n->childs[1]->parent = p;
- n->childs[i] = p;
- n->childs[j] = s;
+ p->children[0] = n->children[0];
+ p->children[1] = n->children[1];
+ n->children[0]->parent = p;
+ n->children[1]->parent = p;
+ n->children[i] = p;
+ n->children[j] = s;
SWAP(p->volume, n->volume);
return (p);
}
@@ -320,7 +320,7 @@ void DynamicBVH::optimize_incremental(int passes) {
Node *node = bvh_root;
unsigned bit = 0;
while (node->is_internal()) {
- node = _node_sort(node, bvh_root)->childs[(opath >> bit) & 1];
+ node = _node_sort(node, bvh_root)->children[(opath >> bit) & 1];
bit = (bit + 1) & (sizeof(unsigned) * 8 - 1);
}
_update(node);
@@ -396,8 +396,8 @@ void DynamicBVH::remove(const ID &p_id) {
void DynamicBVH::_extract_leaves(Node *p_node, List<ID> *r_elements) {
if (p_node->is_internal()) {
- _extract_leaves(p_node->childs[0], r_elements);
- _extract_leaves(p_node->childs[1], r_elements);
+ _extract_leaves(p_node->children[0], r_elements);
+ _extract_leaves(p_node->children[1], r_elements);
} else {
ID id;
id.node = p_node;
diff --git a/core/math/dynamic_bvh.h b/core/math/dynamic_bvh.h
index 46bf56ae58..21b5340aaa 100644
--- a/core/math/dynamic_bvh.h
+++ b/core/math/dynamic_bvh.h
@@ -182,21 +182,21 @@ private:
Volume volume;
Node *parent = nullptr;
union {
- Node *childs[2];
+ Node *children[2];
void *data;
};
- _FORCE_INLINE_ bool is_leaf() const { return childs[1] == nullptr; }
+ _FORCE_INLINE_ bool is_leaf() const { return children[1] == nullptr; }
_FORCE_INLINE_ bool is_internal() const { return (!is_leaf()); }
_FORCE_INLINE_ int get_index_in_parent() const {
ERR_FAIL_COND_V(!parent, 0);
- return (parent->childs[1] == this) ? 1 : 0;
+ return (parent->children[1] == this) ? 1 : 0;
}
void get_max_depth(int depth, int &maxdepth) {
if (is_internal()) {
- childs[0]->get_max_depth(depth + 1, maxdepth);
- childs[1]->get_max_depth(depth + 1, maxdepth);
+ children[0]->get_max_depth(depth + 1, maxdepth);
+ children[1]->get_max_depth(depth + 1, maxdepth);
} else {
maxdepth = MAX(maxdepth, depth);
}
@@ -205,7 +205,7 @@ private:
//
int count_leaves() const {
if (is_internal()) {
- return childs[0]->count_leaves() + childs[1]->count_leaves();
+ return children[0]->count_leaves() + children[1]->count_leaves();
} else {
return (1);
}
@@ -216,8 +216,8 @@ private:
}
Node() {
- childs[0] = nullptr;
- childs[1] = nullptr;
+ children[0] = nullptr;
+ children[1] = nullptr;
}
};
@@ -350,8 +350,8 @@ void DynamicBVH::aabb_query(const AABB &p_box, QueryResult &r_result) {
stack = aux_stack.ptr();
threshold = aux_stack.size() - 2;
}
- stack[depth++] = n->childs[0];
- stack[depth++] = n->childs[1];
+ stack[depth++] = n->children[0];
+ stack[depth++] = n->children[1];
} else {
if (r_result(n->data)) {
return;
@@ -406,8 +406,8 @@ void DynamicBVH::convex_query(const Plane *p_planes, int p_plane_count, const Ve
stack = aux_stack.ptr();
threshold = aux_stack.size() - 2;
}
- stack[depth++] = n->childs[0];
- stack[depth++] = n->childs[1];
+ stack[depth++] = n->children[0];
+ stack[depth++] = n->children[1];
} else {
if (r_result(n->data)) {
return;
@@ -463,8 +463,8 @@ void DynamicBVH::ray_query(const Vector3 &p_from, const Vector3 &p_to, QueryResu
stack = aux_stack.ptr();
threshold = aux_stack.size() - 2;
}
- stack[depth++] = node->childs[0];
- stack[depth++] = node->childs[1];
+ stack[depth++] = node->children[0];
+ stack[depth++] = node->children[1];
} else {
if (r_result(node->data)) {
return;
diff --git a/core/variant/array.cpp b/core/variant/array.cpp
index d3c5ca801f..2d7dff0b27 100644
--- a/core/variant/array.cpp
+++ b/core/variant/array.cpp
@@ -246,7 +246,7 @@ void Array::assign(const Array &p_array) {
ERR_FAIL_COND_MSG(ce.error, vformat(R"(Unable to convert array index %i from "%s" to "%s".)", i, Variant::get_type_name(value->get_type()), Variant::get_type_name(typed.type)));
}
} else if (Variant::can_convert_strict(source_typed.type, typed.type)) {
- // from primitives to different convertable primitives
+ // from primitives to different convertible primitives
for (int i = 0; i < size; i++) {
const Variant *value = source + i;
Callable::CallError ce;
diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml
index f92ea255cc..4e3a1bc0ef 100644
--- a/doc/classes/RenderingServer.xml
+++ b/doc/classes/RenderingServer.xml
@@ -58,14 +58,14 @@
<param index="6" name="near_transition" type="float" />
<param index="7" name="amount" type="float" />
<description>
- Sets the parameters to use with the dof blur effect. These parameters take on the same meaning as their counterparts in [CameraAttributesPractical].
+ Sets the parameters to use with the DOF blur effect. These parameters take on the same meaning as their counterparts in [CameraAttributesPractical].
</description>
</method>
<method name="camera_attributes_set_dof_blur_bokeh_shape">
<return type="void" />
<param index="0" name="shape" type="int" enum="RenderingServer.DOFBokehShape" />
<description>
- Sets the shape of the dof bokeh pattern. Different shapes may be used to acheive artistic effect, or to meet performance targets. For more detail on available options see [enum DOFBokehShape].
+ Sets the shape of the DOF bokeh pattern. Different shapes may be used to achieve artistic effect, or to meet performance targets. For more detail on available options see [enum DOFBokehShape].
</description>
</method>
<method name="camera_attributes_set_dof_blur_quality">
@@ -73,7 +73,7 @@
<param index="0" name="quality" type="int" enum="RenderingServer.DOFBlurQuality" />
<param index="1" name="use_jitter" type="bool" />
<description>
- Sets the quality level of the dof blur effect to one of the options in [enum DOFBlurQuality]. [param use_jitter] can be used to jitter samples taken during the blur pass to hide artifacts at the cost of looking more fuzzy.
+ Sets the quality level of the DOF blur effect to one of the options in [enum DOFBlurQuality]. [param use_jitter] can be used to jitter samples taken during the blur pass to hide artifacts at the cost of looking more fuzzy.
</description>
</method>
<method name="camera_attributes_set_exposure">
@@ -3272,7 +3272,7 @@
<param index="0" name="viewport" type="RID" />
<param index="1" name="mode" type="int" enum="RenderingServer.ViewportEnvironmentMode" />
<description>
- Sets the viewport's environment mode which allows enabling or disabling rendering of 3D environment over 2D canvas. When disabled, 2D will not be affected by the environment. When enabled, 2D will be affected by the environment if the environment background mode is [constant ENV_BG_CANVAS]. The default behaviour is to inherit the setting from the viewport's parent. If the topmost parent is also set to [constant VIEWPORT_ENVIRONMENT_INHERIT], then the behavior will be the same as if it was set to [constant VIEWPORT_ENVIRONMENT_ENABLED].
+ Sets the viewport's environment mode which allows enabling or disabling rendering of 3D environment over 2D canvas. When disabled, 2D will not be affected by the environment. When enabled, 2D will be affected by the environment if the environment background mode is [constant ENV_BG_CANVAS]. The default behavior is to inherit the setting from the viewport's parent. If the topmost parent is also set to [constant VIEWPORT_ENVIRONMENT_INHERIT], then the behavior will be the same as if it was set to [constant VIEWPORT_ENVIRONMENT_ENABLED].
</description>
</method>
<method name="viewport_set_fsr_sharpness">
diff --git a/misc/scripts/codespell.sh b/misc/scripts/codespell.sh
index 44084b3348..0551492420 100755
--- a/misc/scripts/codespell.sh
+++ b/misc/scripts/codespell.sh
@@ -1,5 +1,8 @@
#!/bin/sh
-SKIP_LIST="./.*,./bin,./editor/project_converter_3_to_4.cpp,./platform/web/node_modules,./platform/android/java/lib/src/com,./thirdparty,*.gen.*,*.po,*.pot,*.rc,package-lock.json,./core/string/locales.h,./AUTHORS.md,./COPYRIGHT.txt,./DONORS.md,./misc/dist/linux/org.godotengine.Godot.desktop,./misc/scripts/codespell.sh"
-IGNORE_LIST="alo,ba,childs,complies,curvelinear,doubleclick,expct,fave,findn,gird,gud,inout,lod,nd,numer,ois,readded,ro,sav,statics,te,varius,varn,wan"
+SKIP_LIST="./.*,./bin,./thirdparty,*.desktop,*.gen.*,*.po,*.pot,*.rc,./AUTHORS.md,./COPYRIGHT.txt,./DONORS.md,"
+SKIP_LIST+="./core/string/locales.h,./editor/project_converter_3_to_4.cpp,./misc/scripts/codespell.sh,"
+SKIP_LIST+="./platform/android/java/lib/src/com,./platform/web/node_modules,./platform/web/package-lock.json,"
+
+IGNORE_LIST="alo,ba,complies,curvelinear,doubleclick,expct,fave,findn,gird,gud,inout,lod,nd,numer,ois,readded,ro,sav,statics,te,varius,varn,wan"
codespell -w -q 3 -S "${SKIP_LIST}" -L "${IGNORE_LIST}" --builtin "clear,rare,en-GB_to_en-US"
diff --git a/modules/gdscript/gdscript_disassembler.cpp b/modules/gdscript/gdscript_disassembler.cpp
index 9070ba93e7..d4f4358ac1 100644
--- a/modules/gdscript/gdscript_disassembler.cpp
+++ b/modules/gdscript/gdscript_disassembler.cpp
@@ -317,7 +317,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
text += " = ";
text += DADDR(2);
- incr += 3;
+ incr += 6;
} break;
case OPCODE_ASSIGN_TYPED_NATIVE: {
text += "assign typed native (";
@@ -434,7 +434,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
int instr_var_args = _code_ptr[++ip];
int argc = _code_ptr[ip + 1 + instr_var_args];
- Ref<Script> script_type = get_constant(_code_ptr[ip + argc + 2]);
+ Ref<Script> script_type = get_constant(_code_ptr[ip + argc + 2] & GDScriptFunction::ADDR_MASK);
Variant::Type builtin_type = (Variant::Type)_code_ptr[ip + argc + 4];
StringName native_type = get_global_name(_code_ptr[ip + argc + 5]);
@@ -463,7 +463,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
text += "]";
- incr += 4 + instr_var_args;
+ incr += 6 + argc;
} break;
case OPCODE_CONSTRUCT_DICTIONARY: {
int instr_var_args = _code_ptr[++ip];
diff --git a/modules/gltf/editor/editor_import_blend_runner.cpp b/modules/gltf/editor/editor_import_blend_runner.cpp
new file mode 100644
index 0000000000..c203a91834
--- /dev/null
+++ b/modules/gltf/editor/editor_import_blend_runner.cpp
@@ -0,0 +1,314 @@
+/**************************************************************************/
+/* editor_import_blend_runner.cpp */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 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 "editor_import_blend_runner.h"
+
+#ifdef TOOLS_ENABLED
+
+#include "core/io/http_client.h"
+#include "editor/editor_file_system.h"
+#include "editor/editor_node.h"
+#include "editor/editor_settings.h"
+
+static constexpr char PYTHON_SCRIPT_RPC[] = R"(
+import bpy, sys, threading
+from xmlrpc.server import SimpleXMLRPCServer
+req = threading.Condition()
+res = threading.Condition()
+info = None
+def xmlrpc_server():
+ server = SimpleXMLRPCServer(('127.0.0.1', %d))
+ server.register_function(export_gltf)
+ server.serve_forever()
+def export_gltf(opts):
+ with req:
+ global info
+ info = ('export_gltf', opts)
+ req.notify()
+ with res:
+ res.wait()
+if bpy.app.version < (3, 0, 0):
+ print('Blender 3.0 or higher is required.', file=sys.stderr)
+threading.Thread(target=xmlrpc_server).start()
+while True:
+ with req:
+ while info is None:
+ req.wait()
+ method, opts = info
+ if method == 'export_gltf':
+ try:
+ bpy.ops.wm.open_mainfile(filepath=opts['path'])
+ if opts['unpack_all']:
+ bpy.ops.file.unpack_all(method='USE_LOCAL')
+ bpy.ops.export_scene.gltf(**opts['gltf_options'])
+ except:
+ pass
+ info = None
+ with res:
+ res.notify()
+)";
+
+static constexpr char PYTHON_SCRIPT_DIRECT[] = R"(
+import bpy, sys
+opts = %s
+if bpy.app.version < (3, 0, 0):
+ print('Blender 3.0 or higher is required.', file=sys.stderr)
+bpy.ops.wm.open_mainfile(filepath=opts['path'])
+if opts['unpack_all']:
+ bpy.ops.file.unpack_all(method='USE_LOCAL')
+bpy.ops.export_scene.gltf(**opts['gltf_options'])
+)";
+
+String dict_to_python(const Dictionary &p_dict) {
+ String entries;
+ Array dict_keys = p_dict.keys();
+ for (int i = 0; i < dict_keys.size(); i++) {
+ const String key = dict_keys[i];
+ String value;
+ Variant raw_value = p_dict[key];
+
+ switch (raw_value.get_type()) {
+ case Variant::Type::BOOL: {
+ value = raw_value ? "True" : "False";
+ break;
+ }
+ case Variant::Type::STRING:
+ case Variant::Type::STRING_NAME: {
+ value = raw_value;
+ value = vformat("'%s'", value.c_escape());
+ break;
+ }
+ case Variant::Type::DICTIONARY: {
+ value = dict_to_python(raw_value);
+ break;
+ }
+ default: {
+ ERR_FAIL_V_MSG("", vformat("Unhandled Variant type %s for python dictionary", Variant::get_type_name(raw_value.get_type())));
+ }
+ }
+
+ entries += vformat("'%s': %s,", key, value);
+ }
+ return vformat("{%s}", entries);
+}
+
+String dict_to_xmlrpc(const Dictionary &p_dict) {
+ String members;
+ Array dict_keys = p_dict.keys();
+ for (int i = 0; i < dict_keys.size(); i++) {
+ const String key = dict_keys[i];
+ String value;
+ Variant raw_value = p_dict[key];
+
+ switch (raw_value.get_type()) {
+ case Variant::Type::BOOL: {
+ value = vformat("<boolean>%d</boolean>", raw_value ? 1 : 0);
+ break;
+ }
+ case Variant::Type::STRING:
+ case Variant::Type::STRING_NAME: {
+ value = raw_value;
+ value = vformat("<string>%s</string>", value.xml_escape());
+ break;
+ }
+ case Variant::Type::DICTIONARY: {
+ value = dict_to_xmlrpc(raw_value);
+ break;
+ }
+ default: {
+ ERR_FAIL_V_MSG("", vformat("Unhandled Variant type %s for XMLRPC", Variant::get_type_name(raw_value.get_type())));
+ }
+ }
+
+ members += vformat("<member><name>%s</name><value>%s</value></member>", key, value);
+ }
+ return vformat("<struct>%s</struct>", members);
+}
+
+Error EditorImportBlendRunner::start_blender(const String &p_python_script, bool p_blocking) {
+ String blender_path = EDITOR_GET("filesystem/import/blender/blender3_path");
+
+#ifdef WINDOWS_ENABLED
+ blender_path = blender_path.path_join("blender.exe");
+#else
+ blender_path = blender_path.path_join("blender");
+#endif
+
+ List<String> args;
+ args.push_back("--background");
+ args.push_back("--python-expr");
+ args.push_back(p_python_script);
+
+ Error err;
+ if (p_blocking) {
+ int exitcode = 0;
+ err = OS::get_singleton()->execute(blender_path, args, nullptr, &exitcode);
+ if (exitcode != 0) {
+ return FAILED;
+ }
+ } else {
+ err = OS::get_singleton()->create_process(blender_path, args, &blender_pid);
+ }
+ return err;
+}
+
+Error EditorImportBlendRunner::do_import(const Dictionary &p_options) {
+ if (is_using_rpc()) {
+ return do_import_rpc(p_options);
+ } else {
+ return do_import_direct(p_options);
+ }
+}
+
+Error EditorImportBlendRunner::do_import_rpc(const Dictionary &p_options) {
+ kill_timer->stop();
+
+ // Start Blender if not already running.
+ if (!is_running()) {
+ // Start an XML RPC server on the given port.
+ String python = vformat(PYTHON_SCRIPT_RPC, rpc_port);
+ Error err = start_blender(python, false);
+ if (err != OK || blender_pid == 0) {
+ return FAILED;
+ }
+ }
+
+ // Convert options to XML body.
+ String xml_options = dict_to_xmlrpc(p_options);
+ String xml_body = vformat("<?xml version=\"1.0\"?><methodCall><methodName>export_gltf</methodName><params><param><value>%s</value></param></params></methodCall>", xml_options);
+
+ // Connect to RPC server.
+ Ref<HTTPClient> client = HTTPClient::create();
+ client->connect_to_host("127.0.0.1", rpc_port);
+
+ bool done = false;
+ while (!done) {
+ HTTPClient::Status status = client->get_status();
+ switch (status) {
+ case HTTPClient::STATUS_RESOLVING:
+ case HTTPClient::STATUS_CONNECTING: {
+ client->poll();
+ break;
+ }
+ case HTTPClient::STATUS_CONNECTED: {
+ done = true;
+ break;
+ }
+ default: {
+ ERR_FAIL_V_MSG(ERR_CONNECTION_ERROR, vformat("Unexpected status during RPC connection: %d", status));
+ }
+ }
+ }
+
+ // Send XML request.
+ PackedByteArray xml_buffer = xml_body.to_utf8_buffer();
+ Error err = client->request(HTTPClient::METHOD_POST, "/", Vector<String>(), xml_buffer.ptr(), xml_buffer.size());
+ if (err != OK) {
+ ERR_FAIL_V_MSG(err, vformat("Unable to send RPC request: %d", err));
+ }
+
+ // Wait for response.
+ done = false;
+ while (!done) {
+ HTTPClient::Status status = client->get_status();
+ switch (status) {
+ case HTTPClient::STATUS_REQUESTING: {
+ client->poll();
+ break;
+ }
+ case HTTPClient::STATUS_BODY: {
+ client->poll();
+ // Parse response here if needed. For now we can just ignore it.
+ done = true;
+ break;
+ }
+ default: {
+ ERR_FAIL_V_MSG(ERR_CONNECTION_ERROR, vformat("Unexpected status during RPC response: %d", status));
+ }
+ }
+ }
+
+ return OK;
+}
+
+Error EditorImportBlendRunner::do_import_direct(const Dictionary &p_options) {
+ // Export glTF directly.
+ String python = vformat(PYTHON_SCRIPT_DIRECT, dict_to_python(p_options));
+ Error err = start_blender(python, true);
+ if (err != OK) {
+ return err;
+ }
+
+ return OK;
+}
+
+void EditorImportBlendRunner::_resources_reimported(const PackedStringArray &p_files) {
+ if (is_running()) {
+ // After a batch of imports is done, wait a few seconds before trying to kill blender,
+ // in case of having multiple imports trigger in quick succession.
+ kill_timer->start();
+ }
+}
+
+void EditorImportBlendRunner::_kill_blender() {
+ kill_timer->stop();
+ if (is_running()) {
+ OS::get_singleton()->kill(blender_pid);
+ }
+ blender_pid = 0;
+}
+
+void EditorImportBlendRunner::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_PREDELETE: {
+ _kill_blender();
+ break;
+ }
+ }
+}
+
+EditorImportBlendRunner *EditorImportBlendRunner::singleton = nullptr;
+
+EditorImportBlendRunner::EditorImportBlendRunner() {
+ ERR_FAIL_COND_MSG(singleton != nullptr, "EditorImportBlendRunner already created.");
+ singleton = this;
+
+ rpc_port = EDITOR_GET("filesystem/import/blender/rpc_port");
+
+ kill_timer = memnew(Timer);
+ add_child(kill_timer);
+ kill_timer->set_one_shot(true);
+ kill_timer->set_wait_time(EDITOR_GET("filesystem/import/blender/rpc_server_uptime"));
+ kill_timer->connect("timeout", callable_mp(this, &EditorImportBlendRunner::_kill_blender));
+
+ EditorFileSystem::get_singleton()->connect("resources_reimported", callable_mp(this, &EditorImportBlendRunner::_resources_reimported));
+}
+
+#endif // TOOLS_ENABLED
diff --git a/modules/gltf/editor/editor_import_blend_runner.h b/modules/gltf/editor/editor_import_blend_runner.h
new file mode 100644
index 0000000000..b2b82394e1
--- /dev/null
+++ b/modules/gltf/editor/editor_import_blend_runner.h
@@ -0,0 +1,69 @@
+/**************************************************************************/
+/* editor_import_blend_runner.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 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. */
+/**************************************************************************/
+
+#ifndef EDITOR_IMPORT_BLEND_RUNNER_H
+#define EDITOR_IMPORT_BLEND_RUNNER_H
+
+#ifdef TOOLS_ENABLED
+
+#include "core/os/os.h"
+#include "scene/main/node.h"
+#include "scene/main/timer.h"
+
+class EditorImportBlendRunner : public Node {
+ GDCLASS(EditorImportBlendRunner, Node);
+
+ static EditorImportBlendRunner *singleton;
+
+ Timer *kill_timer;
+ void _resources_reimported(const PackedStringArray &p_files);
+ void _kill_blender();
+ void _notification(int p_what);
+
+protected:
+ int rpc_port = 0;
+ OS::ProcessID blender_pid = 0;
+ Error start_blender(const String &p_python_script, bool p_blocking);
+ Error do_import_direct(const Dictionary &p_options);
+ Error do_import_rpc(const Dictionary &p_options);
+
+public:
+ static EditorImportBlendRunner *get_singleton() { return singleton; }
+
+ bool is_running() { return blender_pid != 0 && OS::get_singleton()->is_process_running(blender_pid); }
+ bool is_using_rpc() { return rpc_port != 0; }
+ Error do_import(const Dictionary &p_options);
+
+ EditorImportBlendRunner();
+};
+
+#endif // TOOLS_ENABLED
+
+#endif // EDITOR_IMPORT_BLEND_RUNNER_H
diff --git a/modules/gltf/editor/editor_scene_importer_blend.cpp b/modules/gltf/editor/editor_scene_importer_blend.cpp
index 5415c5818f..520f33261a 100644
--- a/modules/gltf/editor/editor_scene_importer_blend.cpp
+++ b/modules/gltf/editor/editor_scene_importer_blend.cpp
@@ -34,6 +34,7 @@
#include "../gltf_defines.h"
#include "../gltf_document.h"
+#include "editor_import_blend_runner.h"
#include "core/config/project_settings.h"
#include "editor/editor_file_dialog.h"
@@ -68,149 +69,129 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_
// Handle configuration options.
- String parameters_arg;
+ Dictionary request_options;
+ Dictionary parameters_map;
+
+ parameters_map["filepath"] = sink_global;
+ parameters_map["export_keep_originals"] = true;
+ parameters_map["export_format"] = "GLTF_SEPARATE";
+ parameters_map["export_yup"] = true;
if (p_options.has(SNAME("blender/nodes/custom_properties")) && p_options[SNAME("blender/nodes/custom_properties")]) {
- parameters_arg += "export_extras=True,";
+ parameters_map["export_extras"] = true;
} else {
- parameters_arg += "export_extras=False,";
+ parameters_map["export_extras"] = false;
}
if (p_options.has(SNAME("blender/meshes/skins"))) {
int32_t skins = p_options["blender/meshes/skins"];
if (skins == BLEND_BONE_INFLUENCES_NONE) {
- parameters_arg += "export_skins=False,";
+ parameters_map["export_skins"] = false;
} else if (skins == BLEND_BONE_INFLUENCES_COMPATIBLE) {
- parameters_arg += "export_all_influences=False,export_skins=True,";
+ parameters_map["export_skins"] = true;
+ parameters_map["export_all_influences"] = false;
} else if (skins == BLEND_BONE_INFLUENCES_ALL) {
- parameters_arg += "export_all_influences=True,export_skins=True,";
+ parameters_map["export_skins"] = true;
+ parameters_map["export_all_influences"] = true;
}
} else {
- parameters_arg += "export_skins=False,";
+ parameters_map["export_skins"] = false;
}
if (p_options.has(SNAME("blender/materials/export_materials"))) {
int32_t exports = p_options["blender/materials/export_materials"];
if (exports == BLEND_MATERIAL_EXPORT_PLACEHOLDER) {
- parameters_arg += "export_materials='PLACEHOLDER',";
+ parameters_map["export_materials"] = "PLACEHOLDER";
} else if (exports == BLEND_MATERIAL_EXPORT_EXPORT) {
- parameters_arg += "export_materials='EXPORT',";
+ parameters_map["export_materials"] = "EXPORT";
}
} else {
- parameters_arg += "export_materials='PLACEHOLDER',";
+ parameters_map["export_materials"] = "PLACEHOLDER";
}
if (p_options.has(SNAME("blender/nodes/cameras")) && p_options[SNAME("blender/nodes/cameras")]) {
- parameters_arg += "export_cameras=True,";
+ parameters_map["export_cameras"] = true;
} else {
- parameters_arg += "export_cameras=False,";
+ parameters_map["export_cameras"] = false;
}
if (p_options.has(SNAME("blender/nodes/punctual_lights")) && p_options[SNAME("blender/nodes/punctual_lights")]) {
- parameters_arg += "export_lights=True,";
+ parameters_map["export_lights"] = true;
} else {
- parameters_arg += "export_lights=False,";
+ parameters_map["export_lights"] = false;
}
if (p_options.has(SNAME("blender/meshes/colors")) && p_options[SNAME("blender/meshes/colors")]) {
- parameters_arg += "export_colors=True,";
+ parameters_map["export_colors"] = true;
} else {
- parameters_arg += "export_colors=False,";
+ parameters_map["export_colors"] = false;
}
if (p_options.has(SNAME("blender/nodes/visible"))) {
int32_t visible = p_options["blender/nodes/visible"];
if (visible == BLEND_VISIBLE_VISIBLE_ONLY) {
- parameters_arg += "use_visible=True,";
+ parameters_map["use_visible"] = true;
} else if (visible == BLEND_VISIBLE_RENDERABLE) {
- parameters_arg += "use_renderable=True,";
+ parameters_map["use_renderable"] = true;
} else if (visible == BLEND_VISIBLE_ALL) {
- parameters_arg += "use_visible=False,use_renderable=False,";
+ parameters_map["use_renderable"] = false;
+ parameters_map["use_visible"] = false;
}
} else {
- parameters_arg += "use_visible=False,use_renderable=False,";
+ parameters_map["use_renderable"] = false;
+ parameters_map["use_visible"] = false;
}
if (p_options.has(SNAME("blender/meshes/uvs")) && p_options[SNAME("blender/meshes/uvs")]) {
- parameters_arg += "export_texcoords=True,";
+ parameters_map["export_texcoords"] = true;
} else {
- parameters_arg += "export_texcoords=False,";
+ parameters_map["export_texcoords"] = false;
}
if (p_options.has(SNAME("blender/meshes/normals")) && p_options[SNAME("blender/meshes/normals")]) {
- parameters_arg += "export_normals=True,";
+ parameters_map["export_normals"] = true;
} else {
- parameters_arg += "export_normals=False,";
+ parameters_map["export_normals"] = false;
}
if (p_options.has(SNAME("blender/meshes/tangents")) && p_options[SNAME("blender/meshes/tangents")]) {
- parameters_arg += "export_tangents=True,";
+ parameters_map["export_tangents"] = true;
} else {
- parameters_arg += "export_tangents=False,";
+ parameters_map["export_tangents"] = false;
}
if (p_options.has(SNAME("blender/animation/group_tracks")) && p_options[SNAME("blender/animation/group_tracks")]) {
- parameters_arg += "export_nla_strips=True,";
+ parameters_map["export_nla_strips"] = true;
} else {
- parameters_arg += "export_nla_strips=False,";
+ parameters_map["export_nla_strips"] = false;
}
if (p_options.has(SNAME("blender/animation/limit_playback")) && p_options[SNAME("blender/animation/limit_playback")]) {
- parameters_arg += "export_frame_range=True,";
+ parameters_map["export_frame_range"] = true;
} else {
- parameters_arg += "export_frame_range=False,";
+ parameters_map["export_frame_range"] = false;
}
if (p_options.has(SNAME("blender/animation/always_sample")) && p_options[SNAME("blender/animation/always_sample")]) {
- parameters_arg += "export_force_sampling=True,";
+ parameters_map["export_force_sampling"] = true;
} else {
- parameters_arg += "export_force_sampling=False,";
+ parameters_map["export_force_sampling"] = false;
}
if (p_options.has(SNAME("blender/meshes/export_bones_deforming_mesh_only")) && p_options[SNAME("blender/meshes/export_bones_deforming_mesh_only")]) {
- parameters_arg += "export_def_bones=True,";
+ parameters_map["export_def_bones"] = true;
} else {
- parameters_arg += "export_def_bones=False,";
+ parameters_map["export_def_bones"] = false;
}
if (p_options.has(SNAME("blender/nodes/modifiers")) && p_options[SNAME("blender/nodes/modifiers")]) {
- parameters_arg += "export_apply=True";
+ parameters_map["export_apply"] = true;
} else {
- parameters_arg += "export_apply=False";
+ parameters_map["export_apply"] = false;
}
- String unpack_all;
if (p_options.has(SNAME("blender/materials/unpack_enabled")) && p_options[SNAME("blender/materials/unpack_enabled")]) {
- unpack_all = "bpy.ops.file.unpack_all(method='USE_LOCAL');";
+ request_options["unpack_all"] = true;
+ } else {
+ request_options["unpack_all"] = false;
}
- // Prepare Blender export script.
-
- String common_args = vformat("filepath='%s',", sink_global) +
- "export_format='GLTF_SEPARATE',"
- "export_yup=True," +
- parameters_arg;
- String export_script =
- String("import bpy, sys;") +
- "print('Blender 3.0 or higher is required.', file=sys.stderr) if bpy.app.version < (3, 0, 0) else None;" +
- vformat("bpy.ops.wm.open_mainfile(filepath='%s');", source_global) +
- unpack_all +
- vformat("bpy.ops.export_scene.gltf(export_keep_originals=True,%s);", common_args);
- print_verbose(export_script);
-
- // Run script with configured Blender binary.
+ request_options["path"] = source_global;
+ request_options["gltf_options"] = parameters_map;
- String blender_path = EDITOR_GET("filesystem/import/blender/blender3_path");
-
-#ifdef WINDOWS_ENABLED
- blender_path = blender_path.path_join("blender.exe");
-#else
- blender_path = blender_path.path_join("blender");
-#endif
-
- List<String> args;
- args.push_back("--background");
- args.push_back("--python-expr");
- args.push_back(export_script);
-
- String standard_out;
- int ret;
- OS::get_singleton()->execute(blender_path, args, &standard_out, &ret, true);
- print_verbose(blender_path);
- print_verbose(standard_out);
-
- if (ret != 0) {
+ // Run Blender and export glTF.
+ Error err = EditorImportBlendRunner::get_singleton()->do_import(request_options);
+ if (err != OK) {
if (r_err) {
*r_err = ERR_SCRIPT_FAILED;
}
- ERR_PRINT(vformat("Blend export to glTF failed with error: %d.", ret));
return nullptr;
}
@@ -226,7 +207,7 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_
if (p_options.has(SNAME("blender/materials/unpack_enabled")) && p_options[SNAME("blender/materials/unpack_enabled")]) {
base_dir = sink.get_base_dir();
}
- Error err = gltf->append_from_file(sink.get_basename() + ".gltf", state, p_flags, base_dir);
+ err = gltf->append_from_file(sink.get_basename() + ".gltf", state, p_flags, base_dir);
if (err != OK) {
if (r_err) {
*r_err = FAILED;
diff --git a/modules/gltf/register_types.cpp b/modules/gltf/register_types.cpp
index f80e12bbae..78589090db 100644
--- a/modules/gltf/register_types.cpp
+++ b/modules/gltf/register_types.cpp
@@ -36,6 +36,7 @@
#ifdef TOOLS_ENABLED
#include "core/config/project_settings.h"
+#include "editor/editor_import_blend_runner.h"
#include "editor/editor_node.h"
#include "editor/editor_scene_exporter_gltf_plugin.h"
#include "editor/editor_scene_importer_blend.h"
@@ -52,6 +53,14 @@ static void _editor_init() {
bool blend_enabled = GLOBAL_GET("filesystem/import/blender/enabled");
// Defined here because EditorSettings doesn't exist in `register_gltf_types` yet.
+ EDITOR_DEF_RST("filesystem/import/blender/rpc_port", 6011);
+ EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT,
+ "filesystem/import/blender/rpc_port", PROPERTY_HINT_RANGE, "0,65535,1"));
+
+ EDITOR_DEF_RST("filesystem/import/blender/rpc_server_uptime", 5);
+ EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::FLOAT,
+ "filesystem/import/blender/rpc_server_uptime", PROPERTY_HINT_RANGE, "0,300,1,or_greater,suffix:s"));
+
String blender3_path = EDITOR_DEF_RST("filesystem/import/blender/blender3_path", "");
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,
"filesystem/import/blender/blender3_path", PROPERTY_HINT_GLOBAL_DIR));
@@ -71,6 +80,8 @@ static void _editor_init() {
EditorFileSystem::get_singleton()->add_import_format_support_query(blend_import_query);
}
}
+ memnew(EditorImportBlendRunner);
+ EditorNode::get_singleton()->add_child(EditorImportBlendRunner::get_singleton());
// FBX to glTF importer.
diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp
index c09da2f7b3..8377e81a53 100644
--- a/platform/linuxbsd/x11/display_server_x11.cpp
+++ b/platform/linuxbsd/x11/display_server_x11.cpp
@@ -3672,8 +3672,23 @@ Rect2i DisplayServerX11::window_get_popup_safe_rect(WindowID p_window) const {
void DisplayServerX11::popup_open(WindowID p_window) {
_THREAD_SAFE_METHOD_
+ bool has_popup_ancestor = false;
+ WindowID transient_root = p_window;
+ while (true) {
+ WindowID parent = windows[transient_root].transient_parent;
+ if (parent == INVALID_WINDOW_ID) {
+ break;
+ } else {
+ transient_root = parent;
+ if (windows[parent].is_popup) {
+ has_popup_ancestor = true;
+ break;
+ }
+ }
+ }
+
WindowData &wd = windows[p_window];
- if (wd.is_popup) {
+ if (wd.is_popup || has_popup_ancestor) {
// Find current popup parent, or root popup if new window is not transient.
List<WindowID>::Element *C = nullptr;
List<WindowID>::Element *E = popup_list.back();
@@ -4897,7 +4912,7 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V
// handling decorations and placement.
// On the other hand, focus changes need to be handled manually when this is set.
// - save_under is a hint for the WM to keep the content of windows behind to avoid repaint.
- if (wd.is_popup || wd.no_focus) {
+ if (wd.no_focus) {
windowAttributes.override_redirect = True;
windowAttributes.save_under = True;
valuemask |= CWOverrideRedirect | CWSaveUnder;
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index 2832495693..b1880c2fb6 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -3681,8 +3681,23 @@ Rect2i DisplayServerMacOS::window_get_popup_safe_rect(WindowID p_window) const {
void DisplayServerMacOS::popup_open(WindowID p_window) {
_THREAD_SAFE_METHOD_
+ bool has_popup_ancestor = false;
+ WindowID transient_root = p_window;
+ while (true) {
+ WindowID parent = windows[transient_root].transient_parent;
+ if (parent == INVALID_WINDOW_ID) {
+ break;
+ } else {
+ transient_root = parent;
+ if (windows[parent].is_popup) {
+ has_popup_ancestor = true;
+ break;
+ }
+ }
+ }
+
WindowData &wd = windows[p_window];
- if (wd.is_popup) {
+ if (wd.is_popup || has_popup_ancestor) {
bool was_empty = popup_list.is_empty();
// Find current popup parent, or root popup if new window is not transient.
List<WindowID>::Element *C = nullptr;
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index cc230575c8..777d05584c 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -2360,8 +2360,23 @@ Rect2i DisplayServerWindows::window_get_popup_safe_rect(WindowID p_window) const
void DisplayServerWindows::popup_open(WindowID p_window) {
_THREAD_SAFE_METHOD_
- const WindowData &wd = windows[p_window];
- if (wd.is_popup) {
+ bool has_popup_ancestor = false;
+ WindowID transient_root = p_window;
+ while (true) {
+ WindowID parent = windows[transient_root].transient_parent;
+ if (parent == INVALID_WINDOW_ID) {
+ break;
+ } else {
+ transient_root = parent;
+ if (windows[parent].is_popup) {
+ has_popup_ancestor = true;
+ break;
+ }
+ }
+ }
+
+ WindowData &wd = windows[p_window];
+ if (wd.is_popup || has_popup_ancestor) {
// Find current popup parent, or root popup if new window is not transient.
List<WindowID>::Element *C = nullptr;
List<WindowID>::Element *E = popup_list.back();
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index ddc11d97b9..0eeac2f285 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -840,6 +840,9 @@ void PopupMenu::_notification(int p_what) {
float pm_delay = pm->get_submenu_popup_delay();
set_submenu_popup_delay(pm_delay);
}
+ if (!is_embedded()) {
+ set_flag(FLAG_NO_FOCUS, true);
+ }
} break;
case NOTIFICATION_THEME_CHANGED:
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index cde3503bdf..541c7a0587 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -408,8 +408,8 @@ void CanvasItem::set_as_top_level(bool p_top_level) {
void CanvasItem::_toplevel_changed() {
// Inform children that toplevel status has changed on a parent.
- int childs = get_child_count();
- for (int i = 0; i < childs; i++) {
+ int children = get_child_count();
+ for (int i = 0; i < children; i++) {
CanvasItem *child = Object::cast_to<CanvasItem>(get_child(i));
if (child) {
child->_toplevel_changed_on_parent();
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 9ce2a0e893..c31155bd5c 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -527,6 +527,11 @@ void Viewport::_process_picking() {
if (to_screen_rect != Rect2i() && Input::get_singleton()->get_mouse_mode() == Input::MOUSE_MODE_CAPTURED) {
return;
}
+ if (!gui.mouse_in_viewport) {
+ // Clear picking events if mouse has left viewport.
+ physics_picking_events.clear();
+ return;
+ }
_drop_physics_mouseover(true);