Skip to content

Commit

Permalink
Merge pull request #7 from sharkmob/main
Browse files Browse the repository at this point in the history
Merge all updates
  • Loading branch information
munkybutt authored Sep 8, 2023
2 parents 7f7f0da + cc0a6a1 commit 1203be1
Show file tree
Hide file tree
Showing 22 changed files with 320 additions and 64 deletions.
10 changes: 8 additions & 2 deletions PYProjects/.projects/SkinPlusPlus.sublime-project
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"folders":
[
{
"path": "../../../SkinPlusPlus",
}
"path": "C:\\p4ws\\sharkmob\\Tools\\tech_art\\base\\_standalone\\c++\\SkinPlusPlus",
},
{
"path": "C:\\p4ws\\sharkmob\\Tools\\tech_art\\base\\_standalone\\python\\_third_party"
},
],
"debugger_configurations":
[
],
}
18 changes: 18 additions & 0 deletions PYProjects/skin_plus_plus/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "3DsMax",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 6000
},
"justMyCode": false
}
]
}
18 changes: 18 additions & 0 deletions PYProjects/skin_plus_plus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@
get_skin_data = None
set_skin_weights = None
skin_plus_plus_py = None
SkinData = None
# get_vertex_positions = None

try:
is_reloading # type: ignore
is_reloading = True
except NameError:
is_reloading = False

__py_version__ = f"{sys.version_info.major}{sys.version_info.minor}"


def __get_skin_plus_plus_py(python_version: str, debug: bool = False):
global skin_plus_plus_py
global SkinData

debug = bool(os.environ.get("SKIN_PLUS_PLUS_DEBUG", False)) or debug
if debug:
Expand All @@ -34,6 +42,11 @@ def __get_skin_plus_plus_py(python_version: str, debug: bool = False):
del sys.modules["skin_plus_plus_py"]

skin_plus_plus_py = importlib.import_module(import_path)
if is_reloading:
importlib.reload(skin_plus_plus_py)

SkinData = skin_plus_plus_py.SkinData

return skin_plus_plus_py


Expand All @@ -47,6 +60,8 @@ def __get_dcc_backend(dcc:str, version: str, api:str):

import_path = f"{__name__}.dccs.{dcc}.{sub_module_name}.skin_plus_plus_{api}"
backend = importlib.import_module(import_path)
if is_reloading:
importlib.reload(backend)

global get_skin_data
global set_skin_weights
Expand Down Expand Up @@ -171,3 +186,6 @@ def __getattr__(name: str) -> Any:
"max_to_maya",
"maya_to_max"
)

def __dir__():
return __all__
24 changes: 22 additions & 2 deletions PYProjects/skin_plus_plus/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import numpy.typing as np_typing
import typing

from .core import FileType as _FileType
from .core import export_skin_data as _export_skin_data
Expand Down Expand Up @@ -45,11 +46,30 @@ class SkinData:
- `weights`: The weights of each influence assigned to each vertext.
- `positions`: The positions of each vertex.
"""

bone_names: list[str]
bone_ids: np_typing.NDArray[np.int64]
weights: np_typing.NDArray[np.float32]
positions: np_typing.NDArray[np.float32]

@typing.overload
def __init__(self):
...

@typing.overload
def __init__(
self,
names: tuple[str, ...],
bone_ids: tuple[tuple[int, ...], ...],
weights: tuple[tuple[float, ...], ...],
positions: tuple[tuple[float, float, float], ...],
):
...


def get_skin_data(mesh_name: str) -> SkinData:
...


def get_skin_data(mesh_name: str) -> SkinData: ...
def set_skin_weights(mesh_name: str, skin_data: SkinData) -> bool: ...
def set_skin_weights(mesh_name: str, skin_data: SkinData) -> bool:
...
2 changes: 2 additions & 0 deletions PYProjects/skin_plus_plus/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def import_skin_data(
tuple(data["positions"])
)

print(f"skin_data.bone_ids: {skin_data.bone_ids}")

return set_skin_weights(mesh_name, skin_data)

# if import_type == ImportType.nearest:
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified PYProjects/skin_plus_plus/py/39/skin_plus_plus_py.exp
Binary file not shown.
Binary file modified PYProjects/skin_plus_plus/py/39/skin_plus_plus_py.pyd
Binary file not shown.
Binary file modified PYProjects/skin_plus_plus/py/debug_39/skin_plus_plus_py.exp
Binary file not shown.
Binary file modified PYProjects/skin_plus_plus/py/debug_39/skin_plus_plus_py.pyd
Binary file not shown.
58 changes: 58 additions & 0 deletions PYProjects/skin_plus_plus_test/ordering_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from __future__ import annotations


def get_flat_weights(bone_ids: list[list[int]], weights: list[list[float]], max_influence_count: int = 3):
vertex_count = len(bone_ids)
m_weights = [0.0] * vertex_count * max_influence_count
for vertex_index in range(vertex_count):
vertex_bone_ids = bone_ids[vertex_index]
array_index = vertex_index * max_influence_count
for influence_index in range(len(vertex_bone_ids)):
bone_id = vertex_bone_ids[influence_index]
if bone_id == -1:
continue
index = array_index + bone_id
m_weights[index] = weights[vertex_index][influence_index]

return m_weights

names = ["one", "two", "three"]
new_names = ["FART", "three", "one", "two", "RANDOM"]
bone_ids = [[0, 1, -1], [-1, 1, 2], [0, 1, 2]]
weights = [[0.25, 0.75, None], [None, 0.5, 0.5], [0.25, 0.25, 0.5]]

m_weights = get_flat_weights(bone_ids, weights)

print(m_weights)
print(m_weights == [0.25, 0.75, 0.0, 0.0, 0.5, 0.5, 0.25, 0.25, 0.5])


name_map = {}
for index, name in enumerate(new_names):
name_map[name] = index

new_bone_ids = []
for name in names:
new_index = name_map[name]
new_bone_ids.append(new_index)

def get_sorted_bone_ids(bone_ids: list[list[int]], new_bone_id_order: list[int]):
for vertex in bone_ids:
for i, bone_id in enumerate(vertex):
if bone_id == -1:
continue

new_index = new_bone_id_order[bone_id]
vertex[i] = new_index

return bone_ids


sorted_bone_ids = get_sorted_bone_ids(bone_ids, new_bone_ids)
print(bone_ids)
print(bone_ids == [[1, 2, -1], [-1, 2, 0], [1, 2, 0]])

m_weights = get_flat_weights(sorted_bone_ids, weights)

print(m_weights)
print(m_weights == [0.0, 0.25, 0.75, 0.5, 0.0, 0.5, 0.5, 0.25, 0.25])
55 changes: 44 additions & 11 deletions PYProjects/skin_plus_plus_test/skin_plus_plus_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
from __future__ import annotations

import functools

import inspect
import numpy as np
import pathlib
import random
import site
import sys
import time
import unittest

if __name__ == "__main__":

Expand All @@ -24,15 +19,23 @@ def __setup__():

__setup__()

import functools
import numpy as np
import random
import sys
import time
import unittest


import skin_plus_plus

# skin_plus_plus.set_debug(False)

if __name__ == "__main__":
from importlib import reload
reload(skin_plus_plus.core)
reload(skin_plus_plus.io)
reload(skin_plus_plus)
# reload(skin_plus_plus.core)
# reload(skin_plus_plus.io)
# reload(skin_plus_plus)

_typing = False
if _typing:
Expand Down Expand Up @@ -673,9 +676,39 @@ def add_bones():


if __name__ == "__main__":
skin_plus_plus.io.max_to_maya(file_type=skin_plus_plus.FileType.pickle)
pass
# skin_plus_plus.io.max_to_maya(file_type=skin_plus_plus.FileType.pickle)
# skin_plus_plus
# bones = ["one", "two"]
# ids = np.array([[0, 1], [1, 0]], dtype=np.float64)
# weights = np.array([[0.25, 0.75], [0.25, 0.75]], dtype=np.float64)
# pos = np.array([[0.1, 0.75, 2.0], [0.25, 0.75, 30]], dtype=np.float64)
# sd = skin_plus_plus.skin_plus_plus_py.SkinData(bones, ids, weights, pos)
# print(sd)

# print(sd.bone_ids)
# skin_plus_plus.io.save(file_type=skin_plus_plus.FileType.json)
skin_plus_plus.io.load(file_type=skin_plus_plus.FileType.json)
# skin_plus_plus.io.load(file_type=skin_plus_plus.FileType.json)
import json
import pickle

path = r""

with open(path, "r") as file:
data = json.load(file)
skin_data = skin_plus_plus.SkinData(
tuple(data["bone_names"]),
tuple(data["bone_ids"]),
tuple(data["weights"]),
tuple(data["positions"])
)
# with open(path, "rb") as file:
# skin_data = pickle.load(file)

print(skin_data)
# for ids in skin_data.bone_ids:
# print(ids)
skin_plus_plus.set_skin_weights("Skeleton", skin_data)
# skin_data = skin_plus_plus.get_skin_data("Weapon_Shield_1H_001_Model_Main_01_:Shield_GEO")
# print(skin_data)
# skin_plus_plus.set_skin_weights("SM_EliteEnemy_Axe_GEO", skin_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ struct PySkinData final

PySkinData(UINT vertexCount, UINT maxInfluenceCount)
{
this->boneIDs = BoneIDsMatrix(vertexCount, maxInfluenceCount);
this->weights = WeightsMatrix(vertexCount, maxInfluenceCount);
this->boneIDs = BoneIDsMatrix::Constant(vertexCount, maxInfluenceCount, -1);
this->weights = WeightsMatrix::Zero(vertexCount, maxInfluenceCount);
this->positions = PositionMatrix(vertexCount, 3);
}

Expand Down Expand Up @@ -142,8 +142,8 @@ struct PySkinData final
// Set a new maximum influence count
void setMaximumVertexWeightCount(int influenceCount)
{
this->boneIDs.resize(eg::NoChange, influenceCount);
this->weights.resize(eg::NoChange, influenceCount);
this->boneIDs.conservativeResize(eg::NoChange, influenceCount);
this->weights.conservativeResize(eg::NoChange, influenceCount);
}

// Get the bone ids in their correct order as well as any missing bones
Expand Down
6 changes: 3 additions & 3 deletions PYProjects/source/skin_plus_plus_py/skin_plus_plus_py.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='2023-Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down Expand Up @@ -90,7 +90,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)..\..\PYProjects\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 Label="Vcpkg">
Expand Down
Loading

0 comments on commit 1203be1

Please sign in to comment.