UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CADKernelEngine.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
5
6#if PLATFORM_DESKTOP
8#include "TechSoftIncludes.h"
9
10namespace UE::CADKernel
11{
12 class FModel;
13 class FModelMesh;
14 class FTopologicalFace;
15}
16
17namespace UE::Geometry
18{
19 class FDynamicMesh3;
20}
21
22namespace UE::CADKernel::MeshUtilities
23{
25}
26
27struct FMeshDescription;
28
29namespace UE::CADKernel
30{
32 {
33 public:
34 static bool CADKERNELENGINE_API Save(TSharedPtr<UE::CADKernel::FModel>& Model, const FString& FilePath);
35 static bool CADKERNELENGINE_API Load(TSharedPtr<UE::CADKernel::FModel>& Model, const FString& FilePath);
36 static bool CADKERNELENGINE_API Tessellate(UE::CADKernel::FModel& Model, const FTessellationContext& Context, FMeshDescription& MeshOut, bool bSkipDeletedFaces = false, bool bEmptyMesh = false);
37 static bool CADKERNELENGINE_API Tessellate(UE::CADKernel::FModel& Model, const FTessellationContext& Context, UE::Geometry::FDynamicMesh3& MeshOut, bool bSkipDeletedFaces = false, bool bEmptyMesh = false);
38
39 /* Note: Meshes are expected to be in their native coordinates system and unit */
40 static void CADKERNELENGINE_API ApplyExtractionContext(const FMeshExtractionContext& Context, FMeshDescription& MeshInOut);
42 // Set the proper attributes for FMeshDescription created from CAD data.
43 static void CADKERNELENGINE_API RegisterAttributes(FMeshDescription& MeshInOut, bool bKeepExistingAttribute = false);
45 };
46
47 enum class ECADFormat
48 {
49 ACIS,
50 AUTOCAD,
51 CATIA,
54 CATIAV4,
55 CREO,
56 DWG,
57 DGN,
59 IFC,
60 IGES,
62 JT,
63 N_X,
68 STEP,
69 OTHER
70 };
71
72
74 {
75 public:
76 static CADKERNELENGINE_API const TCHAR* GetVersion();
77 static bool CADKERNELENGINE_API Initialize();
78 static bool CADKERNELENGINE_API IsInitialized() { return bIsInitialized; }
79
80
81#ifdef WITH_HOOPS
83
92
96
98
99
100 static CADKERNELENGINE_API A3DAsmModelFile* LoadModelFileFromFile(const A3DImport& Import, const TCHAR* Filename);
101 static CADKERNELENGINE_API A3DAsmModelFile* LoadModelFile(const TCHAR* Filename, const FTechSoftImportOverrides& LoadOverrides, FString& OutReason);
102
107 static CADKERNELENGINE_API A3DStatus DeleteEntity(A3DEntity* EntityPtr);
109
110 static CADKERNELENGINE_API FString CleanLabel(const FString& Name);
112
114 {
115 bool bIsRemoved = false;
116 bool bShow = true;
117
118 int32 ColorUid = 0;
119 int32 StyleIndex = 0;
120
121 enum class EInheritance
122 {
123 Unset,
124 Father,
125 Child
126 };
127
128 EInheritance MaterialInheritance = EInheritance::Unset;
129
130 };
132
133 struct FMaterial
134 {
136 FColor Ambient;
138 float Shininess;
139 float Transparency = 0;
140 };
141
145
146 static CADKERNELENGINE_API bool ParseRootBaseData(const A3DEntity* Entity, TMap<FString, FString>& MetaData, FString& UniqueID, FString& Label);
148
149
150 static CADKERNELENGINE_API bool IsMaterialTexture(const uint32 MaterialIndex);
152
155
156#endif
157
158 private:
159 static bool bIsInitialized;
160 };
161
163 {
164 public:
165 /*
166 ** @param FilePath: Absolute path to the prc file to load
167 ** @param bSewModel: Optional argument to force a stitching of the model
168 ** @param StitchingTolerance: Optional stitching tolerance in mm
169 */
170 static CADKERNELENGINE_API bool Save(const TArray<A3DRiRepresentationItem*>& Representations, const FString& FilePath, const FString& Attributes = FString());
171 static CADKERNELENGINE_API bool Save(A3DRiRepresentationItem* Representation, const FString& FilePath, const FString& Attributes = FString())
172 {
173 return Save(TArray<A3DRiRepresentationItem*>( &Representation, 1 ), FilePath, Attributes);
174 }
175 static CADKERNELENGINE_API bool Tessellate(A3DRiRepresentationItem* Representation, const FTessellationContext& Context, FMeshDescription& MeshOut, bool bSkipDeletedFaces = false, bool bEmptyMesh = false);
177
179 /* Limitation: Non of the implicit geometry is supported */
183
184 };
185
186 namespace MathUtils
187 {
188 /*
189 ** Converts a transform from a given coordinates system to UE's one
190 ** UE's coordinates system is ZUp_LeftHanded
191 */
192 inline FTransform ConvertTransform(ECADKernelModelCoordSystem SourceCoordSystem, const FTransform& LocalTransform)
193 {
194 const FTransform RightHanded(FRotator(0.0f, 0.0f, 0.0f), FVector(0.0f, 0.0f, 0.0f), FVector(-1.0f, 1.0f, 1.0f));
195 const FTransform RightHandedLegacy(FRotator(0.0f, 0.0f, 0.0f), FVector(0.0f, 0.0f, 0.0f), FVector(1.0f, -1.0f, 1.0f));
196 const FTransform YUpMatrix(FMatrix(FVector(0.0f, 0.0f, 1.0f), FVector(1.0f, 0.0f, 0.0f), FVector(0.0f, 1.0f, 0.0f), FVector(0.0f, 0.0f, 0.0f)));
197 const FTransform YUpMatrixInv(YUpMatrix.Inverse());
198
199 switch (SourceCoordSystem)
200 {
202 {
203 return RightHanded * LocalTransform * RightHanded;
204 }
206 {
207 return YUpMatrix * LocalTransform * YUpMatrixInv;
208 }
210 {
211 return RightHanded * YUpMatrix * LocalTransform * YUpMatrixInv * RightHanded;
212 }
214 {
215 return RightHandedLegacy * LocalTransform * RightHandedLegacy;
216 }
217 default:
218 {
219 return LocalTransform;
220 }
221 }
222 }
223
224 template<typename VecType>
225 void ConvertVectorArray(ECADKernelModelCoordSystem ModelCoordSys, TArrayView<VecType>& Array)
226 {
227 switch (ModelCoordSys)
228 {
230 for (VecType& Vector : Array)
231 {
232 Vector.Set(Vector[2], Vector[0], Vector[1]);
233 }
234 break;
235
237 for (VecType& Vector : Array)
238 {
239 Vector.Set(-Vector[2], Vector[0], Vector[1]);
240 }
241 break;
242
244 for (VecType& Vector : Array)
245 {
246 Vector.Set(-Vector[0], Vector[1], Vector[2]);
247 }
248 break;
249
251 for (VecType& Vector : Array)
252 {
253 Vector.Set(Vector[0], -Vector[1], Vector[2]);
254 }
255 break;
256
258 default:
259 break;
260 }
261 }
262
263 template<typename VecType>
264 void ConvertVectorArray(uint8 ModelCoordSys, TArrayView<VecType>& Array)
265 {
266 ConvertVectorArray(static_cast<ECADKernelModelCoordSystem>(ModelCoordSys), Array);
267 }
268
269 template<typename VecType>
270 void ConvertVectorArray(ECADKernelModelCoordSystem ModelCoordSys, TArray<VecType>& Array)
271 {
272 TArrayView<VecType> ArrayView(Array);
273 ConvertVectorArray(ModelCoordSys, ArrayView);
274 }
275
276 template<typename VecType>
277 void ConvertVectorArray(uint8 ModelCoordSys, TArray<VecType>& Array)
278 {
279 TArrayView<VecType> ArrayView(Array);
280 ConvertVectorArray(static_cast<ECADKernelModelCoordSystem>(ModelCoordSys), ArrayView);
281 }
282
283 template<typename VecType>
284 VecType ConvertVector(ECADKernelModelCoordSystem ModelCoordSys, const VecType& V)
285 {
286 switch (ModelCoordSys)
287 {
289 return VecType(V[2], V[0], V[1]);
290
292 return VecType(-V[2], V[0], V[1]);
293
295 return VecType(-V[0], V[1], V[2]);
296
298 return VecType(V[0], -V[1], V[2]);
299
301 default:
302 return VecType(V[0], V[1], V[2]);
303 }
304 }
305
306 template<typename VecType>
307 VecType ConvertVector(uint8 ModelCoordSys, const VecType& V)
308 {
309 return ConvertVector(static_cast<ECADKernelModelCoordSystem>(ModelCoordSys), V);
310 }
311 }
312}
313#endif
ECADKernelModelCoordSystem
Definition CADKernelEngineDefinitions.h:11
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define FVector
Definition IOSSystemIncludes.h:8
UE::Math::TMatrix< double > FMatrix
Definition MathFwd.h:51
UE::Math::TRotator< double > FRotator
Definition MathFwd.h:57
void A3DRiRepresentationItem
Definition ParametricSurfaceData.h:25
void A3DAsmModelFile
Definition ParametricSurfaceData.h:26
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition MaterialShared.h:2058
Definition ArrayView.h:139
Definition Array.h:670
Definition AssetRegistryState.h:50
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition Model.h:22
Definition DynamicMesh3.h:108
Definition CADEntity.cpp:23
ENGINE_API void Tessellate(TArray< FVector > &Output, const FVector &P0, const FVector &P1, const FVector &P2, const FVector &P3, const float Tolerance, const int MaxLevel=6)
Definition BezierUtilities.cpp:207
Definition ParametricSurfaceData.h:18
Definition Color.h:486
Definition MeshDescription.h:94