@@ -20,12 +20,19 @@ class AddToComponentFromNodesTestCase(_ComponentCreatorTestBase, unittest.TestCa
2020 def setUpClass (cls ):
2121 fixturesUtils .readOnlySetUpClass (__file__ , initializeStandalone = False )
2222
23+ @classmethod
24+ def tearDownClass (cls ):
25+ cls ._resetDefaultTemplate ()
26+ return super ().tearDownClass ()
27+
2328 def setUp (self ):
2429 self ._setUpCC ()
2530 # Clear the variant editor state so there is no lingering component from a
2631 # previous test.
2732 #from usd_component_creator_plugin import update_variant_editor_window
2833 #update_variant_editor_window(None, force_update=True)
34+ self ._resetDefaultTemplate ()
35+ return super ().setUp ()
2936
3037 def _createInitialComponent (self , node_name = 'pCube1' ):
3138 """Create a polyCube, build a single-node component, and return (proxy, desc)."""
@@ -181,6 +188,109 @@ def testTargetedVariantUnchangedAfterAdd(self):
181188 AdskUsdComponentCreator .ComponentAPI .IsVariantTarget (
182189 updated_desc , [updated_vs , updated_default_var_desc ]))
183190
191+ def testAddWithPurpose (self ):
192+ """add_to_component_from_nodes with purpose specified."""
193+ from usd_component_creator_plugin import add_to_component_from_nodes
194+ proxy , desc = self ._createInitialComponent ('pCube1' )
195+ self .assertIsNotNone (desc , 'Could not get initial ComponentDescription' )
196+ first_vs = next (iter (desc .GetVariantSets ().values ()))
197+
198+ cmds .polyCube (name = 'pCube2' )
199+ path2 = cmds .ls ('pCube2' , long = True )[0 ]
200+
201+ before = self ._snapshotProxyShapes ()
202+
203+ # Add pCube2 to the existing default variant (not a new one)
204+ result = add_to_component_from_nodes (
205+ [path2 ],
206+ [(first_vs .name , first_vs .default_variant )],
207+ is_replacing = False ,
208+ component_desc = desc ,
209+ purpose = 'guide' )
210+ self .assertTrue (result , "add_to_component_from_nodes should return True on success" )
211+
212+ new_proxy = self ._findNewProxyShape (before )
213+ self .assertIsNone (new_proxy , "No new proxy shape should be created when adding to an existing component" )
214+
215+ stage = mayaUsd .ufe .getStage (proxy )
216+
217+ cube_path = Sdf .Path ('/root/geo/pCube1' )
218+ cube_prim = stage .GetPrimAtPath (cube_path )
219+ self .assertTrue (cube_prim .IsValid (), f"{ cube_path } should be a valid prim" )
220+
221+ purposed_path = Sdf .Path ('/root/geo/guide/pCube2' )
222+ purposed_prim = stage .GetPrimAtPath (purposed_path )
223+ self .assertTrue (purposed_prim .IsValid (), f"{ purposed_path } should be a valid prim after add_to_component_from_nodes with purpose" )
224+
225+ def testAddWithPurposeCollidingName (self ):
226+ """add_to_component_from_nodes with purpose specified."""
227+ from usd_component_creator_plugin import add_to_component_from_nodes
228+ proxy , desc = self ._createInitialComponent ('pCube1' )
229+ self .assertIsNotNone (desc , 'Could not get initial ComponentDescription' )
230+ first_vs = next (iter (desc .GetVariantSets ().values ()))
231+
232+ cmds .setAttr ('pCube1.translateX' , 22.2 )
233+ before = self ._snapshotProxyShapes ()
234+
235+ # Add pCube1 to the existing default variant (not a new one) under a purpose.
236+ # Because it will be placed under the purpose scope, its name will *not* conflict
237+ # with the existing pCube1
238+ result = add_to_component_from_nodes (
239+ ['pCube1' ],
240+ [(first_vs .name , first_vs .default_variant )],
241+ is_replacing = False ,
242+ component_desc = desc ,
243+ purpose = 'guide' )
244+ self .assertTrue (result , "add_to_component_from_nodes should return True on success" )
245+ new_proxy = self ._findNewProxyShape (before )
246+ self .assertIsNone (new_proxy , "No new proxy shape should be created when adding to an existing component" )
247+
248+ stage = mayaUsd .ufe .getStage (proxy )
249+
250+ cube_path = Sdf .Path ('/root/geo/pCube1' )
251+ cube_prim = stage .GetPrimAtPath (cube_path )
252+ self .assertTrue (cube_prim .IsValid (), f"{ cube_path } should be a valid prim" )
253+
254+ purposed_path = Sdf .Path ('/root/geo/guide/pCube1' )
255+ purposed_prim = stage .GetPrimAtPath (purposed_path )
256+ self .assertTrue (purposed_prim .IsValid (), f"{ purposed_path } should be a valid prim after add_to_component_from_nodes with purpose" )
257+ translateAttr = purposed_prim .GetAttribute ('xformOp:translate' )
258+ self .assertTrue (translateAttr )
259+ self .assertAlmostEqual (translateAttr .Get ()[0 ], 22.2 )
260+
261+ def testAddWithCustomPurposeScopeName (self ):
262+ """add_to_component_from_nodes with purpose specified and custom purpose scope names."""
263+ from usd_component_creator_plugin import add_to_component_from_nodes
264+ self ._setCustomPurposeTemplate ()
265+ proxy , desc = self ._createInitialComponent ('pCube1' )
266+ self .assertIsNotNone (desc , 'Could not get initial ComponentDescription' )
267+ first_vs = next (iter (desc .GetVariantSets ().values ()))
268+
269+ cmds .polyCube (name = 'pCube2' )
270+ path2 = cmds .ls ('pCube2' , long = True )[0 ]
271+
272+ before = self ._snapshotProxyShapes ()
273+
274+ # Add pCube2 to the existing default variant (not a new one)
275+ result = add_to_component_from_nodes (
276+ [path2 ],
277+ [(first_vs .name , first_vs .default_variant )],
278+ is_replacing = False ,
279+ component_desc = desc ,
280+ purpose = 'guide' )
281+ self .assertTrue (result , "add_to_component_from_nodes should return True on success" )
282+ new_proxy = self ._findNewProxyShape (before )
283+ self .assertIsNone (new_proxy , "No new proxy shape should be created when adding to an existing component" )
284+
285+ stage = mayaUsd .ufe .getStage (proxy )
286+
287+ cube_path = Sdf .Path ('/root/geo/pCube1' )
288+ cube_prim = stage .GetPrimAtPath (cube_path )
289+ self .assertTrue (cube_prim .IsValid (), f"{ cube_path } should be a valid prim" )
290+
291+ purposed_path = Sdf .Path ('/root/geo/gui/pCube2' )
292+ purposed_prim = stage .GetPrimAtPath (purposed_path )
293+ self .assertTrue (purposed_prim .IsValid (), f"{ purposed_path } should be a valid prim after add_to_component_from_nodes with purpose" )
184294
185295
186296if __name__ == '__main__' :
0 commit comments