]> OCCT Git - occt.git/commitdiff
Data Exchange, RWObj_Reader - Facets with empty normals like 'f 1// 2// 3//' (#520)
authorKirill Gavrilov <kirill@sview.ru>
Wed, 16 Jul 2025 12:16:52 +0000 (13:16 +0100)
committerdpasukhi <dpasukhi@opencascade.com>
Wed, 16 Jul 2025 14:24:48 +0000 (15:24 +0100)
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.

src/DataExchange/TKDEOBJ/RWObj/RWObj_Reader.cxx
tests/de_mesh/obj_read/emptynorm [new file with mode: 0644]

index d120daf4793869e2c74372b562645af693a45ed8..fc7f9436300a8eff241d5339a3dfe7895d099fb3 100644 (file)
@@ -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 (file)
index 0000000..4b4814d
--- /dev/null
@@ -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