1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0028811: Visualization - merge texturing support into AIS_Shape class and get rid of AIS_TexturedShape

AIS_Shape and AIS_ColoredShape now computes Shaded presentation
with UV coordinates if texture mapping is enabled in Drawer.

OpenGl_Context::SetTextureMatrix() - fixed inconsistent handling
of texture cooridnates translation vector.

vtexture command has been extended to handle new arguments:
* -trsfTrans, -trsfScale, -trsfAngle defining transformation matrix
* -setFilter, -setAnisoFilter to setup texture filtering
This commit is contained in:
kgv 2017-07-17 15:19:33 +03:00 committed by bugmaster
parent 798849860f
commit a6dee93dfa
19 changed files with 648 additions and 481 deletions

View File

@ -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(). * 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). * 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. 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 @subsection upgrade_720_BOP_DataStructure BOP - Pairs of interfering indices

View File

@ -75,7 +75,6 @@
#include <AIS_InteractiveObject.hxx> #include <AIS_InteractiveObject.hxx>
#include <AIS_LocalContext.hxx> #include <AIS_LocalContext.hxx>
#include <AIS_TextLabel.hxx> #include <AIS_TextLabel.hxx>
#include <AIS_TexturedShape.hxx>
#include <Aspect_TypeOfline.hxx> #include <Aspect_TypeOfline.hxx>
#include <Aspect_WidthOfline.hxx> #include <Aspect_WidthOfline.hxx>

View File

@ -9,9 +9,9 @@
#include <TopExp.hxx> #include <TopExp.hxx>
#include <TopTools_IndexedMapOfShape.hxx> #include <TopTools_IndexedMapOfShape.hxx>
#include <BRepBuilderAPI_MakeFace.hxx> #include <BRepBuilderAPI_MakeFace.hxx>
#include <AIS_TexturedShape.hxx> #include <AIS_Shape.hxx>
#include <BRepTools.hxx> #include <BRepTools.hxx>
#include <Graphic3d_Texture2D.hxx> #include <Graphic3d_Texture2Dmanual.hxx>
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
#include <TopoDS.hxx> #include <TopoDS.hxx>
#include <BRepBuilderAPI_Transform.hxx> #include <BRepBuilderAPI_Transform.hxx>
@ -80,7 +80,7 @@ void TexturesExt_Presentation::Init()
" // aShape = ..." EOL " // aShape = ..." EOL
"" EOL "" EOL
" // create a textured presentation object for aShape" 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 "" EOL
" TCollection_AsciiString aTFileName;" EOL " TCollection_AsciiString aTFileName;" EOL
"" EOL "" EOL
@ -90,22 +90,10 @@ void TexturesExt_Presentation::Init()
" // which will indicate use of predefined texture of this number" EOL " // which will indicate use of predefined texture of this number" EOL
" // aTFileName = ..." EOL " // aTFileName = ..." EOL
"" EOL "" EOL
" aTShape->SetTextureFileName(aTFileName);" EOL " aTShape->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());" EOL
"" EOL " Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual (aTFileName);" EOL
" // do other initialization of AIS_TexturedShape" EOL " aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (aTexture);" EOL
" Standard_Real nRepeat;" EOL " aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();" 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);
// CString text(Message.ToCString()); // CString text(Message.ToCString());
getDocument()->ClearDialog(); getDocument()->ClearDialog();
getDocument()->SetDialogTitle("Change face color"); getDocument()->SetDialogTitle("Change face color");
@ -117,12 +105,12 @@ void TexturesExt_Presentation::Init()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
//================================================================ //================================================================
// Function : TexturesExt_Presentation::Texturize // 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 // filename can also be an integer value ("2", "5", etc.), in this case
// a predefined texture from Graphic3d_NameOfTexture2D with number = this value // a predefined texture from Graphic3d_NameOfTexture2D with number = this value
// is loaded. // 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, TCollection_AsciiString aTFileName,
Standard_Real toScaleU, Standard_Real toScaleU,
Standard_Real toScaleV, Standard_Real toScaleV,
@ -132,7 +120,7 @@ Handle(AIS_TexturedShape) TexturesExt_Presentation::Texturize(const TopoDS_Shape
Standard_Real originV) Standard_Real originV)
{ {
// create a textured presentation object for aShape // 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; TCollection_AsciiString TFileName;
// load texture from file if it is not an integer value // load texture from file if it is not an integer value
// integer value indicates a number of texture in predefined TexturesExt enumeration // 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(); 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 // do other initialization of AIS_Shape
aTShape->SetTextureMapOn(); aTShape->SetTextureScaleUV (gp_Pnt2d ( toScaleU, toScaleV));
aTShape->SetTextureScale(Standard_True, toScaleU, toScaleV); aTShape->SetTextureRepeatUV(gp_Pnt2d (toRepeatU, toRepeatV));
aTShape->SetTextureRepeat(Standard_True, toRepeatU, toRepeatV); aTShape->SetTextureOriginUV(gp_Pnt2d ( originU, originV));
aTShape->SetTextureOrigin(Standard_True, originU, originV);
aTShape->SetDisplayMode(3); // mode 3 is "textured" mode aTShape->SetDisplayMode(AIS_Shaded);
return aTShape; return aTShape;
} }
@ -255,10 +247,10 @@ aShape = Transformer.Shape();
aShapeIO->SetPolygonOffsets(Aspect_POM_Fill, 1.5, 0.5); aShapeIO->SetPolygonOffsets(Aspect_POM_Fill, 1.5, 0.5);
DISP(aShapeIO); 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); 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); DISP(aTFace2);
getViewer()->Update(); getViewer()->Update();

View File

@ -10,7 +10,7 @@
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
#include "OCCDemo_Presentation.h" #include "OCCDemo_Presentation.h"
#include <AIS_TexturedShape.hxx> #include <AIS_Shape.hxx>
class TopoDS_Shape; class TopoDS_Shape;
class TCollection_AsciiString; class TCollection_AsciiString;
@ -28,11 +28,11 @@ public:
virtual void Init(); virtual void Init();
private: 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 // filename can also be an integer value ("2", "5", etc.), in this case
// a predefined texture from Graphic3d_NameOfTexture2D with number = this value // a predefined texture from Graphic3d_NameOfTexture2D with number = this value
// is loaded. // is loaded.
Handle(AIS_TexturedShape) Texturize( Handle(AIS_Shape) Texturize(
const TopoDS_Shape& aShape, TCollection_AsciiString aTFileName, const TopoDS_Shape& aShape, TCollection_AsciiString aTFileName,
Standard_Real toScaleU=1.0, Standard_Real toScaleV=1.0, Standard_Real toScaleU=1.0, Standard_Real toScaleV=1.0,
Standard_Real toRepeatU=1.0, Standard_Real toRepeatV=1.0, Standard_Real toRepeatU=1.0, Standard_Real toRepeatV=1.0,

View File

@ -2,13 +2,15 @@
#include "Sample2D_Image.h" #include "Sample2D_Image.h"
IMPLEMENT_STANDARD_RTTIEXT(Sample2D_Image,AIS_TexturedShape) #include <Graphic3d_Texture2Dmanual.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Sample2D_Image,AIS_Shape)
Sample2D_Image::Sample2D_Image(TCollection_AsciiString& aFileName, Sample2D_Image::Sample2D_Image(TCollection_AsciiString& aFileName,
const Standard_Real X, const Standard_Real X,
const Standard_Real Y, const Standard_Real Y,
const Standard_Real aScale) const Standard_Real aScale)
:AIS_TexturedShape(TopoDS_Shape()) :AIS_Shape(TopoDS_Shape())
{ {
myFilename = aFileName; myFilename = aFileName;
myX = X; myX = X;
@ -35,9 +37,7 @@ void Sample2D_Image::SetContext(const Handle(AIS_InteractiveContext)& theContext
AIS_InteractiveObject::SetContext(theContext); AIS_InteractiveObject::SetContext(theContext);
MakeShape(); MakeShape();
this->Set(TopoDS_Shape(myFace)); 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();
} }

View File

@ -11,8 +11,8 @@
#include <Standard_OStream.hxx> #include <Standard_OStream.hxx>
#include <Standard_IStream.hxx> #include <Standard_IStream.hxx>
class Sample2D_Image; class Sample2D_Image;
DEFINE_STANDARD_HANDLE(Sample2D_Image,AIS_TexturedShape) DEFINE_STANDARD_HANDLE(Sample2D_Image,AIS_Shape)
class Sample2D_Image : public AIS_TexturedShape { class Sample2D_Image : public AIS_Shape {
public: public:
@ -26,7 +26,7 @@ Standard_EXPORT inline Standard_Real GetScale() const;
Standard_EXPORT inline void SetScale(const Standard_Real aNewScale) ; Standard_EXPORT inline void SetScale(const Standard_Real aNewScale) ;
Standard_EXPORT virtual void SetContext(const Handle(AIS_InteractiveContext)& theContext) ; 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: private:
void MakeShape(); void MakeShape();
protected: protected:

View File

@ -27,7 +27,6 @@
#include <AIS_Line.hxx> #include <AIS_Line.hxx>
#include <AIS_Shape.hxx> #include <AIS_Shape.hxx>
#include <AIS_Point.hxx> #include <AIS_Point.hxx>
#include <AIS_TexturedShape.hxx>
#include <Aspect_Grid.hxx> #include <Aspect_Grid.hxx>
#include <Aspect_PolygonOffsetMode.hxx> #include <Aspect_PolygonOffsetMode.hxx>
#include <Aspect_DisplayConnection.hxx> #include <Aspect_DisplayConnection.hxx>

View File

@ -298,11 +298,13 @@ void AIS_ColoredShape::UnsetTransparency()
if (myDrawer->HasOwnShadingAspect()) if (myDrawer->HasOwnShadingAspect())
{ {
myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel); myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
} if (!HasColor()
if (!HasColor() && !HasMaterial()) && !HasMaterial()
&& !myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
{ {
myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
} }
}
for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next()) 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 // add special wireframe presentation for faces without triangulation
StdPrs_ShadedShape::AddWireframeForFacesWithoutTriangles (thePrs, aShapeDraw, aDrawer); 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 (!aTriangles.IsNull())
{ {
if (aShadedGroup.IsNull()) if (aShadedGroup.IsNull())

View File

@ -80,16 +80,19 @@ static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard
} }
//================================================== //==================================================
// Function: // Function: AIS_Shape
// Purpose : // Purpose :
//================================================== //==================================================
AIS_Shape::AIS_Shape(const TopoDS_Shape& theShape)
AIS_Shape:: : AIS_InteractiveObject (PrsMgr_TOP_ProjectorDependant),
AIS_Shape(const TopoDS_Shape& shap): myshape (theShape),
AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant), myUVOrigin(0.0, 0.0),
myInitAng(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 try
{ {
OCC_CATCH_SIGNALS 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) catch (Standard_Failure)
{ {
@ -562,6 +568,7 @@ void AIS_Shape::UnsetColor()
return; return;
} }
hasOwnColor = Standard_False; hasOwnColor = Standard_False;
myDrawer->SetColor (myDrawer->HasLink() ? myDrawer->Link()->Color() : Quantity_Color (Quantity_NOC_WHITE));
if (!HasWidth()) if (!HasWidth())
{ {
@ -605,22 +612,34 @@ void AIS_Shape::UnsetColor()
myDrawer->SeenLineAspect()->SetColor (aColor); myDrawer->SeenLineAspect()->SetColor (aColor);
} }
if (HasMaterial() if (!myDrawer->HasOwnShadingAspect())
|| IsTransparent())
{ {
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; 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()) 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()) if (HasMaterial())
{ {
Quantity_Color aColor = aDefaultMat.AmbientColor(); const Quantity_Color aColor = myDrawer->HasLink()
if (myDrawer->HasLink()) ? myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel)
{ : aDefaultMat.AmbientColor();
aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
}
mat.SetColor (aColor); mat.SetColor (aColor);
} }
if (IsTransparent()) if (IsTransparent())
@ -629,6 +648,8 @@ void AIS_Shape::UnsetColor()
mat.SetTransparency (Standard_ShortReal(aTransp)); 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 else
{ {
@ -638,8 +659,8 @@ void AIS_Shape::UnsetColor()
// modify shading presentation without re-computation // modify shading presentation without re-computation
const PrsMgr_Presentations& aPrsList = Presentations(); const PrsMgr_Presentations& aPrsList = Presentations();
Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect(); Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect(); Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->LineAspect()->Aspect();
for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt) for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
{ {
const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt); const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
@ -866,8 +887,13 @@ void AIS_Shape::UnsetMaterial()
return; return;
} }
if (HasColor() if (!myDrawer->HasOwnShadingAspect())
|| IsTransparent()) {
//
}
else if (HasColor()
|| IsTransparent()
|| myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
{ {
if(myDrawer->HasLink()) if(myDrawer->HasLink())
{ {
@ -981,7 +1007,9 @@ void AIS_Shape::UnsetTransparency()
{ {
return; return;
} }
else if (HasColor() || HasMaterial()) else if (HasColor()
|| HasMaterial()
|| myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
{ {
myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel); myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
} }

View File

@ -49,6 +49,17 @@ class Bnd_Box;
//! above deviation angle and coefficient functions return //! above deviation angle and coefficient functions return
//! true indicating that there is a local setting available //! true indicating that there is a local setting available
//! for the specific object. //! 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 class AIS_Shape : public AIS_InteractiveObject
{ {
DEFINE_STANDARD_RTTIEXT(AIS_Shape, AIS_InteractiveObject) DEFINE_STANDARD_RTTIEXT(AIS_Shape, AIS_InteractiveObject)
@ -218,6 +229,31 @@ public:
//! - mode 8 - Compound //! - mode 8 - Compound
Standard_EXPORT static Standard_Integer SelectionMode (const TopAbs_ShapeEnum aShapeType); 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: protected:
Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, const Handle(Prs3d_Presentation)& aPresentation, const Standard_Integer aMode = 0) Standard_OVERRIDE; 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; 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: private:
Standard_EXPORT void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation, const TopoDS_Shape& ashape); Standard_EXPORT void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation, const TopoDS_Shape& ashape);
private: protected:
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_Real myInitAng;
Standard_Boolean myCompBB; //!< if TRUE, then bounding box should be recomputed
}; };

View File

@ -52,11 +52,8 @@ AIS_TexturedShape::AIS_TexturedShape (const TopoDS_Shape& theShape)
myPredefTexture (Graphic3d_NameOfTexture2D(0)), myPredefTexture (Graphic3d_NameOfTexture2D(0)),
myToMapTexture (Standard_True), myToMapTexture (Standard_True),
myModulate (Standard_True), myModulate (Standard_True),
myUVOrigin (0.0, 0.0),
myIsCustomOrigin (Standard_True), myIsCustomOrigin (Standard_True),
myUVRepeat (1.0, 1.0),
myToRepeat (Standard_True), myToRepeat (Standard_True),
myUVScale (1.0, 1.0),
myToScale (Standard_True), myToScale (Standard_True),
myToShowTriangles (Standard_False) myToShowTriangles (Standard_False)
{ {

View File

@ -196,11 +196,8 @@ protected: //! @name texture mapping properties
Standard_Boolean myToMapTexture; Standard_Boolean myToMapTexture;
Standard_Boolean myModulate; Standard_Boolean myModulate;
gp_Pnt2d myUVOrigin;
Standard_Boolean myIsCustomOrigin; Standard_Boolean myIsCustomOrigin;
gp_Pnt2d myUVRepeat;
Standard_Boolean myToRepeat; Standard_Boolean myToRepeat;
gp_Pnt2d myUVScale;
Standard_Boolean myToScale; Standard_Boolean myToScale;
Standard_Boolean myToShowTriangles; Standard_Boolean myToShowTriangles;

View File

@ -3251,7 +3251,8 @@ void OpenGl_Context::SetTextureMatrix (const Handle(Graphic3d_TextureParams)& th
// pack transformation parameters // pack transformation parameters
OpenGl_Vec4 aTrsf[2]; 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[0].zw() = theParams->Scale();
aTrsf[1].x() = std::sin (-theParams->Rotation() * static_cast<float> (M_PI / 180.0)); aTrsf[1].x() = std::sin (-theParams->Rotation() * static_cast<float> (M_PI / 180.0));
aTrsf[1].y() = std::cos (-theParams->Rotation() * static_cast<float> (M_PI / 180.0)); aTrsf[1].y() = std::cos (-theParams->Rotation() * static_cast<float> (M_PI / 180.0));

View File

@ -17,7 +17,7 @@
#include <AIS_InteractiveContext.hxx> #include <AIS_InteractiveContext.hxx>
#include <AIS_LocalContext.hxx> #include <AIS_LocalContext.hxx>
#include <AIS_TexturedShape.hxx> #include <AIS_Shape.hxx>
#include <BRepAlgoAPI_Cut.hxx> #include <BRepAlgoAPI_Cut.hxx>
#include <BRepOffsetAPI_MakePipe.hxx> #include <BRepOffsetAPI_MakePipe.hxx>
#include <BRepPrimAPI_MakeBox.hxx> #include <BRepPrimAPI_MakeBox.hxx>
@ -1792,65 +1792,6 @@ static Standard_Integer OCC23950 (Draw_Interpretor& di, Standard_Integer argc, c
return 0; 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<Image_ColorRGB> (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 //function : OCC24667
//purpose : //purpose :
@ -5431,7 +5372,6 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
theCommands.Add ("OCC24533", "OCC24533", __FILE__, OCC24533, group); theCommands.Add ("OCC24533", "OCC24533", __FILE__, OCC24533, group);
theCommands.Add ("OCC24012", "OCC24012 face edge", __FILE__, OCC24012, group); theCommands.Add ("OCC24012", "OCC24012 face edge", __FILE__, OCC24012, group);
theCommands.Add ("OCC24086", "OCC24086 face wire", __FILE__, OCC24086, 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 ("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 ("OCC24755", "OCC24755", __FILE__, OCC24755, group);
theCommands.Add ("OCC24834", "OCC24834", __FILE__, OCC24834, group); theCommands.Add ("OCC24834", "OCC24834", __FILE__, OCC24834, group);

View File

@ -49,8 +49,9 @@
#include <Graphic3d_AspectFillArea3d.hxx> #include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_AspectLine3d.hxx> #include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_CStructure.hxx> #include <Graphic3d_CStructure.hxx>
#include <Graphic3d_TextureRoot.hxx> #include <Graphic3d_Texture2Dmanual.hxx>
#include <Image_AlienPixMap.hxx> #include <Image_AlienPixMap.hxx>
#include <OSD_File.hxx>
#include <Prs3d_Drawer.hxx> #include <Prs3d_Drawer.hxx>
#include <Prs3d_ShadingAspect.hxx> #include <Prs3d_ShadingAspect.hxx>
#include <Prs3d_IsoAspect.hxx> #include <Prs3d_IsoAspect.hxx>
@ -396,7 +397,6 @@ void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,S
#include <AIS_InteractiveContext.hxx> #include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx> #include <AIS_Shape.hxx>
#include <AIS_TexturedShape.hxx>
#include <AIS_DisplayMode.hxx> #include <AIS_DisplayMode.hxx>
#include <TColStd_MapOfInteger.hxx> #include <TColStd_MapOfInteger.hxx>
#include <AIS_MapOfInteractive.hxx> #include <AIS_MapOfInteractive.hxx>
@ -3398,200 +3398,291 @@ int VBounding (Draw_Interpretor& theDI,
//function : VTexture //function : VTexture
//purpose : //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]); const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
if (aCtx.IsNull())
NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
if (aCommandName == "vtexture")
{ {
if (theArgsNb < 2) std::cout << "Error: no active view!\n";
{
std::cout << theArgv[0] << ": invalid arguments.\n";
std::cout << "Type help for more information.\n";
return 1; return 1;
} }
// look for options of vtexture command int toModulate = -1;
TCollection_AsciiString aParseKey; bool toSetFilter = false;
for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt) bool toSetAniso = false;
{ bool toSetTrsfAngle = false;
TCollection_AsciiString anArg (theArgv [anArgIt]); 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;
anArg.UpperCase(); Handle(AIS_Shape) aTexturedIO;
if (anArg.Value (1) == '-' && !anArg.IsRealValue()) Handle(Graphic3d_TextureMap) aTextureOld;
{ Handle(Graphic3d_Texture2Dmanual) aTextureNew;
aParseKey = anArg; bool toSetGenRepeat = false;
aParseKey.Remove (1); bool toSetGenScale = false;
aParseKey.UpperCase(); bool toSetGenOrigin = false;
aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); bool toSetImage = false;
continue; bool toSetNewImage = false;
}
if (aParseKey.IsEmpty()) 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))
{ {
continue; 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;
}
aMapOfArgs(aParseKey)->Append (anArg); if (aTexturedIO->Attributes()->HasOwnShadingAspect())
{
aTextureOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap();
} }
} }
else if (aCommandName == "vtexscale" else if (aNameCase == "-scale"
|| aCommandName == "vtexorigin" || 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;
}
else if (aNameCase == "-origin"
|| aNameCase == "-setorigin"
|| aCommandName == "vtexorigin")
{
if (aCommandName != "vtexorigin")
{
++anArgIter;
}
if (anArgIter < theArgsNb)
{
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;
}
}
}
std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
return 1;
}
else if (aNameCase == "-repeat"
|| aNameCase == "-setrepeat"
|| aCommandName == "vtexrepeat") || aCommandName == "vtexrepeat")
{ {
// scan for parameters of vtexscale, vtexorigin, vtexrepeat commands if (aCommandName != "vtexrepeat")
// equal to -scale, -origin, -repeat options of vtexture command
if (theArgsNb < 2 || theArgsNb > 4)
{ {
std::cout << theArgv[0] << ": invalid arguments.\n"; ++anArgIter;
std::cout << "Type help for more information.\n"; }
if (anArgIter < theArgsNb)
{
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; return 1;
} }
else if (aNameCase == "-modulate")
Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
if (theArgsNb == 2)
{ {
anArgs->Append ("OFF"); bool toModulateBool = true;
if (anArgIter + 1 < theArgsNb
&& ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
{
++anArgIter;
} }
else if (theArgsNb == 4) toModulate = toModulateBool ? 1 : 0;
{
anArgs->Append (TCollection_AsciiString (theArgv[2]));
anArgs->Append (TCollection_AsciiString (theArgv[3]));
} }
else if ((aNameCase == "-setfilter"
TCollection_AsciiString anArgKey; || aNameCase == "-filter")
if (aCommandName == "vtexscale") && anArgIter + 1 < theArgsNb)
{ {
anArgKey = "SCALE"; TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
aValue.LowerCase();
++anArgIter;
toSetFilter = true;
if (aValue == "nearest")
{
aFilter = Graphic3d_TOTF_NEAREST;
} }
else if (aCommandName == "vtexorigin") else if (aValue == "bilinear")
{ {
anArgKey = "ORIGIN"; aFilter = Graphic3d_TOTF_BILINEAR;
}
else if (aValue == "trilinear")
{
aFilter = Graphic3d_TOTF_TRILINEAR;
} }
else else
{ {
anArgKey = "REPEAT"; std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
}
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<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::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; return 1;
} }
Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
if (anAISContext.IsNull())
{
std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
return 1;
} }
else if ((aNameCase == "-setaniso"
Standard_Integer aPreviousMode = 0; || aNameCase == "-setanisofilter"
|| aNameCase == "-aniso"
TCollection_AsciiString aShapeName (theArgv[1]); || aNameCase == "-anisofilter")
Handle(AIS_InteractiveObject) anIO; && anArgIter + 1 < theArgsNb)
const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
if (aMapOfIO.IsBound2 (aShapeName))
{ {
anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName)); TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
aValue.LowerCase();
++anArgIter;
toSetAniso = true;
if (aValue == "off")
{
anAnisoFilter = Graphic3d_LOTA_OFF;
} }
else if (aValue == "fast")
if (anIO.IsNull())
{ {
std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n"; anAnisoFilter = Graphic3d_LOTA_FAST;
return 1;
} }
else if (aValue == "middle")
Handle(AIS_TexturedShape) aTexturedIO;
if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
{ {
aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO); anAnisoFilter = Graphic3d_LOTA_MIDDLE;
aPreviousMode = aTexturedIO->DisplayMode(); }
else if (aValue == "quality"
|| aValue == "high")
{
anAnisoFilter = Graphic3d_LOTA_QUALITY;
} }
else else
{ {
aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1])); std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
return 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);
} }
else if ((aNameCase == "-rotateangle"
// ------------------------------------------- || aNameCase == "-rotangle"
// Turn texturing on/off - only for vtexture || aNameCase == "-rotate"
// ------------------------------------------- || aNameCase == "-angle"
|| aNameCase == "-trsfangle")
if (aCommandName == "vtexture") && anArgIter + 1 < theArgsNb)
{ {
TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : ""); aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
toSetTrsfAngle = true;
if (aTextureArg.IsEmpty()) ++anArgIter;
{
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)
{
anAISContext->RecomputePrsOnly (aTexturedIO, Standard_False);
} }
else if ((aNameCase == "-trsftrans"
anAISContext->Display (aTexturedIO, Standard_True); || aNameCase == "-trsftranslate"
return 0; || 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 (aTextureArg.Value(1) != '-') // "-option" on place of texture argument else if ((aNameCase == "-trsfscale")
&& anArgIter + 2 < theArgsNb)
{ {
if (aTextureArg == "?") 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")
{ {
TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder(); 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 << "\n Files in current directory : \n\n";
theDi.Eval ("glob -nocomplain *"); theDi.Eval ("glob -nocomplain *");
@ -3600,91 +3691,180 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
aCmnd += aTextureFolder; aCmnd += aTextureFolder;
aCmnd += "/* "; aCmnd += "/* ";
theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n"; theDi << "Files in " << aTextureFolder << " : \n\n";
theDi.Eval (aCmnd.ToCString()); theDi.Eval (aCmnd.ToCString());
return 0; return 0;
} }
else else if (aNameCase != "off")
{ {
aTexturedIO->SetTextureFileName (aTextureArg); 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())
// Process other options and commands
// ------------------------------------
Handle(TColStd_HSequenceOfAsciiString) aValues;
if (aMapOfArgs.Find ("DEFAULT", aValues))
{ {
aTexturedIO->SetTextureRepeat (Standard_False); if (!aTextureOld.IsNull())
aTexturedIO->SetTextureOrigin (Standard_False); {
aTexturedIO->SetTextureScale (Standard_False); *aTextureNew->GetParams() = *aTextureOld->GetParams();
aTexturedIO->EnableTextureModulate(); 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 else
{ {
if (aMapOfArgs.Find ("SCALE", aValues)) aTexturedIO->SetToUpdate (AIS_Shaded);
{
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 (!aTexturedIO->Attributes()->HasOwnShadingAspect())
{ {
if (aValues->Value(1) != "OFF") aTexturedIO->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
*aTexturedIO->Attributes()->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
}
if (!aTextureNew.IsNull())
{ {
aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue()); aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
} }
else else
{ {
aTexturedIO->SetTextureOrigin (Standard_False); aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
} }
} aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (aTextureNew);
aTextureOld.Nullify();
if (aMapOfArgs.Find ("REPEAT", aValues))
{
if (aValues->Value(1) != "OFF")
{
aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
} }
else else
{ {
aTexturedIO->SetTextureRepeat (Standard_False); std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
return 1;
} }
} }
if (aMapOfArgs.Find ("MODULATE", aValues)) if (toSetDefaults)
{ {
if (aValues->Value(1) == "ON") if (toModulate != -1)
{ {
aTexturedIO->EnableTextureModulate(); toModulate = 1;
} }
else if (!toSetFilter)
{ {
aTexturedIO->DisableTextureModulate(); 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 (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3) if (aCommandName == "vtexture"
&& theArgsNb == 2)
{ {
anAISContext->RecomputePrsOnly (aTexturedIO, Standard_True); if (!aTextureOld.IsNull())
{
toSetNewImage = true;
aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (Handle(Graphic3d_TextureMap)());
aTextureOld.Nullify();
} }
else
{
anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
anAISContext->Display (aTexturedIO, Standard_True);
anAISContext->Update (aTexturedIO,Standard_True);
} }
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; return 0;
} }
@ -6086,47 +6266,46 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
__FILE__,VShading,group); __FILE__,VShading,group);
theCommands.Add ("vtexture", theCommands.Add ("vtexture",
"\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n" "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
" [-scale u v] [-scale off]\n" "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
" [-origin u v] [-origin off]\n" "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
" [-repeat u v] [-repeat off]\n" "\n\t\t: [-modulate {on|off}]"
" [-modulate {on | off}]" "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
" [-default]'\n" "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
" The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n" "\n\t\t: [-default]"
" specifying one of the predefined textures.\n" "\n\t\t: The texture can be specified by filepath"
" The options are: \n" "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
" -scale u v : enable texture scaling and set scale factors\n" "\n\t\t: The options are:"
" -scale off : disable texture scaling\n" "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
" -origin u v : enable texture origin positioning and set the origin\n" "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
" -origin off : disable texture origin positioning\n" "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
" -repeat u v : enable texture repeat and set texture coordinate scaling\n" "\n\t\t: -modulate Enable or disable texture color modulation"
" -repeat off : disable texture repeat\n" "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
" -modulate {on | off} : enable or disable texture modulation\n" "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
" -default : sets texture mapping default parameters\n" "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
"or 'vtexture NameOfShape' if you want to disable texture mapping\n" "\n\t\t: -setFilter Setup texture filter"
"or 'vtexture NameOfShape ?' to list available textures\n", "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
"\n\t\t: -default Sets texture mapping default parameters",
__FILE__, VTexture, group); __FILE__, VTexture, group);
theCommands.Add("vtexscale", theCommands.Add("vtexscale",
"'vtexscale NameOfShape ScaleU ScaleV' \n \ "vtexscale name ScaleU ScaleV"
or 'vtexscale NameOfShape ScaleUV' \n \ "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
or 'vtexscale NameOfShape' to disable scaling\n ",
__FILE__,VTexture,group); __FILE__,VTexture,group);
theCommands.Add("vtexorigin", theCommands.Add("vtexorigin",
"'vtexorigin NameOfShape UOrigin VOrigin' \n \ "vtexorigin name OriginU OriginV"
or 'vtexorigin NameOfShape UVOrigin' \n \ "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
or 'vtexorigin NameOfShape' to disable origin positioning\n ",
__FILE__,VTexture,group); __FILE__,VTexture,group);
theCommands.Add("vtexrepeat", theCommands.Add("vtexrepeat",
"'vtexrepeat NameOfShape URepeat VRepeat' \n \ "vtexrepeat name RepeatU RepeatV"
or 'vtexrepeat NameOfShape UVRepeat \n \ "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
VTexture,group); VTexture,group);
theCommands.Add("vtexdefault", theCommands.Add("vtexdefault",
"'vtexdefault NameOfShape' to set texture mapping default parameters \n", "vtexdefault name"
"\n\t\t: Alias for vtexture name -default.",
VTexture,group); VTexture,group);
theCommands.Add("vsetam", theCommands.Add("vsetam",

View File

@ -18,6 +18,7 @@ vdump $imagedir/${casename}_1.png
vsetcolor b ANTIQUEWHITE vsetcolor b ANTIQUEWHITE
vdump $imagedir/${casename}_2.png vdump $imagedir/${casename}_2.png
vunsetcolor b
vtexture b 3 vtexture b 3
vdump $imagedir/${casename}_3.png vdump $imagedir/${casename}_3.png

View File

@ -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

View File

@ -1,5 +1,5 @@
puts "========" puts "========"
puts "Texture 2D transformation" puts "Texture 2D transformation (UV coordinates generation)"
puts "========" puts "========"
set aTexture [locate_data_file bug26122_texture_trsf_ref.png] set aTexture [locate_data_file bug26122_texture_trsf_ref.png]

View File

@ -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