Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding mesh transform validation for maya #105

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions tik_manager4/dcc/maya/validate/mesh_transforms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Validates all meshes to have frozen transforms."""

from maya import cmds
from tik_manager4.dcc.validate_core import ValidateCore

class MeshTransform(ValidateCore):
"""Mesh Transform Validation for Maya."""

nice_name = "Mesh Transforms"

def __init__(self):
super().__init__()
self.autofixable = True
self.ignorable = False
self.selectable = True

self.non_frozen_meshes = []

def collect(self):
"""Collect all mesh transforms in the scene."""
all_meshes = cmds.ls(type="mesh")
self.collection = [cmds.listRelatives(mesh, parent=True)[0] for mesh in all_meshes]

def _check_frozen(self, mesh_transform):
"""Check if the mesh transform is frozen."""
for attr in "tr":
if cmds.getAttr(f"{mesh_transform}.{attr}") != [(0.0, 0.0, 0.0)]:
return False
if cmds.getAttr(f"{mesh_transform}.s") != [(1.0, 1.0, 1.0)]:
return False
return True

def validate(self):
"""Check if the mesh transforms are not frozen."""
self.collect()
self.non_frozen_meshes = []
for mesh_transform in self.collection:
if not self._check_frozen(mesh_transform):
self.non_frozen_meshes.append(mesh_transform)

if self.non_frozen_meshes:
self.failed(msg=f"Non-frozen mesh transforms found: {self.non_frozen_meshes}")
else:
self.passed()

def fix(self):
"""Freeze all non-frozen meshes."""
for mesh_transform in self.non_frozen_meshes:
cmds.makeIdentity(mesh_transform, apply=True)
self.passed()

def select(self):
"""Select the non-frozen meshes."""
cmds.select(self.non_frozen_meshes)
Loading