#include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_AspectMarker3d.hxx>
#include <Graphic3d_ClipPlane.hxx>
+#include <Graphic3d_CubeMapPacked.hxx>
+#include <Graphic3d_CubeMapSeparate.hxx>
#include <Graphic3d_GraduatedTrihedron.hxx>
#include <Graphic3d_NameOfTextureEnv.hxx>
#include <Graphic3d_Texture2Dmanual.hxx>
// Defines possible commands related to background changing
enum BackgroundCommand
{
- BackgroundCommand_Main, //!< The main command that manages other commands through options
- BackgroundCommand_Image, //!< Sets an image as a background
- BackgroundCommand_ImageMode, //!< Changes a background image mode
- BackgroundCommand_Gradient, //!< Sets a gradient as a background
- BackgroundCommand_GradientMode, //!< Changes a background gradient mode
- BackgroundCommand_Color, //!< Fills background with a specified color
- BackgroundCommand_Default //!< Sets the background default color or gradient
+ BackgroundCommand_Main, //!< The main command that manages other commands through options
+ BackgroundCommand_Image, //!< Sets an image as a background
+ BackgroundCommand_ImageMode, //!< Changes a background image mode
+ BackgroundCommand_Gradient, //!< Sets a gradient as a background
+ BackgroundCommand_GradientMode, //!< Changes a background gradient mode
+ BackgroundCommand_Color, //!< Fills background with a specified color
+ BackgroundCommand_Default //!< Sets the background default color or gradient
};
//! Map from background command names to its codes
static BackgroundCommandNameMap createBackgroundCommandNameMap()
{
BackgroundCommandNameMap aBackgroundCommandNameMap;
- aBackgroundCommandNameMap["vbackground"] = BackgroundCommand_Main;
- aBackgroundCommandNameMap["vsetbg"] = BackgroundCommand_Image;
- aBackgroundCommandNameMap["vsetbgmode"] = BackgroundCommand_ImageMode;
- aBackgroundCommandNameMap["vsetgradientbg"] = BackgroundCommand_Gradient;
- aBackgroundCommandNameMap["vsetgrbgmode"] = BackgroundCommand_GradientMode;
- aBackgroundCommandNameMap["vsetcolorbg"] = BackgroundCommand_Color;
- aBackgroundCommandNameMap["vsetdefaultbg"] = BackgroundCommand_Default;
+ aBackgroundCommandNameMap["vbackground"] = BackgroundCommand_Main;
+ aBackgroundCommandNameMap["vsetbg"] = BackgroundCommand_Image;
+ aBackgroundCommandNameMap["vsetbgmode"] = BackgroundCommand_ImageMode;
+ aBackgroundCommandNameMap["vsetgradientbg"] = BackgroundCommand_Gradient;
+ aBackgroundCommandNameMap["vsetgrbgmode"] = BackgroundCommand_GradientMode;
+ aBackgroundCommandNameMap["vsetcolorbg"] = BackgroundCommand_Color;
+ aBackgroundCommandNameMap["vsetdefaultbg"] = BackgroundCommand_Default;
return aBackgroundCommandNameMap;
}
//! the option key for the command that sets default background gradient or color
ViewerTest_CommandOptionKey myDefaultOptionKey;
+ //! the option key for the command that sets an environment cubemap as a background
+ ViewerTest_CommandOptionKey myCubeMapOptionKey;
+
+ //! the option key for the command that defines order of tiles in one image packed cubemap
+ ViewerTest_CommandOptionKey myCubeMapOrderOptionKey;
+
+ //! the option key for the command that sets inversion of Z axis for background cubemap
+ ViewerTest_CommandOptionKey myCubeMapInvertedZOptionKey;
+
//! the variable set of options that are allowed for the old scenario (without any option passed)
CommandOptionKeyVariableSet myUnnamedOptionVariableSet;
+ //! the variable set of options that are allowed for setting an environment cubemap as background
+ CommandOptionKeyVariableSet myCubeMapOptionVariableSet;
+
//! the variable set of options that are allowed for setting an image as a background
CommandOptionKeyVariableSet myImageOptionVariableSet;
"DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, CORNER4");
myColorOptionKey = myCommandParser.AddOption ("color|col", "background color");
myDefaultOptionKey = myCommandParser.AddOption ("default|def", "sets background default gradient or color");
+
+ myCubeMapOptionKey = myCommandParser.AddOption ("cubemap|cmap|cm", "background cubemap");
+ myCubeMapOrderOptionKey = myCommandParser.AddOption ("order|o", "order of sides in one image packed cubemap");
+ myCubeMapInvertedZOptionKey = myCommandParser.AddOption (
+ "invertedz|invz|iz", "whether Z axis is inverted or not during background cubemap rendering");
}
//! Creates option sets used to determine if a passed option set is valid or not
anUnnamedOptionSet.insert (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY);
myUnnamedOptionVariableSet = CommandOptionKeyVariableSet (anUnnamedOptionSet);
+ ViewerTest_CommandOptionKeySet aCubeMapOptionSet;
+ aCubeMapOptionSet.insert (myCubeMapOptionKey);
+ ViewerTest_CommandOptionKeySet aCubeMapAdditionalOptionKeySet;
+ aCubeMapAdditionalOptionKeySet.insert (myCubeMapInvertedZOptionKey);
+ aCubeMapAdditionalOptionKeySet.insert (myCubeMapOrderOptionKey);
+ myCubeMapOptionVariableSet = CommandOptionKeyVariableSet (aCubeMapOptionSet, aCubeMapAdditionalOptionKeySet);
+
ViewerTest_CommandOptionKeySet anImageOptionSet;
anImageOptionSet.insert (myImageOptionKey);
ViewerTest_CommandOptionKeySet anImageModeOptionSet;
{
const bool isMain = (theBackgroundCommand == BackgroundCommand_Main);
const ViewerTest_CommandOptionKeySet aUsedOptions = myCommandParser.GetUsedOptions();
+ if (myCubeMapOptionVariableSet.IsInSet (aUsedOptions) && isMain)
+ {
+ return processCubeMapOptionSet();
+ }
if (myImageOptionVariableSet.IsInSet (aUsedOptions)
&& (isMain || (theBackgroundCommand == BackgroundCommand_Image)))
{
return false;
}
+ //! Process the cubemap option set in named and unnamed case.
+ //! @return true if processing was successful, or false otherwise
+ bool processCubeMapOptionSet() const
+ {
+ NCollection_Array1<TCollection_AsciiString> aFilePaths;
+
+ if (!processCubeMapOptions (aFilePaths))
+ {
+ return false;
+ }
+
+ Graphic3d_CubeMapOrder anOrder = Graphic3d_CubeMapOrder::Default();
+
+ if (myCommandParser.HasOption (myCubeMapOrderOptionKey))
+ {
+ if (!processCubeMapOrderOptions (anOrder))
+ {
+ return false;
+ }
+ }
+
+ bool aZIsInverted = false;
+ if (myCommandParser.HasOption (myCubeMapInvertedZOptionKey))
+ {
+ if (!processCubeMapInvertedZOptionSet())
+ {
+ return false;
+ }
+ aZIsInverted = true;
+ }
+
+ setCubeMap (aFilePaths, anOrder.Validated(), aZIsInverted);
+ return true;
+ }
+
//! Processes the image option set
//! @return true if processing was successful, or false otherwise
bool processImageOptionSet() const
return printHelp (theBackgroundCommandName, theDrawInterpretor);
}
+ //! Processes the cubemap option
+ //! @param theFilePaths the array of filenames of cubemap sides
+ //! @return true if processing was successful, or false otherwise
+ bool processCubeMapOptions (NCollection_Array1<TCollection_AsciiString> &theFilePaths) const
+ {
+ const Standard_Integer aNumberOfCubeMapOptionArguments = myCommandParser.GetNumberOfOptionArguments (myCubeMapOptionKey);
+
+ if (aNumberOfCubeMapOptionArguments != 1
+ && aNumberOfCubeMapOptionArguments != 6)
+ {
+ return false;
+ }
+
+ theFilePaths.Resize(0, aNumberOfCubeMapOptionArguments - 1, Standard_False);
+
+ for (int i = 0; i < aNumberOfCubeMapOptionArguments; ++i)
+ {
+ std::string aCubeMapFileName;
+ if (!myCommandParser.Arg (myCubeMapOptionKey, i, aCubeMapFileName))
+ {
+ return false;
+ }
+ theFilePaths[i] = aCubeMapFileName.c_str();
+ }
+
+ return true;
+ }
+
+ //! Processes the cubemap option
+ //! @param theIsNeededToRedraw defines need of redraw after option's processing
+ //! @return true if processing was successful, or false otherwise
+ bool processCubeMapInvertedZOptionSet () const
+ {
+ const Standard_Integer aNumberOfCubeMapZInversionOptionArguments =
+ myCommandParser.GetNumberOfOptionArguments (myCubeMapInvertedZOptionKey);
+
+ if (aNumberOfCubeMapZInversionOptionArguments != 0)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ //! Processes the tiles order option
+ //! @param theOrder the array of indexes if cubemap sides in tile grid
+ //! @return true if processing was successful, or false otherwise
+ bool processCubeMapOrderOptions (Graphic3d_CubeMapOrder& theOrder) const
+ {
+ const Standard_Integer aNumberOfCubeMapOrderOptionArguments = myCommandParser.GetNumberOfOptionArguments(
+ myCubeMapOrderOptionKey);
+
+ if (aNumberOfCubeMapOrderOptionArguments != 6)
+ {
+ return false;
+ }
+
+
+ for (unsigned int i = 0; i < 6; ++i)
+ {
+ std::string anOrderItem;
+ if (!myCommandParser.Arg (myCubeMapOrderOptionKey, i, anOrderItem))
+ {
+ return false;
+ }
+
+ theOrder.Set (Graphic3d_CubeMapSide (i),
+ static_cast<unsigned char> (Draw::Atoi (anOrderItem.c_str())));
+ }
+
+ return theOrder.IsValid();
+ }
+
//! Processes the image option
//! @param theImageFileName the filename of the image to be used as a background
//! @return true if processing was successful, or false otherwise
return theDrawInterpretor.PrintHelp (theBackgroundCommandName) == TCL_OK;
}
+ //! Sets the cubemap as a background
+ //! @param theFileNames the array of filenames of packed or multifile cubemap
+ //! @param theOrder array of cubemap sides indexes mapping them from tiles in packed cubemap
+ static void setCubeMap (const NCollection_Array1<TCollection_AsciiString>& theFileNames,
+ const Graphic3d_ValidatedCubeMapOrder theOrder = Graphic3d_CubeMapOrder::Default(),
+ bool theZIsInverted = false)
+ {
+ const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
+ Handle(Graphic3d_CubeMap) aCubeMap;
+
+ if (theFileNames.Size() == 1)
+ aCubeMap = new Graphic3d_CubeMapPacked(theFileNames[0], theOrder);
+ else
+ aCubeMap = new Graphic3d_CubeMapSeparate(theFileNames);
+
+ aCubeMap->SetZInversion (theZIsInverted);
+
+ aCubeMap->GetParams()->SetFilter(Graphic3d_TOTF_BILINEAR);
+ aCubeMap->GetParams()->SetRepeat(Standard_False);
+ aCubeMap->GetParams()->SetTextureUnit(Graphic3d_TextureUnit_EnvMap);
+
+ aCurrentView->SetBackgroundCubeMap (aCubeMap, Standard_True);
+ }
+
//! Sets the image as a background
//! @param theImageFileName the filename of the image to be used as a background
//! @param theImageMode the fill type used for a background image
const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
Graphic3d_MaterialAspect aMat;
aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
- aMat.SetAmbient (1.0);
- aMat.SetDiffuse (1.0);
- aMat.SetSpecular (1.0);
- aMat.SetEmissive (1.0);
- aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
- aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
- aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
- aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
- aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
- aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
- aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
- aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
+ aMat.SetAmbientColor (Quantity_NOC_BLACK);
+ aMat.SetDiffuseColor (Quantity_NOC_WHITE);
+ aMat.SetSpecularColor (Quantity_NOC_BLACK);
+ aMat.SetEmissiveColor (Quantity_NOC_BLACK);
aFillAspect->SetFrontMaterial (aMat);
aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
aFillAspect->SetTextureMapOn();
std::cout << "Syntax error: need more arguments.\n";
return 1;
}
-
- Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
- aMat.SetAmbientColor (aColor);
- aMat.SetDiffuseColor (aColor);
- aClipPlane->SetCappingMaterial (aMat);
+ aClipPlane->SetCappingColor (aColor);
anArgIter += aNbParsed;
}
+ else if (aNbChangeArgs >= 1
+ && (aChangeArg == "-material"
+ || aChangeArg == "material"))
+ {
+ ++anArgIter;
+ Graphic3d_NameOfMaterial aMatName;
+ if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeArgs[1], aMatName))
+ {
+ std::cout << "Syntax error: unknown material '" << aChangeArgs[1] << "'.\n";
+ return 1;
+ }
+ aClipPlane->SetCappingMaterial (aMatName);
+ }
else if ((aChangeArg == "-transparency"
|| aChangeArg == "-transp")
&& aNbChangeArgs >= 2)
const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
if (aCtx.IsNull())
{
- std::cerr << "No active viewer!\n";
+ std::cout << "Error: no active viewer\n";
return 1;
}
|| anArg == "-AUTOTRIANG"
|| anArg == "-AUTOTRIANGULATION")
{
- if (++anArgIter >= theArgsNb)
+ ++anArgIter;
+ bool toTurnOn = true;
+ if (anArgIter >= theArgsNb
+ || !ViewerTest::ParseOnOff (theArgVec[anArgIter], toTurnOn))
{
- std::cout << "Error: wrong syntax at " << anArg << "\n";
+ std::cout << "Syntax error at '" << anArg << "'\n";
return 1;
}
- TCollection_AsciiString aValue (theArgVec[anArgIter]);
- aValue.LowerCase();
- if (aValue == "on"
- || aValue == "1")
- {
- aDefParams->SetAutoTriangulation (Standard_True);
- }
- else if (aValue == "off"
- || aValue == "0")
- {
- aDefParams->SetAutoTriangulation (Standard_False);
- }
+ aDefParams->SetAutoTriangulation (toTurnOn);
}
else
{
- std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
+ std::cout << "Syntax error: unknown argument '" << anArg << "'\n";
+ return 1;
}
}
" vbackground -imageMode FillType\n"
" vbackground -gradient Color1 Color2 [-gradientMode FillMethod]\n"
" vbackground -gradientMode FillMethod\n"
+ " vbackground -cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]\n"
" vbackground -color Color\n"
" vbackground -default -gradient Color1 Color2 [-gradientMode FillType]\n"
" vbackground -default -color Color\n"
" -imageMode (-imgMode, -imageMd, -imgMd): sets image fill type\n"
" -gradient (-grad, -gr): sets background gradient starting and ending colors\n"
" -gradientMode (-gradMode, -gradMd, -grMode, -grMd): sets gradient fill method\n"
+ " -cubemap (-cmap, -cm): sets environmet cubemap as background\n"
+ " -invertedz (-invz, -iz): sets inversion of Z axis for background cubemap rendering\n"
+ " -order (-o): defines order of tiles in one image cubemap\n"
+ " (has no effect in case of multi image cubemaps)\n"
" -color (-col): sets background color\n"
" -default (-def): sets background default gradient or color\n"
" -help (-h): outputs short help message\n"
"\n"
"Arguments:\n"
- " Color: Red Green Blue - where Red, Green, Blue must be integers within the range [0, 255]\n"
+ " Color: Red Green Blue - where Red, Green, Blue must be integers within the range [0, 255]\n"
" or reals within the range [0.0, 1.0]\n"
- " ColorName - one of WHITE, BLACK, RED, GREEN, BLUE, etc.\n"
- " #HHH, [#]HHHHHH - where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F)\n"
- " FillMethod: one of NONE, HOR[IZONTAL], VER[TICAL], DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, "
+ " ColorName - one of WHITE, BLACK, RED, GREEN, BLUE, etc.\n"
+ " #HHH, [#]HHHHHH - where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F)\n"
+ " FillMethod: one of NONE, HOR[IZONTAL], VER[TICAL], DIAG[ONAL]1, DIAG[ONAL]2, CORNER1, CORNER2, CORNER3, "
"CORNER4\n"
- " FillType: one of CENTERED, TILED, STRETCH, NONE\n"
- " ImageFile: a name of the file with the image used as a background\n",
+ " FillType: one of CENTERED, TILED, STRETCH, NONE\n"
+ " ImageFile: a name of the file with the image used as a background\n"
+ " CubemapFilei: a name of the file with one image packed cubemap or names of separate files with every cubemap side\n"
+ " TileIndexi: a cubemap side index in range [0, 5] for i tile of one image packed cubemap\n",
__FILE__,
vbackground,
group);
"\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
"\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
"\n '-shadingModel model' Controls shading model from enumeration"
- "\n color, flat, gouraud, phong"
+ "\n unlit, flat, gouraud, phong"
"\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
"\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
"\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"