Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…chMoveSolver into develop
  • Loading branch information
david-cattermole committed Sep 17, 2024
2 parents f646baf + 3e4f2fa commit 49f07e7
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 55 deletions.
2 changes: 1 addition & 1 deletion python/mmSolver/_api/sethelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_annotation(self):
return ret

def set_annotation(self, value):
assert isinstance(value, str)
assert isinstance(value, pycompat.TEXT_TYPE)
set_node = self.get_node()
maya.cmds.sets(set_node, edit=True, text=value)
return
Expand Down
2 changes: 1 addition & 1 deletion python/mmSolver/_api/solveresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,5 +715,5 @@ def format_timestamp(value):
# Remove microseconds from the datetime object.
stamp = ts.replace(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, 0)
stamp = stamp.isoformat(' ')
assert isinstance(stamp, str)
assert isinstance(stamp, pycompat.TEXT_TYPE)
return stamp
2 changes: 1 addition & 1 deletion python/mmSolver/tools/createimageplane/_lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _set_locked_string_attr(node_attr, value):
def _set_image_sequence_v2(mm_image_plane_node, image_sequence_path, attr_name=None):
if attr_name is None:
attr_name = lib_const.DEFAULT_IMAGE_SEQUENCE_ATTR_NAME
assert isinstance(attr_name, str)
assert isinstance(attr_name, pycompat.TEXT_TYPE)
assert attr_name in lib_const.VALID_INPUT_IMAGE_SEQUENCE_ATTR_NAMES
version = lib_const.MM_IMAGE_PLANE_VERSION_TWO

Expand Down
12 changes: 6 additions & 6 deletions python/mmSolver/tools/createimageplane/_lib/mmimageplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ def create_shape_node(


def set_image_sequence(shp, image_sequence_path, attr_name, version=None):
assert isinstance(shp, str)
assert isinstance(image_sequence_path, str)
assert isinstance(attr_name, str)
assert isinstance(shp, pycompat.TEXT_TYPE)
assert isinstance(image_sequence_path, pycompat.TEXT_TYPE)
assert isinstance(attr_name, pycompat.TEXT_TYPE)
assert version in lib_const.MM_IMAGE_PLANE_VERSION_LIST
result = None
if version == lib_const.MM_IMAGE_PLANE_VERSION_ONE:
Expand All @@ -247,7 +247,7 @@ def set_image_sequence(shp, image_sequence_path, attr_name, version=None):


def get_shape_node(image_plane_tfm, version=None):
assert isinstance(image_plane_tfm, str)
assert isinstance(image_plane_tfm, pycompat.TEXT_TYPE)
assert maya.cmds.objExists(image_plane_tfm)
assert version in lib_const.MM_IMAGE_PLANE_VERSION_LIST
result = None
Expand All @@ -261,7 +261,7 @@ def get_shape_node(image_plane_tfm, version=None):


def get_transform_node(image_plane_shp, version=None):
assert isinstance(image_plane_shp, str)
assert isinstance(image_plane_shp, pycompat.TEXT_TYPE)
assert maya.cmds.objExists(image_plane_shp)
assert version in lib_const.MM_IMAGE_PLANE_VERSION_LIST
result = None
Expand All @@ -275,7 +275,7 @@ def get_transform_node(image_plane_shp, version=None):


def get_image_plane_node_pair(node, version=None):
assert isinstance(node, str)
assert isinstance(node, pycompat.TEXT_TYPE)
assert maya.cmds.objExists(node)
assert version in lib_const.MM_IMAGE_PLANE_VERSION_LIST
result = None
Expand Down
14 changes: 8 additions & 6 deletions python/mmSolver/tools/createimageplane/_lib/mmimageplane_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import mmSolver.utils.constant as const_utils
import mmSolver.utils.imageseq as imageseq_utils
import mmSolver.utils.node as node_utils
import mmSolver.utils.python_compat as pycompat
import mmSolver.tools.createimageplane._lib.constant as lib_const
import mmSolver.tools.createimageplane._lib.utilities as lib_utils

Expand Down Expand Up @@ -269,7 +270,7 @@ def _slot_number_to_attr_name(slot_number):


def _slot_attr_name_to_number(attr_name):
assert isinstance(attr_name, str)
assert isinstance(attr_name, pycompat.TEXT_TYPE)
assert attr_name in SLOT_ATTR_NAME_VALUES
return SLOT_ATTR_NAME_TO_NUMBER_MAP[attr_name]

Expand Down Expand Up @@ -309,7 +310,7 @@ def get_file_pattern_for_all_slots(shp):


def set_image_sequence(shp, image_sequence_path, attr_name):
assert isinstance(image_sequence_path, str)
assert isinstance(image_sequence_path, pycompat.TEXT_TYPE)
assert maya.cmds.nodeType(shp) == lib_const.MM_IMAGE_PLANE_SHAPE_V2
assert node_utils.attribute_exists(attr_name, shp) is True

Expand Down Expand Up @@ -393,14 +394,14 @@ def set_image_sequence(shp, image_sequence_path, attr_name):


def get_frame_size_bytes(shp):
assert isinstance(shp, str)
assert isinstance(shp, pycompat.TEXT_TYPE)
assert maya.cmds.nodeType(shp) == lib_const.MM_IMAGE_PLANE_SHAPE_V2
image_size_bytes = maya.cmds.getAttr(shp + '.imageSizeBytes')
return int(image_size_bytes)


def get_frame_count(shp):
assert isinstance(shp, str)
assert isinstance(shp, pycompat.TEXT_TYPE)
assert maya.cmds.nodeType(shp) == lib_const.MM_IMAGE_PLANE_SHAPE_V2
start_frame = maya.cmds.getAttr(shp + '.imageSequenceStartFrame')
end_frame = maya.cmds.getAttr(shp + '.imageSequenceEndFrame')
Expand All @@ -411,7 +412,7 @@ def get_frame_count(shp):


def get_image_sequence_size_bytes(shp):
assert isinstance(shp, str)
assert isinstance(shp, pycompat.TEXT_TYPE)
assert maya.cmds.nodeType(shp) == lib_const.MM_IMAGE_PLANE_SHAPE_V2
image_size_bytes = get_frame_size_bytes(shp)
frame_count = get_frame_count(shp)
Expand Down Expand Up @@ -483,6 +484,7 @@ def _set_attribute_editor_color_space(node_attr, control_name, value):

def _maybe_make_menu_item(button_name, label, node_attr, value):
if value and len(value) > 0:

def func(x):
_set_attribute_editor_color_space(node_attr, button_name, value)

Expand All @@ -491,7 +493,7 @@ def func(x):


def color_space_attribute_editor_new(node_attr):
assert isinstance(node_attr, str)
assert isinstance(node_attr, pycompat.TEXT_TYPE)
split = node_attr.split('.')
if len(split) == 0:
LOG.warn('Could not get attribute name from: %r', node_attr)
Expand Down
17 changes: 11 additions & 6 deletions python/mmSolver/tools/imagecache/_lib/erase.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import mmSolver.logger
import mmSolver.utils.imageseq as imageseq_utils
import mmSolver.utils.constant as const_utils
import mmSolver.utils.python_compat as pycompat
import mmSolver.tools.imagecache.constant as const
import mmSolver.tools.imagecache._lib.imagecache_cmd as imagecache_cmd
import mmSolver.tools.createimageplane._lib.constant as imageplane_const
Expand All @@ -40,7 +41,7 @@


def _make_group_name_consistent(group_name):
assert isinstance(group_name, str)
assert isinstance(group_name, pycompat.TEXT_TYPE)
assert len(group_name) > 0

# The ImageCache stores all file paths with UNIX
Expand All @@ -51,14 +52,14 @@ def _make_group_name_consistent(group_name):


def erase_gpu_group_items(group_name):
assert isinstance(group_name, str)
assert isinstance(group_name, pycompat.TEXT_TYPE)
assert len(group_name) > 0
group_name = _make_group_name_consistent(group_name)
return maya.cmds.mmImageCache([group_name], edit=True, gpuEraseGroupItems=True)


def erase_cpu_group_items(group_name):
assert isinstance(group_name, str)
assert isinstance(group_name, pycompat.TEXT_TYPE)
assert len(group_name) > 0
group_name = _make_group_name_consistent(group_name)
return maya.cmds.mmImageCache([group_name], edit=True, cpuEraseGroupItems=True)
Expand Down Expand Up @@ -91,7 +92,9 @@ def erase_all_images_on_image_plane_slots(cache_type, shape_node):
assert maya.cmds.nodeType(shape_node) == _IMAGE_PLANE_SHAPE

file_patterns = imageplane_lib.get_file_pattern_for_all_slots(shape_node)
file_patterns = [x for x in file_patterns if isinstance(x, str) and len(x) > 0]
file_patterns = [
x for x in file_patterns if isinstance(x, pycompat.TEXT_TYPE) and len(x) > 0
]
if len(file_patterns) == 0:
LOG.warn('mmImagePlane unused slots are all invalid; node=%r', shape_node)
return
Expand Down Expand Up @@ -124,7 +127,9 @@ def erase_images_in_unused_image_plane_slots(cache_type, shape_node):
assert maya.cmds.nodeType(shape_node) == _IMAGE_PLANE_SHAPE

file_patterns = imageplane_lib.get_file_pattern_for_unused_slots(shape_node)
file_patterns = [x for x in file_patterns if isinstance(x, str) and len(x) > 0]
file_patterns = [
x for x in file_patterns if isinstance(x, pycompat.TEXT_TYPE) and len(x) > 0
]
if len(file_patterns) == 0:
LOG.warn('mmImagePlane unused slots are all invalid; node=%r', shape_node)
return
Expand All @@ -141,7 +146,7 @@ def erase_image_sequence(
):
assert cache_type in const.CACHE_TYPE_VALUES
assert format_style in const_utils.IMAGE_SEQ_FORMAT_STYLE_VALUES
assert isinstance(file_pattern, str)
assert isinstance(file_pattern, pycompat.TEXT_TYPE)
assert isinstance(start_frame, int)
assert isinstance(end_frame, int)

Expand Down
9 changes: 5 additions & 4 deletions python/mmSolver/tools/imagecache/_lib/imagecache_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import maya.cmds

import mmSolver.logger
import mmSolver.utils.python_compat as pycompat

LOG = mmSolver.logger.get_logger()

Expand Down Expand Up @@ -59,25 +60,25 @@ def get_cpu_cache_slot_count():


def get_gpu_cache_group_item_count(group_name):
assert isinstance(group_name, str)
assert isinstance(group_name, pycompat.TEXT_TYPE)
assert len(group_name) > 0
return int(maya.cmds.mmImageCache(group_name, query=True, gpuGroupItemCount=True))


def get_cpu_cache_group_item_count(group_name):
assert isinstance(group_name, str)
assert isinstance(group_name, pycompat.TEXT_TYPE)
assert len(group_name) > 0
return int(maya.cmds.mmImageCache(group_name, query=True, cpuGroupItemCount=True))


def get_gpu_cache_group_item_names(group_name):
assert isinstance(group_name, str)
assert isinstance(group_name, pycompat.TEXT_TYPE)
assert len(group_name) > 0
return maya.cmds.mmImageCache(group_name, query=True, gpuGroupItemNames=True)


def get_cpu_cache_group_item_names(group_name):
assert isinstance(group_name, str)
assert isinstance(group_name, pycompat.TEXT_TYPE)
assert len(group_name) > 0
return maya.cmds.mmImageCache(group_name, query=True, cpuGroupItemNames=True)

Expand Down
20 changes: 20 additions & 0 deletions python/mmSolver/tools/setmeshholdouts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) 2024 Patcha Saheb Binginapalli.
#
# This file is part of mmSolver.
#
# mmSolver is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# mmSolver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
#
"""
Tools to set hold-out attributes on meshes.
"""
49 changes: 33 additions & 16 deletions python/mmSolver/tools/setmeshholdouts/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,63 @@
# You should have received a copy of the GNU Lesser General Public License
# along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
#
"""
Tools to set hold-out attributes on meshes.
import maya.cmds as cmds
These tools can enable or disable the hold-out attribute on mesh nodes.
"""

import maya.cmds

import mmSolver.logger

import mmSolver.utils.node as node_utils

LOG = mmSolver.logger.get_logger()

NO_SCENE_MESHES_WARNING_MESSAGE = "No mesh nodes found in the Maya scene."
SELECTED_MESHES_WARNING_MESSAGE = (
"Please select mesh objects, no mesh nodes were found from the selection."
)


def set_holdout(mesh_list, enable=True):
for mesh in mesh_list:
cmds.setAttr(mesh + ".holdOut", enable)
def set_holdout(mesh_nodes, value):
assert isinstance(value, bool)
attr_name = 'holdOut'
for mesh_node in mesh_nodes:
if node_utils.attribute_exists(attr_name, mesh_node):
node_attr = "{}.holdOut".format(mesh_node)
node_utils.set_attr(node_attr, value, relock=True)
return


def enable_all_meshes():
all_meshes = cmds.ls(dag=True, type="mesh") or []
if not all_meshes:
LOG.warn("Mesh not found.")
all_meshes = maya.cmds.ls(dag=True, type="mesh") or []
if len(all_meshes) == 0:
LOG.warn(NO_SCENE_MESHES_WARNING_MESSAGE)
return
set_holdout(all_meshes, True)


def disable_all_meshes():
all_meshes = cmds.ls(dag=True, type="mesh") or []
if not all_meshes:
LOG.warn("Mesh not found.")
all_meshes = maya.cmds.ls(dag=True, type="mesh") or []
if len(all_meshes) == 0:
LOG.warn(NO_SCENE_MESHES_WARNING_MESSAGE)
return
set_holdout(all_meshes, False)


def enable_selected_meshes():
selected_meshes = cmds.ls(selection=True, dag=True, type="mesh") or []
if not selected_meshes:
LOG.warn("Mesh selection not found.")
selected_meshes = maya.cmds.ls(selection=True, dag=True, type="mesh") or []
if len(selected_meshes) == 0:
LOG.warn(SELECTED_MESHES_WARNING_MESSAGE)
return
set_holdout(selected_meshes, True)


def disable_selected_meshes():
selected_meshes = cmds.ls(selection=True, dag=True, type="mesh") or []
if not selected_meshes:
LOG.warn("Mesh selection not found.")
selected_meshes = maya.cmds.ls(selection=True, dag=True, type="mesh") or []
if len(selected_meshes) == 0:
LOG.warn(SELECTED_MESHES_WARNING_MESSAGE)
return
set_holdout(selected_meshes, False)
4 changes: 3 additions & 1 deletion python/mmSolver/ui/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from __future__ import division
from __future__ import print_function

import mmSolver.utils.python_compat as pycompat


def get_nodes_recursively(top_node):
nodes = []
Expand Down Expand Up @@ -151,7 +153,7 @@ def setNeverHasChildren(self, value):
self._neverHasChildren = value

def icon(self):
assert isinstance(self._iconPath, str)
assert isinstance(self._iconPath, pycompat.TEXT_TYPE)
if self._icon is None:
import mmSolver.ui.uiutils as uiutils

Expand Down
2 changes: 1 addition & 1 deletion python/mmSolver/ui/uiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def getIcon(path):
:return: Qt Icon object.
:rtype: QIcon
"""
assert isinstance(path, str)
assert isinstance(path, pycompat.TEXT_TYPE)
icon = QtGui.QIcon(QtGui.QPixmap(path))
return icon

Expand Down
8 changes: 5 additions & 3 deletions python/mmSolver/utils/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,27 @@ def set_attr(plug, value, relock=False):
Optionally unlocks and re-locks the plugs.
:param plug: Node.Attr to set.
:param value: The ne value to set.
:param value: The new value to set.
:param relock: If the plug was already locked, should we set the new
value, then re-lock afterward?
:return:
:return: True or False, depending if the value was set or not.
:rtype: bool
"""
node = plug.partition('.')[0]
is_referenced = node_is_referenced(node)
locked = maya.cmds.getAttr(plug, lock=True)
if is_referenced is True and locked is True:
msg = 'Cannot set attr %r, it is locked and the node is referenced.'
LOG.warning(msg, plug)
return False
if is_referenced is False:
# Make sure the plug is unlocked.
maya.cmds.setAttr(plug, lock=False)
maya.cmds.setAttr(plug, value)
if is_referenced is False and relock is True:
maya.cmds.setAttr(plug, lock=locked)
return
return True


def get_long_name(node):
Expand Down
Loading

0 comments on commit 49f07e7

Please sign in to comment.