diff --git a/dox/dev_guides/upgrade/upgrade.md b/dox/dev_guides/upgrade/upgrade.md index cacf8d15c9..2c6fd9456b 100644 --- a/dox/dev_guides/upgrade/upgrade.md +++ b/dox/dev_guides/upgrade/upgrade.md @@ -1260,6 +1260,8 @@ In most cases this change should be transparent, however applications implementi * The methods BOPAlgo_Tools::FillMap() have been replaced with the single template method BOPAlgo_Tools::FillMap(). * Package BVH now uses opencascade::handle instead of NCollection_Handle (for classes BVH_Properties, BVH_Builder, BVH_Tree, BVH_Object). Application code using BVH package directly should be updated accordingly. +* AIS_Shape now computes UV texture coordinates for AIS_Shaded presentation in case if texture mapping is enabled within Shaded Attributes. + Therefore, redundant class AIS_TexturedShape has been marked deprecated - applications can use AIS_Shape directly (texture mapping should be defined through AIS_Shape::Attributes()). @subsection upgrade_720_BOP_DataStructure BOP - Pairs of interfering indices diff --git a/samples/mfc/standard/03_Viewer2d/src/StdAfx.h b/samples/mfc/standard/03_Viewer2d/src/StdAfx.h index d174ce7b2f..7130447ee8 100755 --- a/samples/mfc/standard/03_Viewer2d/src/StdAfx.h +++ b/samples/mfc/standard/03_Viewer2d/src/StdAfx.h @@ -75,7 +75,6 @@ #include #include #include -#include #include #include diff --git a/samples/mfc/standard/04_Viewer3d/src/TexturesExt_Presentation.cpp b/samples/mfc/standard/04_Viewer3d/src/TexturesExt_Presentation.cpp index 7e747481b2..902a50410a 100755 --- a/samples/mfc/standard/04_Viewer3d/src/TexturesExt_Presentation.cpp +++ b/samples/mfc/standard/04_Viewer3d/src/TexturesExt_Presentation.cpp @@ -9,9 +9,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include #include @@ -80,7 +80,7 @@ void TexturesExt_Presentation::Init() " // aShape = ..." EOL "" EOL " // create a textured presentation object for aShape" EOL - " Handle(AIS_TexturedShape) aTShape = new AIS_TexturedShape(aShape);" EOL + " Handle(AIS_Shape) aTShape = new AIS_Shape(aShape);" EOL "" EOL " TCollection_AsciiString aTFileName;" EOL "" EOL @@ -90,22 +90,10 @@ void TexturesExt_Presentation::Init() " // which will indicate use of predefined texture of this number" EOL " // aTFileName = ..." EOL "" EOL - " aTShape->SetTextureFileName(aTFileName);" EOL - "" EOL - " // do other initialization of AIS_TexturedShape" EOL - " Standard_Real nRepeat;" EOL - " Standard_Boolean toRepeat;" EOL - " Standard_Boolean toScale;" EOL - " // initialize aRepeat, toRepeat, toScale ..." EOL - "" EOL - " aTShape->SetTextureMapOn();" EOL - " aTShape->SetTextureRepeat(toRepeat, nRepeat, nRepeat);" EOL - " aTShape->SetTexturesExtcale(toScale);" EOL - " " EOL - " // mode 3 is \"textured\" mode of AIS_TexturedShape, " EOL - " // other modes will display the \"normal\", non-textured shape," EOL - " // in wireframe(1) or shaded(2) modes correspondingly" EOL - " aTShape->SetDisplayMode(3); " EOL); + " aTShape->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());" EOL + " Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual (aTFileName);" EOL + " aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (aTexture);" EOL + " aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();" EOL); // CString text(Message.ToCString()); getDocument()->ClearDialog(); getDocument()->SetDialogTitle("Change face color"); @@ -117,12 +105,12 @@ void TexturesExt_Presentation::Init() ////////////////////////////////////////////////////////////////////// //================================================================ // Function : TexturesExt_Presentation::Texturize -// display an AIS_TexturedShape based on a given shape with texture with given filename +// display an AIS_Shape based on a given shape with texture with given filename // filename can also be an integer value ("2", "5", etc.), in this case // a predefined texture from Graphic3d_NameOfTexture2D with number = this value // is loaded. //================================================================ -Handle(AIS_TexturedShape) TexturesExt_Presentation::Texturize(const TopoDS_Shape& aShape, +Handle(AIS_Shape) TexturesExt_Presentation::Texturize(const TopoDS_Shape& aShape, TCollection_AsciiString aTFileName, Standard_Real toScaleU, Standard_Real toScaleV, @@ -132,7 +120,7 @@ Handle(AIS_TexturedShape) TexturesExt_Presentation::Texturize(const TopoDS_Shape Standard_Real originV) { // create a textured presentation object for aShape - Handle(AIS_TexturedShape) aTShape = new AIS_TexturedShape(aShape); + Handle(AIS_Shape) aTShape = new AIS_Shape(aShape); TCollection_AsciiString TFileName; // load texture from file if it is not an integer value // integer value indicates a number of texture in predefined TexturesExt enumeration @@ -144,15 +132,19 @@ Handle(AIS_TexturedShape) TexturesExt_Presentation::Texturize(const TopoDS_Shape initfile += aTFileName.ToCString(); } - aTShape->SetTextureFileName (TCollection_AsciiString ((const wchar_t* )initfile)); + if (!aTShape->Attributes()->HasOwnShadingAspect()) + { + aTShape->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect()); + } + aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (new Graphic3d_Texture2Dmanual (TCollection_AsciiString ((const wchar_t* )initfile))); + aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn(); - // do other initialization of AIS_TexturedShape - aTShape->SetTextureMapOn(); - aTShape->SetTextureScale(Standard_True, toScaleU, toScaleV); - aTShape->SetTextureRepeat(Standard_True, toRepeatU, toRepeatV); - aTShape->SetTextureOrigin(Standard_True, originU, originV); - - aTShape->SetDisplayMode(3); // mode 3 is "textured" mode + // do other initialization of AIS_Shape + aTShape->SetTextureScaleUV (gp_Pnt2d ( toScaleU, toScaleV)); + aTShape->SetTextureRepeatUV(gp_Pnt2d (toRepeatU, toRepeatV)); + aTShape->SetTextureOriginUV(gp_Pnt2d ( originU, originV)); + + aTShape->SetDisplayMode(AIS_Shaded); return aTShape; } @@ -255,10 +247,10 @@ aShape = Transformer.Shape(); aShapeIO->SetPolygonOffsets(Aspect_POM_Fill, 1.5, 0.5); DISP(aShapeIO); - Handle(AIS_TexturedShape) aTFace1 = Texturize(aFaces(16), "carrelage1.gif", 1, 1, 3, 2); + Handle(AIS_Shape) aTFace1 = Texturize(aFaces(16), "carrelage1.gif", 1, 1, 3, 2); DISP(aTFace1); - Handle(AIS_TexturedShape) aTFace2 = Texturize(aFaces(21), "carrelage1.gif", 1, 1, 3, 2); + Handle(AIS_Shape) aTFace2 = Texturize(aFaces(21), "carrelage1.gif", 1, 1, 3, 2); DISP(aTFace2); getViewer()->Update(); diff --git a/samples/mfc/standard/04_Viewer3d/src/TexturesExt_Presentation.h b/samples/mfc/standard/04_Viewer3d/src/TexturesExt_Presentation.h index 3157c29de7..1c67a95be5 100755 --- a/samples/mfc/standard/04_Viewer3d/src/TexturesExt_Presentation.h +++ b/samples/mfc/standard/04_Viewer3d/src/TexturesExt_Presentation.h @@ -10,7 +10,7 @@ #endif // _MSC_VER > 1000 #include "OCCDemo_Presentation.h" -#include +#include class TopoDS_Shape; class TCollection_AsciiString; @@ -28,11 +28,11 @@ public: virtual void Init(); private: - // display an AIS_TexturedShape based on a given shape with texture with given filename + // display an AIS_Shape based on a given shape with texture with given filename // filename can also be an integer value ("2", "5", etc.), in this case // a predefined texture from Graphic3d_NameOfTexture2D with number = this value // is loaded. - Handle(AIS_TexturedShape) Texturize( + Handle(AIS_Shape) Texturize( const TopoDS_Shape& aShape, TCollection_AsciiString aTFileName, Standard_Real toScaleU=1.0, Standard_Real toScaleV=1.0, Standard_Real toRepeatU=1.0, Standard_Real toRepeatV=1.0, diff --git a/samples/mfc/standard/Common/Primitive/Sample2D_Image.cpp b/samples/mfc/standard/Common/Primitive/Sample2D_Image.cpp index 39b3d677d5..56fb6f938c 100755 --- a/samples/mfc/standard/Common/Primitive/Sample2D_Image.cpp +++ b/samples/mfc/standard/Common/Primitive/Sample2D_Image.cpp @@ -2,13 +2,15 @@ #include "Sample2D_Image.h" -IMPLEMENT_STANDARD_RTTIEXT(Sample2D_Image,AIS_TexturedShape) +#include + +IMPLEMENT_STANDARD_RTTIEXT(Sample2D_Image,AIS_Shape) Sample2D_Image::Sample2D_Image(TCollection_AsciiString& aFileName, const Standard_Real X, const Standard_Real Y, const Standard_Real aScale) - :AIS_TexturedShape(TopoDS_Shape()) + :AIS_Shape(TopoDS_Shape()) { myFilename = aFileName; myX = X; @@ -35,9 +37,7 @@ void Sample2D_Image::SetContext(const Handle(AIS_InteractiveContext)& theContext AIS_InteractiveObject::SetContext(theContext); MakeShape(); this->Set(TopoDS_Shape(myFace)); - this->SetTextureFileName(myFilename); - + myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); + myDrawer->ShadingAspect()->Aspect()->SetTextureMap (new Graphic3d_Texture2Dmanual (myFilename)); + myDrawer->ShadingAspect()->Aspect()->SetTextureMapOn(); } - - - diff --git a/samples/mfc/standard/Common/Primitive/Sample2D_Image.h b/samples/mfc/standard/Common/Primitive/Sample2D_Image.h index f5d69c5507..0de9ef8311 100755 --- a/samples/mfc/standard/Common/Primitive/Sample2D_Image.h +++ b/samples/mfc/standard/Common/Primitive/Sample2D_Image.h @@ -11,8 +11,8 @@ #include #include class Sample2D_Image; -DEFINE_STANDARD_HANDLE(Sample2D_Image,AIS_TexturedShape) -class Sample2D_Image : public AIS_TexturedShape { +DEFINE_STANDARD_HANDLE(Sample2D_Image,AIS_Shape) +class Sample2D_Image : public AIS_Shape { public: @@ -26,7 +26,7 @@ Standard_EXPORT inline Standard_Real GetScale() const; Standard_EXPORT inline void SetScale(const Standard_Real aNewScale) ; Standard_EXPORT virtual void SetContext(const Handle(AIS_InteractiveContext)& theContext) ; -DEFINE_STANDARD_RTTIEXT(Sample2D_Image,AIS_TexturedShape) +DEFINE_STANDARD_RTTIEXT(Sample2D_Image,AIS_Shape) private: void MakeShape(); protected: diff --git a/samples/mfc/standard/Common/StdAfx.h b/samples/mfc/standard/Common/StdAfx.h index 4eb9b892e2..b91219f1bc 100755 --- a/samples/mfc/standard/Common/StdAfx.h +++ b/samples/mfc/standard/Common/StdAfx.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/src/AIS/AIS_ColoredShape.cxx b/src/AIS/AIS_ColoredShape.cxx index b3b3816397..9c528251ab 100644 --- a/src/AIS/AIS_ColoredShape.cxx +++ b/src/AIS/AIS_ColoredShape.cxx @@ -298,10 +298,12 @@ void AIS_ColoredShape::UnsetTransparency() if (myDrawer->HasOwnShadingAspect()) { myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel); - } - if (!HasColor() && !HasMaterial()) - { - myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); + if (!HasColor() + && !HasMaterial() + && !myDrawer->ShadingAspect()->Aspect()->ToMapTexture()) + { + myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); + } } for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next()) @@ -499,7 +501,10 @@ void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation // add special wireframe presentation for faces without triangulation StdPrs_ShadedShape::AddWireframeForFacesWithoutTriangles (thePrs, aShapeDraw, aDrawer); - Handle(Graphic3d_ArrayOfTriangles) aTriangles = StdPrs_ShadedShape::FillTriangles (aShapeDraw); + Handle(Graphic3d_ArrayOfTriangles) aTriangles = StdPrs_ShadedShape::FillTriangles (aShapeDraw, + aDrawer->ShadingAspect()->Aspect()->ToMapTexture() + && !aDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(), + myUVOrigin, myUVRepeat, myUVScale); if (!aTriangles.IsNull()) { if (aShadedGroup.IsNull()) diff --git a/src/AIS/AIS_Shape.cxx b/src/AIS/AIS_Shape.cxx index 1d3cdfc023..5b6bff4ccf 100644 --- a/src/AIS/AIS_Shape.cxx +++ b/src/AIS/AIS_Shape.cxx @@ -80,16 +80,19 @@ static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard } //================================================== -// Function: +// Function: AIS_Shape // Purpose : //================================================== - -AIS_Shape:: -AIS_Shape(const TopoDS_Shape& shap): -AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant), -myInitAng(0.) +AIS_Shape::AIS_Shape(const TopoDS_Shape& theShape) +: AIS_InteractiveObject (PrsMgr_TOP_ProjectorDependant), + myshape (theShape), + myUVOrigin(0.0, 0.0), + myUVRepeat(1.0, 1.0), + myUVScale (1.0, 1.0), + myInitAng (0.0), + myCompBB (Standard_True) { - Set (shap); + // } //======================================================================= @@ -183,7 +186,10 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat try { OCC_CATCH_SIGNALS - StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer); + StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer, + myDrawer->ShadingAspect()->Aspect()->ToMapTexture() + && !myDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(), + myUVOrigin, myUVRepeat, myUVScale); } catch (Standard_Failure) { @@ -562,6 +568,7 @@ void AIS_Shape::UnsetColor() return; } hasOwnColor = Standard_False; + myDrawer->SetColor (myDrawer->HasLink() ? myDrawer->Link()->Color() : Quantity_Color (Quantity_NOC_WHITE)); if (!HasWidth()) { @@ -605,22 +612,34 @@ void AIS_Shape::UnsetColor() myDrawer->SeenLineAspect()->SetColor (aColor); } - if (HasMaterial() - || IsTransparent()) + if (!myDrawer->HasOwnShadingAspect()) { - Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS); + // + } + else if (HasMaterial() + || IsTransparent() + || myDrawer->ShadingAspect()->Aspect()->ToMapTexture()) + { + const Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS); Graphic3d_MaterialAspect mat = aDefaultMat; + Quantity_Color anInteriorColors[2] = {Quantity_NOC_CYAN1, Quantity_NOC_CYAN1}; + if (myDrawer->HasLink()) + { + anInteriorColors[0] = myDrawer->Link()->ShadingAspect()->Aspect()->InteriorColor(); + anInteriorColors[1] = myDrawer->Link()->ShadingAspect()->Aspect()->BackInteriorColor(); + } if (HasMaterial() || myDrawer->HasLink()) { - mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link()); + const Handle(Graphic3d_AspectFillArea3d)& aSrcAspect = (HasMaterial() ? myDrawer : myDrawer->Link())->ShadingAspect()->Aspect(); + mat = myCurrentFacingModel != Aspect_TOFM_BACK_SIDE + ? aSrcAspect->FrontMaterial() + : aSrcAspect->BackMaterial(); } if (HasMaterial()) { - Quantity_Color aColor = aDefaultMat.AmbientColor(); - if (myDrawer->HasLink()) - { - aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel); - } + const Quantity_Color aColor = myDrawer->HasLink() + ? myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel) + : aDefaultMat.AmbientColor(); mat.SetColor (aColor); } if (IsTransparent()) @@ -628,7 +647,9 @@ void AIS_Shape::UnsetColor() Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel); mat.SetTransparency (Standard_ShortReal(aTransp)); } - myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel); + myDrawer->ShadingAspect()->SetMaterial (mat, myCurrentFacingModel); + myDrawer->ShadingAspect()->Aspect()->SetInteriorColor (anInteriorColors[0]); + myDrawer->ShadingAspect()->Aspect()->SetBackInteriorColor(anInteriorColors[1]); } else { @@ -638,8 +659,8 @@ void AIS_Shape::UnsetColor() // modify shading presentation without re-computation const PrsMgr_Presentations& aPrsList = Presentations(); - Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect(); - Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect(); + Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); + Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->LineAspect()->Aspect(); for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) { const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); @@ -866,8 +887,13 @@ void AIS_Shape::UnsetMaterial() return; } - if (HasColor() - || IsTransparent()) + if (!myDrawer->HasOwnShadingAspect()) + { + // + } + else if (HasColor() + || IsTransparent() + || myDrawer->ShadingAspect()->Aspect()->ToMapTexture()) { if(myDrawer->HasLink()) { @@ -981,7 +1007,9 @@ void AIS_Shape::UnsetTransparency() { return; } - else if (HasColor() || HasMaterial()) + else if (HasColor() + || HasMaterial() + || myDrawer->ShadingAspect()->Aspect()->ToMapTexture()) { myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel); } diff --git a/src/AIS/AIS_Shape.hxx b/src/AIS/AIS_Shape.hxx index 78ab8c6f9a..396a9e98f5 100644 --- a/src/AIS/AIS_Shape.hxx +++ b/src/AIS/AIS_Shape.hxx @@ -49,6 +49,17 @@ class Bnd_Box; //! above deviation angle and coefficient functions return //! true indicating that there is a local setting available //! for the specific object. +//! +//! This class allows to map textures on shapes using native UV parametric space of underlying surface of each Face +//! (this means that texture will be visually duplicated on all Faces). +//! To generate texture coordinates, appropriate shading attribute should be set before computing presentation in AIS_Shaded display mode: +//! @code +//! Handle(AIS_Shape) aPrs = new AIS_Shape(); +//! aPrs->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect()); +//! aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn(); +//! aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (new Graphic3d_Texture2Dmanual (Graphic3d_NOT_2D_ALUMINUM)); +//! @endcode +//! The texture itself is parametrized in (0,1)x(0,1). class AIS_Shape : public AIS_InteractiveObject { DEFINE_STANDARD_RTTIEXT(AIS_Shape, AIS_InteractiveObject) @@ -218,6 +229,31 @@ public: //! - mode 8 - Compound Standard_EXPORT static Standard_Integer SelectionMode (const TopAbs_ShapeEnum aShapeType); +public: //! @name methods to alter texture mapping properties + + //! Return texture repeat UV values; (1, 1) by default. + const gp_Pnt2d& TextureRepeatUV() const { return myUVRepeat; } + + //! Sets the number of occurrences of the texture on each face. The texture itself is parameterized in (0,1) by (0,1). + //! Each face of the shape to be textured is parameterized in UV space (Umin,Umax) by (Vmin,Vmax). + void SetTextureRepeatUV (const gp_Pnt2d& theRepeatUV) { myUVRepeat = theRepeatUV; } + + //! Return texture origin UV position; (0, 0) by default. + const gp_Pnt2d& TextureOriginUV() const { return myUVOrigin; } + + //! Use this method to change the origin of the texture. + //! The texel (0,0) will be mapped to the surface (myUVOrigin.X(), myUVOrigin.Y()). + void SetTextureOriginUV (const gp_Pnt2d& theOriginUV) { myUVOrigin = theOriginUV; } + + //! Return scale factor for UV coordinates; (1, 1) by default. + const gp_Pnt2d& TextureScaleUV() const { return myUVScale; } + + //! Use this method to scale the texture (percent of the face). + //! You can specify a scale factor for both U and V. + //! Example: if you set ScaleU and ScaleV to 0.5 and you enable texture repeat, + //! the texture will appear twice on the face in each direction. + void SetTextureScaleUV (const gp_Pnt2d& theScaleUV) { myUVScale = theScaleUV; } + protected: Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, const Handle(Prs3d_Presentation)& aPresentation, const Standard_Integer aMode = 0) Standard_OVERRIDE; @@ -238,19 +274,19 @@ protected: Standard_EXPORT void setMaterial (const Handle(Prs3d_Drawer)& theDrawer, const Graphic3d_MaterialAspect& theMaterial, const Standard_Boolean theToKeepColor, const Standard_Boolean theToKeepTransp) const; -protected: - - TopoDS_Shape myshape; - Bnd_Box myBB; - Standard_Boolean myCompBB; - private: - + Standard_EXPORT void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation, const TopoDS_Shape& ashape); -private: +protected: - Standard_Real myInitAng; + TopoDS_Shape myshape; //!< shape to display + Bnd_Box myBB; //!< cached bounding box of the shape + gp_Pnt2d myUVOrigin; //!< UV origin vector for generating texture coordinates + gp_Pnt2d myUVRepeat; //!< UV repeat vector for generating texture coordinates + gp_Pnt2d myUVScale; //!< UV scale vector for generating texture coordinates + Standard_Real myInitAng; + Standard_Boolean myCompBB; //!< if TRUE, then bounding box should be recomputed }; diff --git a/src/AIS/AIS_TexturedShape.cxx b/src/AIS/AIS_TexturedShape.cxx index 4b7ba3b449..8cce640d65 100644 --- a/src/AIS/AIS_TexturedShape.cxx +++ b/src/AIS/AIS_TexturedShape.cxx @@ -52,11 +52,8 @@ AIS_TexturedShape::AIS_TexturedShape (const TopoDS_Shape& theShape) myPredefTexture (Graphic3d_NameOfTexture2D(0)), myToMapTexture (Standard_True), myModulate (Standard_True), - myUVOrigin (0.0, 0.0), myIsCustomOrigin (Standard_True), - myUVRepeat (1.0, 1.0), myToRepeat (Standard_True), - myUVScale (1.0, 1.0), myToScale (Standard_True), myToShowTriangles (Standard_False) { diff --git a/src/AIS/AIS_TexturedShape.hxx b/src/AIS/AIS_TexturedShape.hxx index 65b1502ae1..a7fce80e80 100644 --- a/src/AIS/AIS_TexturedShape.hxx +++ b/src/AIS/AIS_TexturedShape.hxx @@ -196,11 +196,8 @@ protected: //! @name texture mapping properties Standard_Boolean myToMapTexture; Standard_Boolean myModulate; - gp_Pnt2d myUVOrigin; Standard_Boolean myIsCustomOrigin; - gp_Pnt2d myUVRepeat; Standard_Boolean myToRepeat; - gp_Pnt2d myUVScale; Standard_Boolean myToScale; Standard_Boolean myToShowTriangles; diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 94dbf6862a..0a7d3963b1 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -3251,7 +3251,8 @@ void OpenGl_Context::SetTextureMatrix (const Handle(Graphic3d_TextureParams)& th // pack transformation parameters OpenGl_Vec4 aTrsf[2]; - aTrsf[0].xy() = theParams->Translation(); + aTrsf[0].x() = -theParams->Translation().x(); + aTrsf[0].y() = -theParams->Translation().y(); aTrsf[0].zw() = theParams->Scale(); aTrsf[1].x() = std::sin (-theParams->Rotation() * static_cast (M_PI / 180.0)); aTrsf[1].y() = std::cos (-theParams->Rotation() * static_cast (M_PI / 180.0)); diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index 0faa795477..cce5e33581 100644 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include @@ -1792,65 +1792,6 @@ static Standard_Integer OCC23950 (Draw_Interpretor& di, Standard_Integer argc, c return 0; } -//======================================================================= -//function : OCC24622 -//purpose : The command tests sourcing Image_PixMap to AIS_TexturedShape -//======================================================================= -static Standard_Integer OCC24622 (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec) -{ - if (theArgNb != 2) - { - std::cout << "Usage : " << theArgVec[0] << " texture={1D|2D}"; - return 1; - } - - const Handle(AIS_InteractiveContext)& anAISContext = ViewerTest::GetAISContext(); - if (anAISContext.IsNull()) - { - std::cout << "Please initialize view with \"vinit\".\n"; - return 1; - } - - Handle(Image_PixMap) anImage = new Image_PixMap(); - - static const Image_ColorRGB aBitmap[8] = - { - {{255, 0, 0}}, {{0, 148, 255}}, {{ 0, 148, 255}}, {{255, 94, 0}}, - {{255, 121, 0}}, {{76, 255, 0}}, {{76, 255, 0}}, {{255, 202, 0}} - }; - - TCollection_AsciiString aTextureTypeArg (theArgVec[1]); - aTextureTypeArg.UpperCase(); - if (aTextureTypeArg == "1D") - { - anImage->InitWrapper (Image_Format_RGB, (Standard_Byte*)aBitmap, 8, 1); - } - else if (aTextureTypeArg == "2D") - { - anImage->InitTrash (Image_Format_RGB, 8, 8); - for (Standard_Integer aRow = 0; aRow < 8; ++aRow) - { - for (Standard_Integer aCol = 0; aCol < 8; ++aCol) - { - anImage->ChangeValue (aRow, aCol) = aBitmap[aRow]; - } - } - } - else - { - std::cout << "Please specify type of texture to test {1D|2D}.\n"; - return 1; - } - - TopoDS_Shape aBlankShape = BRepPrimAPI_MakeBox (10.0, 10.0, 10.0).Shape(); - - Handle(AIS_TexturedShape) aTexturedShape = new AIS_TexturedShape (aBlankShape); - aTexturedShape->SetTexturePixMap (anImage); - anAISContext->Display (aTexturedShape, 3, 0, Standard_True); - - return 0; -} - //======================================================================= //function : OCC24667 //purpose : @@ -5431,7 +5372,6 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) { theCommands.Add ("OCC24533", "OCC24533", __FILE__, OCC24533, group); theCommands.Add ("OCC24012", "OCC24012 face edge", __FILE__, OCC24012, group); theCommands.Add ("OCC24086", "OCC24086 face wire", __FILE__, OCC24086, group); - theCommands.Add ("OCC24622", "OCC24622 texture={1D|2D}\n Tests sourcing of 1D/2D pixmaps for AIS_TexturedShape", __FILE__, OCC24622, group); theCommands.Add ("OCC24667", "OCC24667 result Wire_spine Profile [Mode [Approx]], no args to get help", __FILE__, OCC24667, group); theCommands.Add ("OCC24755", "OCC24755", __FILE__, OCC24755, group); theCommands.Add ("OCC24834", "OCC24834", __FILE__, OCC24834, group); diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index 83e71c5d9c..8eaf0dd1e6 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -49,8 +49,9 @@ #include #include #include -#include +#include #include +#include #include #include #include @@ -396,7 +397,6 @@ void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,S #include #include -#include #include #include #include @@ -3398,200 +3398,291 @@ int VBounding (Draw_Interpretor& theDI, //function : VTexture //purpose : //============================================================================== -Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv) +Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) { - TCollection_AsciiString aCommandName (theArgv[0]); - - NCollection_DataMap aMapOfArgs; - if (aCommandName == "vtexture") + const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); + if (aCtx.IsNull()) { - if (theArgsNb < 2) + std::cout << "Error: no active view!\n"; + return 1; + } + + int toModulate = -1; + bool toSetFilter = false; + bool toSetAniso = false; + bool toSetTrsfAngle = false; + bool toSetTrsfTrans = false; + bool toSetTrsfScale = false; + Standard_ShortReal aTrsfRotAngle = 0.0f; + Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f); + Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f); + Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST; + Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF; + + Handle(AIS_Shape) aTexturedIO; + Handle(Graphic3d_TextureMap) aTextureOld; + Handle(Graphic3d_Texture2Dmanual) aTextureNew; + bool toSetGenRepeat = false; + bool toSetGenScale = false; + bool toSetGenOrigin = false; + bool toSetImage = false; + bool toSetNewImage = false; + + const TCollection_AsciiString aCommandName (theArgVec[0]); + bool toSetDefaults = aCommandName == "vtexdefault"; + + ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); + for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) + { + const TCollection_AsciiString aName = theArgVec[anArgIter]; + TCollection_AsciiString aNameCase = aName; + aNameCase.LowerCase(); + if (anUpdateTool.parseRedrawMode (aName)) { - std::cout << theArgv[0] << ": invalid arguments.\n"; - std::cout << "Type help for more information.\n"; + continue; + } + else if (aTexturedIO.IsNull()) + { + const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS(); + if (aMapOfIO.IsBound2 (aName)) + { + aTexturedIO = Handle(AIS_Shape)::DownCast (aMapOfIO.Find2 (aName)); + } + if (aTexturedIO.IsNull()) + { + std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n"; + return 1; + } + + if (aTexturedIO->Attributes()->HasOwnShadingAspect()) + { + aTextureOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap(); + } + } + else if (aNameCase == "-scale" + || aNameCase == "-setscale" + || aCommandName == "vtexscale") + { + if (aCommandName != "vtexscale") + { + ++anArgIter; + } + if (anArgIter < theArgsNb) + { + TCollection_AsciiString aValU (theArgVec[anArgIter]); + TCollection_AsciiString aValUCase = aValU; + aValUCase.LowerCase(); + toSetGenScale = true; + if (aValUCase == "off") + { + aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0)); + continue; + } + else if (anArgIter + 1 < theArgsNb) + { + TCollection_AsciiString aValV (theArgVec[anArgIter + 1]); + if (aValU.IsRealValue() + && aValV.IsRealValue()) + { + aTexturedIO->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue())); + ++anArgIter; + continue; + } + } + } + std::cout << "Syntax error: unexpected argument '" << aName << "'\n"; return 1; } - - // look for options of vtexture command - TCollection_AsciiString aParseKey; - for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt) + else if (aNameCase == "-origin" + || aNameCase == "-setorigin" + || aCommandName == "vtexorigin") { - TCollection_AsciiString anArg (theArgv [anArgIt]); - - anArg.UpperCase(); - if (anArg.Value (1) == '-' && !anArg.IsRealValue()) + if (aCommandName != "vtexorigin") { - aParseKey = anArg; - aParseKey.Remove (1); - aParseKey.UpperCase(); - aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); - continue; + ++anArgIter; } - - if (aParseKey.IsEmpty()) + if (anArgIter < theArgsNb) { - continue; + TCollection_AsciiString aValU (theArgVec[anArgIter]); + TCollection_AsciiString aValUCase = aValU; + aValUCase.LowerCase(); + toSetGenOrigin = true; + if (aValUCase == "off") + { + aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0)); + continue; + } + else if (anArgIter + 1 < theArgsNb) + { + TCollection_AsciiString aValV (theArgVec[anArgIter + 1]); + if (aValU.IsRealValue() + && aValV.IsRealValue()) + { + aTexturedIO->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue())); + ++anArgIter; + continue; + } + } } - - aMapOfArgs(aParseKey)->Append (anArg); - } - } - else if (aCommandName == "vtexscale" - || aCommandName == "vtexorigin" - || aCommandName == "vtexrepeat") - { - // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands - // equal to -scale, -origin, -repeat options of vtexture command - if (theArgsNb < 2 || theArgsNb > 4) - { - std::cout << theArgv[0] << ": invalid arguments.\n"; - std::cout << "Type help for more information.\n"; + std::cout << "Syntax error: unexpected argument '" << aName << "'\n"; return 1; } - - Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString; - if (theArgsNb == 2) + else if (aNameCase == "-repeat" + || aNameCase == "-setrepeat" + || aCommandName == "vtexrepeat") { - anArgs->Append ("OFF"); - } - else if (theArgsNb == 4) - { - anArgs->Append (TCollection_AsciiString (theArgv[2])); - anArgs->Append (TCollection_AsciiString (theArgv[3])); - } - - TCollection_AsciiString anArgKey; - if (aCommandName == "vtexscale") - { - anArgKey = "SCALE"; - } - else if (aCommandName == "vtexorigin") - { - anArgKey = "ORIGIN"; - } - else - { - anArgKey = "REPEAT"; - } - - aMapOfArgs.Bind (anArgKey, anArgs); - } - else if (aCommandName == "vtexdefault") - { - // scan for parameters of vtexdefault command - // equal to -default option of vtexture command - aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString); - } - - // Check arguments for validity - NCollection_DataMap::Iterator aMapIt (aMapOfArgs); - for (; aMapIt.More(); aMapIt.Next()) - { - const TCollection_AsciiString& aKey = aMapIt.Key(); - const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); - - // -scale, -origin, -repeat: one argument "off", or two real values - if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT")) - && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF") - || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue()))) - { - continue; - } - - // -modulate: single argument "on" / "off" - if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON")) - { - continue; - } - - // -default: no arguments - if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty()) - { - continue; - } - - TCollection_AsciiString aLowerKey; - aLowerKey = "-"; - aLowerKey += aKey; - aLowerKey.LowerCase(); - std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n"; - std::cout << "Type help for more information.\n"; - return 1; - } - - Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); - if (anAISContext.IsNull()) - { - std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n"; - return 1; - } - - Standard_Integer aPreviousMode = 0; - - TCollection_AsciiString aShapeName (theArgv[1]); - Handle(AIS_InteractiveObject) anIO; - - const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS(); - if (aMapOfIO.IsBound2 (aShapeName)) - { - anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName)); - } - - if (anIO.IsNull()) - { - std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n"; - return 1; - } - - Handle(AIS_TexturedShape) aTexturedIO; - if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape))) - { - aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO); - aPreviousMode = aTexturedIO->DisplayMode(); - } - else - { - aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1])); - - if (anIO->HasTransformation()) - { - const gp_Trsf& aLocalTrsf = anIO->LocalTransformation(); - aTexturedIO->SetLocalTransformation (aLocalTrsf); - } - - anAISContext->Remove (anIO, Standard_False); - GetMapOfAIS().UnBind1 (anIO); - GetMapOfAIS().UnBind2 (aShapeName); - GetMapOfAIS().Bind (aTexturedIO, aShapeName); - } - - // ------------------------------------------- - // Turn texturing on/off - only for vtexture - // ------------------------------------------- - - if (aCommandName == "vtexture") - { - TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : ""); - - if (aTextureArg.IsEmpty()) - { - std::cout << aCommandName << ": Texture mapping disabled.\n"; - std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n"; - - anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False); - if (aPreviousMode == 3) + if (aCommandName != "vtexrepeat") { - anAISContext->RecomputePrsOnly (aTexturedIO, Standard_False); + ++anArgIter; } - - anAISContext->Display (aTexturedIO, Standard_True); - return 0; - } - else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument - { - if (aTextureArg == "?") + if (anArgIter < theArgsNb) { - TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder(); + TCollection_AsciiString aValU (theArgVec[anArgIter]); + TCollection_AsciiString aValUCase = aValU; + aValUCase.LowerCase(); + toSetGenRepeat = true; + if (aValUCase == "off") + { + aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0)); + continue; + } + else if (anArgIter + 1 < theArgsNb) + { + TCollection_AsciiString aValV (theArgVec[anArgIter + 1]); + if (aValU.IsRealValue() + && aValV.IsRealValue()) + { + aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue())); + ++anArgIter; + continue; + } + } + } + std::cout << "Syntax error: unexpected argument '" << aName << "'\n"; + return 1; + } + else if (aNameCase == "-modulate") + { + bool toModulateBool = true; + if (anArgIter + 1 < theArgsNb + && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool)) + { + ++anArgIter; + } + toModulate = toModulateBool ? 1 : 0; + } + else if ((aNameCase == "-setfilter" + || aNameCase == "-filter") + && anArgIter + 1 < theArgsNb) + { + TCollection_AsciiString aValue (theArgVec[anArgIter + 1]); + aValue.LowerCase(); + ++anArgIter; + toSetFilter = true; + if (aValue == "nearest") + { + aFilter = Graphic3d_TOTF_NEAREST; + } + else if (aValue == "bilinear") + { + aFilter = Graphic3d_TOTF_BILINEAR; + } + else if (aValue == "trilinear") + { + aFilter = Graphic3d_TOTF_TRILINEAR; + } + else + { + std::cout << "Syntax error: unexpected argument '" << aValue << "'\n"; + return 1; + } + } + else if ((aNameCase == "-setaniso" + || aNameCase == "-setanisofilter" + || aNameCase == "-aniso" + || aNameCase == "-anisofilter") + && anArgIter + 1 < theArgsNb) + { + TCollection_AsciiString aValue (theArgVec[anArgIter + 1]); + aValue.LowerCase(); + ++anArgIter; + toSetAniso = true; + if (aValue == "off") + { + anAnisoFilter = Graphic3d_LOTA_OFF; + } + else if (aValue == "fast") + { + anAnisoFilter = Graphic3d_LOTA_FAST; + } + else if (aValue == "middle") + { + anAnisoFilter = Graphic3d_LOTA_MIDDLE; + } + else if (aValue == "quality" + || aValue == "high") + { + anAnisoFilter = Graphic3d_LOTA_QUALITY; + } + else + { + std::cout << "Syntax error: unexpected argument '" << aValue << "'\n"; + return 1; + } + } + else if ((aNameCase == "-rotateangle" + || aNameCase == "-rotangle" + || aNameCase == "-rotate" + || aNameCase == "-angle" + || aNameCase == "-trsfangle") + && anArgIter + 1 < theArgsNb) + { + aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1])); + toSetTrsfAngle = true; + ++anArgIter; + } + else if ((aNameCase == "-trsftrans" + || aNameCase == "-trsftranslate" + || aNameCase == "-translate" + || aNameCase == "-translation") + && anArgIter + 2 < theArgsNb) + { + aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1])); + aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2])); + toSetTrsfTrans = true; + anArgIter += 2; + } + else if ((aNameCase == "-trsfscale") + && anArgIter + 2 < theArgsNb) + { + aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1])); + aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2])); + toSetTrsfScale = true; + anArgIter += 2; + } + else if (aNameCase == "-default" + || aNameCase == "-defaults") + { + toSetDefaults = true; + } + else if (aTextureNew.IsNull() + && aCommandName == "vtexture") + { + toSetImage = true; + toSetNewImage = true; + if (aName.IsIntegerValue()) + { + const Standard_Integer aValue = aName.IntegerValue(); + if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures()) + { + std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n"; + return 1; + } + aTextureNew = new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)); + } + else if (aNameCase == "?") + { + const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder(); theDi << "\n Files in current directory : \n\n"; theDi.Eval ("glob -nocomplain *"); @@ -3600,91 +3691,180 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, aCmnd += aTextureFolder; aCmnd += "/* "; - theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n"; + theDi << "Files in " << aTextureFolder << " : \n\n"; theDi.Eval (aCmnd.ToCString()); return 0; } + else if (aNameCase != "off") + { + if (!OSD_File (aName).Exists()) + { + std::cout << "Syntax error: non-existing image file has been specified '" << aName << "'.\n"; + return 1; + } + aTextureNew = new Graphic3d_Texture2Dmanual (aName); + } + + if (!aTextureNew.IsNull()) + { + if (!aTextureOld.IsNull()) + { + *aTextureNew->GetParams() = *aTextureOld->GetParams(); + if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld)) + { + TCollection_AsciiString aFilePathOld, aFilePathNew; + aTextureOld->Path().SystemName (aFilePathOld); + aTextureNew->Path().SystemName (aFilePathNew); + if (aTextureNew->Name() == anOldManualTex->Name() + && aFilePathOld == aFilePathNew + && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN)) + { + toSetNewImage = false; + aTextureNew = anOldManualTex; + } + } + } + else + { + aTexturedIO->SetToUpdate (AIS_Shaded); + } + } + + if (!aTexturedIO->Attributes()->HasOwnShadingAspect()) + { + aTexturedIO->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect()); + *aTexturedIO->Attributes()->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect(); + } + + if (!aTextureNew.IsNull()) + { + aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn(); + } else { - aTexturedIO->SetTextureFileName (aTextureArg); + aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff(); } + aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (aTextureNew); + aTextureOld.Nullify(); } - } - - // ------------------------------------ - // Process other options and commands - // ------------------------------------ - - Handle(TColStd_HSequenceOfAsciiString) aValues; - if (aMapOfArgs.Find ("DEFAULT", aValues)) - { - aTexturedIO->SetTextureRepeat (Standard_False); - aTexturedIO->SetTextureOrigin (Standard_False); - aTexturedIO->SetTextureScale (Standard_False); - aTexturedIO->EnableTextureModulate(); - } - else - { - if (aMapOfArgs.Find ("SCALE", aValues)) + else { - if (aValues->Value(1) != "OFF") - { - aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue()); - } - else - { - aTexturedIO->SetTextureScale (Standard_False); - } - } - - if (aMapOfArgs.Find ("ORIGIN", aValues)) - { - if (aValues->Value(1) != "OFF") - { - aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue()); - } - else - { - aTexturedIO->SetTextureOrigin (Standard_False); - } - } - - if (aMapOfArgs.Find ("REPEAT", aValues)) - { - if (aValues->Value(1) != "OFF") - { - aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue()); - } - else - { - aTexturedIO->SetTextureRepeat (Standard_False); - } - } - - if (aMapOfArgs.Find ("MODULATE", aValues)) - { - if (aValues->Value(1) == "ON") - { - aTexturedIO->EnableTextureModulate(); - } - else - { - aTexturedIO->DisableTextureModulate(); - } + std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n"; + return 1; } } - if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3) + if (toSetDefaults) { - anAISContext->RecomputePrsOnly (aTexturedIO, Standard_True); - } - else - { - anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False); - anAISContext->Display (aTexturedIO, Standard_True); - anAISContext->Update (aTexturedIO,Standard_True); + if (toModulate != -1) + { + toModulate = 1; + } + if (!toSetFilter) + { + toSetFilter = true; + aFilter = Graphic3d_TOTF_BILINEAR; + } + if (!toSetAniso) + { + toSetAniso = true; + anAnisoFilter = Graphic3d_LOTA_OFF; + } + if (!toSetTrsfAngle) + { + toSetTrsfAngle = true; + aTrsfRotAngle = 0.0f; + } + if (!toSetTrsfTrans) + { + toSetTrsfTrans = true; + aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f); + } + if (!toSetTrsfScale) + { + toSetTrsfScale = true; + aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f); + } } + if (aCommandName == "vtexture" + && theArgsNb == 2) + { + if (!aTextureOld.IsNull()) + { + toSetNewImage = true; + aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff(); + aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (Handle(Graphic3d_TextureMap)()); + aTextureOld.Nullify(); + } + } + + if (aTexturedIO->Attributes()->HasOwnShadingAspect() + && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull()) + { + if (toModulate != -1) + { + aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1); + } + if (toSetTrsfAngle) + { + aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees + } + if (toSetTrsfTrans) + { + aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans); + } + if (toSetTrsfScale) + { + aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale); + } + if (toSetFilter) + { + aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter); + } + if (toSetAniso) + { + aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter); + } + } + + // set default values if requested + if (!toSetGenRepeat + && (aCommandName == "vtexrepeat" + || toSetDefaults)) + { + aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0)); + toSetGenRepeat = true; + } + if (!toSetGenOrigin + && (aCommandName == "vtexorigin" + || toSetDefaults)) + { + aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0)); + toSetGenOrigin = true; + } + if (!toSetGenScale + && (aCommandName == "vtexscale" + || toSetDefaults)) + { + aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0)); + toSetGenScale = true; + } + + if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toSetNewImage) + { + aTexturedIO->SetToUpdate (AIS_Shaded); + if (toSetImage) + { + if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded) + || aCtx->DisplayMode() != AIS_Shaded) + { + aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false); + } + } + } + aCtx->Display (aTexturedIO, false); + aTexturedIO->SynchronizeAspects(); return 0; } @@ -6086,47 +6266,46 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands) __FILE__,VShading,group); theCommands.Add ("vtexture", - "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n" - " [-scale u v] [-scale off]\n" - " [-origin u v] [-origin off]\n" - " [-repeat u v] [-repeat off]\n" - " [-modulate {on | off}]" - " [-default]'\n" - " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n" - " specifying one of the predefined textures.\n" - " The options are: \n" - " -scale u v : enable texture scaling and set scale factors\n" - " -scale off : disable texture scaling\n" - " -origin u v : enable texture origin positioning and set the origin\n" - " -origin off : disable texture origin positioning\n" - " -repeat u v : enable texture repeat and set texture coordinate scaling\n" - " -repeat off : disable texture repeat\n" - " -modulate {on | off} : enable or disable texture modulation\n" - " -default : sets texture mapping default parameters\n" - "or 'vtexture NameOfShape' if you want to disable texture mapping\n" - "or 'vtexture NameOfShape ?' to list available textures\n", + "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]" + "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]" + "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]" + "\n\t\t: [-modulate {on|off}]" + "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]" + "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]" + "\n\t\t: [-default]" + "\n\t\t: The texture can be specified by filepath" + "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures." + "\n\t\t: The options are:" + "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default" + "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default" + "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default" + "\n\t\t: -modulate Enable or disable texture color modulation" + "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle" + "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector" + "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector" + "\n\t\t: -setFilter Setup texture filter" + "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels" + "\n\t\t: -default Sets texture mapping default parameters", __FILE__, VTexture, group); theCommands.Add("vtexscale", - "'vtexscale NameOfShape ScaleU ScaleV' \n \ - or 'vtexscale NameOfShape ScaleUV' \n \ - or 'vtexscale NameOfShape' to disable scaling\n ", + "vtexscale name ScaleU ScaleV" + "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.", __FILE__,VTexture,group); theCommands.Add("vtexorigin", - "'vtexorigin NameOfShape UOrigin VOrigin' \n \ - or 'vtexorigin NameOfShape UVOrigin' \n \ - or 'vtexorigin NameOfShape' to disable origin positioning\n ", + "vtexorigin name OriginU OriginV" + "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.", __FILE__,VTexture,group); theCommands.Add("vtexrepeat", - "'vtexrepeat NameOfShape URepeat VRepeat' \n \ - or 'vtexrepeat NameOfShape UVRepeat \n \ - or 'vtexrepeat NameOfShape' to disable texture repeat \n ", + "vtexrepeat name RepeatU RepeatV" + "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.", VTexture,group); theCommands.Add("vtexdefault", - "'vtexdefault NameOfShape' to set texture mapping default parameters \n", + "vtexdefault name" + "\n\t\t: Alias for vtexture name -default.", VTexture,group); theCommands.Add("vsetam", diff --git a/tests/bugs/vis/bug23804 b/tests/bugs/vis/bug23804 index baea5ec33e..e408aaeab8 100644 --- a/tests/bugs/vis/bug23804 +++ b/tests/bugs/vis/bug23804 @@ -18,6 +18,7 @@ vdump $imagedir/${casename}_1.png vsetcolor b ANTIQUEWHITE vdump $imagedir/${casename}_2.png +vunsetcolor b vtexture b 3 vdump $imagedir/${casename}_3.png diff --git a/tests/bugs/vis/bug24622 b/tests/bugs/vis/bug24622 deleted file mode 100644 index b9a503db15..0000000000 --- a/tests/bugs/vis/bug24622 +++ /dev/null @@ -1,48 +0,0 @@ -puts "============" -puts "CR24622" -puts "============" -puts "" - -############################################################################## -# Test for mapping Image_PixMap on AIS_TexturedShape / Graphic3d_TextureRoot -############################################################################## - -set aV1 "Driver1/Viewer1/View1" -set aV2 "Driver1/Viewer2/View1" -vinit name=$aV1 l=32 t=32 w=400 h=400 -vinit name=$aV2 l=32 t=32 w=400 h=400 -vactivate $aV1 -vclear - -OCC24622 1D -vtop -vfit - -set aColor [vreadpixel 100 200 rgb name] -if { "$aColor" != "CYAN1" } { - puts "Error: the 1D texture color does not match at px (100, 200)!" -} - -set aColor [vreadpixel 300 200 rgb name] -if { "$aColor" != "CHARTREUSE" } { - puts "Error: the 1D texture color does not match at px (300, 200)!" -} - -vactivate $aV2 -vclear - -OCC24622 2D -vtop -vfit - -set aColor [vreadpixel 100 200 rgb name] -if { "$aColor" != "DARKGOLDENROD1" } { - puts "Error: the 2D texture color does not match at px (200, 100)!" -} - -set aColor [vreadpixel 200 300 rgb name] -if { "$aColor" != "CHARTREUSE" } { - puts "Error: the 2D texture color does not match at px (200, 300)!" -} - -checkview -screenshot -3d -path ${imagedir}/${test_image}.png diff --git a/tests/v3d/glsl/texture_trsf b/tests/v3d/glsl/texture_trsf index ef3d9fb877..cb5ec8b87a 100644 --- a/tests/v3d/glsl/texture_trsf +++ b/tests/v3d/glsl/texture_trsf @@ -1,5 +1,5 @@ puts "========" -puts "Texture 2D transformation" +puts "Texture 2D transformation (UV coordinates generation)" puts "========" set aTexture [locate_data_file bug26122_texture_trsf_ref.png] diff --git a/tests/v3d/glsl/texture_trsf2 b/tests/v3d/glsl/texture_trsf2 new file mode 100644 index 0000000000..7bb7faf56c --- /dev/null +++ b/tests/v3d/glsl/texture_trsf2 @@ -0,0 +1,39 @@ +puts "========" +puts "Texture 2D transformation (presentation trsf)" +puts "========" + +set aTexture [locate_data_file bug26122_texture_trsf_ref.png] +pload MODELING VISUALIZATION +box b 1 1 1 +explode b F +vclear +vclose ALL +vinit View1 w=512 h=512 +vtop +vsetdispmode 1 +vdisplay b_6 +vfit + +vcaps -ffp 1 +vtexture b_6 $aTexture -modulate off +vdump $::imagedir/${::casename}_identity_ffp.png +vcaps -ffp 0 +vdump $::imagedir/${::casename}_identity_glsl.png + +vcaps -ffp 1 +vtexture b_6 $aTexture -trsfTranslate 0.0 0.0 -trsfScale 0.8 2.0 +vdump $::imagedir/${::casename}_scale_ffp.png +vcaps -ffp 0 +vdump $::imagedir/${::casename}_scale_glsl.png + +vcaps -ffp 1 +vtexture b_6 $aTexture -trsfTranslate 0.25 -0.25 -trsfScale 1.0 1.0 +vdump $::imagedir/${::casename}_translate_ffp.png +vcaps -ffp 0 +vdump $::imagedir/${::casename}_translate_glsl.png + +vcaps -ffp 1 +vtexture b_6 $aTexture -trsfTranslate 0.25 -0.25 -trsfScale 1.1 0.8 +vdump $::imagedir/${::casename}_ffp.png +vcaps -ffp 0 +vdump $::imagedir/${::casename}_glsl.png