Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Core/Plugins/SofaUnityAPI/SofaContextAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEngine;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.IO;

namespace SofaUnityAPI
{
Expand Down Expand Up @@ -80,7 +81,9 @@ public SofaContextAPI(bool async)
}

CopyAssetToPersistent();

#if !UNITY_EDITOR
RegenerateSofaIni();
#endif
// load the sofaIni file
string pathIni = Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/sofa.ini";
string sharePath = sofaPhysicsAPI_loadSofaIni(m_native, pathIni);
Expand Down Expand Up @@ -110,6 +113,30 @@ public SofaContextAPI(bool async)
m_sofaVersion = sofaPhysicsAPI_version(m_native);
}


/// <summary>
/// simple method to regenerate sofa.ini
/// PS: don't update the liscence path it's not needed and will make the app crash
/// </summary>
private static void RegenerateSofaIni()
{
string dataPath = Application.dataPath.Replace("\\", "/");
string pluginsPath = dataPath + "/Plugins/x86_64";
string scenesPath = dataPath + "/SofaUnity/scenes/SofaScenes";
//string licensePath = dataPath + "/License/";
string iniPath = dataPath + "/SofaUnity/Core/Plugins/Native/x64/sofa.ini";

using (StreamWriter iniFile = new StreamWriter(iniPath))
{
iniFile.WriteLine("SHARE_DIR=" + scenesPath);
iniFile.WriteLine("EXAMPLES_DIR=" + scenesPath);
//iniFile.WriteLine("LICENSE_DIR=" + licensePath);
iniFile.WriteLine("BUILD_DIR=" + pluginsPath);
}

Debug.Log("[SofaUnity] sofa.ini regenerated at: " + iniPath);
}

/// Destructor
~SofaContextAPI()
{
Expand Down
15 changes: 15 additions & 0 deletions Core/Scripts/Editor/Config/CopyConfigPostProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ static void BuildForWindows(string pathToBuiltProject)
outputIniFile.WriteLine("SHARE_DIR=" + dataBuildPath);
outputIniFile.WriteLine("EXAMPLES_DIR=" + dataBuildPath);
outputIniFile.WriteLine("LICENSE_DIR=" + rootBuildPath + "/License/");
outputIniFile.WriteLine("BUILD_DIR=" + rootBuildPath + "/Plugins/x86_64/");
Debug.Log("[SofaUnity - BuildForWindows] Generate: " + outputIniPath + " file.");
}

Expand All @@ -185,6 +186,20 @@ static void BuildForWindows(string pathToBuiltProject)
{
Debug.LogError("No 'SofaScenes' folder found to copy Sofa scene related to: " + unityScenePath);
}

// Copy python3 folder if exists for python scene build
string sourcePython3Path = Application.dataPath + "/SofaUnity/Core/Plugins/Native/x64/python3/";
string destPython3Path = rootBuildPath + "/Plugins/x86_64/python3/";

if (Directory.Exists(sourcePython3Path))
{
DirectoryCopy(sourcePython3Path, destPython3Path, true);
Debug.Log("[SofaUnity - BuildForWindows] Copied python3 folder to: " + destPython3Path);
}
else
{
Debug.LogWarning("[SofaUnity - BuildForWindows] python3 folder not found at: " + sourcePython3Path + " — skipping python3 copy.");
}
}


Expand Down
9 changes: 9 additions & 0 deletions Core/Scripts/SofaContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@ void Init()
#if !UNITY_ANDROID
m_pluginMgr.LoadPlugins();
#endif
if (m_log)
{
List<PluginInfo> pluginsPresent = m_pluginMgr.GetPluginList();
foreach (PluginInfo pi in pluginsPresent)
{
Debug.Log("Loaded plugin " + pi.Name);
}
}

// start sofa instance
if (m_log)
Debug.Log("## SofaContext status before start: " + m_impl.contextStatus());
Expand Down