mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +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:
@@ -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())
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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
|
||||
|
||||
};
|
||||
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user