From: Kirill Gavrilov Date: Wed, 16 Jul 2025 12:16:52 +0000 (+0100) Subject: Data Exchange, RWObj_Reader - Facets with empty normals like 'f 1// 2// 3//' (#520) X-Git-Tag: V8_0_0_rc2~23 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=468bcd0c27d82d32d69c1680ea5f57145c3ead63;p=occt.git Data Exchange, RWObj_Reader - Facets with empty normals like 'f 1// 2// 3//' (#520) Removing an obsolete header comment in the PPM writer Correcting the handling of facet indices when normals or texture coordinates are empty in the OBJ reader. - In Image_AlienPixMap.cxx, the unused header comment is removed. - In Graphic3d_Aspects.hxx, the default viewer settings comment is updated. - In RWObj_Reader.cxx, additional checks are added to correctly parse OBJ face definitions with empty texture and normal indices. --- diff --git a/src/DataExchange/TKDEOBJ/RWObj/RWObj_Reader.cxx b/src/DataExchange/TKDEOBJ/RWObj/RWObj_Reader.cxx index d120daf479..fc7f943630 100644 --- a/src/DataExchange/TKDEOBJ/RWObj/RWObj_Reader.cxx +++ b/src/DataExchange/TKDEOBJ/RWObj/RWObj_Reader.cxx @@ -301,15 +301,21 @@ void RWObj_Reader::pushIndices(const char* thePos) if (*thePos == '/') { ++thePos; - a3Indices[1] = int(strtol(thePos, &aNext, 10) - 1); - thePos = aNext; + if (*thePos != '/') + { + a3Indices[1] = int(strtol(thePos, &aNext, 10) - 1); + thePos = aNext; + } // parse Normal index if (*thePos == '/') { ++thePos; - a3Indices[2] = int(strtol(thePos, &aNext, 10) - 1); - thePos = aNext; + if (!IsSpace(*thePos)) + { + a3Indices[2] = int(strtol(thePos, &aNext, 10) - 1); + thePos = aNext; + } } } diff --git a/tests/de_mesh/obj_read/emptynorm b/tests/de_mesh/obj_read/emptynorm new file mode 100644 index 0000000000..4b4814d903 --- /dev/null +++ b/tests/de_mesh/obj_read/emptynorm @@ -0,0 +1,44 @@ +puts "========" +puts "Data Exchange, RWObj_Reader - fix reading facets with empty normals like 'f 1// 2// 3//'" +puts "Test reads small generated file." +puts "========" + +set sample_obj {g Group1 +v 0 0 0 +v 2 0 0 +v 2 1 0 +v 1 2 0 +v 0 1 0 +v 0 0 2 +v 2 0 2 +v 2 1 2 +v 1 2 2 +v 0 1 2 +f 5// 4// 3// 2// 1// +f 7// 8// 9// 10// 6// +f 10// 9// 4// 5// +f 9// 8// 3// 4// +f 6// 10// 5// 1// +f 2// 3// 8// 7// +f 1// 2// 7// 6//} + +set fd [open ${imagedir}/${casename}.obj w] +fconfigure $fd -translation lf +puts $fd $sample_obj +close $fd +readobj mlf ${imagedir}/${casename}.obj -singleFace +checknbshapes mlf -face 1 +checktrinfo mlf -tri 16 -nod 10 + +# read OBJ into document +ReadObj D ${imagedir}/${casename}.obj + +# Delete the temporary file after reading +file delete ${imagedir}/${casename}.obj + +vclear +vinit View1 +vdisplay -dispMode 1 mlf +vaxo +vfit +vdump ${imagedir}/${casename}_raw.png