Skip to content

Commit

Permalink
feat(cpmel._object_types.core): 3.5.0版本, 增加了互相独立的读取世界空间变换和局部空间变换的属性
Browse files Browse the repository at this point in the history
  • Loading branch information
苍之幻灵 committed Nov 6, 2022
1 parent ddc6595 commit f00e11b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 23 deletions.
63 changes: 41 additions & 22 deletions scripts/cpmel_test/object_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
64 changes: 64 additions & 0 deletions src/CPMel/_object_types/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/CPMel/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit f00e11b

Please sign in to comment.