]> OCCT Git - occt-copy.git/commitdiff
0023854: Possibility to apply individual transformation to Graphic3d_Group instance
authornds <natalia.ermolaeva@opencascade.com>
Mon, 8 Jun 2020 07:09:58 +0000 (10:09 +0300)
committernds <nds@opencascade.com>
Wed, 13 Jan 2021 22:12:38 +0000 (01:12 +0300)
(cherry picked from commit e50bf38102e562ae74c9c1fdfd13145e072b4615)
(cherry picked from commit 90c3cbae8186a83cecf2115692e744172413b4b2)
(cherry picked from commit 180c8e569284de1f3c93131a2c64e414ed9535ad)
(cherry picked from commit 1594b4de4b2e6565454f847a08180058ec9cbc56)
(cherry picked from commit 2e30d74ef8b4339ba341e79a068f703947e9d664)

src/Graphic3d/Graphic3d_Group.hxx
src/OpenGl/OpenGl_Structure.cxx
src/OpenGl/OpenGl_Structure.hxx

index 022656245db54a1004ca7a07c9221715e1e590d5..ebdd6e3a7fb047ccd5668ae325144ca2c79ebc62 100644 (file)
@@ -32,6 +32,7 @@
 #include <Graphic3d_IndexBuffer.hxx>
 #include <Graphic3d_Buffer.hxx>
 #include <Graphic3d_BoundBuffer.hxx>
+#include <Graphic3d_TransformPers.hxx>
 #include <gp_Ax2.hxx>
 #include <TCollection_ExtendedString.hxx>
 
@@ -140,6 +141,12 @@ public:
   //! sets the flipping to theIsEnabled state.
   Standard_EXPORT virtual void SetFlippingOptions (const Standard_Boolean theIsEnabled, const gp_Ax2& theRefPlane) = 0;
 
+  //! Return transformation persistence.
+  const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myTrsfPers; }
+
+  //! Set transformation persistence.
+  virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { myTrsfPers = theTrsfPers; }
+
   //! Returns true if the group contains Polygons, Triangles or Quadrangles.
   bool ContainsFacet() const { return myContainsFacet; }
 
@@ -294,6 +301,7 @@ protected:
 
 protected:
 
+  Handle(Graphic3d_TransformPers) myTrsfPers; //!< current transform persistence
   Graphic3d_Structure* myStructure;     //!< pointer to the parent structure
   Graphic3d_BndBox4f   myBounds;        //!< bounding box
   bool                 myIsClosed;      //!< flag indicating closed volume
index b7533c16ffd00a68b526d50e42902d85978e99c0..2fc4f91b412e81e148338ecc418f4dcfd918bd46 100644 (file)
@@ -389,10 +389,22 @@ void OpenGl_Structure::renderGeometry (const Handle(OpenGl_Workspace)& theWorksp
     myInstancedStructure->renderGeometry (theWorkspace, theHasClosed);
   }
 
+  const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
   for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
   {
+    Handle(Graphic3d_TransformPers) aTrsfPersistence = aGroupIter.Value()->TransformPersistence();
+    if (!aTrsfPersistence.IsNull())
+    {
+      applyPersistence (aCtx, aTrsfPersistence, Standard_True);
+    }
+
     theHasClosed = theHasClosed || aGroupIter.Value()->IsClosed();
     aGroupIter.Value()->Render (theWorkspace);
+
+    if (!aTrsfPersistence.IsNull())
+    {
+      applyPersistence (aCtx, aTrsfPersistence, Standard_False);
+    }
   }
 }
 
@@ -437,23 +449,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con
 
   if (!myTrsfPers.IsNull())
   {
-    aCtx->WorldViewState.Push();
-    OpenGl_Mat4& aWorldView = aCtx->WorldViewState.ChangeCurrent();
-    myTrsfPers->Apply (aCtx->Camera(),
-                       aCtx->ProjectionState.Current(), aWorldView,
-                       aCtx->VirtualViewport()[2], aCtx->VirtualViewport()[3]);
-
-  #if !defined(GL_ES_VERSION_2_0)
-    if (!aCtx->IsGlNormalizeEnabled()
-      && aCtx->core11 != NULL)
-    {
-      const Standard_Real aScale = Graphic3d_TransformUtils::ScaleFactor<Standard_ShortReal> (aWorldView);
-      if (Abs (aScale - 1.0) > Precision::Confusion())
-      {
-        aCtx->SetGlNormalizeEnabled (Standard_True);
-      }
-    }
-  #endif
+    applyPersistence (aCtx, myTrsfPers, Standard_True);
   }
 
   // Take into account transform persistence
@@ -602,7 +598,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con
 
   if (!myTrsfPers.IsNull())
   {
-    aCtx->WorldViewState.Pop();
+    applyPersistence (aCtx, myTrsfPers, Standard_False);
   }
 
   // Restore named status
@@ -641,6 +637,40 @@ Handle(Graphic3d_CStructure) OpenGl_Structure::ShadowLink (const Handle(Graphic3
   return new OpenGl_StructureShadow (theManager, this);
 }
 
+// =======================================================================
+// function : applyPersistence
+// purpose  :
+// =======================================================================
+void OpenGl_Structure::applyPersistence (const Handle(OpenGl_Context)& theContext,
+                                         const Handle(Graphic3d_TransformPers)& theTrsfPersistence,
+                                         const Standard_Boolean toEnable) const
+{
+  if (toEnable)
+  {
+    theContext->WorldViewState.Push();
+    OpenGl_Mat4& aWorldView = theContext->WorldViewState.ChangeCurrent();
+    theTrsfPersistence->Apply (theContext->Camera(),
+                               theContext->ProjectionState.Current(), aWorldView,
+                               theContext->VirtualViewport()[2], theContext->VirtualViewport()[3]);
+
+  #if !defined(GL_ES_VERSION_2_0)
+    if (!theContext->IsGlNormalizeEnabled()
+      && theContext->core11 != NULL)
+    {
+      const Standard_Real aScale = Graphic3d_TransformUtils::ScaleFactor<Standard_ShortReal> (aWorldView);
+      if (Abs (aScale - 1.0) > Precision::Confusion())
+      {
+        theContext->SetGlNormalizeEnabled (Standard_True);
+      }
+    }
+  #endif
+  }
+  else
+  {
+    theContext->WorldViewState.Pop();
+  }
+}
+
 //=======================================================================
 //function : DumpJson
 //purpose  : 
index b031d31036fe4f7cd1b496bde525988d660c03ec..b9ba4130b07ec1c4b35f74c465e56334961514a7 100644 (file)
@@ -147,6 +147,15 @@ protected:
   //! Render the bounding box.
   Standard_EXPORT void renderBoundingBox(const Handle(OpenGl_Workspace)& theWorkspace) const;
 
+
+  //! Apply transform persistence into context.
+  //! @param theWorkspace current workspace
+  //! @param theTrsfPersistence transform persistence
+  //! @param toEnable flag to switch ON/OFF persistence
+  Standard_EXPORT void applyPersistence (const Handle(OpenGl_Context)& theContext,
+                                         const Handle(Graphic3d_TransformPers)& theTrsfPersistence,
+                                         const Standard_Boolean toEnable) const;
+
 protected:
 
   OpenGl_Structure*          myInstancedStructure;