// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "Core/Types.h" #ifdef USE_TECHSOFT_SDK #include "Geo/GeoEnum.h" #include "Math/MatrixH.h" #include "CADOptions.h" #include "TechSoftInterface.h" namespace UE::CADKernel { class FBody; class FCriterion; class FCurve; class FEntity; class FFaceMesh; class FModel; class FRestrictionCurve; class FSession; class FShell; class FSurface; class FSurfacicBoundary; class FTopologicalEdge; class FTopologicalLoop; class FTopologicalShapeEntity; } namespace CADLibrary { class FArchiveCADObject; class FTechSoftFileParser; namespace TechSoftUtils { class FUVReparameterization { private: double Scale[2] = { 1., 1. }; double Offset[2] = { 0., 0. }; bool bSwapUV = false; bool bNeedApply = false; bool bNeedSwapOrientation = false; public: FUVReparameterization() { } void SetCoef(const double InUScale, const double InUOffset, const double InVScale, const double InVOffset) { Scale[UE::CADKernel::EIso::IsoU] = InUScale; Scale[UE::CADKernel::EIso::IsoV] = InVScale; Offset[UE::CADKernel::EIso::IsoU] = InUOffset; Offset[UE::CADKernel::EIso::IsoV] = InVOffset; SetNeedApply(); } bool GetNeedApply() const { return bNeedApply; } bool GetSwapUV() const { return bSwapUV; } bool GetNeedSwapOrientation() const { return bNeedSwapOrientation != bSwapUV; } void SetNeedSwapOrientation() { bNeedSwapOrientation = true; } void SetNeedApply() { if (!FMath::IsNearlyEqual(Scale[UE::CADKernel::EIso::IsoU], 1.) || !FMath::IsNearlyEqual(Scale[UE::CADKernel::EIso::IsoV], 1.) || !FMath::IsNearlyEqual(Offset[UE::CADKernel::EIso::IsoU], 0.) || !FMath::IsNearlyEqual(Offset[UE::CADKernel::EIso::IsoV], 0.)) { bNeedApply = true; } else { bNeedApply = false; } } void ScaleUVTransform(double InUScale, double InVScale) { if (bSwapUV) { Swap(InUScale, InVScale); } Scale[UE::CADKernel::EIso::IsoU] *= InUScale; Scale[UE::CADKernel::EIso::IsoV] *= InVScale; Offset[UE::CADKernel::EIso::IsoU] *= InUScale; Offset[UE::CADKernel::EIso::IsoV] *= InVScale; SetNeedApply(); } void Process(TArray& Poles) const { using namespace UE::CADKernel; if (bNeedApply) { for (FVector& Point : Poles) { Apply(Point); } } if (bSwapUV) { for (FVector& Point : Poles) { GetSwapUV(Point); } } } void AddUVTransform(A3DUVParameterizationData& Transform) { bSwapUV = (bool) Transform.m_bSwapUV; Scale[0] = Scale[0] * Transform.m_dUCoeffA; Scale[1] = Scale[1] * Transform.m_dVCoeffA; Offset[0] = Offset[0] * Transform.m_dUCoeffA + Transform.m_dUCoeffB; Offset[1] = Offset[1] * Transform.m_dVCoeffA + Transform.m_dVCoeffB; SetNeedApply(); } void Apply(FVector2d& Point) const { using namespace UE::CADKernel; Point.X = Scale[EIso::IsoU] * Point.X + Offset[EIso::IsoU]; Point.Y = Scale[EIso::IsoV] * Point.Y + Offset[EIso::IsoV]; } private: void Apply(FVector& Point) const { using namespace UE::CADKernel; Point.X = Scale[EIso::IsoU] * Point.X + Offset[EIso::IsoU]; Point.Y = Scale[EIso::IsoV] * Point.Y + Offset[EIso::IsoV]; } void GetSwapUV(FVector& Point) const { Swap(Point.X, Point.Y); } }; } // ns TechSoftUtils class FTechSoftBridge { private: FTechSoftFileParser& Parser; UE::CADKernel::FSession& Session; UE::CADKernel::FModel& Model; const double GeometricTolerance; const double EdgeLengthTolerance; const double SquareGeometricTolerance; const double SquareJoiningVertexTolerance; TMap> TechSoftToCADKernel; TMap CADKernelToTechSoft; TMap> A3DEdgeToEdge; EFailureReason FailureReason = EFailureReason::None; bool bConvertionFailed = false; double BodyScale = 1; public: FTechSoftBridge(FTechSoftFileParser& InParser, UE::CADKernel::FSession& InSession); UE::CADKernel::FBody* AddBody(A3DRiBrepModel* A3DBRepModel, FArchiveCADObject& ArchiveBody); UE::CADKernel::FBody* GetBody(A3DRiBrepModel* A3DBRepModel); const A3DRiBrepModel* GetA3DBody(UE::CADKernel::FBody* BRepModel); EFailureReason GetFailureReason() { return FailureReason; } private: void TraverseBrepData(const A3DTopoBrepData* A3DBrepData, TSharedRef& Body); void TraverseConnex(const A3DTopoConnex* A3DConnex, TSharedRef& Body); void TraverseShell(const A3DTopoShell* A3DShell, TSharedRef& Body); void AddFace(const A3DTopoFace* A3DFace, UE::CADKernel::EOrientation Orientation, TSharedRef& Body, uint32 Index); TSharedPtr AddLoop(const A3DTopoLoop* A3DLoop, const TSharedRef& Surface, const TechSoftUtils::FUVReparameterization& UVReparameterization, const bool bIsExternalLoop); TSharedPtr AddEdge(const A3DTopoCoEdge* A3DCoedge, const TSharedRef& Surface, const TechSoftUtils::FUVReparameterization& UVReparameterization, UE::CADKernel::EOrientation& OutOrientation); TSharedPtr AddSurface(const A3DSurfBase* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddConeSurface(const A3DSurfCone* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddCylinderSurface(const A3DSurfCylinder* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddLinearTransfoSurface(const A3DSurfBase* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddNurbsSurface(const A3DSurfNurbs* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddOffsetSurface(const A3DSurfOffset* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddPlaneSurface(const A3DSurfPlane* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddRevolutionSurface(const A3DSurfRevolution* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddRuledSurface(const A3DSurfRuled* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddSphereSurface(const A3DSurfSphere* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddTorusSurface(const A3DSurfTorus* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddBlend01Surface(const A3DSurfBlend01* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddBlend02Surface(const A3DSurfBlend02* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddBlend03Surface(const A3DSurfBlend03* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddCylindricalSurface(const A3DSurfCylindrical* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddPipeSurface(const A3DSurfPipe* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddExtrusionSurface(const A3DSurfExtrusion* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddSurfaceFromCurves(const A3DSurfFromCurves* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddTransformSurface(const A3DSurfTransform* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddSurfaceAsNurbs(const A3DSurfBase* A3DSurface, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddSurfaceNurbs(const A3DSurfNurbsData& A3DNurbsData, TechSoftUtils::FUVReparameterization& OutUVReparameterization); TSharedPtr AddRestrictionCurve(const A3DCrvBase* A3DCurve, const TSharedRef& Surface); TSharedPtr AddCurve(const A3DCrvBase* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveCircle(const A3DCrvCircle* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveComposite(const A3DCrvComposite* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveEllipse(const A3DCrvEllipse* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveHelix(const A3DCrvHelix* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveHyperbola(const A3DCrvHyperbola* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveLine(const A3DCrvLine* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveNurbs(const A3DCrvNurbs* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveParabola(const A3DCrvParabola* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurvePolyLine(const A3DCrvPolyLine* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveBlend02Boundary(const A3DCrvBlend02Boundary* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveEquation(const A3DCrvEquation* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveIntersection(const A3DCrvIntersection* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveOffset(const A3DCrvOffset* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveOnSurf(const A3DCrvOnSurf* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveTransform(const A3DCrvTransform* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); TSharedPtr AddCurveAsNurbs(const A3DCrvBase* A3DCurve, const TechSoftUtils::FUVReparameterization& UVReparameterization); void AddMetaData(FArchiveCADObject& EntityData, UE::CADKernel::FTopologicalShapeEntity& Entity); }; } #endif // USE_TECHSOFT_SDK