Skip to content

Commit f913dd7

Browse files
authored
[src] Fix release/debug config switch to link against the corresponding SOFA dll and libs + small improvments in VisualMesh (#34)
* [src] Fix release/debug config switch to link against the corresponding SOFA dll and libs * [src] Fix simulation pace to call step every dt * small improvment for SofaVIsualMesh
1 parent cd92983 commit f913dd7

4 files changed

Lines changed: 42 additions & 22 deletions

File tree

Source/SofaUE5/Private/SofaContext.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,24 +233,26 @@ void ASofaContext::PostEditChangeProperty(FPropertyChangedEvent & PropertyChange
233233
}
234234
#endif
235235

236-
236+
double nextime = 0.0;
237+
int cptStep = 0;
237238
// Called every frame
238239
void ASofaContext::Tick( float DeltaTime )
239240
{
240241
if (m_status != -1 && m_sofaAPI)
241242
{
242-
// Step SOFA simulation on each UE tick
243-
m_sofaAPI->step();
244-
245-
//double stime = m_sofaAPI->getTime();
246-
247-
//if (m_isMsgHandlerActivated == true)
248-
// catchSofaMessages();
249-
250-
//UE_LOG(LogTemp, Warning, TEXT("## ASofaContext: Tick: %f %f"), value, stime);
243+
float value = this->GetGameTimeSinceCreation();
244+
if (value >= nextime)
245+
{
246+
cptStep++;
247+
nextime = value + Dt;
248+
//UE_LOG(SUnreal_log, Log, TEXT("## ASofaContext: Tick %d: %f"), cptStep, value);
249+
250+
// Step SOFA simulation on each UE tick
251+
m_sofaAPI->step();
252+
}
253+
254+
//UE_LOG(LogTemp, Warning, TEXT("## ASofaContext: Tick: %f"), value);
251255
}
252-
float value = this->GetGameTimeSinceCreation();
253-
UE_LOG(LogTemp, Warning, TEXT("## ASofaContext: Tick: %f"), value);
254256

255257
Super::Tick(DeltaTime);
256258
}
@@ -366,7 +368,8 @@ void ASofaContext::loadDefaultPlugin()
366368

367369
bool debugMode = false;
368370

369-
#if (UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT) && !UE_BUILD_SHIPPING
371+
372+
#if UE_DEBUGGAME
370373
debugMode = true;
371374
#endif
372375

Source/SofaUE5/Private/SofaUE5.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ void FSofaUE5Module::StartupModule()
4242
FString BaseDir = IPluginManager::Get().FindPlugin("SofaUE5")->GetBaseDir();
4343

4444
bool debugMode = false;
45-
46-
#if (UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT) && !UE_BUILD_SHIPPING
45+
46+
#if UE_DEBUGGAME
4747
debugMode = true;
4848
#endif
49+
UE_LOG(LogTemp, Warning, TEXT("FSofaUE5Module::StartupModule debug = %d"), debugMode);
4950

5051
// Add on the relative location of the third party dll and load it
5152
FString LibraryPath;
@@ -98,6 +99,7 @@ void FSofaUE5Module::StartupModule()
9899
FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("ThirdPartyLibraryError", "Failed to load SofaVerseAPI GetDllHandle error"));
99100
}
100101

102+
UE_LOG(LogTemp, Warning, TEXT("LibraryPath = %s"), *LibraryPath);
101103
UE_LOG(LogTemp, Warning, TEXT("_ITERATOR_DEBUG_LEVEL = %d"), _ITERATOR_DEBUG_LEVEL);
102104
}
103105

Source/SofaUE5/Private/SofaVisualMesh.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "SofaVisualMesh.h"
2525
#include "SofaUE5.h"
2626
#include "SofaUE5Library/SofaAdvancePhysicsAPI.h"
27+
#include "KismetProceduralMeshLibrary.h"
2728

2829
// Sets default values
2930
ASofaVisualMesh::ASofaVisualMesh()
@@ -170,8 +171,12 @@ void ASofaVisualMesh::createMesh()
170171
TArray<int32> Triangles;
171172
TArray<FVector> normals;
172173
TArray<FVector2D> UV0;
173-
TArray<FProcMeshTangent> tangents;
174-
TArray<FLinearColor> vertexColors;
174+
//TArray<FProcMeshTangent> tangents;
175+
//TArray<FLinearColor> vertexColors;
176+
177+
vertices.Reserve(nbrV);
178+
normals.Reserve(nbrV);
179+
UV0.Reserve(nbrV);
175180

176181
for (int i = 0; i < nbrV; i++)
177182
{
@@ -182,9 +187,6 @@ void ASofaVisualMesh::createMesh()
182187
normals.Add(FVector(-sofaNormals[i * 3], -sofaNormals[i * 3 + 1], -sofaNormals[i * 3 + 2]));
183188
else
184189
normals.Add(FVector(sofaNormals[i * 3], sofaNormals[i * 3 + 1], sofaNormals[i * 3 + 2]));
185-
186-
tangents.Add(FProcMeshTangent(0, 1, 0));
187-
vertexColors.Add(FLinearColor(0.75, 0.75, 0.75, 1.0));
188190
}
189191

190192
// Add triangles
@@ -206,14 +208,24 @@ void ASofaVisualMesh::createMesh()
206208
Triangles.Add(sofaQuads[i * 4 + 2]);
207209
Triangles.Add(sofaQuads[i * 4 + 3]);
208210
}
211+
212+
213+
// Generate tangents for correct lighting
214+
TArray<FVector> CalcNormals;
215+
TArray<FProcMeshTangent> CalcTangents;
216+
UKismetProceduralMeshLibrary::CalculateTangentsForMesh(vertices, Triangles, UV0, CalcNormals, CalcTangents);
217+
218+
mesh->CreateMeshSection_LinearColor(0, vertices, Triangles, CalcNormals, UV0, {}, CalcTangents, true);
219+
220+
mesh->SetCastShadow(true);
221+
mesh->bCastDynamicShadow = true;
222+
mesh->bAffectDistanceFieldLighting = true;
209223

210224
delete[] sofaVertices;
211225
delete[] sofaNormals;
212226
delete[] sofaTexCoords;
213227
delete[] sofaTriangles;
214228
delete[] sofaQuads;
215-
216-
mesh->CreateMeshSection_LinearColor(0, vertices, Triangles, normals, UV0, vertexColors, tangents, true);
217229

218230
// Enable collision data
219231
//mesh->ContainsPhysicsTriMeshData(true);

Source/ThirdParty/SofaUE5Library/SofaUE5Library.Build.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ public SofaUE5Library(ReadOnlyTargetRules Target) : base(Target)
2626
SofaBinPath = Path.Combine("$(PluginDir)/Binaries/ThirdParty/SofaUE5Library/Win64/", "Debug", SofaBinName);
2727

2828
PublicDefinitions.Add("WITH_SOFA_DEBUG=1");
29+
PublicDefinitions.Add("UE_DEBUGGAME=1");
2930
}
3031
else
3132
{
3233
SofaLibPath = Path.Combine(ModuleDirectory, "x64", "Release", "SofaVerseAPI.lib");
3334
SofaBinName = "SofaVerseAPI.dll";
3435
SofaBinPath = Path.Combine("$(PluginDir)/Binaries/ThirdParty/SofaUE5Library/Win64/", "Release", SofaBinName);
36+
37+
PublicDefinitions.Add("UE_DEBUGGAME=0");
3538
}
3639

3740
// Add the import library

0 commit comments

Comments
 (0)