From 8910dd9f80a35c7365b8634a94aee8e11a0db175 Mon Sep 17 00:00:00 2001 From: drochalo Date: Tue, 26 Sep 2023 10:00:41 +0100 Subject: [PATCH] 0025811: Visualization - Incorrect texture mapping on faces with reversed orientation Added section in StdPrs_ShadedShape to correct UV orientation on face triangulation whose orientation is reversed. Expanded test cases. --- src/StdPrs/StdPrs_ShadedShape.cxx | 21 +++++++++++- tests/v3d/bugs/bug25811 | 53 +++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/v3d/bugs/bug25811 diff --git a/src/StdPrs/StdPrs_ShadedShape.cxx b/src/StdPrs/StdPrs_ShadedShape.cxx index fe2f667dba..060cf2c709 100644 --- a/src/StdPrs/StdPrs_ShadedShape.cxx +++ b/src/StdPrs/StdPrs_ShadedShape.cxx @@ -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 index 0000000000..5ebf2e6ee8 --- /dev/null +++ b/tests/v3d/bugs/bug25811 @@ -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