mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0029097: Visualization - allow picking Graphic3d_TypeOfShadingModel per-object
Graphic3d_AspectFillArea3d has been extended by new property ::ShadingModel(), which is set to Graphic3d_TOSM_DEFAULT by default. The new API allows assigning Shading Model to specific Primitive Array groups instead of entire Viewer, which was the only possibility before. Graphic3d_TypeOfShadingModel has been extended with Graphic3d_TOSM_DEFAULT value meaining that Shading Model defined as default for the Viewer should be used. Graphic3d_TOSM_NONE has been renamed to Graphic3d_TOSM_UNLIT. Documentation of Shading Models has been improved by more details. V3d_TypeOfShadingModel enumeration has been merged into Graphic3d_TypeOfShadingModel avoiding duplicated definitions and confusion. Old values has been left for compatibility with old code and can be marked deprecated in future. Draw Harness command vaspects has been extended by new argument -setShadingModel for testing Shading Models assigned to entire objects. OpenGl_SetOfShaderPrograms now holds an array of Shading Models. OpenGl_ShaderManager interface has been modified and now requires enumeration as input in several places where Boolean flags have been used previously (methods ::BindFaceProgram(), ::BindLineProgram(), ::BindMarkerProgram()). OpenGl_Workspace now defines default (undefined) OpenGl_AspectFace as Graphic3d_TOSM_UNLIT to simplify indication of primitive groups with undefined Fill Area aspects, and so that Graphic3d_TOSM_UNLIT set as default Shading Model will not make artifacts on Lines and Markers. AIS_Manipulator::Axis::Compute() - added missing initialization of Fill Area aspects (leading to undefined behavior).
This commit is contained in:
@@ -330,6 +330,60 @@ Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg,
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ParseShadingModel
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString theArg,
|
||||
Graphic3d_TypeOfShadingModel& theModel)
|
||||
{
|
||||
TCollection_AsciiString aTypeStr (theArg);
|
||||
aTypeStr.LowerCase();
|
||||
if (aTypeStr == "unlit"
|
||||
|| aTypeStr == "color"
|
||||
|| aTypeStr == "none")
|
||||
{
|
||||
theModel = Graphic3d_TOSM_UNLIT;
|
||||
}
|
||||
else if (aTypeStr == "flat"
|
||||
|| aTypeStr == "facet")
|
||||
{
|
||||
theModel = Graphic3d_TOSM_FACET;
|
||||
}
|
||||
else if (aTypeStr == "gouraud"
|
||||
|| aTypeStr == "vertex"
|
||||
|| aTypeStr == "vert")
|
||||
{
|
||||
theModel = Graphic3d_TOSM_VERTEX;
|
||||
}
|
||||
else if (aTypeStr == "phong"
|
||||
|| aTypeStr == "fragment"
|
||||
|| aTypeStr == "frag"
|
||||
|| aTypeStr == "pixel")
|
||||
{
|
||||
theModel = Graphic3d_TOSM_FRAGMENT;
|
||||
}
|
||||
else if (aTypeStr == "default"
|
||||
|| aTypeStr == "def")
|
||||
{
|
||||
theModel = Graphic3d_TOSM_DEFAULT;
|
||||
}
|
||||
else if (aTypeStr.IsIntegerValue())
|
||||
{
|
||||
const int aTypeInt = aTypeStr.IntegerValue();
|
||||
if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB)
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
theModel = (Graphic3d_TypeOfShadingModel)aTypeInt;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetTypeNames
|
||||
//purpose :
|
||||
@@ -1618,52 +1672,56 @@ static int VSetInteriorStyle (Draw_Interpretor& theDI,
|
||||
//! Auxiliary structure for VAspects
|
||||
struct ViewerTest_AspectsChangeSet
|
||||
{
|
||||
Standard_Integer ToSetVisibility;
|
||||
Standard_Integer Visibility;
|
||||
Standard_Integer ToSetVisibility;
|
||||
Standard_Integer Visibility;
|
||||
|
||||
Standard_Integer ToSetColor;
|
||||
Quantity_Color Color;
|
||||
Standard_Integer ToSetColor;
|
||||
Quantity_Color Color;
|
||||
|
||||
Standard_Integer ToSetLineWidth;
|
||||
Standard_Real LineWidth;
|
||||
Standard_Integer ToSetLineWidth;
|
||||
Standard_Real LineWidth;
|
||||
|
||||
Standard_Integer ToSetTypeOfLine;
|
||||
Aspect_TypeOfLine TypeOfLine;
|
||||
Standard_Integer ToSetTypeOfLine;
|
||||
Aspect_TypeOfLine TypeOfLine;
|
||||
|
||||
Standard_Integer ToSetTypeOfMarker;
|
||||
Aspect_TypeOfMarker TypeOfMarker;
|
||||
Handle(Image_PixMap) MarkerImage;
|
||||
Standard_Integer ToSetTypeOfMarker;
|
||||
Aspect_TypeOfMarker TypeOfMarker;
|
||||
Handle(Image_PixMap) MarkerImage;
|
||||
|
||||
Standard_Integer ToSetMarkerSize;
|
||||
Standard_Real MarkerSize;
|
||||
Standard_Integer ToSetMarkerSize;
|
||||
Standard_Real MarkerSize;
|
||||
|
||||
Standard_Integer ToSetTransparency;
|
||||
Standard_Real Transparency;
|
||||
Standard_Integer ToSetTransparency;
|
||||
Standard_Real Transparency;
|
||||
|
||||
Standard_Integer ToSetMaterial;
|
||||
Graphic3d_NameOfMaterial Material;
|
||||
TCollection_AsciiString MatName;
|
||||
Standard_Integer ToSetMaterial;
|
||||
Graphic3d_NameOfMaterial Material;
|
||||
TCollection_AsciiString MatName;
|
||||
|
||||
NCollection_Sequence<TopoDS_Shape> SubShapes;
|
||||
|
||||
Standard_Integer ToSetShowFreeBoundary;
|
||||
Standard_Integer ToSetFreeBoundaryWidth;
|
||||
Standard_Real FreeBoundaryWidth;
|
||||
Standard_Integer ToSetFreeBoundaryColor;
|
||||
Quantity_Color FreeBoundaryColor;
|
||||
Standard_Integer ToSetShowFreeBoundary;
|
||||
Standard_Integer ToSetFreeBoundaryWidth;
|
||||
Standard_Real FreeBoundaryWidth;
|
||||
Standard_Integer ToSetFreeBoundaryColor;
|
||||
Quantity_Color FreeBoundaryColor;
|
||||
|
||||
Standard_Integer ToEnableIsoOnTriangulation;
|
||||
Standard_Integer ToEnableIsoOnTriangulation;
|
||||
|
||||
Standard_Integer ToSetMaxParamValue;
|
||||
Standard_Real MaxParamValue;
|
||||
Standard_Integer ToSetMaxParamValue;
|
||||
Standard_Real MaxParamValue;
|
||||
|
||||
Standard_Integer ToSetSensitivity;
|
||||
Standard_Integer SelectionMode;
|
||||
Standard_Integer Sensitivity;
|
||||
Standard_Integer ToSetSensitivity;
|
||||
Standard_Integer SelectionMode;
|
||||
Standard_Integer Sensitivity;
|
||||
|
||||
Standard_Integer ToSetHatch;
|
||||
Standard_Integer StdHatchStyle;
|
||||
TCollection_AsciiString PathToHatchPattern;
|
||||
Standard_Integer ToSetHatch;
|
||||
Standard_Integer StdHatchStyle;
|
||||
TCollection_AsciiString PathToHatchPattern;
|
||||
|
||||
Standard_Integer ToSetShadingModel;
|
||||
Graphic3d_TypeOfShadingModel ShadingModel;
|
||||
TCollection_AsciiString ShadingModelName;
|
||||
|
||||
//! Empty constructor
|
||||
ViewerTest_AspectsChangeSet()
|
||||
@@ -1689,13 +1747,15 @@ struct ViewerTest_AspectsChangeSet
|
||||
ToSetFreeBoundaryColor (0),
|
||||
FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
|
||||
ToEnableIsoOnTriangulation (-1),
|
||||
ToSetMaxParamValue (0),
|
||||
MaxParamValue (500000),
|
||||
ToSetSensitivity (0),
|
||||
SelectionMode (-1),
|
||||
Sensitivity (-1),
|
||||
ToSetHatch (0),
|
||||
StdHatchStyle (-1)
|
||||
ToSetMaxParamValue (0),
|
||||
MaxParamValue (500000),
|
||||
ToSetSensitivity (0),
|
||||
SelectionMode (-1),
|
||||
Sensitivity (-1),
|
||||
ToSetHatch (0),
|
||||
StdHatchStyle (-1),
|
||||
ToSetShadingModel (0),
|
||||
ShadingModel (Graphic3d_TOSM_DEFAULT)
|
||||
{}
|
||||
|
||||
//! @return true if no changes have been requested
|
||||
@@ -1711,7 +1771,8 @@ struct ViewerTest_AspectsChangeSet
|
||||
&& ToSetFreeBoundaryWidth == 0
|
||||
&& ToSetMaxParamValue == 0
|
||||
&& ToSetSensitivity == 0
|
||||
&& ToSetHatch == 0;
|
||||
&& ToSetHatch == 0
|
||||
&& ToSetShadingModel == 0;
|
||||
}
|
||||
|
||||
//! @return true if properties are valid
|
||||
@@ -1768,6 +1829,12 @@ struct ViewerTest_AspectsChangeSet
|
||||
std::cout << "Error: hatch style must be specified\n";
|
||||
isOk = Standard_False;
|
||||
}
|
||||
if (ToSetShadingModel == 1
|
||||
&& (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
|
||||
{
|
||||
std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
|
||||
isOk = Standard_False;
|
||||
}
|
||||
return isOk;
|
||||
}
|
||||
|
||||
@@ -2321,6 +2388,8 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
|
||||
aChangeSet->ToSetHatch = -1;
|
||||
aChangeSet->StdHatchStyle = -1;
|
||||
aChangeSet->PathToHatchPattern.Clear();
|
||||
aChangeSet->ToSetShadingModel = -1;
|
||||
aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
|
||||
}
|
||||
else if (anArg == "-isoontriangulation"
|
||||
|| anArg == "-isoontriang")
|
||||
@@ -2413,6 +2482,26 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
|
||||
aChangeSet->PathToHatchPattern = anArgHatch;
|
||||
}
|
||||
}
|
||||
else if (anArg == "-setshadingmodel")
|
||||
{
|
||||
if (++anArgIter >= theArgNb)
|
||||
{
|
||||
std::cout << "Error: wrong syntax at " << anArg << "\n";
|
||||
return 1;
|
||||
}
|
||||
aChangeSet->ToSetShadingModel = 1;
|
||||
aChangeSet->ShadingModelName = theArgVec[anArgIter];
|
||||
if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
|
||||
{
|
||||
std::cout << "Error: wrong syntax at " << anArg << "\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (anArg == "-unsetshadingmodel")
|
||||
{
|
||||
aChangeSet->ToSetShadingModel = -1;
|
||||
aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Error: wrong syntax at " << anArg << "\n";
|
||||
@@ -2504,6 +2593,10 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
|
||||
{
|
||||
aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
|
||||
}
|
||||
if (aChangeSet->ToSetShadingModel == 1)
|
||||
{
|
||||
aDrawer->ShadingAspect()->Aspect()->SetShadingModel (aChangeSet->ShadingModel);
|
||||
}
|
||||
|
||||
// redisplay all objects in context
|
||||
for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
|
||||
@@ -2699,6 +2792,11 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
|
||||
}
|
||||
toRedisplay = Standard_True;
|
||||
}
|
||||
if (aChangeSet->ToSetShadingModel != 0)
|
||||
{
|
||||
aDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
|
||||
toRedisplay = Standard_True;
|
||||
}
|
||||
}
|
||||
|
||||
for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
|
||||
@@ -2735,6 +2833,11 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
|
||||
{
|
||||
aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
|
||||
}
|
||||
if (aChangeSet->ToSetShadingModel != 0)
|
||||
{
|
||||
Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
|
||||
aCurColDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toDisplay)
|
||||
@@ -6235,6 +6338,8 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
|
||||
"\n\t\t: [-setMaxParamValue {value}]"
|
||||
"\n\t\t: [-setSensitivity {selection_mode} {value}]"
|
||||
"\n\t\t: [-setHatch HatchStyle]"
|
||||
"\n\t\t: [-setShadingModel {color|flat|gouraud|phong}]"
|
||||
"\n\t\t: [-unsetShadingModel]"
|
||||
"\n\t\t: Manage presentation properties of all, selected or named objects."
|
||||
"\n\t\t: When -subshapes is specified than following properties will be"
|
||||
"\n\t\t: assigned to specified sub-shapes."
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include <Aspect_TypeOfLine.hxx>
|
||||
#include <Aspect_TypeOfMarker.hxx>
|
||||
#include <Draw_Interpretor.hxx>
|
||||
#include <Graphic3d_TypeOfShadingModel.hxx>
|
||||
#include <Standard_Integer.hxx>
|
||||
#include <Standard_CString.hxx>
|
||||
#include <Standard_DefineAlloc.hxx>
|
||||
@@ -200,6 +201,11 @@ public:
|
||||
Aspect_TypeOfMarker& theType,
|
||||
Handle(Image_PixMap)& theImage);
|
||||
|
||||
//! Parses shading model argument.
|
||||
//! Handles either enumeration (integer) value or string constant.
|
||||
Standard_EXPORT static Standard_Boolean ParseShadingModel (Standard_CString theArg,
|
||||
Graphic3d_TypeOfShadingModel& theModel);
|
||||
|
||||
private:
|
||||
|
||||
//! Returns a window class that implements standard behavior of
|
||||
|
@@ -164,7 +164,7 @@ void VUserDrawObj::Render(const Handle(OpenGl_Workspace)& theWorkspace) const
|
||||
aTA->Aspect()->Font();
|
||||
OpenGl_Vec4 aColor = theWorkspace->LineColor();
|
||||
|
||||
aCtx->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(), false, false, false, Handle(OpenGl_ShaderProgram)());
|
||||
aCtx->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(), Aspect_TOL_SOLID, Graphic3d_TOSM_UNLIT, false, Handle(OpenGl_ShaderProgram)());
|
||||
aCtx->SetColor4fv (aColor);
|
||||
|
||||
const OpenGl_Vec3 aVertArray[4] =
|
||||
|
@@ -10020,10 +10020,11 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
|
||||
theDI << "shadingModel: ";
|
||||
switch (aView->ShadingModel())
|
||||
{
|
||||
case V3d_COLOR: theDI << "color"; break;
|
||||
case V3d_FLAT: theDI << "flat"; break;
|
||||
case V3d_GOURAUD: theDI << "gouraud"; break;
|
||||
case V3d_PHONG: theDI << "phong"; break;
|
||||
case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
|
||||
case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
|
||||
case Graphic3d_TOSM_FACET: theDI << "flat"; break;
|
||||
case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
|
||||
case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
|
||||
}
|
||||
{
|
||||
theDI << "perfCounters:";
|
||||
@@ -10496,10 +10497,11 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
|
||||
{
|
||||
switch (aView->ShadingModel())
|
||||
{
|
||||
case V3d_COLOR: theDI << "color "; break;
|
||||
case V3d_FLAT: theDI << "flat "; break;
|
||||
case V3d_GOURAUD: theDI << "gouraud "; break;
|
||||
case V3d_PHONG: theDI << "phong "; break;
|
||||
case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
|
||||
case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
|
||||
case Graphic3d_TOSM_FACET: theDI << "flat "; break;
|
||||
case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
|
||||
case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -10509,34 +10511,15 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
|
||||
std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
|
||||
}
|
||||
|
||||
TCollection_AsciiString aMode (theArgVec[anArgIter]);
|
||||
aMode.LowerCase();
|
||||
if (aMode == "color"
|
||||
|| aMode == "none")
|
||||
Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
|
||||
if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
|
||||
&& aModel != Graphic3d_TOSM_DEFAULT)
|
||||
{
|
||||
aView->SetShadingModel (V3d_COLOR);
|
||||
}
|
||||
else if (aMode == "flat"
|
||||
|| aMode == "facet")
|
||||
{
|
||||
aView->SetShadingModel (V3d_FLAT);
|
||||
}
|
||||
else if (aMode == "gouraud"
|
||||
|| aMode == "vertex"
|
||||
|| aMode == "vert")
|
||||
{
|
||||
aView->SetShadingModel (V3d_GOURAUD);
|
||||
}
|
||||
else if (aMode == "phong"
|
||||
|| aMode == "fragment"
|
||||
|| aMode == "frag"
|
||||
|| aMode == "pixel")
|
||||
{
|
||||
aView->SetShadingModel (V3d_PHONG);
|
||||
aView->SetShadingModel (aModel);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Error: unknown shading model '" << aMode << "'\n";
|
||||
std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user