-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for getting node by unique handle
Nodes are no longer queried by their names which could be problematic in scenes with duplicate names. A unique scene handle (id) is now used instead. For 3ds max is the nodes handle, for maya it is the nodes full name. This has involved the implementation of a host interface class IHost. Only implemented IHost for max so far. This has required a large refactor of the dcc sub-package and the setup logic for skin_plus_plus itself.
- Loading branch information
Showing
21 changed files
with
296 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from pymel.core import nodetypes as pm_ntypes | ||
from pymxs import runtime as mxrt | ||
from typing import Callable | ||
from typing import TypeVar | ||
from typing import Union | ||
|
||
from . import SkinData | ||
|
||
T_Node = TypeVar("T_Node", mxrt.Node, pm_ntypes.DagNode) | ||
T_Handle = Union[int, str] | ||
T_CExSD = Callable[[T_Handle], SkinData] | ||
T_CApSD = Callable[[T_Handle, SkinData], None] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from __future__ import annotations | ||
|
||
import abc | ||
import importlib | ||
import pathlib | ||
|
||
|
||
_typing = False | ||
if _typing: | ||
|
||
from .. import _types | ||
from .. import SkinData | ||
|
||
del _typing | ||
|
||
|
||
class IHost(metaclass=abc.ABCMeta): | ||
_extract_skin_data: _types.T_CExSD | ||
_apply_skin_data: _types.T_CApSD | ||
_get_vertex_positions: _types.Callable | ||
|
||
def __init__(self) -> None: | ||
self._get_dcc_backend() | ||
|
||
@property | ||
@abc.abstractmethod | ||
def name(self) -> str: | ||
""" | ||
The name of the host | ||
""" | ||
|
||
@property | ||
@abc.abstractmethod | ||
def api_name(self) -> str: | ||
""" | ||
The api name of the compiled backend for the host. | ||
i.e. pymxs or pymaya | ||
""" | ||
|
||
def _get_dcc_backend(self): | ||
version = self._get_version_number() | ||
current_directory = pathlib.Path(__file__).parent | ||
sub_module_path = current_directory / self.name / str(version) | ||
|
||
if not sub_module_path.exists(): | ||
raise FileNotFoundError(f"Unsupported DCC version: {version}") | ||
|
||
import_path = f"{__name__.rstrip('core')}{self.name}.{version}.skin_plus_plus_{self.api_name}" | ||
backend = importlib.import_module(import_path) | ||
# if is_reloading: | ||
# importlib.reload(backend) | ||
|
||
self._extract_skin_data: _types.T_CExSD = backend.extract_skin_data | ||
self._apply_skin_data: _types.T_CApSD = backend.apply_skin_data | ||
self._get_vertex_positions: _types.Callable = backend.get_vertex_positions | ||
|
||
return backend | ||
|
||
@abc.abstractmethod | ||
def _get_version_number(self) -> int | str: | ||
""" | ||
Get the version number of the host | ||
""" | ||
|
||
@abc.abstractmethod | ||
def get_current_file_path(self) -> pathlib.Path: | ||
""" | ||
Get the file path of the current host scene | ||
""" | ||
|
||
@abc.abstractmethod | ||
def get_selection(self) -> tuple[_types.T_Node, ...]: | ||
""" | ||
Get the selection of the current host scene | ||
""" | ||
|
||
@abc.abstractmethod | ||
def get_node_name(self, node: _types.T_Node) -> str: | ||
""" | ||
Get the name of the given node | ||
""" | ||
|
||
@abc.abstractmethod | ||
def get_node_handle(self, node: _types.T_Node) -> _types.T_Handle: | ||
""" | ||
Get the unique handle of the given node | ||
""" | ||
|
||
|
||
def extract_skin_data(self, node: _types.T_Node) -> SkinData: | ||
handle = self.get_node_handle(node) | ||
return self._extract_skin_data(handle) | ||
|
||
def apply_skin_data(self, node: _types.T_Node, skin_data: SkinData): | ||
handle = self.get_node_handle(node) | ||
return self._apply_skin_data(handle, skin_data) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .core import IHost | ||
|
||
|
||
__all__ = ("IHost",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import annotations | ||
|
||
import pathlib | ||
|
||
from pymxs import runtime as mxrt | ||
|
||
from .. import core | ||
|
||
|
||
class IHost(core.IHost): | ||
|
||
@property | ||
def name(self) -> str: | ||
return "max" | ||
|
||
@property | ||
def api_name(self) -> str: | ||
return "pymxs" | ||
|
||
def _get_version_number(self): | ||
version_info = mxrt.MaxVersion() | ||
version_number = version_info[7] | ||
return version_number | ||
|
||
def get_current_file_path(self) -> pathlib.Path: | ||
max_file_path = mxrt.MaxFilePath | ||
if not max_file_path: | ||
raise RuntimeError("File is not saved!") | ||
|
||
return pathlib.Path(max_file_path, mxrt.MaxFileName) | ||
|
||
def get_selection(self) -> tuple[mxrt.Node, ...]: | ||
return tuple(mxrt.Selection) | ||
|
||
def get_node_name(self, node: mxrt.Node) -> str: | ||
return node.Name | ||
|
||
def get_node_handle(self, node: mxrt.Node) -> int: | ||
return node.Handle |
Binary file removed
BIN
-246 KB
PYProjects/skin_plus_plus/dccs/max/skin_plus_plus_pymxs_2024/skin_plus_plus_pymxs.pyd
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.