From f00e11b6a3650e8a86c0cd34803b63638fdbb8b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8D=E4=B9=8B=E5=B9=BB=E7=81=B5?= Date: Sun, 6 Nov 2022 23:51:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(cpmel.=5Fobject=5Ftypes.core):=203.5.0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=8C=20=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E4=BA=92=E7=9B=B8=E7=8B=AC=E7=AB=8B=E7=9A=84=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E4=B8=96=E7=95=8C=E7=A9=BA=E9=97=B4=E5=8F=98=E6=8D=A2=E5=92=8C?= =?UTF-8?q?=E5=B1=80=E9=83=A8=E7=A9=BA=E9=97=B4=E5=8F=98=E6=8D=A2=E7=9A=84?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/cpmel_test/object_types.py | 63 +++++++++++++++++++---------- src/CPMel/_object_types/core.py | 64 ++++++++++++++++++++++++++++++ src/CPMel/versions.py | 2 +- 3 files changed, 106 insertions(+), 23 deletions(-) diff --git a/scripts/cpmel_test/object_types.py b/scripts/cpmel_test/object_types.py index a0b4b01..7eb7ea7 100644 --- a/scripts/cpmel_test/object_types.py +++ b/scripts/cpmel_test/object_types.py @@ -17,6 +17,8 @@ import sys import subprocess +from cpapi.all import * +from cpapi.utils import * import cpmel.cmds as cc from maya.cmds import file, about @@ -106,28 +108,45 @@ def test_dag_node_type(self): init_scene() # test DagNode - print("\n## test DagNode type: ") - - o = cc.new_object('group5') - - print('api1_m_dag_path >> ', o.api1_m_dag_path()) - print('api2_m_dag_path >> ', o.api2_m_dag_path()) - - print('full_path_name >> ', o.full_path_name()) - - cc.new_object('group4').get_scale(), - cc.new_object('group4').set_matrix(o.get_matrix()) - print('get_matrix set_matrix end >> ', - "get_translation: ", cc.new_object('group4').get_translation(), - "get_rotation: ", cc.new_object('group4').get_rotation(), - "get_scale: ", cc.new_object('group4').get_scale(), - "get_matrix: ", cc.new_object('group4').get_matrix(), - ) - - a, b, c = (cc.createNode('transform'), - cc.createNode('transform'), - cc.createNode('transform')) - print('test hierarchy: ', b.set_parent(a).add_child(c).childs) + print("# test DagNode type") + + group4 = cc.new_object('group4') + group5 = cc.new_object('group5') + joint8 = cc.new_object('joint8') + + # 检查读取api MDagPath的功能的结果是否正确 + self.assertTrue(group5.api1_m_dag_path().fullPathName() == '|group5') + self.assertTrue(group5.api2_m_dag_path().fullPathName() == '|group5') + + # 检查读取完整路径的功能的结果是否正确 + self.assertTrue(group5.full_path_name() == '|group5') + + # 检查读取平移旋转缩放及矩阵的功能的结果是否正确 + self.assertTrue(group4.get_translation() == MVector(0, 0, 0)) + self.assertTrue(group4.get_rotation() == MEulerRotation(0, 0, 0)) + self.assertTrue(group4.get_scale() == [1.0, 1.0, 1.0]) + self.assertTrue(group4.get_matrix() == new_matrix([ + [1.0, 0.0, 0.0, 0.0], + [0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 1.0, 0.0], + [0.0, 0.0, 0.0, 1.0], + ])) + # 单纯的检查返回值 + self.assertTrue(group4.set_matrix(group5.get_matrix()) == group4) + + # 检查世界空间下的平移、旋转、缩放及矩阵是否与局部空间下的不一致(他们应该不一致,因为joint8存在拥有变换的父对象) + self.assertTrue(joint8.world_translation != joint8.local_translation) + self.assertTrue(joint8.world_rotation != joint8.local_rotation) + self.assertTrue(joint8.world_scale != joint8.local_scale) + self.assertTrue(joint8.world_matrix != joint8.local_matrix) + + a, b, c = ( + cc.createNode('transform'), + cc.createNode('transform'), + cc.createNode('transform'), + ) + + self.assertTrue(b.set_parent(a).add_child(c).childs == [cc.new_object('transform3')]) @file_new def test_attr_type(self): diff --git a/src/CPMel/_object_types/core.py b/src/CPMel/_object_types/core.py index 2f5748a..4d5752a 100644 --- a/src/CPMel/_object_types/core.py +++ b/src/CPMel/_object_types/core.py @@ -172,6 +172,22 @@ def set_translation(self, p, ws=True): mc.xform(self.name(), t=(p[0], p[1], p[2]), ws=ws) return self + @property + def local_translation(self): + return self.get_translation(ws=False) + + @local_translation.setter + def local_translation(self, value): + self.set_translation(value, ws=False) + + @property + def world_translation(self): + return self.get_translation(ws=True) + + @world_translation.setter + def world_translation(self, value): + self.set_translation(value, ws=True) + @property def translation(self): return self.get_translation(ws=True) @@ -190,6 +206,22 @@ def set_rotation(self, r, ws=True): mc.xform(self.name(), ro=(r[0], r[1], r[2]), ws=ws) return self + @property + def local_rotation(self): + return self.get_rotation(ws=False) + + @local_rotation.setter + def local_rotation(self, value): + self.set_rotation(value, ws=False) + + @property + def world_rotation(self): + return self.get_rotation(ws=True) + + @world_rotation.setter + def world_rotation(self, value): + self.set_rotation(value, ws=True) + @property def rotation(self): return self.get_rotation(ws=True) @@ -208,6 +240,22 @@ def set_scale(self, s, ws=True): mc.xform(self.name(), s=(s[0], s[1], s[2]), ws=ws) return self + @property + def local_scale(self): + return self.get_scale(ws=False) + + @local_scale.setter + def local_scale(self, value): + self.set_scale(value, ws=False) + + @property + def world_scale(self): + return self.get_scale(ws=True) + + @world_scale.setter + def world_scale(self, value): + self.set_scale(value, ws=True) + @property def scale(self): return self.get_scale(ws=True) @@ -226,6 +274,22 @@ def set_matrix(self, m, ws=True): mc.xform(self.name(), m=m, ws=ws) return self + @property + def local_matrix(self): + return self.get_matrix(ws=False) + + @local_matrix.setter + def local_matrix(self, value): + self.set_matrix(value, ws=False) + + @property + def world_matrix(self): + return self.get_matrix(ws=True) + + @world_matrix.setter + def world_matrix(self, value): + self.set_matrix(value, ws=True) + @property def matrix(self): return self.get_matrix(ws=True) diff --git a/src/CPMel/versions.py b/src/CPMel/versions.py index ed25636..a6bb6c0 100644 --- a/src/CPMel/versions.py +++ b/src/CPMel/versions.py @@ -40,7 +40,7 @@ def to_str(self): def ver_info(): - return VersionInfo(major=3, minor=4, patch=1, adv_ver=R, adv_ver_index=0) + return VersionInfo(major=3, minor=5, patch=0, adv_ver=R, adv_ver_index=0) def ver_str():