Skip to content

Commit

Permalink
Fixed get vertex count bug in max
Browse files Browse the repository at this point in the history
  • Loading branch information
munkybutt committed Nov 23, 2024
1 parent f3d783c commit 796c083
Show file tree
Hide file tree
Showing 29 changed files with 315 additions and 155 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

PyProjects/.3rdparty/
PyProjects/.venvs/
.dev/
build/
pypi/
temp.cpp
Expand Down
17 changes: 17 additions & 0 deletions .projects/SkinPlusPlus.sublime-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"folders":
[
{
"path": "../src",
}
],
"settings": {
"lsp_code_actions_on_save": {
"source.fixAll": false,
"source.organizeImports": true,
},
},
"debugger_configurations":
[
],
}
73 changes: 73 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
"vendor",
"generated",
]

# Same as Black.
line-length = 100
indent-width = 4

target-version = "py39"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = ["E4", "E7", "E9", "F", "W", "I"]
ignore = ["F811"]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.lint.isort]
force-single-line = true
force-sort-within-sections = true
required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.format]
docstring-code-format = true

# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
10 changes: 0 additions & 10 deletions pyrightconfig.json

This file was deleted.

31 changes: 0 additions & 31 deletions src/.projects/SkinPlusPlus.sublime-project

This file was deleted.

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

Expand All @@ -15,8 +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 "..\.venvs\py$majorMinor\.venv\Lib\site-packages\pybind11" -ErrorAction SilentlyContinue
$pybindPath = Resolve-Path -Path "$devFolder\venv\$majorMinor\.venv\Lib\site-packages\pybind11"
if ($pybindPath) {
Write-Host "Setting PyBind11 path: $pybindPath"
Set-Item "Env:PYBIND11_$majorMinor" $pybindPath
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/skin_plus_plus_py/skin_plus_plus_py.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='2024-Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.pyd</TargetExt>
<OutDir>$(SolutionDir)..\..\PYProjects\skin_plus_plus\py\310\</OutDir>
<OutDir>$(SolutionDir)..\skin_plus_plus\py\310\</OutDir>
<IncludePath>$(THIRD_PARTY_EIGEN);$(THIRD_PARTY_FMT)\include;$(ProjectDir)headers;$(PYTHON_310)\include;$(PYBIND11_310)\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Label="Vcpkg">
Expand Down Expand Up @@ -270,6 +270,7 @@
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
4 changes: 0 additions & 4 deletions src/cpp/skin_plus_plus_py/skin_plus_plus_py.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\skin_plus_plus_py.cpp">
Expand Down
17 changes: 4 additions & 13 deletions src/cpp/skin_plus_plus_pymaya/skin_plus_plus_pymaya.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <maya/MObject.h>



//bool getMeshPositions(const MDagPath& dagPath, Array<Vector3>* pointArray)
//{
// nvDebugCheck(pointArray != NULL);
Expand Down Expand Up @@ -33,18 +32,6 @@
//}


//MStatus getNodesByName(const MStringArray& nodeNames, MObject& node)
//{
// MSelectionList selectionList;
// MStatus status = MGlobal::getSelectionListByName(nodeNames, selectionList);
// if (status == MS::kSuccess)
// {
// status = selectionList.getDependNode(0, node);
// }
// return status;
//}


bool SkinManagerMaya::initialise(const wchar_t* name, std::optional<VertexIDsMatrix> vertexIDs)
{
MStatus status;
Expand Down Expand Up @@ -306,6 +293,10 @@ PySkinData SkinManagerMaya::extractSkinData(const bool safeMode)
{
UINT weightIndex = weightIndexBase + boneIndex;
double influenceWeight = weights[weightIndex];
if (influenceWeight == 0)
{
continue;
}
pySkinData.weights(vertexIndex, influenceIndex) = influenceWeight;
pySkinData.boneIDs(vertexIndex, influenceIndex) = boneIndex;
influenceIndex += 1;
Expand Down
3 changes: 2 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 @@ -141,7 +141,7 @@
<TargetExt>.pyd</TargetExt>
<IncludePath>$(THIRD_PARTY_EIGEN);$(THIRD_PARTY_FMT)\include;$(ProjectDir);$(ProjectDir)..\skin_plus_plus_py\headers;$(ADSK_MAYA_SDK_2024)\include;$(PYTHON_310)\include;$(PYBIND11_310)\include;$(IncludePath)</IncludePath>
<LibraryPath>$(ADSK_MAYA_SDK_2024)\lib;$(PYTHON_310)\libs;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)..\..\PYProjects\skin_plus_plus\dccs\maya\2024\</OutDir>
<OutDir>$(SolutionDir)..\skin_plus_plus\dccs\maya\2024\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='2023-Debug|x64'">
<LinkIncremental>true</LinkIncremental>
Expand Down Expand Up @@ -250,6 +250,7 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="skin_plus_plus_pymaya.cpp">
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/skin_plus_plus_pymxs/headers/skin_plus_plus_pymxs.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include <skin_plus_plus_py.h>

#include <fmt/xchar.h>

#include <algorithm>
#include <cwchar>
#include <locale>
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/skin_plus_plus_pymxs/skin_plus_plus_pymxs.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<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>
<LibraryPath>$(PYTHON_310)\libs;$(ADSK_3DSMAX_SDK_2024)\lib\x64\Release;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)..\..\PYProjects\skin_plus_plus\dccs\max\2024\</OutDir>
<OutDir>$(SolutionDir)..\skin_plus_plus\dccs\max\2024\</OutDir>
<TargetName>$(ProjectName)</TargetName>
</PropertyGroup>
<PropertyGroup Label="Vcpkg">
Expand Down Expand Up @@ -295,6 +295,7 @@
<ClCompile>
<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>
</ClCompile>
</ItemDefinitionGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\skin_plus_plus_pymxs.cpp">
Expand Down
32 changes: 26 additions & 6 deletions src/cpp/skin_plus_plus_pymxs/source/skin_plus_plus_pymxs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,34 @@ static inline MeshType getMeshType(INode* node)
}


static const inline int getVertexCount(INode* node)
{
const MeshType meshType = getMeshType(node);
if (meshType == MeshType::mesh)
{
GET_MESH_DATA(node);
return mesh.getNumVerts();
}
else if (meshType == MeshType::poly)
{
GET_POLY_DATA(node)
return mnMesh.VNum();
}
throw py::type_error("Incorrect mesh type!");
}


bool SkinManager::initialiseSkin()
{
if (!this->node)
{
throw py::type_error("SkinData init failed. No node initialised!");
}
py::print(fmt::format(L"Node name: {}", node->GetName()));
Object* object = this->node->GetObjectRef();
if (!object || (object->SuperClassID() != GEN_DERIVOB_CLASS_ID))
{
/*fmt::format(L"SkinData init failed. Node is incorrect type: ", this->node->GetName())*/
throw py::type_error("SkinData init failed. Node is incorrect type " + convertWCharToChar(this->node->GetName()));
}
IDerivedObject* iDerivedObject = (IDerivedObject*)(object);
Expand All @@ -109,6 +128,7 @@ bool SkinManager::initialiseSkin()
this->isValid = true;
return this->isValid;
}
return this->isValid;
}


Expand Down Expand Up @@ -379,17 +399,17 @@ inline static BoneData getBoneData(ISkin* iSkin, const int skinBoneCount)

bool SkinManager::applySkinData(PySkinData& skinData)
{
auto boneIDsRows = skinData.boneIDs.rows();
auto vertexWeightsRows = skinData.weights.rows();
auto boneIDsCols = skinData.boneIDs.cols();
auto vertexWeightsCols = skinData.weights.cols();
const eg::Index boneIDsRows = skinData.boneIDs.rows();
const eg::Index vertexWeightsRows = skinData.weights.rows();
const eg::Index boneIDsCols = skinData.boneIDs.cols();
const eg::Index vertexWeightsCols = skinData.weights.cols();
if (boneIDsRows != vertexWeightsRows) throw std::length_error(
"skin bone ids count does not match skin weights count: " + convertWCharToChar(this->node->GetName())
);
if (boneIDsCols != vertexWeightsCols) throw std::length_error(
"skin bone ids count does not match skin weights count: " + convertWCharToChar(this->node->GetName())
);
auto vertexCount = this->iSkinContextData->GetNumPoints();
const int vertexCount = getVertexCount(node);
if (boneIDsRows != vertexCount && !skinData.vertexIDs.has_value()) throw std::length_error(
fmt::format("skin vertex count does not match provided data count: {}", convertWCharToChar(this->node->GetName()))
);
Expand All @@ -402,7 +422,7 @@ bool SkinManager::applySkinData(PySkinData& skinData)
BoneData boneData = getBoneData(this->iSkin, skinBoneCount);
SortedBoneNameData sortedBoneIDs = skinData.getSortedBoneIDs(boneData.names);
Tab<INode*> skinBones = boneData.nodes;
size_t sortedBoneIDCount = sortedBoneIDs.sortedBoneIDs.size();
const size_t sortedBoneIDCount = sortedBoneIDs.sortedBoneIDs.size();
if (sortedBoneIDs.unfoundBoneNames.size() > 0)
{
this->addMissingBones(sortedBoneIDs.unfoundBoneNames);
Expand Down
Loading

0 comments on commit 796c083

Please sign in to comment.