From: nds Date: Thu, 27 Sep 2018 15:19:06 +0000 (+0300) Subject: #265 Possibility to display materials by different hatching style when we make clipping X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=24616c50906ed16c8c1ef60229b6c47d39b7887e;p=occt-copy.git #265 Possibility to display materials by different hatching style when we make clipping Conflicts: src/Graphic3d/Graphic3d_ClipPlane.cxx src/Graphic3d/Graphic3d_ClipPlane.hxx src/OpenGl/OpenGl_CappingAlgo.cxx src/OpenGl/OpenGl_CappingAlgo.hxx src/OpenGl/OpenGl_CappingPlaneResource.cxx src/OpenGl/OpenGl_Element.hxx src/OpenGl/OpenGl_Workspace.cxx src/ViewerTest/ViewerTest_ViewerCommands.cxx --- diff --git a/data/images/hatch_1.png b/data/images/hatch_1.png index 019d721321..83c0be624d 100644 Binary files a/data/images/hatch_1.png and b/data/images/hatch_1.png differ diff --git a/src/AIS/AIS_ColoredShape.cxx b/src/AIS/AIS_ColoredShape.cxx index 0fc54c84c9..464ffc119c 100644 --- a/src/AIS/AIS_ColoredShape.cxx +++ b/src/AIS/AIS_ColoredShape.cxx @@ -642,6 +642,9 @@ void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation { aShadedGroup = Prs3d_Root::NewGroup (thePrs); aShadedGroup->SetClosed (isClosed); + if (isClosed + && !myCappingStyle.IsNull()) + aShadedGroup->SetGroupPrimitivesAspect (myCappingStyle); } aShadedGroup->SetPrimitivesAspect (aDrawer->ShadingAspect()->Aspect()); aShadedGroup->AddPrimitiveArray (aTriangles); diff --git a/src/AIS/AIS_InteractiveObject.cxx b/src/AIS/AIS_InteractiveObject.cxx index fba30b6cf0..a9d86a6c16 100644 --- a/src/AIS/AIS_InteractiveObject.cxx +++ b/src/AIS/AIS_InteractiveObject.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -277,6 +278,37 @@ void AIS_InteractiveObject::UnsetMaterial() hasOwnMaterial = Standard_False; } +//======================================================================= +//function : SetCappingStyle +//purpose : +//======================================================================= +void AIS_InteractiveObject::SetCappingStyle (const Handle(Graphic3d_AspectFillCapping)& theStyle) +{ + myCappingStyle = theStyle; + + // Modify existing presentations + for (Standard_Integer aPrsIter = 1, n = myPresentations.Length(); aPrsIter <= n; ++aPrsIter) + { + const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations (aPrsIter).Presentation(); + if (!aPrs3d.IsNull()) + { + const Handle(Graphic3d_Structure)& aStruct = aPrs3d->Presentation(); + if (!aStruct.IsNull()) + { + const Graphic3d_SequenceOfGroup& aGroups = aStruct->Groups(); + for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aGroups); aGroupIter.More(); aGroupIter.Next()) + { + Handle(Graphic3d_Group)& aGrp = aGroupIter.ChangeValue(); + if (aGrp.IsNull()) + continue; + + aGrp->SetGroupPrimitivesAspect (theStyle); + } + } + } + } +} + //======================================================================= //function : SetTransparency //purpose : @@ -623,6 +655,7 @@ void AIS_InteractiveObject::SynchronizeAspects() Handle(Graphic3d_AspectLine3d) aLineAspect = aGrp->LineAspect(); Handle(Graphic3d_AspectFillArea3d) aFaceAspect = aGrp->FillAreaAspect(); + Handle(Graphic3d_AspectFillCapping) aCappingAspect = aGrp->FillCappingAspect(); Handle(Graphic3d_AspectMarker3d) aMarkerAspect = aGrp->MarkerAspect(); Handle(Graphic3d_AspectText3d) aTextAspect = aGrp->TextAspect(); if (!aLineAspect.IsNull()) @@ -633,6 +666,10 @@ void AIS_InteractiveObject::SynchronizeAspects() { aGrp->SetGroupPrimitivesAspect (aFaceAspect); } + if (!aCappingAspect.IsNull()) + { + aGrp->SetGroupPrimitivesAspect (aCappingAspect); + } if (!aMarkerAspect.IsNull()) { aGrp->SetGroupPrimitivesAspect (aMarkerAspect); diff --git a/src/AIS/AIS_InteractiveObject.hxx b/src/AIS/AIS_InteractiveObject.hxx index 17f7b07530..5f0a2fffac 100644 --- a/src/AIS/AIS_InteractiveObject.hxx +++ b/src/AIS/AIS_InteractiveObject.hxx @@ -310,6 +310,12 @@ public: //! Removes the setting for material. Standard_EXPORT virtual void UnsetMaterial(); + //! Set style of filling capping section created by clipping planes. + Standard_EXPORT virtual void SetCappingStyle (const Handle(Graphic3d_AspectFillCapping)& theStyle); + + //! Returns style for filling capping section created by clipping planes. + const Handle(Graphic3d_AspectFillCapping)& CappingStyle() const { return myCappingStyle; } + //! Attributes a setting aValue for transparency. //! The transparency value should be between 0.0 and 1.0. //! At 0.0 an object will be totally opaque, and at 1.0, fully transparent. @@ -416,6 +422,7 @@ protected: Standard_Boolean hasOwnColor; Standard_Boolean hasOwnMaterial; Standard_Boolean myRecomputeEveryPrs; + Handle(Graphic3d_AspectFillCapping) myCappingStyle; }; diff --git a/src/AIS/AIS_Shape.cxx b/src/AIS/AIS_Shape.cxx index b22bc6eea3..9b1b629c48 100644 --- a/src/AIS/AIS_Shape.cxx +++ b/src/AIS/AIS_Shape.cxx @@ -156,10 +156,7 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat try { OCC_CATCH_SIGNALS - StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer, - myDrawer->ShadingAspect()->Aspect()->ToMapTexture() - && !myDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(), - myUVOrigin, myUVRepeat, myUVScale); + StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer, myCappingStyle); } catch (Standard_Failure const& anException) { diff --git a/src/Graphic3d/FILES b/src/Graphic3d/FILES index 2c15a0d70f..5fed7ee2fb 100755 --- a/src/Graphic3d/FILES +++ b/src/Graphic3d/FILES @@ -12,6 +12,8 @@ Graphic3d_ArrayOfTriangles.hxx Graphic3d_ArrayOfTriangleStrips.hxx Graphic3d_AspectFillArea3d.cxx Graphic3d_AspectFillArea3d.hxx +Graphic3d_AspectFillCapping.cxx +Graphic3d_AspectFillCapping.hxx Graphic3d_AspectLine3d.cxx Graphic3d_AspectLine3d.hxx Graphic3d_AspectMarker3d.cxx diff --git a/src/Graphic3d/Graphic3d_AspectFillCapping.cxx b/src/Graphic3d/Graphic3d_AspectFillCapping.cxx new file mode 100644 index 0000000000..3f6bff8042 --- /dev/null +++ b/src/Graphic3d/Graphic3d_AspectFillCapping.cxx @@ -0,0 +1,110 @@ +// Created on: 2017-04-14 +// Created by: Anton POLETAEV +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_AspectFillCapping, Standard_Transient) + +// ======================================================================= +// function : Graphic3d_AspectFillCapping +// purpose : +// ======================================================================= +Graphic3d_AspectFillCapping::Graphic3d_AspectFillCapping() +: myFlags (Flags_None), + myHatchingState (0) +{ + Graphic3d_MaterialAspect aMaterial; + aMaterial.SetColor (Quantity_NOC_BLACK); + aMaterial.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); + aMaterial.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); + aMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); + aMaterial.SetReflectionModeOff (Graphic3d_TOR_EMISSION); + aMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); + SetHatchStyle (Aspect_HS_HORIZONTAL); + SetHatchMaterial (aMaterial); +} + +// ======================================================================= +// function : SetHatchStyle +// purpose : +// ======================================================================= +void Graphic3d_AspectFillCapping::SetHatchStyle (const Aspect_HatchStyle theStyle) +{ + myStippleHatch = new Graphic3d_HatchStyle (theStyle); + myTextureHatch.Nullify(); + myHatchingState++; +} + +// ======================================================================= +// function : SetHatchStyle +// purpose : +// ======================================================================= +void Graphic3d_AspectFillCapping::SetHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle) +{ + myStippleHatch = theStyle; + myTextureHatch.Nullify(); + myHatchingState++; +} + +// ======================================================================= +// function : SetHatchStyle +// purpose : +// ======================================================================= +void Graphic3d_AspectFillCapping::SetHatchStyle (const Handle(Graphic3d_TextureMap)& theTexture) +{ + myStippleHatch.Nullify(); + myTextureHatch = theTexture; + myHatchingState++; +} + +// ======================================================================= +// function : SetHatchMaterial +// purpose : +// ======================================================================= +void Graphic3d_AspectFillCapping::SetHatchMaterial (const Graphic3d_MaterialAspect& theMaterial) +{ + myHatchMaterial = theMaterial; + myHatchingState++; +} + +// ======================================================================= +// function : SetToDrawHatch +// purpose : +// ======================================================================= +void Graphic3d_AspectFillCapping::SetToDrawHatch (const Standard_Boolean theToDraw) +{ + setFlag (theToDraw, Flags_DrawHatching); + myHatchingState++; +} + +// ======================================================================= +// function : SetHatchZoomPeristent +// purpose : +// ======================================================================= +void Graphic3d_AspectFillCapping::SetHatchZoomPeristent (const Standard_Boolean theToSet) +{ + setFlag (theToSet, Flags_HatchZoomPersistent); + myHatchingState++; +} + +// ======================================================================= +// function : SetHatchRotationPeristent +// purpose : +// ======================================================================= +void Graphic3d_AspectFillCapping::SetHatchRotationPeristent (const Standard_Boolean theToSet) +{ + setFlag (theToSet, Flags_HatchRotationPersistent); + myHatchingState++; +} diff --git a/src/Graphic3d/Graphic3d_AspectFillCapping.hxx b/src/Graphic3d/Graphic3d_AspectFillCapping.hxx new file mode 100644 index 0000000000..59ceb017cf --- /dev/null +++ b/src/Graphic3d/Graphic3d_AspectFillCapping.hxx @@ -0,0 +1,163 @@ +// Created on: 2017-04-14 +// Created by: Anton POLETAEV +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _Graphic3d_AspectFillCapping_HeaderFile +#define _Graphic3d_AspectFillCapping_HeaderFile + +#include +#include +#include +#include +#include +#include + +//! Defines graphical attributes for drawing section planes on solids resulted from clipping (cutting) planes. +class Graphic3d_AspectFillCapping : public Standard_Transient +{ +public: + + //! Default constructor. + Standard_EXPORT Graphic3d_AspectFillCapping(); + +public: + + //! Sets material for filling section created by clipping. + void SetMaterial (const Graphic3d_MaterialAspect& theMaterial) { myMaterial = theMaterial; } + + //! Returns material for filling section created by clipping. + const Graphic3d_MaterialAspect& Material() const { return myMaterial; } + + //! Sets flag indicating whether object's material (instead of defined by this aspect) should be used for filling section. + void SetUseObjectMaterial (const Standard_Boolean theToUse) { setFlag (theToUse, Flags_UseObjectMaterial); } + + //! Returns flag indicating whether object's material (instead of defined by this aspect) should be used for filling section. + Standard_Boolean ToUseObjectMaterial() const { return (myFlags & Flags_UseObjectMaterial) != 0; } + + //! Sets texture for filling section created by clipping. + void SetTexture (const Handle(Graphic3d_TextureMap)& theTexture) { myTexture = theTexture; } + + //! Returns texture for filling section created by clipping. + const Handle(Graphic3d_TextureMap)& Texture() const { return myTexture; } + + //! Sets flag indicating whether object's texture (instead of defined by this aspect) should be used for filling section. + void SetUseObjectTexture (const Standard_Boolean theToUse) { setFlag (theToUse, Flags_UseObjectTexture); } + + //! Returns flag indicating whether object's texture (instead of defined by this aspect) should be used for filling section. + Standard_Boolean ToUseObjectTexture() const { return (myFlags & Flags_UseObjectTexture) != 0; } + + //! Sets OpenGL/GLSL shader program. + void SetShader (const Handle(Graphic3d_ShaderProgram)& theShader) { myShader = theShader; } + + //! Returns OpenGL/GLSL shader program. + const Handle(Graphic3d_ShaderProgram)& Shader() const { return myShader; } + + //! Sets flag indicating whether object's shader (instead of defined by this aspect) should be used for filling section. + void SetUseObjectShader (const Standard_Boolean theToUse) { setFlag (theToUse, Flags_UseObjectShader); } + + //! Returns flag indicating whether object's shader (instead of defined by this aspect) should be used for filling section. + Standard_Boolean ToUseObjectShader() const { return (myFlags & Flags_UseObjectShader) != 0; } + +public: + + //! Sets style of hatch defined by predefined stipple mask. + Standard_EXPORT void SetHatchStyle (const Aspect_HatchStyle theStyle); + + //! Sets style of hatch defined by custom stipple mask. + Standard_EXPORT void SetHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle); + + //! Sets style of hatch defined by texture map (decal texture with alpha channel should be used). + Standard_EXPORT void SetHatchStyle (const Handle(Graphic3d_TextureMap)& theTexture); + + //! Sets material style for hatch lines (texture). + Standard_EXPORT void SetHatchMaterial (const Graphic3d_MaterialAspect& theMaterial); + + //! Returns material style for hatch lines (texture). + const Graphic3d_MaterialAspect& HatchMaterial() const { return myHatchMaterial; } + + //! Sets boolean flag indicating whether the hatch layer should be drawn or not. + Standard_EXPORT void SetToDrawHatch (const Standard_Boolean theToDraw); + + //! Returns boolean flag indicating whether the hatch layer should be drawn or not. + Standard_Boolean ToDrawHatch() const { return (myFlags & Flags_DrawHatching) != 0; } + + //! Sets flag controlling behavior of hatch texture mapping on zooming. + //! @param theToSet [in] if passed TRUE the texture will keep constant screen-scale independent of zooming. + Standard_EXPORT void SetHatchZoomPeristent (const Standard_Boolean theToSet); + + //! Returns value of flag controlling behavior of hatch texture mapping on zooming. + Standard_Boolean IsHatchZoomPersistent() { return (myFlags & Flags_HatchZoomPersistent) != 0; } + + //! Sets flag controlling behavior of hatch texture mapping on camera rotation around heading vector. + Standard_EXPORT void SetHatchRotationPeristent (const Standard_Boolean theToSet); + + //! Returns value of flag controlling behavior of hatch texture mapping on camera rotation around heading vector. + Standard_Boolean IsHatchRotationPersistent() { return (myFlags & Flags_HatchRotationPersistent) != 0; } + + //! Returns true if hatch is defined by texture. + Standard_Boolean IsTextureHatch() const { return !myTextureHatch.IsNull(); } + + //! Returns texture map defining the hatch. + const Handle(Graphic3d_TextureMap)& TextureHatch() const { return myTextureHatch; } + + //! Returns true if hatch is defined by stipple mask. + Standard_Boolean IsStippleHatch() const { return !myStippleHatch.IsNull(); } + + //! Returns the stipple mask. + const Handle(Graphic3d_HatchStyle)& StippleHatch() const { return myStippleHatch; } + + //! Returns modification counter for hatching state. + Standard_Size HatchingState() const { return myHatchingState; } + +private: + + enum Flags + { + Flags_None = 0x00, //!< no flags + Flags_UseObjectMaterial = 0x01, //!< use object material + Flags_UseObjectTexture = 0x02, //!< use object texture + Flags_UseObjectShader = 0x04, //!< use object GLSL program + Flags_HatchZoomPersistent = 0x08, //!< zoom-persistent texturing + Flags_HatchRotationPersistent = 0x10, //!< rotation-persistent texturing + Flags_DrawHatching = 0x20, //!< draw hatching + Flags_UseObjectProperties = //!< use entire fill area aspect from object + Flags_UseObjectMaterial + | Flags_UseObjectTexture + | Flags_UseObjectShader + }; + + void setFlag (const Standard_Boolean theToUse, const unsigned int theFlag) + { + myFlags = theToUse ? myFlags | theFlag : myFlags & ~theFlag; + } + +private: + + Graphic3d_MaterialAspect myMaterial; + Handle(Graphic3d_TextureMap) myTexture; + Handle(Graphic3d_ShaderProgram) myShader; + Handle(Graphic3d_HatchStyle) myStippleHatch; + Handle(Graphic3d_TextureMap) myTextureHatch; + Graphic3d_MaterialAspect myHatchMaterial; + unsigned int myFlags; + Standard_Size myHatchingState; + +public: + + DEFINE_STANDARD_RTTIEXT(Graphic3d_AspectFillCapping, Standard_Transient) +}; + +DEFINE_STANDARD_HANDLE (Graphic3d_AspectFillCapping, Standard_Transient) + +#endif // _Graphic3d_AspectFillCapping_HeaderFile diff --git a/src/Graphic3d/Graphic3d_ClipPlane.cxx b/src/Graphic3d/Graphic3d_ClipPlane.cxx index 22ac56c4b6..f52ffe82bf 100755 --- a/src/Graphic3d/Graphic3d_ClipPlane.cxx +++ b/src/Graphic3d/Graphic3d_ClipPlane.cxx @@ -24,19 +24,6 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ClipPlane,Standard_Transient) namespace { static volatile Standard_Integer THE_CLIP_PLANE_COUNTER = 0; - - static Handle(Graphic3d_AspectFillArea3d) defaultAspect() - { - const Graphic3d_MaterialAspect aMaterial (Graphic3d_NOM_DEFAULT); - Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d(); - anAspect->SetDistinguishOff(); - anAspect->SetFrontMaterial (aMaterial); - anAspect->SetHatchStyle (Aspect_HS_HORIZONTAL); - anAspect->SetInteriorStyle (Aspect_IS_SOLID); - anAspect->SetInteriorColor (aMaterial.Color()); - anAspect->SetSuppressBackFaces (false); - return anAspect; - } } // ======================================================================= @@ -44,19 +31,8 @@ namespace // purpose : // ======================================================================= Graphic3d_ClipPlane::Graphic3d_ClipPlane() -: myAspect (defaultAspect()), - myPrevInChain(NULL), - myPlane (0.0, 0.0, 1.0, 0.0), - myEquation (0.0, 0.0, 1.0, 0.0), - myEquationRev(0.0, 0.0,-1.0, 0.0), - myChainLenFwd(1), - myFlags (Graphic3d_CappingFlags_None), - myEquationMod(0), - myAspectMod (0), - myIsOn (Standard_True), - myIsCapping (Standard_False) { - makeId(); + init(); } // ======================================================================= @@ -64,19 +40,8 @@ Graphic3d_ClipPlane::Graphic3d_ClipPlane() // purpose : // ======================================================================= Graphic3d_ClipPlane::Graphic3d_ClipPlane (const Graphic3d_Vec4d& theEquation) -: myAspect (defaultAspect()), - myPrevInChain(NULL), - myPlane (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w()), - myEquation (theEquation), - myEquationRev(0.0, 0.0,-1.0, 0.0), - myChainLenFwd(1), - myFlags (Graphic3d_CappingFlags_None), - myEquationMod(0), - myAspectMod (0), - myIsOn (Standard_True), - myIsCapping (Standard_False) { - makeId(); + init (gp_Pln (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.a())); updateInversedPlane(); } @@ -84,42 +49,27 @@ Graphic3d_ClipPlane::Graphic3d_ClipPlane (const Graphic3d_Vec4d& theEquation) // function : Graphic3d_ClipPlane // purpose : // ======================================================================= -Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther) -: Standard_Transient(theOther), - myAspect (defaultAspect()), - myPrevInChain(NULL), - myPlane (theOther.myPlane), - myEquation (theOther.myEquation), - myEquationRev(theOther.myEquationRev), - myChainLenFwd(1), - myFlags (theOther.myFlags), - myEquationMod(0), - myAspectMod (0), - myIsOn (theOther.myIsOn), - myIsCapping (theOther.myIsCapping) +Graphic3d_ClipPlane::Graphic3d_ClipPlane (const Graphic3d_ClipPlane& theOther) +: Standard_Transient (theOther) { - makeId(); - *myAspect = *theOther.CappingAspect(); + *mySectionStyle = *theOther.CappingSectionStyle(); + init (theOther.myPlane, + theOther.myEquationRev, + theOther.myIsOn, + theOther.myIsCapping, + theOther.ToOverrideCappingAspect(), + theOther.CappingSectionStyle()); + updateInversedPlane(); } // ======================================================================= // function : Graphic3d_ClipPlane // purpose : // ======================================================================= -Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane) -: myAspect (defaultAspect()), - myPrevInChain(NULL), - myPlane (thePlane), - myChainLenFwd(1), - myFlags (Graphic3d_CappingFlags_None), - myEquationMod(0), - myAspectMod (0), - myIsOn (Standard_True), - myIsCapping (Standard_False) +Graphic3d_ClipPlane::Graphic3d_ClipPlane (const gp_Pln& thePlane) { - thePlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]); + init (thePlane); updateInversedPlane(); - makeId(); } // ======================================================================= @@ -131,7 +81,7 @@ void Graphic3d_ClipPlane::SetEquation (const Graphic3d_Vec4d& theEquation) myPlane = gp_Pln (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w()); myEquation = theEquation; updateInversedPlane(); - myEquationMod++; + myOrientationDirty = Standard_True; } // ======================================================================= @@ -143,7 +93,7 @@ void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane) myPlane = thePlane; thePlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]); updateInversedPlane(); - myEquationMod++; + myOrientationDirty = Standard_True; } // ======================================================================= @@ -178,119 +128,106 @@ Handle(Graphic3d_ClipPlane) Graphic3d_ClipPlane::Clone() const } // ======================================================================= -// function : SetCappingMaterial +// function : SetCappingSectionStyle // purpose : // ======================================================================= -void Graphic3d_ClipPlane::SetCappingMaterial (const Graphic3d_MaterialAspect& theMat) +void Graphic3d_ClipPlane::SetCappingSectionStyle (const Handle(Graphic3d_AspectFillCapping)& theStyle) { - myAspect->SetFrontMaterial (theMat); - myAspect->SetInteriorColor (theMat.Color()); - ++myAspectMod; + mySectionStyle = theStyle; } // ======================================================================= -// function : SetCappingTexture +// function : OrientationMatrix // purpose : // ======================================================================= -void Graphic3d_ClipPlane::SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture) +const Graphic3d_Mat4& Graphic3d_ClipPlane::OrientationMatrix() const { - if (!theTexture.IsNull()) + if (myOrientationDirty) { - myAspect->SetTextureMapOn(); - Handle(Graphic3d_TextureSet) aTextureSet = myAspect->TextureSet(); - if (aTextureSet.IsNull() || aTextureSet->Size() != 1) + const Standard_ShortReal aDirection[] = { + static_cast (myEquation[0]), + static_cast (myEquation[1]), + static_cast (myEquation[2]) + }; + + const Standard_ShortReal aTranslate[] = { + static_cast (myEquation[0] * -myEquation[3]), + static_cast (myEquation[1] * -myEquation[3]), + static_cast (myEquation[2] * -myEquation[3]) + }; + + Standard_ShortReal aSide1[] = { 0.0f, 0.0f, 0.0f }; + Standard_ShortReal aSide2[] = { 0.0f, 0.0f, 0.0f }; + + const Standard_ShortReal aMagintude = static_cast (Sqrt (myEquation[0] * myEquation[0] + myEquation[2] * myEquation[2])); + + if (aMagintude < ShortRealSmall()) { - aTextureSet = new Graphic3d_TextureSet (theTexture); + aSide1[0] = 1.0f; } else { - aTextureSet->SetFirst (theTexture); + aSide1[0] = aDirection[2] / aMagintude; + aSide1[2] = -aDirection[0] / aMagintude; } - myAspect->SetTextureSet (aTextureSet); - } - else - { - myAspect->SetTextureMapOff(); - myAspect->SetTextureSet (Handle(Graphic3d_TextureSet)()); - } - ++myAspectMod; -} -// ======================================================================= -// function : SetCappingHatch -// purpose : -// ======================================================================= -void Graphic3d_ClipPlane::SetCappingHatch (const Aspect_HatchStyle theStyle) -{ - myAspect->SetHatchStyle (theStyle); - ++myAspectMod; -} + aSide2[0] = (-aSide1[1] * aDirection[2]) - (-aSide1[2] * aDirection[1]); + aSide2[1] = (-aSide1[2] * aDirection[0]) - (-aSide1[0] * aDirection[2]); + aSide2[2] = (-aSide1[0] * aDirection[1]) - (-aSide1[1] * aDirection[0]); -// ======================================================================= -// function : SetCappingCustomHatch -// purpose : -// ======================================================================= -void Graphic3d_ClipPlane::SetCappingCustomHatch (const Handle(Graphic3d_HatchStyle)& theStyle) -{ - myAspect->SetHatchStyle (theStyle); - ++myAspectMod; -} + myOrientationMat.SetValue (0, 0, aSide1[0]); + myOrientationMat.SetValue (1, 0, aSide1[1]); + myOrientationMat.SetValue (2, 0, aSide1[2]); + myOrientationMat.SetValue (3, 0, 0.0F); -// ======================================================================= -// function : SetCappingHatchOn -// purpose : -// ======================================================================= -void Graphic3d_ClipPlane::SetCappingHatchOn() -{ - myAspect->SetInteriorStyle (Aspect_IS_HATCH); - ++myAspectMod; -} + myOrientationMat.SetValue (0, 1, aDirection[0]); + myOrientationMat.SetValue (1, 1, aDirection[1]); + myOrientationMat.SetValue (2, 1, aDirection[2]); + myOrientationMat.SetValue (3, 1, 0.0F); -// ======================================================================= -// function : SetCappingHatchOff -// purpose : -// ======================================================================= -void Graphic3d_ClipPlane::SetCappingHatchOff() -{ - myAspect->SetInteriorStyle (Aspect_IS_SOLID); - ++myAspectMod; -} + myOrientationMat.SetValue (0, 2, aSide2[0]); + myOrientationMat.SetValue (1, 2, aSide2[1]); + myOrientationMat.SetValue (2, 2, aSide2[2]); + myOrientationMat.SetValue (3, 2, 0.0F); -// ======================================================================= -// function : SetCappingAspect -// purpose : -// ======================================================================= -void Graphic3d_ClipPlane::SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect) -{ - myAspect = theAspect; - ++myAspectMod; + myOrientationMat.SetValue (0, 3, aTranslate[0]); + myOrientationMat.SetValue (1, 3, aTranslate[1]); + myOrientationMat.SetValue (2, 3, aTranslate[2]); + myOrientationMat.SetValue (3, 3, 1.0F); + + myOrientationDirty = Standard_False; + } + + return myOrientationMat; } // ======================================================================= -// function : setCappingFlag +// function : init // purpose : // ======================================================================= -void Graphic3d_ClipPlane::setCappingFlag (bool theToUse, int theFlag) +void Graphic3d_ClipPlane::init (const gp_Pln& thePlane, + const Graphic3d_Vec4d& theEquationRev, + const Standard_Boolean theIsOn, + const Standard_Boolean theIsCapping, + const Standard_Boolean theOverrideStyle, + const Handle(Graphic3d_AspectFillCapping)& theStyle) { - if (theToUse) - { - myFlags |= theFlag; - } - else + if (myEntityUID.IsEmpty()) { - myFlags &= ~(theFlag); + myEntityUID = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name() + + TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER)); } - ++myAspectMod; -} -// ======================================================================= -// function : makeId -// purpose : -// ======================================================================= -void Graphic3d_ClipPlane::makeId() -{ - myId = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name() - + TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER)); + myPrevInChain = NULL; + myEquationRev = theEquationRev; + myChainLenFwd = 1; + myPlane = thePlane; + myPlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]); + myIsOn = theIsOn; + myIsCapping = theIsCapping; + myOverrideObjectStyle = theOverrideStyle; + mySectionStyle = theStyle.IsNull() ? new Graphic3d_AspectFillCapping() : theStyle; + myOrientationDirty = Standard_True; } // ======================================================================= @@ -312,7 +249,7 @@ void Graphic3d_ClipPlane::updateChainLen() // ======================================================================= void Graphic3d_ClipPlane::SetChainNextPlane (const Handle(Graphic3d_ClipPlane)& thePlane) { - ++myEquationMod; + myOrientationDirty = Standard_True; if (!myNextInChain.IsNull()) { myNextInChain->myPrevInChain = NULL; diff --git a/src/Graphic3d/Graphic3d_ClipPlane.hxx b/src/Graphic3d/Graphic3d_ClipPlane.hxx index b1857607e1..8e4c34835e 100755 --- a/src/Graphic3d/Graphic3d_ClipPlane.hxx +++ b/src/Graphic3d/Graphic3d_ClipPlane.hxx @@ -19,9 +19,12 @@ #include #include #include +#include #include #include +#include #include +#include #include #include #include @@ -166,44 +169,6 @@ public: public: // @name user-defined graphical attributes - //! Set material for rendering capping surface. - //! @param theMat [in] the material. - Standard_EXPORT void SetCappingMaterial (const Graphic3d_MaterialAspect& theMat); - - //! @return capping material. - const Graphic3d_MaterialAspect& CappingMaterial() const { return myAspect->FrontMaterial(); } - - //! Set texture to be applied on capping surface. - //! @param theTexture [in] the texture. - Standard_EXPORT void SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture); - - //! @return capping texture map. - Handle(Graphic3d_TextureMap) CappingTexture() const { return !myAspect->TextureSet().IsNull() && !myAspect->TextureSet()->IsEmpty() - ? myAspect->TextureSet()->First() - : Handle(Graphic3d_TextureMap)(); } - - //! Set hatch style (stipple) and turn hatching on. - //! @param theStyle [in] the hatch style. - Standard_EXPORT void SetCappingHatch (const Aspect_HatchStyle theStyle); - - //! @return hatching style. - Aspect_HatchStyle CappingHatch() const { return (Aspect_HatchStyle)myAspect->HatchStyle()->HatchType(); } - - //! Set custom hatch style (stipple) and turn hatching on. - //! @param theStyle [in] the hatch pattern. - Standard_EXPORT void SetCappingCustomHatch (const Handle(Graphic3d_HatchStyle)& theStyle); - - //! @return hatching style. - const Handle(Graphic3d_HatchStyle)& CappingCustomHatch() const { return myAspect->HatchStyle(); } - - //! Turn on hatching. - Standard_EXPORT void SetCappingHatchOn(); - - //! Turn off hatching. - Standard_EXPORT void SetCappingHatchOff(); - - //! @return True if hatching mask is turned on. - Standard_Boolean IsHatchOn() const { return myAspect->InteriorStyle() == Aspect_IS_HATCH; } //! This ID is used for managing associated resources in graphical driver. //! The clip plane can be assigned within a range of IO which can be @@ -214,41 +179,18 @@ public: // @name user-defined graphical attributes //! @return clip plane resource identifier string. const TCollection_AsciiString& GetId() const { - return myId; + return myEntityUID; } public: - //! Return capping aspect. + //! Returns style used for drawing capping section. //! @return capping surface rendering aspect. - const Handle(Graphic3d_AspectFillArea3d)& CappingAspect() const { return myAspect; } + const Handle(Graphic3d_AspectFillCapping)& CappingSectionStyle() const { return mySectionStyle; } - //! Assign capping aspect. - Standard_EXPORT void SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect); + //! Sets clipping section filling aspect. + Standard_EXPORT void SetCappingSectionStyle (const Handle(Graphic3d_AspectFillCapping)& theStyle); - //! Flag indicating whether material for capping plane should be taken from object. - //! Default value: FALSE (use dedicated capping plane material). - bool ToUseObjectMaterial() const { return (myFlags & Graphic3d_CappingFlags_ObjectMaterial) != 0; } - - //! Set flag for controlling the source of capping plane material. - void SetUseObjectMaterial (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectMaterial); } - - //! Flag indicating whether texture for capping plane should be taken from object. - //! Default value: FALSE. - bool ToUseObjectTexture() const { return (myFlags & Graphic3d_CappingFlags_ObjectTexture) != 0; } - - //! Set flag for controlling the source of capping plane texture. - void SetUseObjectTexture (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectTexture); } - - //! Flag indicating whether shader program for capping plane should be taken from object. - //! Default value: FALSE. - bool ToUseObjectShader() const { return (myFlags & Graphic3d_CappingFlags_ObjectShader) != 0; } - - //! Set flag for controlling the source of capping plane shader program. - void SetUseObjectShader(bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectShader); } - - //! Return true if some fill area aspect properties should be taken from object. - bool ToUseObjectProperties() const { return myFlags != Graphic3d_CappingFlags_None; } public: @@ -352,14 +294,25 @@ public: // @name modification counters { return myAspectMod; } + //! Flag indicating whether section style of the plane should overrides similar property of object presentation. + //! Default value: FALSE (use dedicated presentation aspect style). + bool ToOverrideCappingAspect() const { return myOverrideObjectStyle; } -private: + //! Sets flag for controlling the preference of using section style between clip plane and object. + void SetToOverrideCappingAspect (const bool theToOverride) { myOverrideObjectStyle = theToOverride; } - //! Generate unique object id for OpenGL graphic resource manager. - void makeId(); + //! Returns plane's orientation matrix. + Standard_EXPORT const Graphic3d_Mat4& OrientationMatrix() const; + +private: - //! Set capping flag. - Standard_EXPORT void setCappingFlag (bool theToUse, int theFlag); + //! Initializes plane and makes unique identifier (UID) to differentiate clipping plane entities. + void init (const gp_Pln& thePlane = gp_Pln(), + const Graphic3d_Vec4d& theEquationRev = Graphic3d_Vec4d(0.0, 0.0,-1.0, 0.0), + const Standard_Boolean theIsOn = Standard_True, + const Standard_Boolean theIsCapping = Standard_False, + const Standard_Boolean theOverrideStyle = Standard_False, + const Handle(Graphic3d_AspectFillCapping)& theStyle = Handle(Graphic3d_AspectFillCapping)()); //! Update chain length in backward direction. void updateChainLen(); @@ -374,10 +327,10 @@ private: private: - Handle(Graphic3d_AspectFillArea3d) myAspect; //!< fill area aspect + Handle(Graphic3d_AspectFillCapping) mySectionStyle; //!< Style set for drawing capped solid section. Handle(Graphic3d_ClipPlane) myNextInChain; //!< next plane in a chain of planes defining logical AND operation Graphic3d_ClipPlane* myPrevInChain; //!< previous plane in a chain of planes defining logical AND operation - TCollection_AsciiString myId; //!< resource id + TCollection_AsciiString myEntityUID; //!< Unique identifier for the plane gp_Pln myPlane; //!< plane definition Graphic3d_Vec4d myEquation; //!< plane equation vector Graphic3d_Vec4d myEquationRev; //!< reversed plane equation @@ -387,6 +340,9 @@ private: unsigned int myAspectMod; //!< modification counter of aspect Standard_Boolean myIsOn; //!< state of the clipping plane Standard_Boolean myIsCapping; //!< state of graphic driver capping + Standard_Boolean myOverrideObjectStyle; //!< Flag forcing to use plane's section style rather than section style defined for object + mutable Standard_Boolean myOrientationDirty; //!< Boolean flag indicating whether orientation matrix is dirty or not. + mutable Graphic3d_Mat4 myOrientationMat; //!< Plane orientation matrix (for visualization purposes). }; diff --git a/src/Graphic3d/Graphic3d_Group.cxx b/src/Graphic3d/Graphic3d_Group.cxx index f19c62c647..86e0f20e05 100644 --- a/src/Graphic3d/Graphic3d_Group.cxx +++ b/src/Graphic3d/Graphic3d_Group.cxx @@ -231,10 +231,11 @@ Standard_Boolean Graphic3d_Group::IsGroupPrimitivesAspectSet (const Graphic3d_Gr // function : GroupPrimitivesAspect // purpose : // ======================================================================= -void Graphic3d_Group::GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine, - const Handle(Graphic3d_AspectText3d)& theAspText, - const Handle(Graphic3d_AspectMarker3d)& theAspMarker, - const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const +void Graphic3d_Group::GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine, + const Handle(Graphic3d_AspectText3d)& theAspText, + const Handle(Graphic3d_AspectMarker3d)& theAspMarker, + const Handle(Graphic3d_AspectFillArea3d)& theAspFill, + const Handle(Graphic3d_AspectFillCapping)& theAspCapping) const { if (!theAspLine.IsNull()) { @@ -271,6 +272,15 @@ void Graphic3d_Group::GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d *theAspFill.operator->() = *aFillAspect; } } + + if (!theAspCapping.IsNull()) + { + Handle(Graphic3d_AspectFillCapping) aCappingAspect = FillCappingAspect(); + if (!aCappingAspect.IsNull()) + { + *theAspCapping.operator->() = *aCappingAspect; + } + } } // ======================================================================= diff --git a/src/Graphic3d/Graphic3d_Group.hxx b/src/Graphic3d/Graphic3d_Group.hxx index 4e1c26f9de..0802dafefb 100644 --- a/src/Graphic3d/Graphic3d_Group.hxx +++ b/src/Graphic3d/Graphic3d_Group.hxx @@ -17,30 +17,30 @@ #ifndef _Graphic3d_Group_HeaderFile #define _Graphic3d_Group_HeaderFile -#include -#include - -#include -#include -#include #include -#include +#include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -#include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include #include -#include -#include +#include +#include +#include +#include #include +#include class Graphic3d_Structure; class Graphic3d_ArrayOfPrimitives; @@ -56,7 +56,7 @@ class Graphic3d_ArrayOfPrimitives; //! 1) Non-modifiable, or unbounded, group ('black box'). //! Developers can repeat a sequence of //! SetPrimitivesAspect() with AddPrimitiveArray() methods arbitrary number of times -//! to define arbitrary number of primitive "blocks" each having individual apect values. +//! to define arbitrary number of primitive "blocks" each having individual aspect values. //! Any modification of such a group is forbidden, as aspects and primitives are mixed //! in memory without any high-level logical structure, and any modification is very likely to result //! in corruption of the group internal data. @@ -82,7 +82,7 @@ class Graphic3d_Group : public Standard_Transient public: - //! Supress all primitives and attributes of . + //! Suppress all primitives and attributes of . //! To clear group without update in Graphic3d_StructureManager //! pass Standard_False as . This //! used on context and viewer destruction, when the pointer @@ -91,13 +91,13 @@ public: //! cross-reference); Standard_EXPORT virtual void Clear (const Standard_Boolean theUpdateStructureMgr = Standard_True); - //! Supress the group in the structure. + //! Suppress the group in the structure. Standard_EXPORT virtual ~Graphic3d_Group(); - //! Supress the group in the structure. + //! Suppress the group in the structure. //! Warning: No more graphic operations in after this call. - //! Modifies the current modelling transform persistence (pan, zoom or rotate) - //! Get the current modelling transform persistence (pan, zoom or rotate) + //! Modifies the current modeling transform persistence (pan, zoom or rotate) + //! Get the current modeling transform persistence (pan, zoom or rotate) Standard_EXPORT void Remove(); public: @@ -126,6 +126,12 @@ public: //! Modifies the context for all the marker primitives of the group. virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspect) = 0; + //! Returns style of filling clipping sections on closed shell primitives. + virtual Handle(Graphic3d_AspectFillCapping) FillCappingAspect() const = 0; + + //! Modifies the context for filling clipping section for all closed shell primitives of the group. + virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillCapping)& theAspect) = 0; + //! Modifies the current context of the group to give //! another aspect for all the line primitives created //! after this call in the group. @@ -153,15 +159,17 @@ public: Standard_EXPORT void GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine, const Handle(Graphic3d_AspectText3d)& theAspText, const Handle(Graphic3d_AspectMarker3d)& theAspMarker, - const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const; + const Handle(Graphic3d_AspectFillArea3d)& theAspFill, + const Handle(Graphic3d_AspectFillCapping)& theAspFillCapping) const; //! Returns the last inserted context in the group for each kind of primitives. void PrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine, const Handle(Graphic3d_AspectText3d)& theAspText, const Handle(Graphic3d_AspectMarker3d)& theAspMarker, - const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const + const Handle(Graphic3d_AspectFillArea3d)& theAspFill, + const Handle(Graphic3d_AspectFillCapping)& theAspFillCapping) const { - GroupPrimitivesAspect (theAspLine, theAspText, theAspMarker, theAspFill); + GroupPrimitivesAspect (theAspLine, theAspText, theAspMarker, theAspFill, theAspFillCapping); } public: diff --git a/src/Graphic3d/Graphic3d_GroupAspect.hxx b/src/Graphic3d/Graphic3d_GroupAspect.hxx index 6aff132f41..ca53a75a37 100644 --- a/src/Graphic3d/Graphic3d_GroupAspect.hxx +++ b/src/Graphic3d/Graphic3d_GroupAspect.hxx @@ -21,13 +21,15 @@ //! - ASPECT_LINE: aspect for line primitives; //! - ASPECT_TEXT: aspect for text primitives; //! - ASPECT_MARKER: aspect for marker primitives; -//! - ASPECT_FILL_AREA: aspect for face primitives. +//! - ASPECT_FILL_AREA: aspect for face primitives; +//! - Graphic3d_ASPECT_FILL_CAPPING: aspect for filling clipping sections. enum Graphic3d_GroupAspect { Graphic3d_ASPECT_LINE, Graphic3d_ASPECT_TEXT, Graphic3d_ASPECT_MARKER, -Graphic3d_ASPECT_FILL_AREA +Graphic3d_ASPECT_FILL_AREA, +Graphic3d_ASPECT_FILL_CAPPING }; #endif // _Graphic3d_GroupAspect_HeaderFile diff --git a/src/NCollection/NCollection_Mat4.hxx b/src/NCollection/NCollection_Mat4.hxx index df74c37ff4..a67de2b94f 100755 --- a/src/NCollection/NCollection_Mat4.hxx +++ b/src/NCollection/NCollection_Mat4.hxx @@ -291,7 +291,7 @@ public: //! Compute per-element multiplication. //! @param theFactor [in] the scale factor. - //! @return the result of multiplicaton. + //! @return the result of multiplication. NCollection_Mat4 operator* (const Element_t theFactor) const { return Multiplied (theFactor); @@ -299,7 +299,7 @@ public: //! Compute per-element multiplication. //! @param theFactor [in] the scale factor. - //! @return the result of multiplicaton. + //! @return the result of multiplication. NCollection_Mat4 Multiplied (const Element_t theFactor) const { NCollection_Mat4 aTempMat (*this); diff --git a/src/OpenGl/OpenGl_CappingAlgo.cxx b/src/OpenGl/OpenGl_CappingAlgo.cxx index 4338d502d5..c13cf3d869 100755 --- a/src/OpenGl/OpenGl_CappingAlgo.cxx +++ b/src/OpenGl/OpenGl_CappingAlgo.cxx @@ -21,11 +21,16 @@ #include #include #include +#include #include #include namespace { + static const OpenGl_CappingPlaneResource THE_DEFAULT_ASPECT = OpenGl_CappingPlaneResource (new Graphic3d_AspectFillCapping); + static const TCollection_AsciiString THE_QUAD_PARRAY = "OpenGl_CappingAlgo_Quad"; + static const TCollection_AsciiString THE_PLANE_STYLE = "OpenGl_CappingAlgo_CappingStyle_"; + //! Auxiliary sentry object managing stencil test. struct StencilTestSentry { @@ -58,21 +63,113 @@ namespace GLint myDepthFuncPrev; }; - //! Render infinite capping plane. - //! @param theWorkspace [in] the GL workspace, context state. - //! @param thePlane [in] the graphical plane, for which the capping surface is rendered. - static void renderPlane (const Handle(OpenGl_Workspace)& theWorkspace, - const Handle(OpenGl_CappingPlaneResource)& thePlane) + class OpenGl_SharedElement : public OpenGl_Resource + { + public: + OpenGl_SharedElement (OpenGl_Element* theGlElement) : myGlElement (theGlElement) {} + virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE + { + OpenGl_Element::Destroy (theGlCtx, myGlElement); + } + OpenGl_Element* GlElement() const { return myGlElement; } + + //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules. + Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; } + + private: + OpenGl_Element* myGlElement; + + public: + + DEFINE_STANDARD_RTTI_INLINE (OpenGl_SharedElement, OpenGl_Resource) + }; + + //! Iitializes and returns vertex buffer for plane section + OpenGl_PrimitiveArray* initQuad (const Handle(OpenGl_Context)& theContext) + { + Handle(OpenGl_SharedElement) aSharedResource; + + if (!theContext->GetResource (THE_QUAD_PARRAY, aSharedResource)) + { + aSharedResource = new OpenGl_SharedElement (OpenGl_CappingPlaneResource::BuildInfinitPlaneVertices()); + theContext->ShareResource (THE_QUAD_PARRAY, aSharedResource); + } + + return dynamic_cast (aSharedResource->GlElement()); + } + + //! Render section plane using the given aspects. + void renderSection (const Handle(OpenGl_Workspace)& theWorkspace, + const OpenGl_PrimitiveArray* theQuad, + const OpenGl_AspectFace* theCappingAspect, + const OpenGl_AspectFace* theHatchAspect, + const OpenGl_Mat4& theCappingMatrix, + const Standard_ShortReal theHatchScale, + const Standard_ShortReal theHatchRotate) { const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); const bool wasCullAllowed = theWorkspace->SetAllowFaceCulling (true); - // set identity model matrix + const Standard_Boolean isTextureHatch = + theHatchAspect != NULL + && theHatchAspect->Aspect()->TextureMapState(); + aContext->ModelWorldState.Push(); - aContext->ModelWorldState.SetCurrent (OpenGl_Mat4::Map (*thePlane->Orientation()->mat)); + aContext->ModelWorldState.SetCurrent (theCappingMatrix); aContext->ApplyModelViewMatrix(); - thePlane->Primitives().Render (theWorkspace); + theWorkspace->SetAspectFace (theCappingAspect); + theWorkspace->ApplyAspectFace(); + + theQuad->Render (theWorkspace); + + if (theHatchAspect != NULL) + { + Graphic3d_Vec2 aPrevScale; + Standard_ShortReal aPrevRotate = 0.0; + + if (isTextureHatch) + { + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + if ((theHatchScale != 1.0 || theHatchRotate != 0.0) && !theHatchAspect->TextureSet(aContext)->IsEmpty()) + { + Handle(OpenGl_Texture) aTexture = theHatchAspect->TextureSet(aContext)->First(); + const Handle(Graphic3d_TextureParams)& aTexParams = aTexture->Sampler()->Parameters(); + + aPrevScale = aTexParams->Scale(); + aPrevRotate = aTexParams->Rotation(); + + const Standard_Boolean isMirror = aPrevScale.x() * aPrevScale.y() < 0.0; + aTexParams->SetScale (aPrevScale * theHatchScale); + aTexParams->SetRotation (isMirror ? aPrevRotate - theHatchRotate : aPrevRotate + theHatchRotate); + } + } + + theWorkspace->SetAspectFace (theHatchAspect); + theWorkspace->ApplyAspectFace(); + + glDepthFunc (GL_LEQUAL); + + theQuad->Render (theWorkspace); + + glDepthFunc (GL_LESS); + + if (isTextureHatch) + { + glDisable (GL_BLEND); + + if (theHatchScale != 1.0 || theHatchRotate != 0.0) + { + Handle(OpenGl_Texture) aTexture = theHatchAspect->TextureSet(aContext)->First(); + const Handle(Graphic3d_TextureParams)& aTexParams = aTexture->Sampler()->Parameters(); + + aTexParams->SetScale (aPrevScale); + aTexParams->SetRotation (aPrevRotate); + } + } + } aContext->ModelWorldState.Pop(); aContext->ApplyModelViewMatrix(); @@ -86,13 +183,23 @@ namespace const OpenGl_Structure& theStructure, const Handle(Graphic3d_ClipPlane)& theClipChain, const Standard_Integer theSubPlaneIndex, - const Handle(OpenGl_CappingPlaneResource)& thePlane) + const Handle(OpenGl_CappingPlaneResource)& thePlane, + const OpenGl_PrimitiveArray* theQuad) { const Standard_Integer aPrevFilter = theWorkspace->RenderFilter(); const Standard_Integer anAnyFilter = aPrevFilter & ~(Standard_Integer )(OpenGl_RenderFilter_OpaqueOnly | OpenGl_RenderFilter_TransparentOnly); + const Handle(Graphic3d_ClipPlane)& aPlane = theClipChain; + const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); - const Handle(Graphic3d_ClipPlane)& aRenderPlane = thePlane->Plane(); + const Handle(Graphic3d_Camera) aCamera = theWorkspace->View() != NULL + ? theWorkspace->View()->Camera() + : Handle(Graphic3d_Camera)(); + const OpenGl_Mat4& aPlaneMat = OpenGl_Mat4::Map (aPlane->OrientationMatrix()); + Standard_ShortReal aRotateAngle = 0.0; + Standard_ShortReal aViewScale = ShortRealLast(); + OpenGl_Mat4 aRotateZoomMat; + for (OpenGl_Structure::GroupIterator aGroupIter (theStructure.Groups()); aGroupIter.More(); aGroupIter.Next()) { if (!aGroupIter.Value()->IsClosed()) @@ -103,16 +210,6 @@ namespace // clear stencil only if something has been actually drawn theStencilSentry.Init(); - // check if capping plane should be rendered within current pass (only opaque / only transparent) - const OpenGl_AspectFace* anObjAspectFace = aRenderPlane->ToUseObjectProperties() ? aGroupIter.Value()->AspectFace() : NULL; - thePlane->Update (aContext, anObjAspectFace != NULL ? anObjAspectFace->Aspect() : Handle(Graphic3d_AspectFillArea3d)()); - theWorkspace->SetAspectFace (thePlane->AspectFace()); - theWorkspace->SetRenderFilter (aPrevFilter); - if (!theWorkspace->ShouldRender (&thePlane->Primitives())) - { - continue; - } - // suppress only opaque/transparent filter since for filling stencil the whole geometry should be drawn theWorkspace->SetRenderFilter (anAnyFilter); @@ -121,7 +218,7 @@ namespace aContext->ShaderManager()->UpdateClippingState(); glClear (GL_STENCIL_BUFFER_BIT); - const bool aColorMaskBack = aContext->SetColorMask (false); + glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // override aspects, disable culling theWorkspace->SetAspectFace (&theWorkspace->NoneCulling()); @@ -140,20 +237,7 @@ namespace glStencilOp (GL_KEEP, GL_INVERT, GL_INVERT); // render closed primitives - if (aRenderPlane->ToUseObjectProperties()) - { - aGroupIter.Value()->Render (theWorkspace); - } - else - { - for (; aGroupIter.More(); aGroupIter.Next()) - { - if (aGroupIter.Value()->IsClosed()) - { - aGroupIter.Value()->Render (theWorkspace); - } - } - } + aGroupIter.Value()->Render (theWorkspace); // override material, cull back faces theWorkspace->SetAspectFace (&theWorkspace->FrontCulling()); @@ -164,7 +248,7 @@ namespace aContext->ShaderManager()->UpdateClippingState(); // render capping plane using the generated stencil mask - aContext->SetColorMask (aColorMaskBack); + glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); if (theWorkspace->UseDepthWrite()) { glDepthMask (GL_TRUE); @@ -176,8 +260,66 @@ namespace glEnable (GL_DEPTH_TEST); } - theWorkspace->SetAspectFace (thePlane->AspectFace()); - renderPlane (theWorkspace, thePlane); + const OpenGl_AspectFace* aGroupAspectFace = aGroupIter.Value()->AspectFace(); + const OpenGl_CappingPlaneResource* aGroupAspectCapping = aGroupIter.Value()->AspectFillCapping(); + const OpenGl_CappingPlaneResource* anAspectCapping = + thePlane && (!aGroupAspectCapping || aGroupAspectCapping->Aspect().IsNull() || aPlane->ToOverrideCappingAspect()) + ? thePlane.get() + : aGroupAspectCapping; + + if (anAspectCapping == NULL) + { + anAspectCapping = &THE_DEFAULT_ASPECT; + } + + const OpenGl_AspectFace* anAspectFace = anAspectCapping->CappingFaceAspect (aGroupAspectFace); + const Standard_Boolean hasHatch = anAspectCapping->Aspect()->ToDrawHatch(); + const OpenGl_AspectFace* anAspectHatching = hasHatch ? anAspectCapping->HatchingFaceAspect() : NULL; + const Standard_Boolean hasTextureHatch = hasHatch && !anAspectCapping->Aspect()->TextureHatch().IsNull(); + const Standard_Boolean isRotatePers = hasTextureHatch && !aCamera.IsNull() && anAspectCapping->Aspect()->IsHatchRotationPersistent(); + const Standard_Boolean isZoomPers = hasTextureHatch && !aCamera.IsNull() && anAspectCapping->Aspect()->IsHatchZoomPersistent(); + + Standard_ShortReal aHatchScale = 1.0; + Standard_ShortReal aHatchAngle = 0.0; + + if (isRotatePers || isZoomPers) + { + + if (isRotatePers) + { + if (aRotateAngle == 0.0) + { + const gp_Dir aPlaneSide (aPlaneMat.GetValue (0, 0), aPlaneMat.GetValue (1, 0), aPlaneMat.GetValue (2, 0)); + const gp_Dir aPlaneUp (aPlaneMat.GetValue (0, 2), aPlaneMat.GetValue (1, 2), aPlaneMat.GetValue (2, 2)); + const gp_Dir& aCameraUp = aCamera->Up(); + const gp_Vec aCameraPln = aPlaneSide.Dot (aCameraUp) * aPlaneSide + aPlaneUp.Dot (aCameraUp) * aPlaneUp; + const gp_Dir& aCameraDir = aCamera->Direction(); + aRotateAngle = static_cast (aCameraPln.AngleWithRef (aPlaneUp, aCameraDir) / M_PI * 180.0); + } + + aHatchAngle = aRotateAngle; + } + + if (isZoomPers) + { + if (aViewScale == ShortRealLast()) + { + const Standard_Real aFocus = aCamera->IsOrthographic() + ? aCamera->Distance() + : (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Relative + ? Standard_Real(aCamera->ZFocus() * aCamera->Distance()) + : Standard_Real(aCamera->ZFocus())); + + const gp_XYZ aViewDim = aCamera->ViewDimensions (aFocus); + aViewScale = static_cast (aViewDim.Y() / aContext->Viewport()[3]); + } + + if (!anAspectHatching->TextureSet(aContext)->IsEmpty()) + aHatchScale = 1.0f / (aViewScale * anAspectHatching->TextureSet(aContext)->First()->SizeY()); + } + } + + renderSection (theWorkspace, theQuad, anAspectFace, hasHatch ? anAspectCapping->HatchingFaceAspect() : NULL, aPlaneMat, aHatchScale, aHatchAngle); // turn on the current plane to restore initial state aContext->ChangeClipping().ResetCappingFilter(); @@ -187,7 +329,7 @@ namespace if (theStructure.InstancedStructure() != NULL) { - renderCappingForStructure (theStencilSentry, theWorkspace, *theStructure.InstancedStructure(), theClipChain, theSubPlaneIndex, thePlane); + renderCappingForStructure (theStencilSentry, theWorkspace, *theStructure.InstancedStructure(), theClipChain, theSubPlaneIndex, thePlane, theQuad); } } } @@ -206,6 +348,12 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorks return; } + const OpenGl_PrimitiveArray* aCappingQuad = initQuad (aContext); + if (!aCappingQuad) + { + return; + } + // remember current aspect face defined in workspace const OpenGl_AspectFace* aFaceAsp = theWorkspace->AspectFace(); @@ -214,6 +362,16 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorks theWorkspace->SetRenderFilter (aPrevFilter | OpenGl_RenderFilter_FillModeOnly); StencilTestSentry aStencilSentry; + GLboolean aPrevBlend = glIsEnabled (GL_BLEND); + GLint aPrevBlendSrc = GL_ONE; + GLint aPrevBlendDst = GL_ZERO; + if (aPrevBlend == GL_TRUE) + { + glGetIntegerv (GL_BLEND_SRC_ALPHA, &aPrevBlendSrc); + glGetIntegerv (GL_BLEND_DST_ALPHA, &aPrevBlendDst); + glDisable (GL_BLEND); + } + // generate capping for every clip plane for (OpenGl_ClippingIterator aCappingIt (aContext->Clipping()); aCappingIt.More(); aCappingIt.Next()) { @@ -229,23 +387,33 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorks for (const Graphic3d_ClipPlane* aSubPlaneIter = aClipChain.get(); aSubPlaneIter != NULL; aSubPlaneIter = aSubPlaneIter->ChainNextPlane().get(), ++aSubPlaneIndex) { // get resource for the plane - const TCollection_AsciiString& aResId = aSubPlaneIter->GetId(); + const TCollection_AsciiString& aResId = THE_PLANE_STYLE + aSubPlaneIter->GetId(); Handle(OpenGl_CappingPlaneResource) aPlaneRes; if (!aContext->GetResource (aResId, aPlaneRes)) { // share and register for release once the resource is no longer used - aPlaneRes = new OpenGl_CappingPlaneResource (aSubPlaneIter); + aPlaneRes = new OpenGl_CappingPlaneResource (aSubPlaneIter->CappingSectionStyle()); aContext->ShareResource (aResId, aPlaneRes); } - renderCappingForStructure (aStencilSentry, theWorkspace, theStructure, aClipChain, aSubPlaneIndex, aPlaneRes); + renderCappingForStructure (aStencilSentry, theWorkspace, theStructure, aClipChain, aSubPlaneIndex, aPlaneRes, aCappingQuad); // set delayed resource release aPlaneRes.Nullify(); - aContext->ReleaseResource (aResId, Standard_True); + if (!aResId.IsEmpty()) + { + // schedule release of resource if not used + aContext->ReleaseResource (aResId, Standard_True); + } } } + if (aPrevBlend == GL_TRUE) + { + glEnable (GL_BLEND); + glBlendFunc (aPrevBlendSrc, aPrevBlendDst); + } + // restore rendering aspects theWorkspace->SetAspectFace (aFaceAsp); theWorkspace->SetRenderFilter (aPrevFilter); diff --git a/src/OpenGl/OpenGl_CappingPlaneResource.cxx b/src/OpenGl/OpenGl_CappingPlaneResource.cxx index d551231791..9b6678b875 100755 --- a/src/OpenGl/OpenGl_CappingPlaneResource.cxx +++ b/src/OpenGl/OpenGl_CappingPlaneResource.cxx @@ -55,21 +55,28 @@ namespace { 0.0f, 0.0f, 0.0f, 1.0f } } }; + Handle(Graphic3d_AspectFillArea3d) defaultMaterial() + { + Handle(Graphic3d_AspectFillArea3d) anAspect; + const Graphic3d_MaterialAspect aMaterial (Graphic3d_NOM_DEFAULT); + anAspect = new Graphic3d_AspectFillArea3d(); + anAspect->SetDistinguishOff(); + anAspect->SetFrontMaterial (aMaterial); + anAspect->SetInteriorStyle (Aspect_IS_SOLID); + anAspect->SetInteriorColor (aMaterial.Color()); + anAspect->SetSuppressBackFaces (false); + return anAspect; + } } // ======================================================================= -// function : OpenGl_CappingPlaneResource +// function : BuildInfinitPlaneVertices // purpose : // ======================================================================= -OpenGl_CappingPlaneResource::OpenGl_CappingPlaneResource (const Handle(Graphic3d_ClipPlane)& thePlane) -: myPrimitives (NULL), - myOrientation (OpenGl_IdentityMatrix), - myAspect (NULL), - myPlaneRoot (thePlane), - myEquationMod ((unsigned int )-1), - myAspectMod ((unsigned int )-1) +OpenGl_PrimitiveArray* OpenGl_CappingPlaneResource::BuildInfinitPlaneVertices() { + OpenGl_PrimitiveArray* aPrimitives = NULL; // Fill primitive array Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16); Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (anAlloc); @@ -82,8 +89,23 @@ OpenGl_CappingPlaneResource::OpenGl_CappingPlaneResource (const Handle(Graphic3d if (anAttribs->Init (12, anAttribInfo, 3)) { memcpy (anAttribs->ChangeData(), THE_CAPPING_PLN_VERTS, sizeof(THE_CAPPING_PLN_VERTS)); - myPrimitives.InitBuffers (NULL, Graphic3d_TOPA_TRIANGLES, NULL, anAttribs, NULL); + + aPrimitives = new OpenGl_PrimitiveArray (NULL); + aPrimitives->InitBuffers (NULL, Graphic3d_TOPA_TRIANGLES, NULL, anAttribs, NULL); } + return aPrimitives; +} + +// ======================================================================= +// function : OpenGl_CappingPlaneResource +// purpose : +// ======================================================================= +OpenGl_CappingPlaneResource::OpenGl_CappingPlaneResource (const Handle(Graphic3d_AspectFillCapping)& theAspect) +: myCappingAspect (defaultMaterial()), + myHatchingAspect (defaultMaterial()), + myHatchingState (0) +{ + SetAspect (theAspect); } // ======================================================================= @@ -92,18 +114,83 @@ OpenGl_CappingPlaneResource::OpenGl_CappingPlaneResource (const Handle(Graphic3d // ======================================================================= OpenGl_CappingPlaneResource::~OpenGl_CappingPlaneResource() { - Release (NULL); } // ======================================================================= -// function : Update +// function : SetAspect // purpose : // ======================================================================= -void OpenGl_CappingPlaneResource::Update (const Handle(OpenGl_Context)& , - const Handle(Graphic3d_AspectFillArea3d)& theObjAspect) +void OpenGl_CappingPlaneResource::SetAspect (const Handle(Graphic3d_AspectFillCapping)& theAspect) { - updateTransform(); - updateAspect (theObjAspect); + myAspect = theAspect; + + if (theAspect.IsNull()) + { + return; + } + + if (!theAspect->ToUseObjectMaterial() + || !theAspect->ToUseObjectTexture() + || !theAspect->ToUseObjectShader()) + { + Handle(Graphic3d_AspectFillArea3d) aFillAspect = myCappingAspect.Aspect(); + + if (!theAspect->ToUseObjectMaterial()) + { + aFillAspect->SetFrontMaterial (theAspect->Material()); + aFillAspect->SetInteriorColor (theAspect->Material().Color()); + } + + if (!theAspect->ToUseObjectTexture()) + { + aFillAspect->SetTextureMap (theAspect->Texture()); + + if (!theAspect->Texture().IsNull()) + { + aFillAspect->SetTextureMapOn(); + } + else + { + aFillAspect->SetTextureMapOff(); + } + } + else + { + aFillAspect->SetTextureMap (Handle(Graphic3d_TextureMap)()); + aFillAspect->SetTextureMapOff(); + } + + if (!theAspect->ToUseObjectShader()) + { + aFillAspect->SetShaderProgram (theAspect->Shader()); + } + + myCappingAspect.SetAspect (aFillAspect); + } + + if (theAspect->ToDrawHatch() + && (theAspect->IsTextureHatch() + || theAspect->IsStippleHatch())) + { + Handle(Graphic3d_AspectFillArea3d) aFillAspect = myHatchingAspect.Aspect(); + + aFillAspect->SetInteriorStyle (theAspect->IsStippleHatch() ? Aspect_IS_HATCH : Aspect_IS_SOLID); + aFillAspect->SetHatchStyle (theAspect->IsStippleHatch() ? theAspect->StippleHatch() : Handle(Graphic3d_HatchStyle)()); + aFillAspect->SetTextureMap (theAspect->IsTextureHatch() ? theAspect->TextureHatch() : Handle(Graphic3d_TextureMap)()); + aFillAspect->SetFrontMaterial (theAspect->HatchMaterial()); + aFillAspect->SetInteriorColor (theAspect->HatchMaterial().Color()); + if (theAspect->IsTextureHatch()) + { + aFillAspect->SetTextureMapOn(); + } + else + { + aFillAspect->SetTextureMapOff(); + } + + myHatchingAspect.SetAspect (aFillAspect); + myHatchingState = theAspect->HatchingState(); + } } // ======================================================================= @@ -112,133 +199,110 @@ void OpenGl_CappingPlaneResource::Update (const Handle(OpenGl_Context)& , // ======================================================================= void OpenGl_CappingPlaneResource::Release (OpenGl_Context* theContext) { - OpenGl_Element::Destroy (theContext, myAspect); - myPrimitives.Release (theContext); - myEquationMod = (unsigned int )-1; - myAspectMod = (unsigned int )-1; + myCappingAspect .Release (theContext); + myHatchingAspect.Release (theContext); } // ======================================================================= -// function : updateAspect +// function : CappingFaceAspect // purpose : // ======================================================================= -void OpenGl_CappingPlaneResource::updateAspect (const Handle(Graphic3d_AspectFillArea3d)& theObjAspect) +const OpenGl_AspectFace* OpenGl_CappingPlaneResource::CappingFaceAspect (const OpenGl_AspectFace* theObjectAspect) const { - if (myAspect == NULL) + if (myAspect.IsNull()) { - myAspect = new OpenGl_AspectFace(); - myAspectMod = myPlaneRoot->MCountAspect() - 1; // mark out of sync + return NULL; } - if (theObjAspect.IsNull()) - { - if (myAspectMod != myPlaneRoot->MCountAspect()) - { - myAspect->SetAspect (myPlaneRoot->CappingAspect()); - myAspectMod = myPlaneRoot->MCountAspect(); - } - return; - } + Handle(Graphic3d_AspectFillArea3d) aFillAspect = myCappingAspect.Aspect(); - if (myFillAreaAspect.IsNull()) + if (myAspect->ToUseObjectMaterial() && theObjectAspect != NULL) { - myFillAreaAspect = new Graphic3d_AspectFillArea3d(); + // only front material currently supported by capping rendering + aFillAspect->SetFrontMaterial (theObjectAspect->Aspect()->FrontMaterial()); + aFillAspect->SetInteriorColor (theObjectAspect->Aspect()->InteriorColor()); } - if (myAspectMod != myPlaneRoot->MCountAspect()) + else { - *myFillAreaAspect = *myPlaneRoot->CappingAspect(); + aFillAspect->SetFrontMaterial (myAspect->Material()); + aFillAspect->SetInteriorColor (myAspect->Material().Color()); } - if (myPlaneRoot->ToUseObjectMaterial()) + if (myAspect->ToUseObjectTexture() && theObjectAspect != NULL) { - // only front material currently supported by capping rendering - myFillAreaAspect->SetFrontMaterial (theObjAspect->FrontMaterial()); - myFillAreaAspect->SetInteriorColor (theObjAspect->InteriorColor()); + if (theObjectAspect->Aspect()->ToMapTexture()) + { + aFillAspect->SetTextureMap (theObjectAspect->Aspect()->TextureMap()); + aFillAspect->SetTextureMapOn(); + } + else + { + aFillAspect->SetTextureMapOff(); + } } - if (myPlaneRoot->ToUseObjectTexture()) + else { - myFillAreaAspect->SetTextureSet (theObjAspect->TextureSet()); - if (theObjAspect->ToMapTexture()) + aFillAspect->SetTextureMap (myAspect->Texture()); + if (!myAspect->Texture().IsNull()) { - myFillAreaAspect->SetTextureMapOn(); + aFillAspect->SetTextureMapOn(); } else { - myFillAreaAspect->SetTextureMapOff(); + aFillAspect->SetTextureMapOff(); } } - if (myPlaneRoot->ToUseObjectShader()) + + if (myAspect->ToUseObjectShader() && theObjectAspect != NULL) { - myFillAreaAspect->SetShaderProgram (theObjAspect->ShaderProgram()); + aFillAspect->SetShaderProgram (theObjectAspect->Aspect()->ShaderProgram()); } + else + { + aFillAspect->SetShaderProgram (myAspect->Shader()); + } + + myCappingAspect.SetAspect (aFillAspect); - myAspect->SetAspect (myFillAreaAspect); + return &myCappingAspect; } // ======================================================================= -// function : updateTransform +// function : HatchingFaceAspect // purpose : // ======================================================================= -void OpenGl_CappingPlaneResource::updateTransform() +const OpenGl_AspectFace* OpenGl_CappingPlaneResource::HatchingFaceAspect() const { - const Graphic3d_ClipPlane::Equation& anEquation = myPlaneRoot->GetEquation(); - if (myEquationMod == myPlaneRoot->MCountEquation()) + if (myAspect.IsNull()) { - return; // nothing to update + return NULL; } - // re-evaluate infinite plane transformation matrix - Standard_ShortReal N[3] = - { (Standard_ShortReal)anEquation[0], - (Standard_ShortReal)anEquation[1], - (Standard_ShortReal)anEquation[2] }; - - Standard_ShortReal T[3] = - { (Standard_ShortReal)(anEquation[0] * -anEquation[3]), - (Standard_ShortReal)(anEquation[1] * -anEquation[3]), - (Standard_ShortReal)(anEquation[2] * -anEquation[3]) }; - - Standard_ShortReal L[3] = { 0.0f, 0.0f, 0.0f }; - Standard_ShortReal F[3] = { 0.0f, 0.0f, 0.0f }; - - // project plane normal onto OX to find left vector - Standard_ShortReal aProjLen = - sqrt ( (Standard_ShortReal)(anEquation[0] * anEquation[0]) - + (Standard_ShortReal)(anEquation[2] * anEquation[2])); - if (aProjLen < ShortRealSmall()) - { - L[0] = 1.0f; - } - else + const Standard_Size aHatchingState = myAspect->HatchingState(); + if (myHatchingState != aHatchingState) { - L[0] = N[2] / aProjLen; - L[2] = -N[0] / aProjLen; - } - - // (-aLeft) x aNorm - F[0] = (-L[1])*N[2] - (-L[2])*N[1]; - F[1] = (-L[2])*N[0] - (-L[0])*N[2]; - F[2] = (-L[0])*N[1] - (-L[1])*N[0]; - - myOrientation.mat[0][0] = L[0]; - myOrientation.mat[0][1] = L[1]; - myOrientation.mat[0][2] = L[2]; - myOrientation.mat[0][3] = 0.0f; - - myOrientation.mat[1][0] = N[0]; - myOrientation.mat[1][1] = N[1]; - myOrientation.mat[1][2] = N[2]; - myOrientation.mat[1][3] = 0.0f; + if (myAspect->ToDrawHatch()) + { + Handle(Graphic3d_AspectFillArea3d) aFillAspect = myHatchingAspect.Aspect(); - myOrientation.mat[2][0] = F[0]; - myOrientation.mat[2][1] = F[1]; - myOrientation.mat[2][2] = F[2]; - myOrientation.mat[2][3] = 0.0f; + aFillAspect->SetInteriorStyle (myAspect->IsStippleHatch() ? Aspect_IS_HATCH : Aspect_IS_SOLID); + aFillAspect->SetHatchStyle (myAspect->IsStippleHatch() ? myAspect->StippleHatch() : Handle(Graphic3d_HatchStyle)()); + aFillAspect->SetTextureMap (myAspect->IsTextureHatch() ? myAspect->TextureHatch() : Handle(Graphic3d_TextureMap)()); + aFillAspect->SetFrontMaterial (myAspect->HatchMaterial()); + aFillAspect->SetInteriorColor (myAspect->HatchMaterial().Color()); + if (myAspect->IsTextureHatch()) + { + aFillAspect->SetTextureMapOn(); + } + else + { + aFillAspect->SetTextureMapOff(); + } - myOrientation.mat[3][0] = T[0]; - myOrientation.mat[3][1] = T[1]; - myOrientation.mat[3][2] = T[2]; - myOrientation.mat[3][3] = 1.0f; + myHatchingAspect.SetAspect (aFillAspect); + myHatchingState = aHatchingState; + } + } - myEquationMod = myPlaneRoot->MCountEquation(); + return &myHatchingAspect; } diff --git a/src/OpenGl/OpenGl_CappingPlaneResource.hxx b/src/OpenGl/OpenGl_CappingPlaneResource.hxx index 7ac029f9f7..8c1b8b8b73 100755 --- a/src/OpenGl/OpenGl_CappingPlaneResource.hxx +++ b/src/OpenGl/OpenGl_CappingPlaneResource.hxx @@ -20,7 +20,7 @@ #include #include #include -#include +#include class OpenGl_CappingPlaneResource; DEFINE_STANDARD_HANDLE (OpenGl_CappingPlaneResource, OpenGl_Resource) @@ -30,25 +30,23 @@ DEFINE_STANDARD_HANDLE (OpenGl_CappingPlaneResource, OpenGl_Resource) //! This resource holds data necessary for OpenGl_CappingAlgo. //! This object is implemented as OpenGl resource for the following reasons: //! - one instance should be shared between contexts. -//! - instance associated to Graphic3d_ClipPlane data by id. +//! - instance associated to Graphic3d_AspectFillCapping data. //! - should created and released within context (owns OpenGl elements and resources). class OpenGl_CappingPlaneResource : public OpenGl_Resource { public: - //! Constructor. - //! Create capping plane presentation associated to clipping plane data. - //! @param thePlane [in] the plane data. - Standard_EXPORT OpenGl_CappingPlaneResource (const Handle(Graphic3d_ClipPlane)& thePlane); + //! Create and assign style. + Standard_EXPORT OpenGl_CappingPlaneResource (const Handle(Graphic3d_AspectFillCapping)& theAspect); //! Destroy object. Standard_EXPORT virtual ~OpenGl_CappingPlaneResource(); - //! Update resource data in the passed context. - //! @param theContext [in] the context - //! @param theObjAspect [in] object aspect - Standard_EXPORT void Update (const Handle(OpenGl_Context)& theContext, - const Handle(Graphic3d_AspectFillArea3d)& theObjAspect); + //! Assign section style. + Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillCapping)& theAspect); + + //! Returns section style parameters. + const Handle(Graphic3d_AspectFillCapping)& Aspect() const { return myAspect; } //! Release associated OpenGl resources. //! @param theContext [in] the resource context. @@ -57,17 +55,23 @@ public: //! Returns estimated GPU memory usage - not implemented. virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; } - //! Return parent clipping plane structure. - const Handle(Graphic3d_ClipPlane)& Plane() const { return myPlaneRoot; } + //! @return primitive array of vertices to render infinite plane. + static OpenGl_PrimitiveArray* BuildInfinitPlaneVertices(); - //! @return aspect face for rendering capping surface. - inline const OpenGl_AspectFace* AspectFace() const { return myAspect; } + //! Returns true if capping should draw hatch layer. + Standard_Boolean ToDrawHatch() const + { + return myAspect->ToDrawHatch() + && (myAspect->IsStippleHatch() + || myAspect->IsTextureHatch()); + } - //! @return evaluated orientation matrix to transform infinite plane. - inline const OpenGl_Matrix* Orientation() const { return &myOrientation; } + //! Returns the shading aspect for drawing face of a clipping section itself. + //! @param theObjectAspect [in] the aspect of an object if it requires combining. + Standard_EXPORT const OpenGl_AspectFace* CappingFaceAspect (const OpenGl_AspectFace* theObjectAspect) const; - //! @return primitive array of vertices to render infinite plane. - inline const OpenGl_PrimitiveArray& Primitives() const { return myPrimitives; } + //! Returns the shading aspect for drawing hatch layer of a section. + Standard_EXPORT const OpenGl_AspectFace* HatchingFaceAspect() const; private: @@ -79,13 +83,10 @@ private: private: - OpenGl_PrimitiveArray myPrimitives; //!< vertices and texture coordinates for rendering - OpenGl_Matrix myOrientation; //!< plane transformation matrix. - OpenGl_AspectFace* myAspect; //!< capping face aspect. - Handle(Graphic3d_ClipPlane) myPlaneRoot; //!< parent clipping plane structure. - Handle(Graphic3d_AspectFillArea3d) myFillAreaAspect; //!< own capping aspect - unsigned int myEquationMod; //!< modification counter for plane equation. - unsigned int myAspectMod; //!< modification counter for aspect. + Handle(Graphic3d_AspectFillCapping) myAspect; //!< Section style settings from application's level. + mutable OpenGl_AspectFace myCappingAspect; //!< GL aspect for shading base layer of a capping section. + mutable OpenGl_AspectFace myHatchingAspect; //!< GL aspect for shading hatching layer (additional to base) of a capping section. + mutable Standard_Size myHatchingState; public: diff --git a/src/OpenGl/OpenGl_Group.cxx b/src/OpenGl/OpenGl_Group.cxx index c9211adcc5..874864e3b9 100644 --- a/src/OpenGl/OpenGl_Group.cxx +++ b/src/OpenGl/OpenGl_Group.cxx @@ -264,6 +264,28 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& th Update(); } +// ======================================================================= +// function : SetGroupPrimitivesAspect +// purpose : +// ======================================================================= +void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillCapping)& theAspect) +{ + if (IsDeleted()) + { + return; + } + + if (myAspectFillCapping == NULL) + { + myAspectFillCapping = new OpenGl_CappingPlaneResource (theAspect); + } + else + { + myAspectFillCapping->SetAspect (theAspect); + } + Update(); +} + // ======================================================================= // function : AddPrimitiveArray // purpose : diff --git a/src/OpenGl/OpenGl_Group.hxx b/src/OpenGl/OpenGl_Group.hxx index c845615d48..ae0e1b3cd5 100644 --- a/src/OpenGl/OpenGl_Group.hxx +++ b/src/OpenGl/OpenGl_Group.hxx @@ -24,9 +24,11 @@ #include #include #include +#include #include class OpenGl_Group; +class OpenGl_CappingPlaneResource; class OpenGl_Structure; struct OpenGl_ElementNode @@ -103,6 +105,17 @@ public: //! Append text aspect as an element. Standard_EXPORT virtual void SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspect) Standard_OVERRIDE; + //! Update section style aspect. + Standard_EXPORT virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillCapping)& theAspect) Standard_OVERRIDE; + + //! Returns section style aspect. + virtual Handle(Graphic3d_AspectFillCapping) FillCappingAspect() const Standard_OVERRIDE + { + return myAspectFillCapping != NULL + ? myAspectFillCapping->Aspect() + : Handle(Graphic3d_AspectFillCapping)(); + } + //! Add primitive array element Standard_EXPORT virtual void AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType, const Handle(Graphic3d_IndexBuffer)& theIndices, @@ -153,6 +166,9 @@ public: //! Returns OpenGL face aspect. const OpenGl_AspectFace* AspectFace() const { return myAspectFace; } + //! Returns OpenGL capping filling aspect. + const OpenGl_CappingPlaneResource* AspectFillCapping() const { return myAspectFillCapping; } + //! Is the group ray-tracable (contains ray-tracable elements)? Standard_Boolean IsRaytracable() const { return myIsRaytracable; } @@ -166,6 +182,7 @@ protected: OpenGl_AspectFace* myAspectFace; OpenGl_AspectMarker* myAspectMarker; OpenGl_AspectText* myAspectText; + OpenGl_CappingPlaneResource* myAspectFillCapping; OpenGl_ElementNode* myFirst; OpenGl_ElementNode* myLast; diff --git a/src/OpenGl/OpenGl_ShaderManager.cxx b/src/OpenGl/OpenGl_ShaderManager.cxx index 71f6bda586..83301a6f4f 100644 --- a/src/OpenGl/OpenGl_ShaderManager.cxx +++ b/src/OpenGl/OpenGl_ShaderManager.cxx @@ -1249,11 +1249,11 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramFont() EOL"}"; TCollection_AsciiString - aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occSamplerBaseColor, TexCoord.st).a; }"; + aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, TexCoord.st).a; }"; #if !defined(GL_ES_VERSION_2_0) if (myContext->core11 == NULL) { - aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occSamplerBaseColor, TexCoord.st).r; }"; + aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, TexCoord.st).r; }"; } #endif @@ -1468,12 +1468,12 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramOitCompositing (const St // ======================================================================= TCollection_AsciiString OpenGl_ShaderManager::pointSpriteAlphaSrc (const Standard_Integer theBits) { - TCollection_AsciiString aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occSamplerBaseColor, " THE_VEC2_glPointCoord ").a; }"; + TCollection_AsciiString aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord ").a; }"; #if !defined(GL_ES_VERSION_2_0) if (myContext->core11 == NULL && (theBits & OpenGl_PO_TextureA) != 0) { - aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occSamplerBaseColor, " THE_VEC2_glPointCoord ").r; }"; + aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord ").r; }"; } #else (void )theBits; @@ -1516,7 +1516,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha if ((theBits & OpenGl_PO_TextureRGB) != 0) { aSrcFragGetColor = - EOL"vec4 getColor(void) { return occTexture2D(occSamplerBaseColor, " THE_VEC2_glPointCoord "); }"; + EOL"vec4 getColor(void) { return occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord "); }"; } if (textureUsed (theBits)) @@ -1554,7 +1554,10 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha aSrcVertExtraMain += THE_VARY_TexCoord_Trsf; aSrcFragGetColor = - EOL"vec4 getColor(void) { return occTexture2D(occSamplerBaseColor, TexCoord.st / TexCoord.w); }"; + EOL"vec4 getColor(void)" + EOL"{" + EOL" return occTexture2D(occActiveSampler, TexCoord.st / TexCoord.w) * occColor;" + EOL"}"; } else if ((theBits & OpenGl_PO_TextureEnv) != 0) { @@ -1571,7 +1574,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha EOL" TexCoord = vec4(aReflect.xy * inversesqrt (dot (aReflect, aReflect)) * 0.5 + vec2 (0.5), 0.0, 1.0);"; aSrcFragGetColor = - EOL"vec4 getColor(void) { return occTexture2D (occSamplerBaseColor, TexCoord.st); }"; + EOL"vec4 getColor(void) { return occTexture2D (occActiveSampler, TexCoord.st); }"; } } if ((theBits & OpenGl_PO_VertColor) != 0) @@ -1752,7 +1755,7 @@ TCollection_AsciiString OpenGl_ShaderManager::pointSpriteShadingSrc (const TColl EOL"vec4 getColor(void)" EOL"{" EOL" vec4 aColor = " + theBaseColorSrc + ";" - EOL" aColor = occTexture2D(occSamplerBaseColor, " THE_VEC2_glPointCoord ") * aColor;" + EOL" aColor = occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord ") * aColor;" EOL" if (aColor.a <= 0.1) discard;" EOL" return aColor;" EOL"}"; @@ -1939,7 +1942,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramGouraud (Handle(OpenGl_S EOL"vec4 getColor(void)" EOL"{" EOL" vec4 aColor = gl_FrontFacing ? FrontColor : BackColor;" - EOL" return occTexture2D(occSamplerBaseColor, TexCoord.st / TexCoord.w) * aColor;" + EOL" return occTexture2D(occActiveSampler, TexCoord.st / TexCoord.w) * aColor;" EOL"}"; } } @@ -2109,7 +2112,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramPhong (Handle(OpenGl_Sha EOL"vec4 getColor(void)" EOL"{" EOL" vec4 aColor = " thePhongCompLight ";" - EOL" return occTexture2D(occSamplerBaseColor, TexCoord.st / TexCoord.w) * aColor;" + EOL" return occTexture2D(occActiveSampler, TexCoord.st / TexCoord.w) * aColor;" EOL"}"; } } diff --git a/src/StdPrs/StdPrs_ShadedShape.cxx b/src/StdPrs/StdPrs_ShadedShape.cxx index 8f2de978c8..5ef1cd8123 100644 --- a/src/StdPrs/StdPrs_ShadedShape.cxx +++ b/src/StdPrs/StdPrs_ShadedShape.cxx @@ -281,6 +281,7 @@ namespace static Standard_Boolean shadeFromShape (const TopoDS_Shape& theShape, const Handle(Prs3d_Presentation)& thePrs, const Handle(Prs3d_Drawer)& theDrawer, + const Handle(Graphic3d_AspectFillCapping)& theCappingStyle, const Standard_Boolean theHasTexels, const gp_Pnt2d& theUVOrigin, const gp_Pnt2d& theUVRepeat, @@ -296,6 +297,9 @@ namespace Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs); aGroup->SetClosed (theIsClosed); aGroup->SetGroupPrimitivesAspect (theDrawer->ShadingAspect()->Aspect()); + if (!theCappingStyle.IsNull()) + aGroup->SetGroupPrimitivesAspect (theCappingStyle); + aGroup->AddPrimitiveArray (aPArray); return Standard_True; } @@ -500,11 +504,12 @@ void StdPrs_ShadedShape::ExploreSolids (const TopoDS_Shape& theShape, void StdPrs_ShadedShape::Add (const Handle(Prs3d_Presentation)& thePrs, const TopoDS_Shape& theShape, const Handle(Prs3d_Drawer)& theDrawer, + const Handle(Graphic3d_AspectFillCapping)& theCappingStyle, const StdPrs_Volume theVolume) { gp_Pnt2d aDummy; StdPrs_ShadedShape::Add (thePrs, theShape, theDrawer, - Standard_False, aDummy, aDummy, aDummy, theVolume); + Standard_False, aDummy, aDummy, aDummy, theCappingStyle, theVolume); } // ======================================================================= @@ -518,6 +523,7 @@ void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs, const gp_Pnt2d& theUVOrigin, const gp_Pnt2d& theUVRepeat, const gp_Pnt2d& theUVScale, + const Handle(Graphic3d_AspectFillCapping)& theCappingStyle, const StdPrs_Volume theVolume) { if (theShape.IsNull()) @@ -555,20 +561,20 @@ void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs, if (aClosed.NbChildren() > 0) { - shadeFromShape (aClosed, thePrs, theDrawer, + shadeFromShape (aClosed, thePrs, theDrawer, theCappingStyle, theHasTexels, theUVOrigin, theUVRepeat, theUVScale, true); } if (anOpened.NbChildren() > 0) { - shadeFromShape (anOpened, thePrs, theDrawer, + shadeFromShape (anOpened, thePrs, theDrawer, theCappingStyle, theHasTexels, theUVOrigin, theUVRepeat, theUVScale, false); } } else { // if the shape type is not compound, composolid or solid, use autodetection back-facing filled - shadeFromShape (theShape, thePrs, theDrawer, + shadeFromShape (theShape, thePrs, theDrawer, theCappingStyle, theHasTexels, theUVOrigin, theUVRepeat, theUVScale, theVolume == StdPrs_Volume_Closed); } diff --git a/src/StdPrs/StdPrs_ShadedShape.hxx b/src/StdPrs/StdPrs_ShadedShape.hxx index cbb2a7df75..d62859041a 100644 --- a/src/StdPrs/StdPrs_ShadedShape.hxx +++ b/src/StdPrs/StdPrs_ShadedShape.hxx @@ -43,13 +43,25 @@ public: //! @param theVolumeType defines the way how to interpret input shapes - as Closed volumes (to activate back-face //! culling and capping plane algorithms), as Open volumes (shells or solids with holes) //! or to perform Autodetection (would split input shape into two groups) - Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation, const TopoDS_Shape& theShape, const Handle(Prs3d_Drawer)& theDrawer, const StdPrs_Volume theVolume = StdPrs_Volume_Autodetection); + Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation, + const TopoDS_Shape& theShape, + const Handle(Prs3d_Drawer)& theDrawer, + const Handle(Graphic3d_AspectFillCapping)& theCappingStyle = Handle(Graphic3d_AspectFillCapping)(), + StdPrs_Volume theVolume = StdPrs_Volume_Autodetection); //! Shades with texture coordinates. //! @param theVolumeType defines the way how to interpret input shapes - as Closed volumes (to activate back-face //! culling and capping plane algorithms), as Open volumes (shells or solids with holes) //! or to perform Autodetection (would split input shape into two groups) - Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation, const TopoDS_Shape& theShape, const Handle(Prs3d_Drawer)& theDrawer, const Standard_Boolean theHasTexels, const gp_Pnt2d& theUVOrigin, const gp_Pnt2d& theUVRepeat, const gp_Pnt2d& theUVScale, const StdPrs_Volume theVolume = StdPrs_Volume_Autodetection); + Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation, + const TopoDS_Shape& theShape, + const Handle(Prs3d_Drawer)& theDrawer, + const Standard_Boolean theHasTexels, + const gp_Pnt2d& theUVOrigin, + const gp_Pnt2d& theUVRepeat, + const gp_Pnt2d& theUVScale, + const Handle(Graphic3d_AspectFillCapping)& theCappingStyle = Handle(Graphic3d_AspectFillCapping)(), + const StdPrs_Volume theVolume = StdPrs_Volume_Autodetection); //! Searches closed and unclosed subshapes in shape structure and puts them //! into two compounds for separate processing of closed and unclosed sub-shapes diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 16777c8487..077a78b3b5 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -8494,7 +8494,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) { - aClipPlane->SetUseObjectMaterial (toEnable == Standard_True); + aClipPlane->CappingSectionStyle()->SetUseObjectMaterial (toEnable == Standard_True); anArgIter += 1; } } @@ -8511,7 +8511,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) { - aClipPlane->SetUseObjectTexture (toEnable == Standard_True); + aClipPlane->CappingSectionStyle()->SetUseObjectTexture (toEnable == Standard_True); anArgIter += 1; } } @@ -8526,7 +8526,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) { - aClipPlane->SetUseObjectShader (toEnable == Standard_True); + aClipPlane->CappingSectionStyle()->SetUseObjectShader (toEnable == Standard_True); anArgIter += 1; } } @@ -8543,10 +8543,10 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons return 1; } - Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); + Graphic3d_MaterialAspect aMat = aClipPlane->CappingSectionStyle()->Material(); aMat.SetAmbientColor (aColor); aMat.SetDiffuseColor (aColor); - aClipPlane->SetCappingMaterial (aMat); + aClipPlane->CappingSectionStyle()->SetMaterial (aMat); anArgIter += aNbParsed; } else if ((aChangeArg == "-transparency" @@ -8554,44 +8554,34 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons && aNbChangeArgs >= 2) { TCollection_AsciiString aValStr (aChangeArgs[1]); - Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect(); if (aValStr.IsRealValue()) { - Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); + Graphic3d_MaterialAspect aMat = aClipPlane->CappingSectionStyle()->Material(); aMat.SetTransparency ((float )aValStr.RealValue()); - anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto); - aClipPlane->SetCappingMaterial (aMat); + aClipPlane->CappingSectionStyle()->SetMaterial (aMat); } else { - aValStr.LowerCase(); - Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto; - if (aValStr == "opaque") - { - aMode = Graphic3d_AlphaMode_Opaque; - } - else if (aValStr == "mask") - { - aMode = Graphic3d_AlphaMode_Mask; - } - else if (aValStr == "blend") - { - aMode = Graphic3d_AlphaMode_Blend; - } - else if (aValStr == "blendauto") - { - aMode = Graphic3d_AlphaMode_BlendAuto; - } - else - { - std::cout << "Syntax error at '" << aValStr << "'\n"; - return 1; - } - anAspect->SetAlphaMode (aMode); - aClipPlane->SetCappingAspect (anAspect); + std::cout << "Syntax error at '" << aValStr << "'\n"; + return 1; } anArgIter += 1; } + else if (aChangeArg == "-overrideaspect" + || aChangeArg == "overrideaspect") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return 1; + } + + if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) + { + aClipPlane->SetToOverrideCappingAspect (toEnable == Standard_True); + anArgIter += 1; + } + } else if (aChangeArg == "-texname" || aChangeArg == "texname") { @@ -8605,20 +8595,22 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); if (!aTexture->IsDone()) { - aClipPlane->SetCappingTexture (NULL); + aClipPlane->CappingSectionStyle()->SetTexture (Handle(Graphic3d_TextureMap)()); } else { aTexture->EnableModulate(); aTexture->EnableRepeat(); - aClipPlane->SetCappingTexture (aTexture); + aClipPlane->CappingSectionStyle()->SetTexture (aTexture.get()); } anArgIter += 1; } else if (aChangeArg == "-texscale" || aChangeArg == "texscale") { - if (aClipPlane->CappingTexture().IsNull()) + const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->Texture(); + + if (aHatchTexture.IsNull()) { std::cout << "Error: no texture is set.\n"; return 1; @@ -8632,13 +8624,15 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); - aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); + aHatchTexture->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); anArgIter += 2; } else if (aChangeArg == "-texorigin" || aChangeArg == "texorigin") // texture origin { - if (aClipPlane->CappingTexture().IsNull()) + const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->Texture(); + + if (aHatchTexture.IsNull()) { std::cout << "Error: no texture is set.\n"; return 1; @@ -8653,13 +8647,15 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); - aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); + aHatchTexture->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); anArgIter += 2; } else if (aChangeArg == "-texrotate" || aChangeArg == "texrotate") // texture rotation { - if (aClipPlane->CappingTexture().IsNull()) + const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->Texture(); + + if (aHatchTexture.IsNull()) { std::cout << "Error: no texture is set.\n"; return 1; @@ -8672,7 +8668,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons } Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); - aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot); + aHatchTexture->GetParams()->SetRotation (aRot); anArgIter += 1; } else if (aChangeArg == "-hatch" @@ -8684,22 +8680,165 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons return 1; } - TCollection_AsciiString aHatchStr (aChangeArgs[1]); - aHatchStr.LowerCase(); - if (aHatchStr == "on") + if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) { - aClipPlane->SetCappingHatchOn(); + aClipPlane->CappingSectionStyle()->SetToDrawHatch (toEnable == Standard_True); + anArgIter += 1; + } + } + else if (aChangeArg == "-hatchtexture" + || aChangeArg == "hatchtexture") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return 1; } - else if (aHatchStr == "off") + + TCollection_AsciiString aTextureName (aChangeArgs[1]); + Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); + if (!aTexture->IsDone()) { - aClipPlane->SetCappingHatchOff(); + aClipPlane->CappingSectionStyle()->SetHatchStyle (Handle(Graphic3d_TextureMap)()); } else { - aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1])); + aTexture->EnableModulate(); + aTexture->EnableRepeat(); + aClipPlane->CappingSectionStyle()->SetHatchStyle (aTexture.get()); + aClipPlane->CappingSectionStyle()->SetToDrawHatch (true); + } + anArgIter += 1; + } + else if (aChangeArg == "-hatchstipple" + || aChangeArg == "hatchstipple") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return 1; } + + aClipPlane->CappingSectionStyle()->SetHatchStyle ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1])); + aClipPlane->CappingSectionStyle()->SetToDrawHatch (true); anArgIter += 1; } + else if (aChangeArg == "-hatchcolor" + || aChangeArg == "hatchcolor") + { + Quantity_Color aColor; + Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1, + aChangeArgs + 1, + aColor); + if (aNbParsed == 0) + { + std::cout << "Syntax error: need more arguments.\n"; + return 1; + } + + Graphic3d_MaterialAspect aMat = aClipPlane->CappingSectionStyle()->HatchMaterial(); + aMat.SetAmbientColor (aColor); + aMat.SetDiffuseColor (aColor); + aClipPlane->CappingSectionStyle()->SetHatchMaterial (aMat); + anArgIter += aNbParsed; + } + + else if (aChangeArg == "-hatchscale" + || aChangeArg == "hatchscale") + { + const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->TextureHatch(); + + if (aHatchTexture.IsNull()) + { + std::cout << "Error: no texture is set.\n"; + return 1; + } + + if (aNbChangeArgs < 3) + { + std::cout << "Syntax error: need more arguments.\n"; + return 1; + } + + Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); + Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); + aHatchTexture->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); + anArgIter += 2; + } + else if (aChangeArg == "-hatchorigin" + || aChangeArg == "hatchorigin") // texture origin + { + const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->TextureHatch(); + + if (aHatchTexture.IsNull()) + { + std::cout << "Error: no texture is set.\n"; + return 1; + } + + if (aNbChangeArgs < 3) + { + std::cout << "Syntax error: need more arguments.\n"; + return 1; + } + + Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); + Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); + + aHatchTexture->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); + anArgIter += 2; + } + else if (aChangeArg == "-hatchrotate" + || aChangeArg == "hatchrotate") // texture rotation + { + const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->TextureHatch(); + + if (aHatchTexture.IsNull()) + { + std::cout << "Error: no texture is set.\n"; + return 1; + } + + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return 1; + } + + Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); + aHatchTexture->GetParams()->SetRotation (aRot); + anArgIter += 1; + } + else if (aChangeArg == "-hatchzoompers" + || aChangeArg == "hatchzoompers") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return 1; + } + + if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) + { + aClipPlane->CappingSectionStyle()->SetHatchZoomPeristent (toEnable == Standard_True); + anArgIter += 1; + } + } + else if (aChangeArg == "-hatchrotatepers" + || aChangeArg == "hatchrotatepers") + { + if (aNbChangeArgs < 2) + { + std::cout << "Syntax error: need more arguments.\n"; + return 1; + } + + if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) + { + aClipPlane->CappingSectionStyle()->SetHatchRotationPeristent (toEnable == Standard_True); + anArgIter += 1; + } + } else if (aChangeArg == "-delete" || aChangeArg == "delete") { @@ -12616,6 +12755,16 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]" "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]" "\n\t\t: [-texRotate Angle]" + /*"\n\t\t: [-overrideAspect {0|1}]" + "\n\t\t: [-color R G B]" + "\n\t\t: [-texture Texture] [-texScale SX SY]" + "\n\t\t: [-texOrigin TX TY] [-texRotate Angle]" + "\n\t\t: [-hatch {on|off}] [-hatchStipple mask]" + "\n\t\t: [-hatchColor R G B] [-hatchTexture texture]" + "\n\t\t: [-hatchScale SX SY] [-hatchOrigin TX TY]" + "\n\t\t: [-hatchRotate Angle]" + "\n\t\t: [-hatchZoomPers {0|1}]" + "\n\t\t: [-hatchRotatePers {0|1}]"*/ "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]" "\n\t\t: [-useObjShader {0|1}]" "\n\t\t: Clipping planes management:" @@ -12628,13 +12777,22 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) "\n\t\t: -clone SourcePlane NewPlane clone the plane definition." "\n\t\t: Capping options:" "\n\t\t: -capping {off|on|0|1} turn capping on/off" + "\n\t\t: -overrideAspect override presentation aspect (if defined)" "\n\t\t: -color R G B set capping color" "\n\t\t: -transparency Value set capping transparency 0..1" "\n\t\t: -texName Texture set capping texture" "\n\t\t: -texScale SX SY set capping tex scale" "\n\t\t: -texOrigin TX TY set capping tex origin" "\n\t\t: -texRotate Angle set capping tex rotation" - "\n\t\t: -hatch {on|off|ID} set capping hatching mask" + "\n\t\t: -hatch {on|off} turn on/off hatch style on capping" + "\n\t\t: -hatchStipple ID set stipple mask for drawing hatch" + "\n\t\t: -hatchColor R G B set color for hatch material" + "\n\t\t: -hatchTexture Texture set texture (semi-opaque) for drawing hatch" + "\n\t\t: -hatchScale SX SY set hatch texture scale" + "\n\t\t: -hatchOrigin TX TY set hatch texture origin" + "\n\t\t: -hatchRotate Angle set hatch texture rotation" + "\n\t\t: -hatchZoomPers allow hatch tetxure mapping to be constant when zooming" + "\n\t\t: -hatchRotatePers allow hatch tetxure mapping to be constant when rotating" "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object" "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object" "\n\t\t: -useObjShader {off|on|0|1} use shader program of object", diff --git a/tests/bugs/vis/bug24224 b/tests/bugs/vis/bug24224 index 8ba33feb3b..17893134e4 100644 --- a/tests/bugs/vis/bug24224 +++ b/tests/bugs/vis/bug24224 @@ -46,6 +46,7 @@ vclipplane change pln2 equation -0.707 0.707 0 -25 vclipplane change pln2 capping on vclipplane change pln2 capping color 0.5 0.5 0.9 vclipplane change pln2 capping hatch on +vclipplane change pln2 capping hatchStipple 7 vclipplane set pln2 object b3 checkcolor $x3_coord $y3_coord 0.5 0.5 0.9 diff --git a/tests/bugs/vis/bug27751_capping b/tests/bugs/vis/bug27751_capping index 122c566446..10333acdff 100644 --- a/tests/bugs/vis/bug27751_capping +++ b/tests/bugs/vis/bug27751_capping @@ -72,5 +72,5 @@ vdisplay pp1 pp2 vzoom 0.8 puts "Enable capping planes" -vclipplane pln1 -set -equation 0 0 -1 $aPln1Z -capping 1 -color 0.5 0.5 0.5 -texname $aHatch -texscale 0.02 -0.02 -useObjMaterial 1 -vclipplane pln2 -set -equation 0 1 0 [expr -$aPln2Y] -capping 1 -color 0.8 0.8 0.9 -texname $aHatch -texscale 0.02 -0.02 +vclipplane pln1 -set -equation 0 0 -1 $aPln1Z -capping 1 -color 0.5 0.5 0.5 -hatchtexture $aHatch -hatchscale 0.02 -0.02 -useObjMaterial 1 +vclipplane pln2 -set -equation 0 1 0 [expr -$aPln2Y] -capping 1 -color 0.8 0.8 0.9 -hatchtexture $aHatch -hatchscale 0.02 -0.02