-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from masqu3rad3/adding-mesh-transform-validat…
…ion-for-maya Adding mesh transform validation for maya
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 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
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) |