diff --git a/gt/utils/data/py_meshes/preview_images/studio_background.jpg b/gt/utils/data/py_meshes/preview_images/studio_background.jpg new file mode 100644 index 00000000..8c7c93c6 Binary files /dev/null and b/gt/utils/data/py_meshes/preview_images/studio_background.jpg differ diff --git a/gt/utils/data/py_meshes/scale_volume.py b/gt/utils/data/py_meshes/scale_volume.py index cf6693c4..5293f5ca 100644 --- a/gt/utils/data/py_meshes/scale_volume.py +++ b/gt/utils/data/py_meshes/scale_volume.py @@ -1,5 +1,5 @@ """ -Parametric Mesh Creation Scripts (Meshes with Logic or extra components) +Parametric Mesh Creation functions for Scale and Volume meshes (Meshes with Logic or extra components) """ from gt.utils.iterable_utils import round_numbers_in_list from gt.utils.data.py_meshes.mesh_data import MeshData diff --git a/gt/utils/data/py_meshes/scene_setup.py b/gt/utils/data/py_meshes/scene_setup.py new file mode 100644 index 00000000..824893de --- /dev/null +++ b/gt/utils/data/py_meshes/scene_setup.py @@ -0,0 +1,74 @@ +""" +Parametric Mesh Creation for Scene Setup +""" +from gt.utils.data.py_meshes.mesh_data import MeshData +import maya.cmds as cmds +import logging + +# Logging Setup +logging.basicConfig() +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) + + +def create_studio_background(name="studio_background", initial_scale=1): + """ + Creates a studio background mesh + Args: + name (str, optional): The name for the created mesh. + initial_scale (int, float, optional): Sets the initial scale of the mesh object + """ + selection = cmds.ls(selection=True) + plane_transform, poly_plane_node = cmds.polyPlane(name=name, w=1, h=1, sx=10, sy=10, ax=(0, 1, 0), cuv=2, ch=1) + + # Set attributes for the poly plane + cmds.setAttr(f"{poly_plane_node}.height", 40) + cmds.setAttr(f"{poly_plane_node}.width", 40) + cmds.setAttr(f"{poly_plane_node}.subdivisionsHeight", 50) + cmds.setAttr(f"{poly_plane_node}.subdivisionsWidth", 50) + + cmds.rename(poly_plane_node, f'{name}_polyPlane') + + # Create a bend deformer and set its attributes + bend_node_one, bend_handle_one = cmds.nonLinear(plane_transform, name=f'{name}_bendY', typ="bend", + lowBound=0, highBound=1, curvature=90) + + cmds.rotate(0, -90, 0, bend_handle_one, r=True, os=True, fo=True) + cmds.rotate(0, 0, 90, bend_handle_one, r=True, os=True, fo=True) + + bend_node_two, bend_handle_two = cmds.nonLinear(plane_transform, name=f'{name}_bendZ', typ="bend", + lowBound=-1, highBound=1, curvature=110) + + bend_handles = [bend_handle_one, bend_handle_two] + + cmds.rotate(0, -90, 0, bend_handle_two, r=True, os=True, fo=True) + cmds.rotate(-90, 0, 0, bend_handle_two, r=True, os=True, fo=True) + cmds.move(0, 0, 7, bend_handle_two, r=True) + + cmds.parent([bend_handle_one, bend_handle_two], plane_transform) + + cmds.move(0, 0, -10, plane_transform, r=True) + cmds.xform(plane_transform, piv=(0, 0, 11), ws=True) + cmds.move(0, 0, 0, plane_transform, a=True, rpr=True) # rpr flag moves it according to the pivot + + for handle in bend_handles: + cmds.setAttr(f'{handle}.v', 0) + + cmds.setAttr(f'{plane_transform}.sx', initial_scale) + cmds.setAttr(f'{plane_transform}.sy', initial_scale) + cmds.setAttr(f'{plane_transform}.sz', initial_scale) + + cmds.select(clear=True) + if selection: + try: + cmds.select(selection) + except Exception as e: + logger.debug(f'Unable to recover selection. Issue: {str(e)}') + + return MeshData(name=plane_transform, setup=bend_handles) + + +if __name__ == "__main__": + logger.setLevel(logging.DEBUG) + cmds.file(new=True, force=True) + create_studio_background() diff --git a/gt/utils/mesh_utils.py b/gt/utils/mesh_utils.py index 662f129e..38302278 100644 --- a/gt/utils/mesh_utils.py +++ b/gt/utils/mesh_utils.py @@ -2,8 +2,8 @@ Mesh (Geometry) Utilities github.com/TrevisanGMW/gt-tools """ +from gt.utils.data.py_meshes import scale_volume, scene_setup from gt.utils import system_utils, iterable_utils -from gt.utils.data.py_meshes import scale_volume from gt.utils.data_utils import DataDirConstants from collections import namedtuple import maya.cmds as cmds @@ -665,6 +665,7 @@ def __init__(self): # Creatures/Bipeds scale_human_male = ParametricMesh(build_function=scale_volume.create_scale_human_male) scale_human_female = ParametricMesh(build_function=scale_volume.create_scale_human_female) + studio_background = ParametricMesh(build_function=scene_setup.create_studio_background) def print_code_for_obj_files(target_dir=None, ignore_private=True, use_output_window=False):