Skip to content

Commit

Permalink
Added support for namespaces
Browse files Browse the repository at this point in the history
This has required converting all std::string to std::wstring
  • Loading branch information
munkybutt committed Nov 29, 2024
1 parent 34137ba commit 22b570e
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 40 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,7 @@ MigrationBackup/

# End of https://www.toptal.com/developers/gitignore/api/c++,visualstudio,visualstudiocode,sublimetext

**/.3rdParty/**
**/.venvs/**
**/.dev/**
build/
pypi/
temp.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/.sln.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Set dependency variables here:
$devFolder = Resolve-Path -Path "$PSScriptRoot\..\..\.dev"
Write-Host $devFolder
Set-Location "$devFolder\3rdparty"
Set-Location "$devFolder\ThirdParty"
$Env:THIRD_PARTY_EIGEN = (Resolve-Path -Path "./eigen")
$Env:THIRD_PARTY_FMT = (Resolve-Path -Path "./fmt")

Expand All @@ -17,7 +17,7 @@ foreach ($version in $installedVersions) {
$pythonRootPath = (Get-Item $pythonPath).Directory.FullName
$majorMinor = $version -replace '(\d+\.\d+).*', '$1' -replace '\.', ''
Set-Item "Env:PYTHON_$majorMinor" $pythonRootPath
$pybindPath = Resolve-Path -Path "$devFolder\venv\$majorMinor\.venv\Lib\site-packages\pybind11"
$pybindPath = Resolve-Path -Path "$devFolder\venvs\py$majorMinor\.venv\Lib\site-packages\pybind11" -ErrorAction SilentlyContinue
if ($pybindPath) {
Write-Host "Setting PyBind11 path: $pybindPath"
Set-Item "Env:PYBIND11_$majorMinor" $pybindPath
Expand Down
18 changes: 9 additions & 9 deletions src/cpp/skin_plus_plus_py/headers/skin_plus_plus_py.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#define FMT_HEADER_ONLY
#define FMT_DEPRECATED_INCLUDE_XCHAR
#include <fmt/format.h>
//#include <fmt/xchar.h>
#include <fmt/xchar.h>

namespace py = pybind11;
namespace eg = Eigen;


typedef std::vector<std::string> BoneNamesVector;
typedef std::vector<std::wstring> BoneNamesVector;
typedef eg::MatrixXi BoneIDsMatrix;
typedef eg::MatrixXd WeightsMatrix;
typedef eg::MatrixXd PositionMatrix;
Expand Down Expand Up @@ -83,13 +83,13 @@ const char* convertStringToChar(std::string text)
struct SortedBoneNameData
{
std::vector<UINT> sortedBoneIDs;
std::vector<std::string> unfoundBoneNames;
std::vector<std::wstring> unfoundBoneNames;
UINT highestBoneID;
UINT lowestBoneID;
SortedBoneNameData(UINT boneCount)
{
sortedBoneIDs = std::vector<UINT>(boneCount);
unfoundBoneNames = std::vector<std::string>();
unfoundBoneNames = std::vector<std::wstring>();
};
~SortedBoneNameData() {}
};
Expand Down Expand Up @@ -219,15 +219,15 @@ struct PySkinData final
{
const size_t cachedBoneCount = this->boneNames.size();
auto sortedBoneNameData = SortedBoneNameData(cachedBoneCount);
std::unordered_map<std::string, size_t> nameMap;
std::unordered_map<std::wstring, size_t> nameMap;
for (size_t index = 0; index < currentBoneNames.size(); index++)
{
nameMap[currentBoneNames[index]] = index;
}

for (size_t boneIndex = 0; boneIndex < cachedBoneCount; boneIndex++)
{
const std::string nameToFind = this->boneNames[boneIndex];
const std::wstring nameToFind = this->boneNames[boneIndex];
const auto lookup = nameMap.find(nameToFind);
if (lookup != nameMap.end())
{
Expand All @@ -240,10 +240,10 @@ struct PySkinData final
}
if (!sortedBoneNameData.unfoundBoneNames.empty())
{
std::string message = "The following bones are not in the skin definition:";
for (const std::string& name : sortedBoneNameData.unfoundBoneNames)
std::wstring message = L"The following bones are not in the skin definition:";
for (const std::wstring& name : sortedBoneNameData.unfoundBoneNames)
{
message += fmt::format("\n- {}", name);
message = fmt::format(L"{}\n- {}", message, name);
}
py::print(message);

Expand Down
5 changes: 3 additions & 2 deletions src/cpp/skin_plus_plus_py/skin_plus_plus_py.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='2023-Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.pyd</TargetExt>
<OutDir>$(SolutionDir)..\..\PYProjects\skin_plus_plus\py\39\</OutDir>
<OutDir>$(SolutionDir)..\skin_plus_plus\py\39\</OutDir>
<IncludePath>$(THIRD_PARTY_EIGEN);$(THIRD_PARTY_FMT)\include;$(ProjectDir)headers;$(PYTHON_39)\include;$(PYBIND11_39)\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='2024-Release|x64'">
Expand Down Expand Up @@ -248,8 +248,9 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>Default</LanguageStandard>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
14 changes: 7 additions & 7 deletions src/cpp/skin_plus_plus_pymaya/skin_plus_plus_pymaya.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ static UINT getFirstFreeIndex(MPlug* arrayPlug)

MObject SkinManagerMaya::addMissingBones(BoneNamesVector& missingBoneNames, const UINT& skinnedBoneCount)
{
for (std::string& name : missingBoneNames)
for (std::wstring& name : missingBoneNames)
{
auto command = fmt::format("skinCluster -e -ai {} {}", name, this->fnSkinCluster.name().asChar());
std::wstring command = fmt::format(L"skinCluster -e -ai {} {}", name, fmt::ptr(this->fnSkinCluster.name().asChar()));
MGlobal::executeCommand(MString(command.c_str()));
}
}
Expand Down Expand Up @@ -278,10 +278,10 @@ PySkinData SkinManagerMaya::extractSkinData(const bool safeMode)
{
throw std::runtime_error("Failed to find influence objects!");
}
pySkinData.boneNames = std::vector<std::string>(skinnedBones.length());
pySkinData.boneNames = std::vector<std::wstring>(skinnedBones.length());
for (UINT boneIndex = 0; boneIndex < skinnedBones.length(); boneIndex++)
{
pySkinData.boneNames[boneIndex] = fmt::format("{}", skinnedBones[boneIndex].partialPathName().asChar());
pySkinData.boneNames[boneIndex] = fmt::format(L"{}", fmt::ptr(skinnedBones[boneIndex].partialPathName().asChar()));
}
MPoint mPoint;
pySkinData.setMaximumVertexWeightCount(boneCount);
Expand Down Expand Up @@ -409,13 +409,13 @@ static MDoubleArray getWeightsAsMDoubleArray(BoneIDsMatrix& boneIDs, WeightsMatr
}


static void getBoneNames(std::vector<std::string>& currentBoneNames, const MDagPathArray& skinnedBones, const UINT& skinnedBoneCount)
static void getBoneNames(std::vector<std::wstring>& currentBoneNames, const MDagPathArray& skinnedBones, const UINT& skinnedBoneCount)
{
currentBoneNames.clear();
currentBoneNames.resize(skinnedBoneCount);
for (UINT boneIndex = 0; boneIndex < skinnedBoneCount; boneIndex++)
{
currentBoneNames[boneIndex] = fmt::format("{}", skinnedBones[boneIndex].partialPathName().asChar());
currentBoneNames[boneIndex] = fmt::format(L"{}", fmt::ptr(skinnedBones[boneIndex].partialPathName().asChar()));
}
}

Expand Down Expand Up @@ -456,7 +456,7 @@ bool SkinManagerMaya::applySkinData(PySkinData& skinData)
throw std::runtime_error("Error querying bones!");
}
auto skinnedBoneCount = skinnedBones.length();
auto currentBoneNames = std::vector<std::string>(skinnedBoneCount);
auto currentBoneNames = std::vector<std::wstring>(skinnedBoneCount);
getBoneNames(currentBoneNames, skinnedBones, skinnedBoneCount);
bool bonesAdded = false;
if (skinnedBoneCount == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/skin_plus_plus_pymaya/skin_plus_plus_pymaya.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class SkinManagerMaya

// Get the skin weights from the given node's skin modifier
//std::vector<std::vector<std::vector <float>>> getSkinWeights();
MObject addMissingBones(std::vector<std::string>& missingBoneNames, const UINT& skinnedBoneCount);
MObject addMissingBones(std::vector<std::wstring>& missingBoneNames, const UINT& skinnedBoneCount);

// Get the vertex weights, bone ids and positions from the given node
PySkinData extractSkinData(const bool safeMode = true);
Expand Down
4 changes: 3 additions & 1 deletion src/cpp/skin_plus_plus_pymaya/skin_plus_plus_pymaya.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<TargetExt>.pyd</TargetExt>
<IncludePath>$(THIRD_PARTY_EIGEN);$(THIRD_PARTY_FMT)\include;$(ProjectDir);$(ProjectDir)..\skin_plus_plus_py\headers;$(ADSK_MAYA_SDK_2023)\include;$(PYTHON_39)\include;$(PYBIND11_39)\include;$(IncludePath)</IncludePath>
<LibraryPath>$(ADSK_MAYA_SDK_2023)\lib;$(PYTHON_39)\libs;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)..\..\PYProjects\skin_plus_plus\dccs\maya\$(ProjectName)_2023\</OutDir>
<OutDir>$(SolutionDir)..\skin_plus_plus\dccs\maya\$(ProjectName)_2023\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='2024-Release|x64'">
<LinkIncremental>false</LinkIncremental>
Expand Down Expand Up @@ -232,6 +232,8 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/skin_plus_plus_pymxs/headers/skin_plus_plus_pymxs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <Max.h>
#include <matrix3.h>
#include <maxscript/maxwrapper/mxsobjects.h>
//#include <modifiers/bonesdef/bonesdef.h>


class SkinManager
Expand Down Expand Up @@ -60,7 +61,7 @@ class SkinManager
void extractDataPoly(const UINT vertexCount);

// Add missing bones to the skin modifier based on the given vector of missing bone names
void addMissingBones(std::vector<std::string> missingBoneNames);
void addMissingBones(std::vector<std::wstring> missingBoneNames);

// Initialise skinModifier, iSkin, iSkinContextData, iSkinImportData
bool initialiseSkin();
Expand Down
9 changes: 7 additions & 2 deletions src/cpp/skin_plus_plus_pymxs/skin_plus_plus_pymxs.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@
<TargetExt>.pyd</TargetExt>
<IncludePath>$(THIRD_PARTY_EIGEN);$(THIRD_PARTY_FMT)\include;$(ProjectDir)\headers;$(ProjectDir)..\skin_plus_plus_py\headers;$(ADSK_3DSMAX_SDK_2023)\include;$(ADSK_3DSMAX_SDK_2023)\include\geom;$(PYTHON_39)\include;$(PYBIND11_39)\include;$(IncludePath)</IncludePath>
<LibraryPath>$(PYTHON_39)\libs;$(ADSK_3DSMAX_SDK_2023)\lib\x64\Release;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)..\..\PYProjects\skin_plus_plus\dccs\max\$(ProjectName)_2023</OutDir>
<OutDir>$(SolutionDir)..\skin_plus_plus\dccs\max\$(ProjectName)_2023</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='2024-Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.pyd</TargetExt>
<IncludePath>$(THIRD_PARTY_EIGEN);$(THIRD_PARTY_FMT)\include;$(ProjectDir)\headers;$(ProjectDir)..\skin_plus_plus_py\headers;$(ADSK_3DSMAX_SDK_2024)\include;$(ADSK_3DSMAX_SDK_2024)\include\geom;$(PYTHON_310)\include;$(PYBIND11_310)\include;$(IncludePath)</IncludePath>
<IncludePath>$(THIRD_PARTY_EIGEN);$(THIRD_PARTY_FMT)\include;$(ProjectDir)\headers;$(ProjectDir)..\skin_plus_plus_py\headers;$(ADSK_3DSMAX_SDK_2024)\include;$(ADSK_3DSMAX_SDK_2024)\include\geom;$(PYTHON_310)\include;$(PYBIND11_310)\include;$(ADSK_3DSMAX_SDK_2024)\samples;$(IncludePath)</IncludePath>
<LibraryPath>$(PYTHON_310)\libs;$(ADSK_3DSMAX_SDK_2024)\lib\x64\Release;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)..\skin_plus_plus\dccs\max\2024\</OutDir>
<TargetName>$(ProjectName)</TargetName>
Expand Down Expand Up @@ -296,6 +296,11 @@
<LanguageStandard Condition="'$(Configuration)|$(Platform)'=='2024-Release|x64'">stdcpp17</LanguageStandard>
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='2024-Release|x64'">Speed</FavorSizeOrSpeed>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='2024-Release|x64'">/utf-8 %(AdditionalOptions)</AdditionalOptions>
<Optimization Condition="'$(Configuration)|$(Platform)'=='2024-Release|x64'">Disabled</Optimization>
</ClCompile>
<ClCompile>
<LanguageStandard Condition="'$(Configuration)|$(Platform)'=='2023-Release|x64'">stdcpp17</LanguageStandard>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='2023-Release|x64'">/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
</Project>
Loading

0 comments on commit 22b570e

Please sign in to comment.