]> OCCT Git - occt.git/commitdiff
0025811: Visualization - Incorrect texture mapping on faces with reversed orientation CR25811
authordrochalo <diogo.lopes@opencascade.com>
Tue, 26 Sep 2023 09:00:41 +0000 (10:00 +0100)
committerdrochalo <diogo.lopes@opencascade.com>
Mon, 8 Apr 2024 16:02:30 +0000 (17:02 +0100)
Added section in StdPrs_ShadedShape to correct UV orientation on face triangulation whose orientation is reversed.
Expanded test cases.

src/StdPrs/StdPrs_ShadedShape.cxx
tests/v3d/bugs/bug25811 [new file with mode: 0644]

index fe2f667dbaa83aeb51e391400e8e172c3a37c4db..060cf2c7091bf38cabf1c63a19bbe2cfa8b59060 100644 (file)
@@ -192,6 +192,7 @@ namespace
       }
 
       const Standard_Integer aDecal = anArray->VertexNumber();
+      Standard_Real aMaxX = -FLT_MAX, aMinX = FLT_MAX;
       for (Standard_Integer aNodeIter = 1; aNodeIter <= aT->NbNodes(); ++aNodeIter)
       {
         aPoint = aT->Node (aNodeIter);
@@ -199,13 +200,19 @@ namespace
         if ((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored)
         {
           aNorm.Reverse();
+          if (aT->HasUVNodes())
+          {
+            gp_Pnt2d aTmpPnt = aT->UVNode(aNodeIter);
+            if (aMaxX < aTmpPnt.X()) { aMaxX = aTmpPnt.X(); }
+            if (aMinX > aTmpPnt.X()) { aMinX = aTmpPnt.X(); }
+          }
         }
         if (!aLoc.IsIdentity())
         {
           aPoint.Transform (aTrsf);
           aNorm .Transform (aTrsf);
         }
-
+        
         if (theHasTexels && aT->HasUVNodes())
         {
           const gp_Pnt2d aNode2d = aT->UVNode (aNodeIter);
@@ -221,6 +228,18 @@ namespace
         }
       }
 
+      // changes uvs for reversed faces depending on number of vertex
+      // by flipping the uv coordinates according to face normal
+      if (((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored) && aT->HasUVNodes())
+      {
+        for (Standard_Integer anIndex = 1; anIndex <= aT->NbNodes(); anIndex++)
+        {
+          gp_Pnt2d aTmpPnt = aT->UVNode (anIndex);
+          aTmpPnt.SetX (aMaxX + aMinX - aTmpPnt.X());
+          aT->SetUVNode (anIndex, aTmpPnt);
+        }
+      }
+
       // Fill array with vertex and edge visibility info
       Standard_Integer anIndex[3];
       for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter)
diff --git a/tests/v3d/bugs/bug25811 b/tests/v3d/bugs/bug25811
new file mode 100644 (file)
index 0000000..5ebf2e6
--- /dev/null
@@ -0,0 +1,53 @@
+puts "========"
+puts "0025811: Visualization - Incorrect texture mapping on faces with reversed orientation"
+puts "========"
+puts ""
+
+pload MODELING VISUALIZATION
+vclear
+vinit View1
+vsetdispmode 1
+vaxo
+box b 10 10 10
+vdisplay b
+#dump image off textured box
+vtexture b [locate_data_file bug25809_salome.png] 
+vfit
+vdump $imagedir/${casename}_box.png
+vviewparams -scale 60.0 -proj 1.0 -1.0 1.0 -up 0.0 0.0 1.0 -at 0 10 0
+vrotate 3.14 0 0
+vdump $imagedir/${casename}_box2.png
+
+#dump image of capped sphere
+vclear
+psphere s 15 -60 60 90
+vdisplay s
+vtexture s [locate_data_file bug25809_salome.png]
+vviewparams -scale 40.0 -proj 1.0 1.0 1.0 -up 0.0 0.0 1.0 -at 0 0 0
+vfit
+vdump $imagedir/${casename}_sphere.png
+vrotate 3.14 0 0
+vfit
+vdump $imagedir/${casename}_sphere2.png
+vviewparams -scale 40.0 -proj 1.0 1.0 1.0 -up 1.0 1.0 0.0 -at 0 0 0
+vrotate 0 1 0
+vfit
+vdump $imagedir/${casename}_sphere3.png
+vrotate 0 3.14 0
+vfit
+vdump $imagedir/${casename}_sphere4.png
+
+#dump image off textured cylinder
+vclear
+pcylinder c 3 10
+vdisplay c
+vtexture c [locate_data_file bug25809_salome.png] 
+vviewparams -scale 60.0 -proj 1.0 1.0 1.0 -up 0.0 0.0 1.0 -at 0 0 5
+vfit
+vdump $imagedir/${casename}_cylinder.png
+vviewparams -scale 60.0 -proj 1.0 1.0 1.0 -up 0.0 1.0 0.0 -at 0 0 5
+vfit
+vdump $imagedir/${casename}_cylinder2.png
+vrotate 0 0 3.14
+vfit
+vdump $imagedir/${casename}_cylinder3.png