#include <TopExp.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
-#include <AIS_TexturedShape.hxx>
+#include <AIS_Shape.hxx>
#include <BRepTools.hxx>
-#include <Graphic3d_Texture2D.hxx>
+#include <Graphic3d_Texture2Dmanual.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <BRepBuilderAPI_Transform.hxx>
" // aShape = ..." EOL
"" EOL
" // create a textured presentation object for aShape" EOL
- " Handle(AIS_TexturedShape) aTShape = new AIS_TexturedShape(aShape);" EOL
+ " Handle(AIS_Shape) aTShape = new AIS_Shape(aShape);" EOL
"" EOL
" TCollection_AsciiString aTFileName;" EOL
"" EOL
" // which will indicate use of predefined texture of this number" EOL
" // aTFileName = ..." EOL
"" EOL
- " aTShape->SetTextureFileName(aTFileName);" EOL
- "" EOL
- " // do other initialization of AIS_TexturedShape" EOL
- " Standard_Real nRepeat;" EOL
- " Standard_Boolean toRepeat;" EOL
- " Standard_Boolean toScale;" EOL
- " // initialize aRepeat, toRepeat, toScale ..." EOL
- "" EOL
- " aTShape->SetTextureMapOn();" EOL
- " aTShape->SetTextureRepeat(toRepeat, nRepeat, nRepeat);" EOL
- " aTShape->SetTexturesExtcale(toScale);" EOL
- " " EOL
- " // mode 3 is \"textured\" mode of AIS_TexturedShape, " EOL
- " // other modes will display the \"normal\", non-textured shape," EOL
- " // in wireframe(1) or shaded(2) modes correspondingly" EOL
- " aTShape->SetDisplayMode(3); " EOL);
+ " aTShape->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());" EOL
+ " Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual (aTFileName);" EOL
+ " aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (aTexture);" EOL
+ " aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();" EOL);
// CString text(Message.ToCString());
getDocument()->ClearDialog();
getDocument()->SetDialogTitle("Change face color");
//////////////////////////////////////////////////////////////////////
//================================================================
// Function : TexturesExt_Presentation::Texturize
-// display an AIS_TexturedShape based on a given shape with texture with given filename
+// display an AIS_Shape based on a given shape with texture with given filename
// filename can also be an integer value ("2", "5", etc.), in this case
// a predefined texture from Graphic3d_NameOfTexture2D with number = this value
// is loaded.
//================================================================
-Handle(AIS_TexturedShape) TexturesExt_Presentation::Texturize(const TopoDS_Shape& aShape,
+Handle(AIS_Shape) TexturesExt_Presentation::Texturize(const TopoDS_Shape& aShape,
TCollection_AsciiString aTFileName,
Standard_Real toScaleU,
Standard_Real toScaleV,
Standard_Real originV)
{
// create a textured presentation object for aShape
- Handle(AIS_TexturedShape) aTShape = new AIS_TexturedShape(aShape);
+ Handle(AIS_Shape) aTShape = new AIS_Shape(aShape);
TCollection_AsciiString TFileName;
// load texture from file if it is not an integer value
// integer value indicates a number of texture in predefined TexturesExt enumeration
initfile += aTFileName.ToCString();
}
- aTShape->SetTextureFileName (TCollection_AsciiString ((const wchar_t* )initfile));
+ if (!aTShape->Attributes()->HasOwnShadingAspect())
+ {
+ aTShape->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
+ }
+ aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (new Graphic3d_Texture2Dmanual (TCollection_AsciiString ((const wchar_t* )initfile)));
+ aTShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
+
+ // do other initialization of AIS_Shape
+ aTShape->SetTextureScaleUV (gp_Pnt2d ( toScaleU, toScaleV));
+ aTShape->SetTextureRepeatUV(gp_Pnt2d (toRepeatU, toRepeatV));
+ aTShape->SetTextureOriginUV(gp_Pnt2d ( originU, originV));
- // do other initialization of AIS_TexturedShape
- aTShape->SetTextureMapOn();
- aTShape->SetTextureScale(Standard_True, toScaleU, toScaleV);
- aTShape->SetTextureRepeat(Standard_True, toRepeatU, toRepeatV);
- aTShape->SetTextureOrigin(Standard_True, originU, originV);
-
- aTShape->SetDisplayMode(3); // mode 3 is "textured" mode
+ aTShape->SetDisplayMode(AIS_Shaded);
return aTShape;
}
aShapeIO->SetPolygonOffsets(Aspect_POM_Fill, 1.5, 0.5);
DISP(aShapeIO);
- Handle(AIS_TexturedShape) aTFace1 = Texturize(aFaces(16), "carrelage1.gif", 1, 1, 3, 2);
+ Handle(AIS_Shape) aTFace1 = Texturize(aFaces(16), "carrelage1.gif", 1, 1, 3, 2);
DISP(aTFace1);
- Handle(AIS_TexturedShape) aTFace2 = Texturize(aFaces(21), "carrelage1.gif", 1, 1, 3, 2);
+ Handle(AIS_Shape) aTFace2 = Texturize(aFaces(21), "carrelage1.gif", 1, 1, 3, 2);
DISP(aTFace2);
getViewer()->Update();
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_CStructure.hxx>
-#include <Graphic3d_TextureRoot.hxx>
+#include <Graphic3d_Texture2Dmanual.hxx>
#include <Image_AlienPixMap.hxx>
+#include <OSD_File.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
-#include <AIS_TexturedShape.hxx>
#include <AIS_DisplayMode.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <AIS_MapOfInteractive.hxx>
//function : VTexture
//purpose :
//==============================================================================
-Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
+Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
{
- TCollection_AsciiString aCommandName (theArgv[0]);
+ const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+ if (aCtx.IsNull())
+ {
+ std::cout << "Error: no active view!\n";
+ return 1;
+ }
+
+ int toModulate = -1;
+ bool toSetFilter = false;
+ bool toSetAniso = false;
+ bool toSetTrsfAngle = false;
+ bool toSetTrsfTrans = false;
+ bool toSetTrsfScale = false;
+ Standard_ShortReal aTrsfRotAngle = 0.0f;
+ Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
+ Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
+ Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST;
+ Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
+
+ Handle(AIS_Shape) aTexturedIO;
+ Handle(Graphic3d_TextureMap) aTextureOld;
+ Handle(Graphic3d_Texture2Dmanual) aTextureNew;
+ bool toSetGenRepeat = false;
+ bool toSetGenScale = false;
+ bool toSetGenOrigin = false;
+ bool toSetImage = false;
+ bool toSetNewImage = false;
+
+ const TCollection_AsciiString aCommandName (theArgVec[0]);
+ bool toSetDefaults = aCommandName == "vtexdefault";
- NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
- if (aCommandName == "vtexture")
+ ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
+ for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
{
- if (theArgsNb < 2)
+ const TCollection_AsciiString aName = theArgVec[anArgIter];
+ TCollection_AsciiString aNameCase = aName;
+ aNameCase.LowerCase();
+ if (anUpdateTool.parseRedrawMode (aName))
{
- std::cout << theArgv[0] << ": invalid arguments.\n";
- std::cout << "Type help for more information.\n";
- return 1;
+ continue;
}
-
- // look for options of vtexture command
- TCollection_AsciiString aParseKey;
- for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
+ else if (aTexturedIO.IsNull())
{
- TCollection_AsciiString anArg (theArgv [anArgIt]);
-
- anArg.UpperCase();
- if (anArg.Value (1) == '-' && !anArg.IsRealValue())
+ const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
+ if (aMapOfIO.IsBound2 (aName))
{
- aParseKey = anArg;
- aParseKey.Remove (1);
- aParseKey.UpperCase();
- aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
- continue;
+ aTexturedIO = Handle(AIS_Shape)::DownCast (aMapOfIO.Find2 (aName));
}
-
- if (aParseKey.IsEmpty())
+ if (aTexturedIO.IsNull())
{
- continue;
+ std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
+ return 1;
}
- aMapOfArgs(aParseKey)->Append (anArg);
+ if (aTexturedIO->Attributes()->HasOwnShadingAspect())
+ {
+ aTextureOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap();
+ }
}
- }
- else if (aCommandName == "vtexscale"
- || aCommandName == "vtexorigin"
- || aCommandName == "vtexrepeat")
- {
- // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
- // equal to -scale, -origin, -repeat options of vtexture command
- if (theArgsNb < 2 || theArgsNb > 4)
+ else if (aNameCase == "-scale"
+ || aNameCase == "-setscale"
+ || aCommandName == "vtexscale")
{
- std::cout << theArgv[0] << ": invalid arguments.\n";
- std::cout << "Type help for more information.\n";
+ if (aCommandName != "vtexscale")
+ {
+ ++anArgIter;
+ }
+ if (anArgIter < theArgsNb)
+ {
+ TCollection_AsciiString aValU (theArgVec[anArgIter]);
+ TCollection_AsciiString aValUCase = aValU;
+ aValUCase.LowerCase();
+ toSetGenScale = true;
+ if (aValUCase == "off")
+ {
+ aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
+ continue;
+ }
+ else if (anArgIter + 1 < theArgsNb)
+ {
+ TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
+ if (aValU.IsRealValue()
+ && aValV.IsRealValue())
+ {
+ aTexturedIO->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
+ ++anArgIter;
+ continue;
+ }
+ }
+ }
+ std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
return 1;
}
-
- Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
- if (theArgsNb == 2)
+ else if (aNameCase == "-origin"
+ || aNameCase == "-setorigin"
+ || aCommandName == "vtexorigin")
{
- anArgs->Append ("OFF");
+ if (aCommandName != "vtexorigin")
+ {
+ ++anArgIter;
+ }
+ if (anArgIter < theArgsNb)
+ {
+ TCollection_AsciiString aValU (theArgVec[anArgIter]);
+ TCollection_AsciiString aValUCase = aValU;
+ aValUCase.LowerCase();
+ toSetGenOrigin = true;
+ if (aValUCase == "off")
+ {
+ aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
+ continue;
+ }
+ else if (anArgIter + 1 < theArgsNb)
+ {
+ TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
+ if (aValU.IsRealValue()
+ && aValV.IsRealValue())
+ {
+ aTexturedIO->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
+ ++anArgIter;
+ continue;
+ }
+ }
+ }
+ std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
+ return 1;
}
- else if (theArgsNb == 4)
+ else if (aNameCase == "-repeat"
+ || aNameCase == "-setrepeat"
+ || aCommandName == "vtexrepeat")
{
- anArgs->Append (TCollection_AsciiString (theArgv[2]));
- anArgs->Append (TCollection_AsciiString (theArgv[3]));
+ if (aCommandName != "vtexrepeat")
+ {
+ ++anArgIter;
+ }
+ if (anArgIter < theArgsNb)
+ {
+ TCollection_AsciiString aValU (theArgVec[anArgIter]);
+ TCollection_AsciiString aValUCase = aValU;
+ aValUCase.LowerCase();
+ toSetGenRepeat = true;
+ if (aValUCase == "off")
+ {
+ aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
+ continue;
+ }
+ else if (anArgIter + 1 < theArgsNb)
+ {
+ TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
+ if (aValU.IsRealValue()
+ && aValV.IsRealValue())
+ {
+ aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
+ ++anArgIter;
+ continue;
+ }
+ }
+ }
+ std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
+ return 1;
}
-
- TCollection_AsciiString anArgKey;
- if (aCommandName == "vtexscale")
+ else if (aNameCase == "-modulate")
{
- anArgKey = "SCALE";
+ bool toModulateBool = true;
+ if (anArgIter + 1 < theArgsNb
+ && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
+ {
+ ++anArgIter;
+ }
+ toModulate = toModulateBool ? 1 : 0;
}
- else if (aCommandName == "vtexorigin")
+ else if ((aNameCase == "-setfilter"
+ || aNameCase == "-filter")
+ && anArgIter + 1 < theArgsNb)
{
- anArgKey = "ORIGIN";
+ TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
+ aValue.LowerCase();
+ ++anArgIter;
+ toSetFilter = true;
+ if (aValue == "nearest")
+ {
+ aFilter = Graphic3d_TOTF_NEAREST;
+ }
+ else if (aValue == "bilinear")
+ {
+ aFilter = Graphic3d_TOTF_BILINEAR;
+ }
+ else if (aValue == "trilinear")
+ {
+ aFilter = Graphic3d_TOTF_TRILINEAR;
+ }
+ else
+ {
+ std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
+ return 1;
+ }
}
- else
+ else if ((aNameCase == "-setaniso"
+ || aNameCase == "-setanisofilter"
+ || aNameCase == "-aniso"
+ || aNameCase == "-anisofilter")
+ && anArgIter + 1 < theArgsNb)
{
- anArgKey = "REPEAT";
+ TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
+ aValue.LowerCase();
+ ++anArgIter;
+ toSetAniso = true;
+ if (aValue == "off")
+ {
+ anAnisoFilter = Graphic3d_LOTA_OFF;
+ }
+ else if (aValue == "fast")
+ {
+ anAnisoFilter = Graphic3d_LOTA_FAST;
+ }
+ else if (aValue == "middle")
+ {
+ anAnisoFilter = Graphic3d_LOTA_MIDDLE;
+ }
+ else if (aValue == "quality"
+ || aValue == "high")
+ {
+ anAnisoFilter = Graphic3d_LOTA_QUALITY;
+ }
+ else
+ {
+ std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
+ return 1;
+ }
}
-
- aMapOfArgs.Bind (anArgKey, anArgs);
- }
- else if (aCommandName == "vtexdefault")
- {
- // scan for parameters of vtexdefault command
- // equal to -default option of vtexture command
- aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
- }
-
- // Check arguments for validity
- NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
- for (; aMapIt.More(); aMapIt.Next())
- {
- const TCollection_AsciiString& aKey = aMapIt.Key();
- const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
-
- // -scale, -origin, -repeat: one argument "off", or two real values
- if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
- && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
- || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
+ else if ((aNameCase == "-rotateangle"
+ || aNameCase == "-rotangle"
+ || aNameCase == "-rotate"
+ || aNameCase == "-angle"
+ || aNameCase == "-trsfangle")
+ && anArgIter + 1 < theArgsNb)
{
- continue;
+ aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
+ toSetTrsfAngle = true;
+ ++anArgIter;
}
-
- // -modulate: single argument "on" / "off"
- if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
+ else if ((aNameCase == "-trsftrans"
+ || aNameCase == "-trsftranslate"
+ || aNameCase == "-translate"
+ || aNameCase == "-translation")
+ && anArgIter + 2 < theArgsNb)
{
- continue;
+ aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
+ aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
+ toSetTrsfTrans = true;
+ anArgIter += 2;
}
-
- // -default: no arguments
- if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
+ else if ((aNameCase == "-trsfscale")
+ && anArgIter + 2 < theArgsNb)
{
- continue;
+ aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
+ aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
+ toSetTrsfScale = true;
+ anArgIter += 2;
}
-
- TCollection_AsciiString aLowerKey;
- aLowerKey = "-";
- aLowerKey += aKey;
- aLowerKey.LowerCase();
- std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
- std::cout << "Type help for more information.\n";
- return 1;
- }
-
- Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
- if (anAISContext.IsNull())
- {
- std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
- return 1;
- }
-
- Standard_Integer aPreviousMode = 0;
-
- TCollection_AsciiString aShapeName (theArgv[1]);
- Handle(AIS_InteractiveObject) anIO;
-
- const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
- if (aMapOfIO.IsBound2 (aShapeName))
- {
- anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
- }
-
- if (anIO.IsNull())
- {
- std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
- return 1;
- }
-
- Handle(AIS_TexturedShape) aTexturedIO;
- if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
- {
- aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
- aPreviousMode = aTexturedIO->DisplayMode();
- }
- else
- {
- aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
-
- if (anIO->HasTransformation())
+ else if (aNameCase == "-default"
+ || aNameCase == "-defaults")
{
- const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
- aTexturedIO->SetLocalTransformation (aLocalTrsf);
+ toSetDefaults = true;
}
-
- anAISContext->Remove (anIO, Standard_False);
- GetMapOfAIS().UnBind1 (anIO);
- GetMapOfAIS().UnBind2 (aShapeName);
- GetMapOfAIS().Bind (aTexturedIO, aShapeName);
- }
-
- // -------------------------------------------
- // Turn texturing on/off - only for vtexture
- // -------------------------------------------
-
- if (aCommandName == "vtexture")
- {
- TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
-
- if (aTextureArg.IsEmpty())
+ else if (aTextureNew.IsNull()
+ && aCommandName == "vtexture")
{
- std::cout << aCommandName << ": Texture mapping disabled.\n";
- std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
-
- anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
- if (aPreviousMode == 3)
+ toSetImage = true;
+ toSetNewImage = true;
+ if (aName.IsIntegerValue())
{
- anAISContext->RecomputePrsOnly (aTexturedIO, Standard_False);
+ const Standard_Integer aValue = aName.IntegerValue();
+ if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
+ {
+ std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
+ return 1;
+ }
+ aTextureNew = new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue));
}
-
- anAISContext->Display (aTexturedIO, Standard_True);
- return 0;
- }
- else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
- {
- if (aTextureArg == "?")
+ else if (aNameCase == "?")
{
- TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
+ const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
theDi << "\n Files in current directory : \n\n";
theDi.Eval ("glob -nocomplain *");
aCmnd += aTextureFolder;
aCmnd += "/* ";
- theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
+ theDi << "Files in " << aTextureFolder << " : \n\n";
theDi.Eval (aCmnd.ToCString());
return 0;
}
- else
+ else if (aNameCase != "off")
{
- aTexturedIO->SetTextureFileName (aTextureArg);
+ if (!OSD_File (aName).Exists())
+ {
+ std::cout << "Syntax error: non-existing image file has been specified '" << aName << "'.\n";
+ return 1;
+ }
+ aTextureNew = new Graphic3d_Texture2Dmanual (aName);
}
- }
- }
-
- // ------------------------------------
- // Process other options and commands
- // ------------------------------------
- Handle(TColStd_HSequenceOfAsciiString) aValues;
- if (aMapOfArgs.Find ("DEFAULT", aValues))
- {
- aTexturedIO->SetTextureRepeat (Standard_False);
- aTexturedIO->SetTextureOrigin (Standard_False);
- aTexturedIO->SetTextureScale (Standard_False);
- aTexturedIO->EnableTextureModulate();
- }
- else
- {
- if (aMapOfArgs.Find ("SCALE", aValues))
- {
- if (aValues->Value(1) != "OFF")
+ if (!aTextureNew.IsNull())
{
- aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
+ if (!aTextureOld.IsNull())
+ {
+ *aTextureNew->GetParams() = *aTextureOld->GetParams();
+ if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
+ {
+ TCollection_AsciiString aFilePathOld, aFilePathNew;
+ aTextureOld->Path().SystemName (aFilePathOld);
+ aTextureNew->Path().SystemName (aFilePathNew);
+ if (aTextureNew->Name() == anOldManualTex->Name()
+ && aFilePathOld == aFilePathNew
+ && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
+ {
+ toSetNewImage = false;
+ aTextureNew = anOldManualTex;
+ }
+ }
+ }
+ else
+ {
+ aTexturedIO->SetToUpdate (AIS_Shaded);
+ }
}
- else
+
+ if (!aTexturedIO->Attributes()->HasOwnShadingAspect())
{
- aTexturedIO->SetTextureScale (Standard_False);
+ aTexturedIO->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
+ *aTexturedIO->Attributes()->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
}
- }
- if (aMapOfArgs.Find ("ORIGIN", aValues))
- {
- if (aValues->Value(1) != "OFF")
+ if (!aTextureNew.IsNull())
{
- aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
+ aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
}
else
{
- aTexturedIO->SetTextureOrigin (Standard_False);
+ aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
}
+ aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (aTextureNew);
+ aTextureOld.Nullify();
}
+ else
+ {
+ std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
+ return 1;
+ }
+ }
- if (aMapOfArgs.Find ("REPEAT", aValues))
+ if (toSetDefaults)
+ {
+ if (toModulate != -1)
{
- if (aValues->Value(1) != "OFF")
- {
- aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
- }
- else
- {
- aTexturedIO->SetTextureRepeat (Standard_False);
- }
+ toModulate = 1;
}
+ if (!toSetFilter)
+ {
+ toSetFilter = true;
+ aFilter = Graphic3d_TOTF_BILINEAR;
+ }
+ if (!toSetAniso)
+ {
+ toSetAniso = true;
+ anAnisoFilter = Graphic3d_LOTA_OFF;
+ }
+ if (!toSetTrsfAngle)
+ {
+ toSetTrsfAngle = true;
+ aTrsfRotAngle = 0.0f;
+ }
+ if (!toSetTrsfTrans)
+ {
+ toSetTrsfTrans = true;
+ aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
+ }
+ if (!toSetTrsfScale)
+ {
+ toSetTrsfScale = true;
+ aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
+ }
+ }
- if (aMapOfArgs.Find ("MODULATE", aValues))
+ if (aCommandName == "vtexture"
+ && theArgsNb == 2)
+ {
+ if (!aTextureOld.IsNull())
{
- if (aValues->Value(1) == "ON")
- {
- aTexturedIO->EnableTextureModulate();
- }
- else
- {
- aTexturedIO->DisableTextureModulate();
- }
+ toSetNewImage = true;
+ aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
+ aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (Handle(Graphic3d_TextureMap)());
+ aTextureOld.Nullify();
}
}
- if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
+ if (aTexturedIO->Attributes()->HasOwnShadingAspect()
+ && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
{
- anAISContext->RecomputePrsOnly (aTexturedIO, Standard_True);
+ if (toModulate != -1)
+ {
+ aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
+ }
+ if (toSetTrsfAngle)
+ {
+ aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
+ }
+ if (toSetTrsfTrans)
+ {
+ aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
+ }
+ if (toSetTrsfScale)
+ {
+ aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
+ }
+ if (toSetFilter)
+ {
+ aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
+ }
+ if (toSetAniso)
+ {
+ aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
+ }
}
- else
+
+ // set default values if requested
+ if (!toSetGenRepeat
+ && (aCommandName == "vtexrepeat"
+ || toSetDefaults))
+ {
+ aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
+ toSetGenRepeat = true;
+ }
+ if (!toSetGenOrigin
+ && (aCommandName == "vtexorigin"
+ || toSetDefaults))
+ {
+ aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
+ toSetGenOrigin = true;
+ }
+ if (!toSetGenScale
+ && (aCommandName == "vtexscale"
+ || toSetDefaults))
{
- anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
- anAISContext->Display (aTexturedIO, Standard_True);
- anAISContext->Update (aTexturedIO,Standard_True);
+ aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
+ toSetGenScale = true;
}
+ if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toSetNewImage)
+ {
+ aTexturedIO->SetToUpdate (AIS_Shaded);
+ if (toSetImage)
+ {
+ if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
+ || aCtx->DisplayMode() != AIS_Shaded)
+ {
+ aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
+ }
+ }
+ }
+ aCtx->Display (aTexturedIO, false);
+ aTexturedIO->SynchronizeAspects();
return 0;
}
__FILE__,VShading,group);
theCommands.Add ("vtexture",
- "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
- " [-scale u v] [-scale off]\n"
- " [-origin u v] [-origin off]\n"
- " [-repeat u v] [-repeat off]\n"
- " [-modulate {on | off}]"
- " [-default]'\n"
- " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
- " specifying one of the predefined textures.\n"
- " The options are: \n"
- " -scale u v : enable texture scaling and set scale factors\n"
- " -scale off : disable texture scaling\n"
- " -origin u v : enable texture origin positioning and set the origin\n"
- " -origin off : disable texture origin positioning\n"
- " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
- " -repeat off : disable texture repeat\n"
- " -modulate {on | off} : enable or disable texture modulation\n"
- " -default : sets texture mapping default parameters\n"
- "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
- "or 'vtexture NameOfShape ?' to list available textures\n",
+ "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
+ "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
+ "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
+ "\n\t\t: [-modulate {on|off}]"
+ "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]"
+ "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]"
+ "\n\t\t: [-default]"
+ "\n\t\t: The texture can be specified by filepath"
+ "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
+ "\n\t\t: The options are:"
+ "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default"
+ "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default"
+ "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default"
+ "\n\t\t: -modulate Enable or disable texture color modulation"
+ "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
+ "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
+ "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector"
+ "\n\t\t: -setFilter Setup texture filter"
+ "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
+ "\n\t\t: -default Sets texture mapping default parameters",
__FILE__, VTexture, group);
theCommands.Add("vtexscale",
- "'vtexscale NameOfShape ScaleU ScaleV' \n \
- or 'vtexscale NameOfShape ScaleUV' \n \
- or 'vtexscale NameOfShape' to disable scaling\n ",
+ "vtexscale name ScaleU ScaleV"
+ "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
__FILE__,VTexture,group);
theCommands.Add("vtexorigin",
- "'vtexorigin NameOfShape UOrigin VOrigin' \n \
- or 'vtexorigin NameOfShape UVOrigin' \n \
- or 'vtexorigin NameOfShape' to disable origin positioning\n ",
+ "vtexorigin name OriginU OriginV"
+ "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
__FILE__,VTexture,group);
theCommands.Add("vtexrepeat",
- "'vtexrepeat NameOfShape URepeat VRepeat' \n \
- or 'vtexrepeat NameOfShape UVRepeat \n \
- or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
+ "vtexrepeat name RepeatU RepeatV"
+ "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
VTexture,group);
theCommands.Add("vtexdefault",
- "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
+ "vtexdefault name"
+ "\n\t\t: Alias for vtexture name -default.",
VTexture,group);
theCommands.Add("vsetam",