Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable mesh compression if vertex position.z is always 0 #86144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion editor/import/3d/editor_import_collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,16 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p
surftool->generate_tangents();
}

if (p_mesh->get_blend_shape_count() != 0 || p_skin_controller) {
// Disable compression if all z equals 0 (the mesh is 2D).
bool is_mesh_2d = true;
for (int k = 0; k < vertex_array.size(); k++) {
if (!Math::is_zero_approx(vertex_array[k].vertex.z)) {
is_mesh_2d = false;
break;
}
};

if (p_mesh->get_blend_shape_count() != 0 || p_skin_controller || is_mesh_2d) {
// Can't compress if attributes missing or if using vertex weights.
mesh_flags &= ~RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES;
}
Expand Down
15 changes: 15 additions & 0 deletions editor/import/3d/resource_importer_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,22 @@ static Error _parse_obj(const String &p_path, List<Ref<ImporterMesh>> &r_meshes,

if (p_disable_compression) {
mesh_flags = 0;
} else {
bool is_mesh_2d = true;

// Disable compression if all z equals 0 (the mesh is 2D).
for (int i = 0; i < vertices.size(); i++) {
if (!Math::is_zero_approx(vertices[i].z)) {
is_mesh_2d = false;
break;
}
}

if (is_mesh_2d) {
mesh_flags = 0;
}
}

//groups are too annoying
if (surf_tool->get_vertex_array().size()) {
//another group going on, commit it
Expand Down
12 changes: 11 additions & 1 deletion modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3059,7 +3059,17 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) {
array[Mesh::ARRAY_TANGENT] = tangents;
}

if (p_state->force_disable_compression || !a.has("POSITION") || !a.has("NORMAL") || p.has("targets") || (a.has("JOINTS_0") || a.has("JOINTS_1"))) {
// Disable compression if all z equals 0 (the mesh is 2D).
const Vector<Vector3> &vertices = array[Mesh::ARRAY_VERTEX];
bool is_mesh_2d = true;
for (int k = 0; k < vertices.size(); k++) {
if (!Math::is_zero_approx(vertices[k].z)) {
is_mesh_2d = false;
break;
}
}

if (p_state->force_disable_compression || is_mesh_2d || !a.has("POSITION") || !a.has("NORMAL") || p.has("targets") || (a.has("JOINTS_0") || a.has("JOINTS_1"))) {
flags &= ~RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES;
}

Expand Down
Loading