diff options
-rw-r--r-- | doc/classes/Basis.xml | 156 | ||||
-rw-r--r-- | misc/dist/html/full-size.html | 25 | ||||
-rw-r--r-- | misc/dist/html/service-worker.js | 172 | ||||
-rw-r--r-- | platform/web/.eslintrc.sw.js | 14 | ||||
-rw-r--r-- | platform/web/doc_classes/EditorExportPlatformWeb.xml | 4 | ||||
-rw-r--r-- | platform/web/export/export_plugin.cpp | 4 | ||||
-rw-r--r-- | platform/web/js/engine/engine.js | 16 | ||||
-rw-r--r-- | platform/web/package.json | 8 | ||||
-rw-r--r-- | scene/3d/camera_3d.cpp | 64 | ||||
-rw-r--r-- | scene/3d/camera_3d.h | 10 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 2 |
11 files changed, 328 insertions, 147 deletions
diff --git a/doc/classes/Basis.xml b/doc/classes/Basis.xml index c271e23f2e..8731b27fc9 100644 --- a/doc/classes/Basis.xml +++ b/doc/classes/Basis.xml @@ -4,10 +4,12 @@ A 3×3 matrix for representing 3D rotation and scale. </brief_description> <description> - A 3×3 matrix used for representing 3D rotation and scale. Usually used as an orthogonal basis for a [Transform3D]. - Contains 3 vector fields X, Y and Z as its columns, which are typically interpreted as the local basis vectors of a transformation. For such use, it is composed of a scaling and a rotation matrix, in that order (M = R.S). - Basis can also be accessed as an array of 3D vectors. These vectors are usually orthogonal to each other, but are not necessarily normalized (due to scaling). + The [Basis] built-in [Variant] type is a 3x3 [url=https://en.wikipedia.org/wiki/Matrix_(mathematics)]matrix[/url] used to represent 3D rotation, scale, and shear. It is frequently used within a [Transform3D]. + A [Basis] is composed by 3 axis vectors, each representing a column of the matrix: [member x], [member y], and [member z]. The length of each axis ([method Vector3.length]) influences the basis's scale, while the direction of all axes influence the rotation. Usually, these axes are perpendicular to one another. However, when you rotate any axis individually, the basis becomes sheared. Applying a sheared basis to a 3D model will make the model appear distorted. + A [Basis] is [b]orthogonal[/b] if its axes are perpendicular to each other. A basis is [b]normalized[/b] if the length of every axis is [code]1[/code]. A basis is [b]uniform[/b] if all axes share the same length (see [method get_scale]). A basis is [b]orthonormal[/b] if it is both orthogonal and normalized, which allows it to only represent rotations. A basis is [b]conformal[/b] if it is both orthogonal and uniform, which ensures it is not distorted. For a general introduction, see the [url=$DOCS_URL/tutorials/math/matrices_and_transforms.html]Matrices and transforms[/url] tutorial. + [b]Note:[/b] Godot uses a [url=https://en.wikipedia.org/wiki/Right-hand_rule]right-handed coordinate system[/url], which is a common standard. For directions, the convention for built-in types like [Camera3D] is for -Z to point forward (+X is right, +Y is up, and +Z is back). Other objects may use different direction conventions. For more information, see the [url=$DOCS_URL/tutorials/assets_pipeline/importing_scenes.html#d-asset-direction-conventions]Importing 3D Scenes[/url] tutorial. + [b]Note:[/b] The basis matrices are exposed as [url=https://www.mindcontrol.org/~hplus/graphics/matrix-layout.html]column-major[/url] order, which is the same as OpenGL. However, they are stored internally in row-major order, which is the same as DirectX. </description> <tutorials> <link title="Math documentation index">$DOCS_URL/tutorials/math/index.html</link> @@ -22,7 +24,7 @@ <constructor name="Basis"> <return type="Basis" /> <description> - Constructs a default-initialized [Basis] set to [constant IDENTITY]. + Constructs a [Basis] identical to the [constant IDENTITY]. </description> </constructor> <constructor name="Basis"> @@ -37,14 +39,16 @@ <param index="0" name="axis" type="Vector3" /> <param index="1" name="angle" type="float" /> <description> - Constructs a pure rotation basis matrix, rotated around the given [param axis] by [param angle] (in radians). The axis must be a normalized vector. + Constructs a [Basis] that only represents rotation, rotated around the [param axis] by the given [param angle], in radians. The axis must be a normalized vector. + [b]Note:[/b] This is the same as using [method rotated] on the [constant IDENTITY] basis. With more than one angle consider using [method from_euler], instead. </description> </constructor> <constructor name="Basis"> <return type="Basis" /> <param index="0" name="from" type="Quaternion" /> <description> - Constructs a pure rotation basis matrix from the given quaternion. + Constructs a [Basis] that only represents rotation from the given [Quaternion]. + [b]Note:[/b] Quaternions [i]only[/i] store rotation, not scale. Because of this, conversions from [Basis] to [Quaternion] cannot always be reversed. </description> </constructor> <constructor name="Basis"> @@ -53,7 +57,7 @@ <param index="1" name="y_axis" type="Vector3" /> <param index="2" name="z_axis" type="Vector3" /> <description> - Constructs a basis matrix from 3 axis vectors (matrix columns). + Constructs a [Basis] from 3 axis vectors. These are the columns of the basis matrix. </description> </constructor> </constructors> @@ -61,8 +65,10 @@ <method name="determinant" qualifiers="const"> <return type="float" /> <description> - Returns the determinant of the basis matrix. If the basis is uniformly scaled, its determinant is the square of the scale. - A negative determinant means the basis has a negative scale. A zero determinant means the basis isn't invertible, and is usually considered invalid. + Returns the [url=https://en.wikipedia.org/wiki/Determinant]determinant[/url] of this basis's matrix. For advanced math, this number can be used to determine a few attributes: + - If the determinant is exactly [code]0[/code], the basis is not invertible (see [method inverse]). + - If the determinant is a negative number, the basis represents a negative scale. + [b]Note:[/b] If the basis's scale is the same for every axis, its determinant is always that scale by the power of 2. </description> </method> <method name="from_euler" qualifiers="static"> @@ -70,7 +76,10 @@ <param index="0" name="euler" type="Vector3" /> <param index="1" name="order" type="int" default="2" /> <description> - Constructs a pure rotation Basis matrix from Euler angles in the specified Euler rotation order. By default, use YXZ order (most common). See the [enum EulerOrder] enum for possible values. + Constructs a new [Basis] that only represents rotation from the given [Vector3] of [url=https://en.wikipedia.org/wiki/Euler_angles]Euler angles[/url], in radians. + - The [member Vector3.x] should contain the angle around the [member x] axis (pitch). + - The [member Vector3.y] should contain the angle around the [member y] axis (yaw). + - The [member Vector3.z] should contain the angle around the [member z] axis (roll). [codeblocks] [gdscript] # Creates a Basis whose z axis points down. @@ -85,13 +94,14 @@ GD.Print(myBasis.Z); // Prints (0, -1, 0). [/csharp] [/codeblocks] + The order of each consecutive rotation can be changed with [param order] (see [enum EulerOrder] constants). By default, the YXZ convention is used ([constant EULER_ORDER_YXZ]): the basis rotates first around the Y axis (yaw), then X (pitch), and lastly Z (roll). When using the opposite method [method get_euler], this order is reversed. </description> </method> <method name="from_scale" qualifiers="static"> <return type="Basis" /> <param index="0" name="scale" type="Vector3" /> <description> - Constructs a pure scale basis matrix with no rotation or shearing. The scale values are set as the diagonal of the matrix, and the other parts of the matrix are zero. + Constructs a new [Basis] that only represents scale, with no rotation or shear, from the given [param scale] vector. [codeblocks] [gdscript] var my_basis = Basis.from_scale(Vector3(2, 4, 8)) @@ -108,26 +118,33 @@ GD.Print(myBasis.Z); // Prints (0, 0, 8). [/csharp] [/codeblocks] + [b]Note:[/b] In linear algebra, the matrix of this basis is also known as a [url=https://en.wikipedia.org/wiki/Diagonal_matrix]diagonal matrix[/url]. </description> </method> <method name="get_euler" qualifiers="const"> <return type="Vector3" /> <param index="0" name="order" type="int" default="2" /> <description> - Returns the basis's rotation in the form of Euler angles. The Euler order depends on the [param order] parameter, by default it uses the YXZ convention: when decomposing, first Z, then X, and Y last. The returned vector contains the rotation angles in the format (X angle, Y angle, Z angle). - Consider using the [method get_rotation_quaternion] method instead, which returns a [Quaternion] quaternion instead of Euler angles. + Returns this basis's rotation as a [Vector3] of [url=https://en.wikipedia.org/wiki/Euler_angles]Euler angles[/url], in radians. + - The [member Vector3.x] contains the angle around the [member x] axis (pitch); + - The [member Vector3.y] contains the angle around the [member y] axis (yaw); + - The [member Vector3.z] contains the angle around the [member z] axis (roll). + The order of each consecutive rotation can be changed with [param order] (see [enum EulerOrder] constants). By default, the YXZ convention is used ([constant EULER_ORDER_YXZ]): Z (roll) is calculated first, then X (pitch), and lastly Y (yaw). When using the opposite method [method from_euler], this order is reversed. + [b]Note:[/b] Euler angles are much more intuitive but are not suitable for 3D math. Because of this, consider using the [method get_rotation_quaternion] method instead, which returns a [Quaternion]. + [b]Note:[/b] In the Inspector dock, a basis's rotation is often displayed in Euler angles (in degrees), as is the case with the [member Node3D.rotation] property. </description> </method> <method name="get_rotation_quaternion" qualifiers="const"> <return type="Quaternion" /> <description> - Returns the basis's rotation in the form of a quaternion. See [method get_euler] if you need Euler angles, but keep in mind quaternions should generally be preferred to Euler angles. + Returns this basis's rotation as a [Quaternion]. + [b]Note:[/b] Quatenions are much more suitable for 3D math but are less intuitive. For user interfaces, consider using the [method get_euler] method, which returns Euler angles. </description> </method> <method name="get_scale" qualifiers="const"> <return type="Vector3" /> <description> - Assuming that the matrix is the combination of a rotation and scaling, return the absolute value of scaling factors along each axis. + Returns the length of each axis of this basis, as a [Vector3]. If the basis is not sheared, this is the scaling factor. It is not affected by rotation. [codeblocks] [gdscript] var my_basis = Basis( @@ -154,18 +171,19 @@ GD.Print(myBasis.Scale); // Prints (2, 4, 8). [/csharp] [/codeblocks] + [b]Note:[/b] If the value returned by [method determinant] is negative, the scale is also negative. </description> </method> <method name="inverse" qualifiers="const"> <return type="Basis" /> <description> - Returns the inverse of the matrix. + Returns the [url=https://en.wikipedia.org/wiki/Invertible_matrix]inverse of this basis's matrix[/url]. </description> </method> <method name="is_conformal" qualifiers="const"> <return type="bool" /> <description> - Returns [code]true[/code] if the basis is conformal, meaning it preserves angles and distance ratios, and may only be composed of rotation and uniform scale. Returns [code]false[/code] if the basis has non-uniform scale or shear/skew. This can be used to validate if the basis is non-distorted, which is important for physics and other use cases. + Returns [code]true[/code] if this basis is conformal. A conformal basis is both [i]orthogonal[/i] (the axes are perpendicular to each other) and [i]uniform[/i] (the axes share the same length). This method can be especially useful during physics calculations. </description> </method> <method name="is_equal_approx" qualifiers="const"> @@ -187,15 +205,16 @@ <param index="1" name="up" type="Vector3" default="Vector3(0, 1, 0)" /> <param index="2" name="use_model_front" type="bool" default="false" /> <description> - Creates a Basis with a rotation such that the forward axis (-Z) points towards the [param target] position. - The up axis (+Y) points as close to the [param up] vector as possible while staying perpendicular to the forward axis. The resulting Basis is orthonormalized. The [param target] and [param up] vectors cannot be zero, and cannot be parallel to each other. - If [param use_model_front] is [code]true[/code], the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the [param target] position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right). + Creates a new [Basis] with a rotation such that the forward axis (-Z) points towards the [param target] position. + By default, the -Z axis (camera forward) is treated as forward (implies +X is right). If [param use_model_front] is [code]true[/code], the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the [param target] position. + The up axis (+Y) points as close to the [param up] vector as possible while staying perpendicular to the forward axis. The returned basis is orthonormalized (see [method orthonormalized]). The [param target] and [param up] vectors cannot be [constant Vector3.ZERO], and cannot be parallel to each other. </description> </method> <method name="orthonormalized" qualifiers="const"> <return type="Basis" /> <description> - Returns the orthonormalized version of the matrix (useful to call from time to time to avoid rounding error for orthogonal matrices). This performs a Gram-Schmidt orthonormalization on the basis of the matrix. + Returns the orthonormalized version of this basis. An orthonormal basis is both [i]orthogonal[/i] (the axes are perpendicular to each other) and [i]normalized[/i] (the axes have a length of [code]1[/code]), which also means it can only represent rotation. + It is often useful to call this method to avoid rounding errors on a rotating basis: [codeblocks] [gdscript] # Rotate this Node3D every frame. @@ -222,7 +241,8 @@ <param index="0" name="axis" type="Vector3" /> <param index="1" name="angle" type="float" /> <description> - Introduce an additional rotation around the given axis by [param angle] (in radians). The axis must be a normalized vector. + Returns this basis rotated around the given [param axis] by [param angle] (in radians). The [param axis] must be a normalized vector (see [method Vector3.normalized]). + Positive values rotate this basis clockwise around the axis, while negative values rotate it counterclockwise. [codeblocks] [gdscript] var my_basis = Basis.IDENTITY @@ -247,7 +267,8 @@ <return type="Basis" /> <param index="0" name="scale" type="Vector3" /> <description> - Introduce an additional scaling specified by the given 3D scaling factor. + Returns this basis with each axis's components scaled by the given [param scale]'s components. + The basis matrix's rows are multiplied by [param scale]'s components. This operation is a global scale (relative to the parent). [codeblocks] [gdscript] var my_basis = Basis( @@ -281,34 +302,48 @@ <param index="0" name="to" type="Basis" /> <param index="1" name="weight" type="float" /> <description> - Assuming that the matrix is a proper rotation matrix, slerp performs a spherical-linear interpolation with another rotation matrix. + Performs a spherical-linear interpolation with the [param to] basis, given a [param weight]. Both this basis and [param to] should represent a rotation. + [b]Example:[/b] Smoothly rotate a [Node3D] to the target basis over time, with a [Tween]. + [codeblock] + var start_basis = Basis.IDENTITY + var target_basis = Basis.IDENTITY.rotated(Vector3.UP, TAU / 2) + + func _ready(): + create_tween().tween_method(interpolate, 0.0, 1.0, 5.0).set_trans(Tween.TRANS_EXPO) + + func interpolate(weight): + basis = start_basis.slerp(target_basis, weight) + [/codeblock] </description> </method> <method name="tdotx" qualifiers="const"> <return type="float" /> <param index="0" name="with" type="Vector3" /> <description> - Transposed dot product with the X axis of the matrix. + Returns the transposed dot product between [param with] and the [member x] axis (see [method transposed]). + This is equivalent to [code]basis.x.dot(vector)[/code]. </description> </method> <method name="tdoty" qualifiers="const"> <return type="float" /> <param index="0" name="with" type="Vector3" /> <description> - Transposed dot product with the Y axis of the matrix. + Returns the transposed dot product between [param with] and the [member y] axis (see [method transposed]). + This is equivalent to [code]basis.y.dot(vector)[/code]. </description> </method> <method name="tdotz" qualifiers="const"> <return type="float" /> <param index="0" name="with" type="Vector3" /> <description> - Transposed dot product with the Z axis of the matrix. + Returns the transposed dot product between [param with] and the [member z] axis (see [method transposed]). + This is equivalent to [code]basis.z.dot(vector)[/code]. </description> </method> <method name="transposed" qualifiers="const"> <return type="Basis" /> <description> - Returns the transposed version of the matrix. + Returns the transposed version of this basis. This turns the basis matrix's columns into rows, and its rows into columns. [codeblocks] [gdscript] var my_basis = Basis( @@ -340,28 +375,49 @@ </methods> <members> <member name="x" type="Vector3" setter="" getter="" default="Vector3(1, 0, 0)"> - The basis matrix's X vector (column 0). Equivalent to array index [code]0[/code]. + The basis's X axis, and the column [code]0[/code] of the matrix. + On the identity basis, this vector points right ([constant Vector3.RIGHT]). </member> <member name="y" type="Vector3" setter="" getter="" default="Vector3(0, 1, 0)"> - The basis matrix's Y vector (column 1). Equivalent to array index [code]1[/code]. + The basis's Y axis, and the column [code]1[/code] of the matrix. + On the identity basis, this vector points up ([constant Vector3.UP]). </member> <member name="z" type="Vector3" setter="" getter="" default="Vector3(0, 0, 1)"> - The basis matrix's Z vector (column 2). Equivalent to array index [code]2[/code]. + The basis's Z axis, and the column [code]2[/code] of the matrix. + On the identity basis, this vector points back ([constant Vector3.BACK]). </member> </members> <constants> <constant name="IDENTITY" value="Basis(1, 0, 0, 0, 1, 0, 0, 0, 1)"> - The identity basis, with no rotation or scaling applied. + The identity basis. This is a basis with no rotation, no shear, and its scale being [code]1[/code]. This means that: + - The [member x] points right ([constant Vector3.RIGHT]); + - The [member y] points up ([constant Vector3.UP]); + - The [member z] points back ([constant Vector3.BACK]). + [codeblock] + var basis := Basis.IDENTITY + print("| X | Y | Z") + print("| %s | %s | %s" % [basis.x.x, basis.y.x, basis.z.x]) + print("| %s | %s | %s" % [basis.x.y, basis.y.y, basis.z.y]) + print("| %s | %s | %s" % [basis.x.z, basis.y.z, basis.z.z]) + # Prints: + # | X | Y | Z + # | 1 | 0 | 0 + # | 0 | 1 | 0 + # | 0 | 0 | 1 + [/codeblock] This is identical to creating [constructor Basis] without any parameters. This constant can be used to make your code clearer, and for consistency with C#. </constant> <constant name="FLIP_X" value="Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1)"> - The basis that will flip something along the X axis when used in a transformation. + When any basis is multiplied by [constant FLIP_X], it negates all components of the [member x] axis (the X column). + When [constant FLIP_X] is multiplied by any basis, it negates the [member Vector3.x] component of all axes (the X row). </constant> <constant name="FLIP_Y" value="Basis(1, 0, 0, 0, -1, 0, 0, 0, 1)"> - The basis that will flip something along the Y axis when used in a transformation. + When any basis is multiplied by [constant FLIP_Y], it negates all components of the [member y] axis (the Y column). + When [constant FLIP_Y] is multiplied by any basis, it negates the [member Vector3.y] component of all axes (the Y row). </constant> <constant name="FLIP_Z" value="Basis(1, 0, 0, 0, 1, 0, 0, 0, -1)"> - The basis that will flip something along the Z axis when used in a transformation. + When any basis is multiplied by [constant FLIP_Z], it negates all components of the [member z] axis (the Z column). + When [constant FLIP_Z] is multiplied by any basis, it negates the [member Vector3.z] component of all axes (the Z row). </constant> </constants> <operators> @@ -369,7 +425,7 @@ <return type="bool" /> <param index="0" name="right" type="Basis" /> <description> - Returns [code]true[/code] if the [Basis] matrices are not equal. + Returns [code]true[/code] if the components of both [Basis] matrices are not equal. [b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable. </description> </operator> @@ -377,49 +433,60 @@ <return type="Basis" /> <param index="0" name="right" type="Basis" /> <description> - Composes these two basis matrices by multiplying them together. This has the effect of transforming the second basis (the child) by the first basis (the parent). + Transforms (multiplies) the [param right] basis by this basis. + This is the operation performed between parent and child [Node3D]s. </description> </operator> <operator name="operator *"> <return type="Vector3" /> <param index="0" name="right" type="Vector3" /> <description> - Transforms (multiplies) the [Vector3] by the given [Basis] matrix. + Transforms (multiplies) the [param right] vector by this basis, returning a [Vector3]. + [codeblocks] + [gdscript] + var my_basis = Basis(Vector3(1, 1, 1), Vector3(1, 1, 1), Vector3(0, 2, 5)) + print(my_basis * Vector3(1, 2, 3)) # Prints (7, 3, 16) + [/gdscript] + [csharp] + var myBasis = new Basis(new Vector3(1, 1, 1), new Vector3(1, 1, 1), new Vector3(0, 2, 5)); + GD.Print(my_basis * new Vector3(1, 2, 3)); // Prints (7, 3, 16) + [/csharp] + [/codeblocks] </description> </operator> <operator name="operator *"> <return type="Basis" /> <param index="0" name="right" type="float" /> <description> - This operator multiplies all components of the [Basis], which scales it uniformly. + Multiplies all components of the [Basis] by the given [float]. This affects the basis's scale uniformly, resizing all 3 axes by the [param right] value. </description> </operator> <operator name="operator *"> <return type="Basis" /> <param index="0" name="right" type="int" /> <description> - This operator multiplies all components of the [Basis], which scales it uniformly. + Multiplies all components of the [Basis] by the given [int]. This affects the basis's scale uniformly, resizing all 3 axes by the [param right] value. </description> </operator> <operator name="operator /"> <return type="Basis" /> <param index="0" name="right" type="float" /> <description> - This operator divides all components of the [Basis], which inversely scales it uniformly. + Divides all components of the [Basis] by the given [float]. This affects the basis's scale uniformly, resizing all 3 axes by the [param right] value. </description> </operator> <operator name="operator /"> <return type="Basis" /> <param index="0" name="right" type="int" /> <description> - This operator divides all components of the [Basis], which inversely scales it uniformly. + Divides all components of the [Basis] by the given [int]. This affects the basis's scale uniformly, resizing all 3 axes by the [param right] value. </description> </operator> <operator name="operator =="> <return type="bool" /> <param index="0" name="right" type="Basis" /> <description> - Returns [code]true[/code] if the [Basis] matrices are exactly equal. + Returns [code]true[/code] if the components of both [Basis] matrices are exactly equal. [b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable. </description> </operator> @@ -427,7 +494,8 @@ <return type="Vector3" /> <param index="0" name="index" type="int" /> <description> - Access basis components using their index. [code]b[0][/code] is equivalent to [code]b.x[/code], [code]b[1][/code] is equivalent to [code]b.y[/code], and [code]b[2][/code] is equivalent to [code]b.z[/code]. + Accesses each axis (column) of this basis by their index. Index [code]0[/code] is the same as [member x], index [code]1[/code] is the same as [member y], and index [code]2[/code] is the same as [member z]. + [b]Note:[/b] In C++, this operator accesses the rows of the basis matrix, [i]not[/i] the columns. For the same behavior as scripting languages, use the [code]set_column[/code] and [code]get_column[/code] methods. </description> </operator> </operators> diff --git a/misc/dist/html/full-size.html b/misc/dist/html/full-size.html index 54571e27c7..8ae25362f8 100644 --- a/misc/dist/html/full-size.html +++ b/misc/dist/html/full-size.html @@ -218,8 +218,29 @@ const engine = new Engine(GODOT_CONFIG); threads: GODOT_THREADS_ENABLED, }); if (missing.length !== 0) { - const missingMsg = 'Error\nThe following features required to run Godot projects on the Web are missing:\n'; - displayFailureNotice(missingMsg + missing.join('\n')); + if (GODOT_CONFIG['serviceWorker'] && GODOT_CONFIG['ensureCrossOriginIsolationHeaders'] && 'serviceWorker' in navigator) { + // There's a chance that installing the service worker would fix the issue + Promise.race([ + navigator.serviceWorker.getRegistration().then((registration) => { + if (registration != null) { + return Promise.reject(new Error('Service worker already exists.')); + } + return registration; + }).then(() => engine.installServiceWorker()), + // For some reason, `getRegistration()` can stall + new Promise((resolve) => { + setTimeout(() => resolve(), 2000); + }), + ]).catch((err) => { + console.error('Error while registering service worker:', err); + }).then(() => { + window.location.reload(); + }); + } else { + // Display the message as usual + const missingMsg = 'Error\nThe following features required to run Godot projects on the Web are missing:\n'; + displayFailureNotice(missingMsg + missing.join('\n')); + } } else { setStatusMode('indeterminate'); engine.startGame({ diff --git a/misc/dist/html/service-worker.js b/misc/dist/html/service-worker.js index 70e7a399e1..a5da7482f4 100644 --- a/misc/dist/html/service-worker.js +++ b/misc/dist/html/service-worker.js @@ -3,101 +3,163 @@ // that they need an Internet connection to run the project if desired. // Incrementing CACHE_VERSION will kick off the install event and force // previously cached resources to be updated from the network. -const CACHE_VERSION = "___GODOT_VERSION___"; -const CACHE_PREFIX = "___GODOT_NAME___-sw-cache-"; +/** @type {string} */ +const CACHE_VERSION = '___GODOT_VERSION___'; +/** @type {string} */ +const CACHE_PREFIX = '___GODOT_NAME___-sw-cache-'; const CACHE_NAME = CACHE_PREFIX + CACHE_VERSION; -const OFFLINE_URL = "___GODOT_OFFLINE_PAGE___"; +/** @type {string} */ +const OFFLINE_URL = '___GODOT_OFFLINE_PAGE___'; +/** @type {boolean} */ +const ENSURE_CROSSORIGIN_ISOLATION_HEADERS = ___GODOT_ENSURE_CROSSORIGIN_ISOLATION_HEADERS___; // Files that will be cached on load. +/** @type {string[]} */ const CACHED_FILES = ___GODOT_CACHE___; // Files that we might not want the user to preload, and will only be cached on first load. +/** @type {string[]} */ const CACHABLE_FILES = ___GODOT_OPT_CACHE___; const FULL_CACHE = CACHED_FILES.concat(CACHABLE_FILES); -self.addEventListener("install", (event) => { - event.waitUntil(caches.open(CACHE_NAME).then(cache => cache.addAll(CACHED_FILES))); +self.addEventListener('install', (event) => { + event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(CACHED_FILES))); }); -self.addEventListener("activate", (event) => { +self.addEventListener('activate', (event) => { event.waitUntil(caches.keys().then( function (keys) { // Remove old caches. - return Promise.all(keys.filter(key => key.startsWith(CACHE_PREFIX) && key != CACHE_NAME).map(key => caches.delete(key))); - }).then(function () { - // Enable navigation preload if available. - return ("navigationPreload" in self.registration) ? self.registration.navigationPreload.enable() : Promise.resolve(); - }) - ); + return Promise.all(keys.filter((key) => key.startsWith(CACHE_PREFIX) && key !== CACHE_NAME).map((key) => caches.delete(key))); + } + ).then(function () { + // Enable navigation preload if available. + return ('navigationPreload' in self.registration) ? self.registration.navigationPreload.enable() : Promise.resolve(); + })); }); -async function fetchAndCache(event, cache, isCachable) { +/** + * Ensures that the response has the correct COEP/COOP headers + * @param {Response} response + * @returns {Response} + */ +function ensureCrossOriginIsolationHeaders(response) { + if (response.headers.get('Cross-Origin-Embedder-Policy') === 'require-corp' + && response.headers.get('Cross-Origin-Opener-Policy') === 'same-origin') { + return response; + } + + const crossOriginIsolatedHeaders = new Headers(response.headers); + crossOriginIsolatedHeaders.set('Cross-Origin-Embedder-Policy', 'require-corp'); + crossOriginIsolatedHeaders.set('Cross-Origin-Opener-Policy', 'same-origin'); + const newResponse = new Response(response.body, { + status: response.status, + statusText: response.statusText, + headers: crossOriginIsolatedHeaders, + }); + + return newResponse; +} + +/** + * Calls fetch and cache the result if it is cacheable + * @param {FetchEvent} event + * @param {Cache} cache + * @param {boolean} isCacheable + * @returns {Response} + */ +async function fetchAndCache(event, cache, isCacheable) { // Use the preloaded response, if it's there + /** @type { Response } */ let response = await event.preloadResponse; - if (!response) { + if (response == null) { // Or, go over network. response = await self.fetch(event.request); } - if (isCachable) { + + if (ENSURE_CROSSORIGIN_ISOLATION_HEADERS) { + response = ensureCrossOriginIsolationHeaders(response); + } + + if (isCacheable) { // And update the cache cache.put(event.request, response.clone()); } + return response; } -self.addEventListener("fetch", (event) => { - const isNavigate = event.request.mode === "navigate"; - const url = event.request.url || ""; - const referrer = event.request.referrer || ""; - const base = referrer.slice(0, referrer.lastIndexOf("/") + 1); - const local = url.startsWith(base) ? url.replace(base, "") : ""; - const isCachable = FULL_CACHE.some(v => v === local) || (base === referrer && base.endsWith(CACHED_FILES[0])); - if (isNavigate || isCachable) { - event.respondWith(async function () { - // Try to use cache first - const cache = await caches.open(CACHE_NAME); - if (event.request.mode === "navigate") { - // Check if we have full cache during HTML page request. - const fullCache = await Promise.all(FULL_CACHE.map(name => cache.match(name))); - const missing = fullCache.some(v => v === undefined); - if (missing) { - try { - // Try network if some cached file is missing (so we can display offline page in case). - return await fetchAndCache(event, cache, isCachable); - } catch (e) { - // And return the hopefully always cached offline page in case of network failure. - console.error("Network error: ", e); - return await caches.match(OFFLINE_URL); +self.addEventListener( + 'fetch', + /** + * Triggered on fetch + * @param {FetchEvent} event + */ + (event) => { + const isNavigate = event.request.mode === 'navigate'; + const url = event.request.url || ''; + const referrer = event.request.referrer || ''; + const base = referrer.slice(0, referrer.lastIndexOf('/') + 1); + const local = url.startsWith(base) ? url.replace(base, '') : ''; + const isCachable = FULL_CACHE.some((v) => v === local) || (base === referrer && base.endsWith(CACHED_FILES[0])); + if (isNavigate || isCachable) { + event.respondWith((async () => { + // Try to use cache first + const cache = await caches.open(CACHE_NAME); + if (isNavigate) { + // Check if we have full cache during HTML page request. + /** @type {Response[]} */ + const fullCache = await Promise.all(FULL_CACHE.map((name) => cache.match(name))); + const missing = fullCache.some((v) => v === undefined); + if (missing) { + try { + // Try network if some cached file is missing (so we can display offline page in case). + const response = await fetchAndCache(event, cache, isCachable); + return response; + } catch (e) { + // And return the hopefully always cached offline page in case of network failure. + console.error('Network error: ', e); // eslint-disable-line no-console + return caches.match(OFFLINE_URL); + } } } - } - const cached = await cache.match(event.request); - if (cached) { - return cached; - } else { + let cached = await cache.match(event.request); + if (cached != null) { + if (ENSURE_CROSSORIGIN_ISOLATION_HEADERS) { + cached = ensureCrossOriginIsolationHeaders(cached); + } + return cached; + } // Try network if don't have it in cache. - return await fetchAndCache(event, cache, isCachable); - } - }()); + const response = await fetchAndCache(event, cache, isCachable); + return response; + })()); + } else if (ENSURE_CROSSORIGIN_ISOLATION_HEADERS) { + event.respondWith((async () => { + let response = await fetch(event.request); + response = ensureCrossOriginIsolationHeaders(response); + return response; + })()); + } } -}); +); -self.addEventListener("message", (event) => { +self.addEventListener('message', (event) => { // No cross origin - if (event.origin != self.origin) { + if (event.origin !== self.origin) { return; } - const id = event.source.id || ""; - const msg = event.data || ""; + const id = event.source.id || ''; + const msg = event.data || ''; // Ensure it's one of our clients. self.clients.get(id).then(function (client) { if (!client) { return; // Not a valid client. } - if (msg === "claim") { + if (msg === 'claim') { self.skipWaiting().then(() => self.clients.claim()); - } else if (msg === "clear") { + } else if (msg === 'clear') { caches.delete(CACHE_NAME); - } else if (msg === "update") { - self.skipWaiting().then(() => self.clients.claim()).then(() => self.clients.matchAll()).then(all => all.forEach(c => c.navigate(c.url))); + } else if (msg === 'update') { + self.skipWaiting().then(() => self.clients.claim()).then(() => self.clients.matchAll()).then((all) => all.forEach((c) => c.navigate(c.url))); } else { onClientMessage(event); } diff --git a/platform/web/.eslintrc.sw.js b/platform/web/.eslintrc.sw.js new file mode 100644 index 0000000000..cba9ed8001 --- /dev/null +++ b/platform/web/.eslintrc.sw.js @@ -0,0 +1,14 @@ +module.exports = { + "extends": [ + "./.eslintrc.js", + ], + "rules": { + "no-restricted-globals": 0, + }, + "globals": { + "onClientMessage": true, + "___GODOT_ENSURE_CROSSORIGIN_ISOLATION_HEADERS___": true, + "___GODOT_CACHE___": true, + "___GODOT_OPT_CACHE___": true, + }, +}; diff --git a/platform/web/doc_classes/EditorExportPlatformWeb.xml b/platform/web/doc_classes/EditorExportPlatformWeb.xml index 929d271676..75125e2708 100644 --- a/platform/web/doc_classes/EditorExportPlatformWeb.xml +++ b/platform/web/doc_classes/EditorExportPlatformWeb.xml @@ -55,6 +55,10 @@ <member name="progressive_web_app/enabled" type="bool" setter="" getter=""> If [code]true[/code], turns this web build into a [url=https://en.wikipedia.org/wiki/Progressive_web_app]progressive web application[/url] (PWA). </member> + <member name="progressive_web_app/ensure_cross_origin_isolation_headers" type="bool" setter="" getter=""> + When enabled, the progressive web app will make sure that each request has cross-origin isolation headers (COEP/COOP). + This can simplify the setup to serve the exported game. + </member> <member name="progressive_web_app/icon_144x144" type="String" setter="" getter=""> File path to the smallest icon for this web application. If not defined, defaults to the project icon. [b]Note:[/b] If the icon is not 144x144, it will be automatically resized for the final build. diff --git a/platform/web/export/export_plugin.cpp b/platform/web/export/export_plugin.cpp index 706bfca8ba..41c969b5f4 100644 --- a/platform/web/export/export_plugin.cpp +++ b/platform/web/export/export_plugin.cpp @@ -150,6 +150,7 @@ void EditorExportPlatformWeb::_fix_html(Vector<uint8_t> &p_html, const Ref<Edito config["executable"] = p_name; config["args"] = args; config["fileSizes"] = p_file_sizes; + config["ensureCrossOriginIsolationHeaders"] = (bool)p_preset->get("progressive_web_app/ensure_cross_origin_isolation_headers"); String head_include; if (p_preset->get("html/export_icon")) { @@ -222,10 +223,12 @@ Error EditorExportPlatformWeb::_build_pwa(const Ref<EditorExportPreset> &p_prese const String dir = p_path.get_base_dir(); const String name = p_path.get_file().get_basename(); bool extensions = (bool)p_preset->get("variant/extensions_support"); + bool ensure_crossorigin_isolation_headers = (bool)p_preset->get("progressive_web_app/ensure_cross_origin_isolation_headers"); HashMap<String, String> replaces; replaces["___GODOT_VERSION___"] = String::num_int64(OS::get_singleton()->get_unix_time()) + "|" + String::num_int64(OS::get_singleton()->get_ticks_usec()); replaces["___GODOT_NAME___"] = proj_name.substr(0, 16); replaces["___GODOT_OFFLINE_PAGE___"] = name + ".offline.html"; + replaces["___GODOT_ENSURE_CROSSORIGIN_ISOLATION_HEADERS___"] = ensure_crossorigin_isolation_headers ? "true" : "false"; // Files cached during worker install. Array cache_files; @@ -353,6 +356,7 @@ void EditorExportPlatformWeb::get_export_options(List<ExportOption> *r_options) r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/focus_canvas_on_start"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/experimental_virtual_keyboard"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "progressive_web_app/enabled"), false)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "progressive_web_app/ensure_cross_origin_isolation_headers"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/offline_page", PROPERTY_HINT_FILE, "*.html"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "progressive_web_app/display", PROPERTY_HINT_ENUM, "Fullscreen,Standalone,Minimal UI,Browser"), 1)); r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "progressive_web_app/orientation", PROPERTY_HINT_ENUM, "Any,Landscape,Portrait"), 0)); diff --git a/platform/web/js/engine/engine.js b/platform/web/js/engine/engine.js index 3d6720a2fc..7e24ad9ae2 100644 --- a/platform/web/js/engine/engine.js +++ b/platform/web/js/engine/engine.js @@ -179,9 +179,7 @@ const Engine = (function () { preloader.preloadedFiles.length = 0; // Clear memory me.rtenv['callMain'](me.config.args); initPromise = null; - if (me.config.serviceWorker && 'serviceWorker' in navigator) { - navigator.serviceWorker.register(me.config.serviceWorker); - } + me.installServiceWorker(); resolve(); }); }); @@ -242,6 +240,17 @@ const Engine = (function () { this.rtenv['request_quit'](); } }, + + /** + * Install the progressive-web app service worker. + * @returns {Promise} The service worker registration promise. + */ + installServiceWorker: function () { + if (this.config.serviceWorker && 'serviceWorker' in navigator) { + return navigator.serviceWorker.register(this.config.serviceWorker); + } + return Promise.resolve(); + }, }; Engine.prototype = proto; @@ -252,6 +261,7 @@ const Engine = (function () { Engine.prototype['startGame'] = Engine.prototype.startGame; Engine.prototype['copyToFS'] = Engine.prototype.copyToFS; Engine.prototype['requestQuit'] = Engine.prototype.requestQuit; + Engine.prototype['installServiceWorker'] = Engine.prototype.installServiceWorker; // Also expose static methods as instance methods Engine.prototype['load'] = Engine.load; Engine.prototype['unload'] = Engine.unload; diff --git a/platform/web/package.json b/platform/web/package.json index 5da0e2a76b..4e17cd530b 100644 --- a/platform/web/package.json +++ b/platform/web/package.json @@ -5,18 +5,20 @@ "description": "Development and linting setup for Godot's Web platform code", "scripts": { "docs": "jsdoc --template js/jsdoc2rst/ js/engine/engine.js js/engine/config.js js/engine/features.js --destination ''", - "lint": "npm run lint:engine && npm run lint:libs && npm run lint:modules && npm run lint:tools && npm run lint:html", + "lint": "npm run lint:engine && npm run lint:libs && npm run lint:modules && npm run lint:tools && npm run lint:sw && npm run lint:html", "lint:engine": "eslint \"js/engine/*.js\" --no-eslintrc -c .eslintrc.engine.js", + "lint:sw": "eslint \"../../misc/dist/html/service-worker.js\" --no-eslintrc -c .eslintrc.sw.js", "lint:libs": "eslint \"js/libs/*.js\" --no-eslintrc -c .eslintrc.libs.js", "lint:modules": "eslint \"../../modules/**/*.js\" --no-eslintrc -c .eslintrc.libs.js", "lint:tools": "eslint \"js/jsdoc2rst/**/*.js\" --no-eslintrc -c .eslintrc.engine.js", "lint:html": "eslint \"../../misc/dist/html/*.html\" --no-eslintrc -c .eslintrc.html.js", - "format": "npm run format:engine && npm run format:libs && npm run format:modules && npm run format:tools && npm run format:html", + "format": "npm run format:engine && npm run format:libs && npm run format:modules && npm run format:tools && format:sw && npm run format:html", "format:engine": "npm run lint:engine -- --fix", "format:libs": "npm run lint:libs -- --fix", "format:modules": "npm run lint:modules -- --fix", "format:tools": "npm run lint:tools -- --fix", - "format:html": "npm run lint:html -- --fix" + "format:html": "npm run lint:html -- --fix", + "format:sw": "npm run lint:sw -- --fix" }, "author": "Godot Engine contributors", "license": "MIT", diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp index c66d9bd2c9..d27233289a 100644 --- a/scene/3d/camera_3d.cpp +++ b/scene/3d/camera_3d.cpp @@ -45,14 +45,14 @@ void Camera3D::_update_camera_mode() { force_change = true; switch (mode) { case PROJECTION_PERSPECTIVE: { - set_perspective(fov, near, far); + set_perspective(fov, _near, _far); } break; case PROJECTION_ORTHOGONAL: { - set_orthogonal(size, near, far); + set_orthogonal(size, _near, _far); } break; case PROJECTION_FRUSTUM: { - set_frustum(size, frustum_offset, near, far); + set_frustum(size, frustum_offset, _near, _far); } break; } } @@ -175,13 +175,13 @@ Projection Camera3D::_get_camera_projection(real_t p_near) const { switch (mode) { case PROJECTION_PERSPECTIVE: { - cm.set_perspective(fov, viewport_size.aspect(), p_near, far, keep_aspect == KEEP_WIDTH); + cm.set_perspective(fov, viewport_size.aspect(), p_near, _far, keep_aspect == KEEP_WIDTH); } break; case PROJECTION_ORTHOGONAL: { - cm.set_orthogonal(size, viewport_size.aspect(), p_near, far, keep_aspect == KEEP_WIDTH); + cm.set_orthogonal(size, viewport_size.aspect(), p_near, _far, keep_aspect == KEEP_WIDTH); } break; case PROJECTION_FRUSTUM: { - cm.set_frustum(size, viewport_size.aspect(), frustum_offset, p_near, far); + cm.set_frustum(size, viewport_size.aspect(), frustum_offset, p_near, _far); } break; } @@ -190,54 +190,54 @@ Projection Camera3D::_get_camera_projection(real_t p_near) const { Projection Camera3D::get_camera_projection() const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Projection(), "Camera is not inside the scene tree."); - return _get_camera_projection(near); + return _get_camera_projection(_near); } void Camera3D::set_perspective(real_t p_fovy_degrees, real_t p_z_near, real_t p_z_far) { - if (!force_change && fov == p_fovy_degrees && p_z_near == near && p_z_far == far && mode == PROJECTION_PERSPECTIVE) { + if (!force_change && fov == p_fovy_degrees && p_z_near == _near && p_z_far == _far && mode == PROJECTION_PERSPECTIVE) { return; } fov = p_fovy_degrees; - near = p_z_near; - far = p_z_far; + _near = p_z_near; + _far = p_z_far; mode = PROJECTION_PERSPECTIVE; - RenderingServer::get_singleton()->camera_set_perspective(camera, fov, near, far); + RenderingServer::get_singleton()->camera_set_perspective(camera, fov, _near, _far); update_gizmos(); force_change = false; } void Camera3D::set_orthogonal(real_t p_size, real_t p_z_near, real_t p_z_far) { - if (!force_change && size == p_size && p_z_near == near && p_z_far == far && mode == PROJECTION_ORTHOGONAL) { + if (!force_change && size == p_size && p_z_near == _near && p_z_far == _far && mode == PROJECTION_ORTHOGONAL) { return; } size = p_size; - near = p_z_near; - far = p_z_far; + _near = p_z_near; + _far = p_z_far; mode = PROJECTION_ORTHOGONAL; force_change = false; - RenderingServer::get_singleton()->camera_set_orthogonal(camera, size, near, far); + RenderingServer::get_singleton()->camera_set_orthogonal(camera, size, _near, _far); update_gizmos(); } void Camera3D::set_frustum(real_t p_size, Vector2 p_offset, real_t p_z_near, real_t p_z_far) { - if (!force_change && size == p_size && frustum_offset == p_offset && p_z_near == near && p_z_far == far && mode == PROJECTION_FRUSTUM) { + if (!force_change && size == p_size && frustum_offset == p_offset && p_z_near == _near && p_z_far == _far && mode == PROJECTION_FRUSTUM) { return; } size = p_size; frustum_offset = p_offset; - near = p_z_near; - far = p_z_far; + _near = p_z_near; + _far = p_z_far; mode = PROJECTION_FRUSTUM; force_change = false; - RenderingServer::get_singleton()->camera_set_frustum(camera, size, frustum_offset, near, far); + RenderingServer::get_singleton()->camera_set_frustum(camera, size, frustum_offset, _near, _far); update_gizmos(); } @@ -309,9 +309,9 @@ Vector3 Camera3D::project_local_ray_normal(const Point2 &p_pos) const { if (mode == PROJECTION_ORTHOGONAL) { ray = Vector3(0, 0, -1); } else { - Projection cm = _get_camera_projection(near); + Projection cm = _get_camera_projection(_near); Vector2 screen_he = cm.get_viewport_half_extents(); - ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_he.x, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_he.y, -near).normalized(); + ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_he.x, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_he.y, -_near).normalized(); } return ray; @@ -338,7 +338,7 @@ Vector3 Camera3D::project_ray_origin(const Point2 &p_pos) const { Vector3 ray; ray.x = pos.x * (hsize)-hsize / 2; ray.y = (1.0 - pos.y) * (vsize)-vsize / 2; - ray.z = -near; + ray.z = -_near; ray = get_camera_transform().xform(ray); return ray; } else { @@ -349,13 +349,13 @@ Vector3 Camera3D::project_ray_origin(const Point2 &p_pos) const { bool Camera3D::is_position_behind(const Vector3 &p_pos) const { Transform3D t = get_global_transform(); Vector3 eyedir = -t.basis.get_column(2).normalized(); - return eyedir.dot(p_pos - t.origin) < near; + return eyedir.dot(p_pos - t.origin) < _near; } Vector<Vector3> Camera3D::get_near_plane_points() const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector<Vector3>(), "Camera is not inside scene."); - Projection cm = _get_camera_projection(near); + Projection cm = _get_camera_projection(_near); Vector3 endpoints[8]; cm.get_endpoints(Transform3D(), endpoints); @@ -375,7 +375,7 @@ Point2 Camera3D::unproject_position(const Vector3 &p_pos) const { Size2 viewport_size = get_viewport()->get_visible_rect().size; - Projection cm = _get_camera_projection(near); + Projection cm = _get_camera_projection(_near); Plane p(get_camera_transform().xform_inv(p_pos), 1.0); @@ -459,8 +459,8 @@ void Camera3D::_attributes_changed() { ERR_FAIL_NULL(physical_attributes); fov = physical_attributes->get_fov(); - near = physical_attributes->get_near(); - far = physical_attributes->get_far(); + _near = physical_attributes->get_near(); + _far = physical_attributes->get_far(); keep_aspect = KEEP_HEIGHT; _update_camera_mode(); } @@ -583,7 +583,7 @@ real_t Camera3D::get_size() const { } real_t Camera3D::get_near() const { - return near; + return _near; } Vector2 Camera3D::get_frustum_offset() const { @@ -591,7 +591,7 @@ Vector2 Camera3D::get_frustum_offset() const { } real_t Camera3D::get_far() const { - return far; + return _far; } Camera3D::ProjectionType Camera3D::get_projection() const { @@ -611,7 +611,7 @@ void Camera3D::set_size(real_t p_size) { } void Camera3D::set_near(real_t p_near) { - near = p_near; + _near = p_near; _update_camera_mode(); } @@ -621,7 +621,7 @@ void Camera3D::set_frustum_offset(Vector2 p_offset) { } void Camera3D::set_far(real_t p_far) { - far = p_far; + _far = p_far; _update_camera_mode(); } @@ -656,7 +656,7 @@ bool Camera3D::get_cull_mask_value(int p_layer_number) const { Vector<Plane> Camera3D::get_frustum() const { ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>()); - Projection cm = _get_camera_projection(near); + Projection cm = _get_camera_projection(_near); return cm.get_projection_planes(get_camera_transform()); } diff --git a/scene/3d/camera_3d.h b/scene/3d/camera_3d.h index 8de607806e..b32eb147c1 100644 --- a/scene/3d/camera_3d.h +++ b/scene/3d/camera_3d.h @@ -36,11 +36,6 @@ #include "scene/resources/camera_attributes.h" #include "scene/resources/environment.h" -#ifdef MINGW_ENABLED -#undef near -#undef far -#endif - class Camera3D : public Node3D { GDCLASS(Camera3D, Node3D); @@ -72,8 +67,9 @@ private: real_t fov = 75.0; real_t size = 1.0; Vector2 frustum_offset; - real_t near = 0.05; - real_t far = 4000.0; + // _ prefix to avoid conflict with Windows defines. + real_t _near = 0.05; + real_t _far = 4000.0; real_t v_offset = 0.0; real_t h_offset = 0.0; KeepAspect keep_aspect = KEEP_HEIGHT; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 6d6b94af19..a0fae16120 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -896,7 +896,7 @@ void Viewport::_process_picking() { if (camera_3d) { Vector3 from = camera_3d->project_ray_origin(pos); Vector3 dir = camera_3d->project_ray_normal(pos); - real_t far = camera_3d->far; + real_t far = camera_3d->get_far(); PhysicsDirectSpaceState3D *space = PhysicsServer3D::get_singleton()->space_get_direct_state(find_world_3d()->get_space()); if (space) { |