1##-***************************************************************************** 2## 3## Copyright (c) 2013, 4## Sony Pictures Imageworks, Inc. and 5## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. 6## 7## All rights reserved. 8## 9## Redistribution and use in source and binary forms, with or without 10## modification, are permitted provided that the following conditions are 11## met: 12## * Redistributions of source code must retain the above copyright 13## notice, this list of conditions and the following disclaimer. 14## * Redistributions in binary form must reproduce the above 15## copyright notice, this list of conditions and the following disclaimer 16## in the documentation and/or other materials provided with the 17## distribution. 18## * Neither the name of Sony Pictures Imageworks, nor 19## Industrial Light & Magic nor the names of their contributors may be used 20## to endorse or promote products derived from this software without specific 21## prior written permission. 22## 23## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34## 35##-***************************************************************************** 36 37from maya import cmds as MayaCmds 38from maya import mel as Mel 39import os 40import subprocess 41import unittest 42import util 43 44class ConnectNamespaceTest(unittest.TestCase): 45 46 def buildScene(self): 47 MayaCmds.file(new=True, force=True) 48 49 MayaCmds.namespace(addNamespace='foo') 50 MayaCmds.namespace(addNamespace='bar') 51 MayaCmds.createNode('transform', name='foo:a') 52 MayaCmds.createNode('transform', name='bar:a') 53 MayaCmds.createNode('transform', name='a') 54 MayaCmds.polyPlane(sx=1, sy=1, w=1, h=1, ch=0, n='foo:b') 55 MayaCmds.polyPlane(sx=1, sy=1, w=1, h=1, ch=0, n='bar:b') 56 MayaCmds.polyPlane(sx=1, sy=1, w=1, h=1, ch=0, n='b') 57 MayaCmds.parent('foo:b', 'foo:a') 58 MayaCmds.parent('bar:b', 'bar:a') 59 MayaCmds.parent('b', 'a') 60 61 MayaCmds.select('foo:b.vtx[0:8]') 62 MayaCmds.setKeyframe(t=[1, 4]) 63 MayaCmds.scale(0.1, 0.1, 0.1, r=True) 64 MayaCmds.setKeyframe(t=2) 65 66 MayaCmds.select('bar:b.vtx[0:8]') 67 MayaCmds.setKeyframe(t=[1, 4]) 68 MayaCmds.scale(2, 2, 2, r=True) 69 MayaCmds.setKeyframe(t=2) 70 71 MayaCmds.select('b.vtx[0:8]') 72 MayaCmds.setKeyframe(t=[1, 4]) 73 MayaCmds.scale(5, 5, 5, r=True) 74 MayaCmds.setKeyframe(t=2) 75 76 def buildStatic(self): 77 MayaCmds.file(new=True, force=True) 78 79 MayaCmds.namespace(addNamespace='foo') 80 MayaCmds.namespace(addNamespace='bar') 81 MayaCmds.createNode('transform', name='foo:a') 82 MayaCmds.createNode('transform', name='bar:a') 83 MayaCmds.createNode('transform', name='a') 84 MayaCmds.polyPlane(sx=1, sy=1, w=1, h=1, ch=0, n='foo:b') 85 MayaCmds.polyPlane(sx=1, sy=1, w=1, h=1, ch=0, n='bar:b') 86 MayaCmds.polyPlane(sx=1, sy=1, w=1, h=1, ch=0, n='b') 87 MayaCmds.parent('foo:b', 'foo:a') 88 MayaCmds.parent('bar:b', 'bar:a') 89 MayaCmds.parent('b', 'a') 90 91 def setUp(self): 92 MayaCmds.file(new=True, force=True) 93 self.__files = [] 94 95 96 def tearDown(self): 97 for f in self.__files: 98 os.remove(f) 99 100 def testNamespace(self): 101 self.buildScene() 102 self.__files.append(util.expandFileName('testNamespace_foo_a.abc')) 103 self.__files.append(util.expandFileName('testNamespace_bar_a.abc')) 104 self.__files.append(util.expandFileName('testNamespace_a.abc')) 105 106 MayaCmds.AbcExport(j='-root foo:a -fr 1 4 -file ' + self.__files[-3]) 107 MayaCmds.AbcExport(j='-root bar:a -fr 1 4 -file ' + self.__files[-2]) 108 MayaCmds.AbcExport(j='-root a -fr 1 4 -file ' + self.__files[-1]) 109 110 self.buildStatic() 111 MayaCmds.AbcImport(self.__files[-3], connect='foo:a') 112 self.failUnless('testNamespace_foo_a_AlembicNode.outPolyMesh[0]' == 113 MayaCmds.connectionInfo("|foo:a|foo:b|foo:bShape.inMesh", sfd=True)) 114 115 MayaCmds.AbcImport(self.__files[-2], connect='bar:a') 116 self.failUnless('testNamespace_bar_a_AlembicNode.outPolyMesh[0]' == 117 MayaCmds.connectionInfo("|bar:a|bar:b|bar:bShape.inMesh", sfd=True)) 118 119 MayaCmds.AbcImport(self.__files[-1], connect='a') 120 self.failUnless('testNamespace_a_AlembicNode.outPolyMesh[0]' == 121 MayaCmds.connectionInfo("|a|b|bShape.inMesh", sfd=True)) 122 123 def testNamespaceChild(self): 124 self.buildScene() 125 self.__files.append(util.expandFileName('testNamespace_foo_b.abc')) 126 self.__files.append(util.expandFileName('testNamespace_bar_b.abc')) 127 self.__files.append(util.expandFileName('testNamespace_b.abc')) 128 129 MayaCmds.AbcExport(j='-root foo:b -fr 1 4 -file ' + self.__files[-3]) 130 MayaCmds.AbcExport(j='-root bar:b -fr 1 4 -file ' + self.__files[-2]) 131 MayaCmds.AbcExport(j='-root b -fr 1 4 -file ' + self.__files[-1]) 132 133 self.buildStatic() 134 MayaCmds.AbcImport(self.__files[-3], connect='foo:a') 135 self.failUnless('testNamespace_foo_b_AlembicNode.outPolyMesh[0]' == 136 MayaCmds.connectionInfo("|foo:a|foo:b|foo:bShape.inMesh", sfd=True)) 137 138 MayaCmds.AbcImport(self.__files[-3], connect='bar:a') 139 self.failUnless('testNamespace_foo_b_AlembicNode1.outPolyMesh[0]' == 140 MayaCmds.connectionInfo("|bar:a|bar:b|bar:bShape.inMesh", sfd=True)) 141 142 MayaCmds.AbcImport(self.__files[-3], connect='a') 143 self.failUnless('testNamespace_foo_b_AlembicNode2.outPolyMesh[0]' == 144 MayaCmds.connectionInfo("|a|b|bShape.inMesh", sfd=True)) 145 146 self.buildStatic() 147 MayaCmds.AbcImport(self.__files[-2], connect='foo:a') 148 self.failUnless('testNamespace_bar_b_AlembicNode.outPolyMesh[0]' == 149 MayaCmds.connectionInfo("|foo:a|foo:b|foo:bShape.inMesh", sfd=True)) 150 151 MayaCmds.AbcImport(self.__files[-2], connect='bar:a') 152 self.failUnless('testNamespace_bar_b_AlembicNode1.outPolyMesh[0]' == 153 MayaCmds.connectionInfo("|bar:a|bar:b|bar:bShape.inMesh", sfd=True)) 154 155 MayaCmds.AbcImport(self.__files[-2], connect='a') 156 self.failUnless('testNamespace_bar_b_AlembicNode2.outPolyMesh[0]' == 157 MayaCmds.connectionInfo("|a|b|bShape.inMesh", sfd=True)) 158