Commit graph

28 commits

Author SHA1 Message Date
Thaddeus Crews
21fd4faf1b
Merge pull request #107469 from Ivorforce/vector-localvector-explicit-span-conversions
Remove implicit conversions between `LocalVector` and `Vector`
2025-09-30 11:19:17 -05:00
Arseny Kapoulkine
e40436d527 Switch LOD generation to use iterative simplification
Instead of simplifying every LOD from the original down to an
increasing number of triangles, we simplify each LOD from the previous
LOD and stop when the simplification can't proceed further.

This has a few benefits:

- It's significantly faster; using sparse flag helps ensure that
  subsequent simplifications after the first one are increasingly
  cheaper.

- It results in higher quality attributes on generated LODs; attribute
  quadrics reduce the quality of attribute preservation the more they
  are accumulated, so recomputing them from intermediate geometry helps.

- It results in monotonic appearance: if a feature is reduced in a
  higher LOD, it will stay reduced or get reduced more significantly in
  lower LODs. This is not a significant problem right now, but can be
  helpful to ensure if the number of LODs increases or some newer
  features get enabled.
2025-09-23 13:28:45 -07:00
Arseny Kapoulkine
92596e3f17 Regularize deformable objects to fix excessive errors post deformation
This significantly improves LOD quality for skinned objects, especially
if the skinned object geometry is very simple (e.g. planar or
cylindrical) in bind pose.

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
2025-09-19 08:45:57 -07:00
Lukas Tenbrink
abe3b481ae Make conversions from LocalVector to Vector explicit. 2025-09-16 21:41:28 +02:00
Aaron Franke
ba92af7d07
ImporterMesh: Validate triangle indices array size is a multiple of 3 2025-08-18 06:36:21 -07:00
Arseny Kapoulkine
6190d412d3 Adjust LOD selection metrics to use attribute error
- Revert meshoptimizer patch; the metric used for LOD selection now
incorporates attribute error
- Since LOD selection is now aware of attribute deviation, we don't
need to use a higher normal weight
- To prevent normal creases from creating input triangles with very
large normal deviation, reduce default normal merge threshold
- Since we now use combined metric to select LODs, we never need LODs
with error>1 as these should not be selected if the mesh is visible.
2025-05-18 17:38:54 +03:00
Arseny Kapoulkine
9a8348cc2c Use vertex colors (if present) as attributes during simplification
When importing meshes with vertex colors, we will now supply them to the
simplifier as attributes with weight=1 (in addition to normals). This will
guide the simplification to preserve regions where vertex colors change.

For this change to take full effect, it is also necessary to respect the
full error when selecting LODs; this change does not do that yet, so there
are going to still be cases where vertex colors change abruptly during LOD
switch in a visible manner.
2025-05-15 21:48:12 +03:00
A Thousand Ships
889410dcda
Add String::replace_char(s) methods for performance and convenience 2025-04-10 13:08:45 +02:00
Yufeng Ying
4f4031a675 Replace size() == 0 with is_empty(). 2025-04-02 19:18:43 +08:00
Michael Alexsander
5ad414d046
Allow to compile templates without physics servers 2025-03-28 11:00:44 -03:00
Thaddeus Crews
f09ee0171a
Style: Begin integrating simple .clangd fixes 2025-03-22 13:24:35 -05:00
Yufeng Ying
bebe037abf Add ConstIterator to Dictionary. 2025-03-13 01:28:46 +08:00
Arseny Kapoulkine
260287b3a1 Rewrite index optimization code for maximum efficiency
While all the previous fixes to optimizeVertexCache invocation fixed the
vertex transform efficiency, the import code still was missing two
crucial recommendations from meshoptimizer documentation:

- All meshes should be optimized for vertex cache (this reorders
  vertices for maximum fetch efficiency)
- When LODs are used with a shared vertex buffer, the vertex order
  should be generated by doing a vertex fetch optimization on the
  concatenated index buffer from coarse to fine LODs; this maximizes
  fetch efficiency for coarse LODs

The last point is especially crucial for Mali GPUs; unlike other GPUs
where vertex order affects fetch efficiency but not shading, these GPUs
have various shading quirks (depending on the GPU generation) that
really require consecutive index ranges for each LOD, which requires the
second optimization mentioned above. However all of these also help
desktop GPUs and other mobile GPUs as well.

Because this optimization is "global" in the sense that it affects all
LODs and all vertex arrays in concert, I've taken this opportunity to
isolate all optimization code in this function and pull it out of
generate_lods and create_shadow_mesh; this doesn't change the vertex
cache efficiency, but makes the code cleaner. Consequently,
optimize_indices should be called after other functions like
create_shadow_mesh / generate_lods.

This required exposing meshopt_optimizeVertexFetchRemap; as a drive-by,
meshopt_simplifySloppy was never used so it's not exposed anymore - this
will simplify future meshopt upgrades if they end up changing the
function's interface.
2024-11-04 06:58:06 -08:00
Arseny Kapoulkine
494fe2fe21 LOD: Remove "Raycast Normals" and associated "Normal Split Angle" settings
"Raycast Normals" was introduced in 4.4 dev and defaulted to "false".
The limited testing results at the time suggested that raycasting
generally reduces normal quality compared to native simplifier results,
at the same time increasing vertex memory and import time.

To play it safe, we introduced a setting that defaulted to false, with
the goal of removing it later in 4.4 development cycle if no regressions
are noticed. Since we already had three dev snapshots and no reports,
this change removes the setting and associated code.

"Normal Split Angle" was only used when raycast normals were enabled;
this change removes it from the settings, but keeps it in the script
binding for compatibility.

Existing meshes import exactly the same after this change (unless they
chose to override raycasting which would be surprising).

split_normals helper was only used in this code path and is also removed
for simplicity; it is unlikely that this code will be useful as is, as
it can only regenerate normals without fixing tangents or updating
positions.
2024-10-28 10:14:04 -07:00
Arseny Kapoulkine
e2cc0e484e Update meshoptimizer to 0.22
The Godot-specific patch is just a single line now; removing this patch
will likely require adjusting Godot importer code to handle error limits
better.

This also adds new SIMPLIFY_ options; Godot is currently not using any
of these but might use SIMPLIFY_PRUNE and SIMPLIFY_SPARSE in the future.
2024-10-26 07:26:07 -07:00
Rémi Verschelde
b214aa8faf
Merge pull request #96880 from zeux/fix-vcache-nontri
Fix a crash in `ImporterMesh::create_shadow_mesh` for non-triangle surfaces
2024-09-12 09:26:01 +02:00
Rémi Verschelde
b9b07d619f
Merge pull request #94783 from TokageItLab/validate-gltf-anim-name
Add validation to glTF importer for Blendshape and Animation
2024-09-12 09:25:10 +02:00
Arseny Kapoulkine
7d7b43bca2 Fix a crash in ImporterMesh::create_shadow_mesh for non-triangle surfaces
optimize_vertex_cache_func assumes the input is a triangle mesh; when an
imported mesh contains points/lines/triangle strips, this code should be
disabled.
2024-09-11 13:18:58 -07:00
Rémi Verschelde
78935cad95
Merge pull request #94954 from raulsntos/mark-internal-properties
Mark underscored properties as internal
2024-08-28 00:12:42 +02:00
Patrick Sean Klein
a1fe6ffa19
NavigationPolygon: Implement get/set_polygon fast paths. 2024-08-17 00:31:58 +02:00
Arseny Kapoulkine
0fde03c0e0 Optimize base and shadow meshes for cache
Previously, vertex cache optimization was ran for the LOD meshes, but
was never ran for the base mesh or for the shadow meshes, including
shadow LOD chain (shadow LOD chain would sometimes get implicitly
optimized for vertex cache as a byproduct of base LOD optimization, but
not always). This could significantly affect the rendering performance
of geometry heavy scenes, especially for depth or shadow passes where
the fragment load is light.
2024-08-16 07:36:12 -07:00
Rémi Verschelde
e58a7530aa
Merge pull request #93727 from zeux/raycast-opt
Disable normal raycaster for LOD generation by default
2024-08-16 10:34:03 +02:00
Raul Santos
7a20ba9b63
Mark underscored properties as internal
These properties look like they were intended to be internal but they were missing the `PROPERTY_USAGE_INTERNAL` flag.

- `PackedScene::_bundled`
- `PortableCompressedTexture2D::_data`
- `ImporterMesh::_data`
2024-07-30 18:50:00 +02:00
Silc 'Tokage' Renew
0235086c14 Add validation to glTF importer for Blendshape and Animation 2024-07-26 18:05:34 +09:00
Arseny Kapoulkine
18d6ae1161 Fix LOD generation for meshes with tangents & mirrored UVs
When UVs are mirrored in a mesh, collapsing vertices across the
mirroring seam can significantly reduce quality in a way that is not
apparent to the simplifier. Even if simplifier was given access to UV
data, the coordinates would need to be weighted very highly to prevent
these collapses, which would penalize overall quality of reasonable
models.

Normally, well behaved models with mirrored UVs have tangent data that
is correctly mirrored, which results in duplicate vertices along the
seam. The simplifier automatically recognizes that seam and preserves
its structure; typically models have few edge loops where UV winding is
flipped so this does not affect simplification quality much.

However, pre-processing for LOD data welded vertices when UVs and
normals were close, which welds these seams and breaks simplification,
creating triangles with distorted UVs.

We now take tangent frame sign into account when the input model has
tangent data, and only weld vertices when the sign is the same.
2024-07-23 16:35:46 -07:00
Arseny Kapoulkine
a13a64eacd Disable normal raycaster for LOD generation by default
Normal raycaster makes LOD generation process >2x slower and often
generates normals that look significantly worse compared to what the
simplifier comes up with by default. This was likely different before
last meshoptimizer upgrade, as the attribute metric was not functioning
properly, but now it looks like it's doing more harm than good.

This change makes it disabled by default but keeps an easy option to
re-enable it per mesh using LOD parameters for now until we get more
confidence and can remove the code outright.

Because the long term plan would be to disable this feature entirely,
the scripting API isn't changed, and it's just off-by-default there with
no way to re-enable.
2024-07-02 10:18:15 -07:00
Lyuma
a99756a07f Expose create_from_arrays in SurfaceTool and cleanup some naming 2024-04-19 18:45:06 -07:00
Aaron Franke
c399424db9
Move 3D-only resources to their own folder 2024-02-26 05:23:04 -06:00
Renamed from scene/resources/importer_mesh.cpp (Browse further)