def testObjectPosition(self): """ Tests that an object created interactively is positioned correctly on the live surface. """ # Make our proxy shape live. cmds.makeLive('Block_1') # Enter interactive creation context. cmds.setToolTo('CreatePolyTorusCtx') # Click in the center of the viewport widget. QTest.mouseClick(self._viewWidget, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier, self._viewWidget.rect().center()) # Find the torus (it should be called pTorus1). self.assertTrue(cmds.ls('pTorus1')) # Check the torus's transform. # The Block_1 is originally 1 unit deep and centered at the origin, so # its original top plane is aligned at z=0.5. # It is scaled 5x, which makes the top plane aligned at z=2.5. # Then it is translated along z by 4.0, so its top plane is finally # aligned at z=6.5. translate = cmds.xform('pTorus1', q=True, t=True) self.assertAlmostEqual(translate[2], 6.5, places=3)
def makePlaneButton(self, *args, **kwargs): '''Make a construction plane based on selected objects''' if self.plane and cmds.objExists(self.plane): cmds.delete(self.plane) sel = cmds.ls(sl=True) if not len(sel) > 2: raise RuntimeError("Please select three objects to make a plane") first, middle, last = sel[:3] #make dummy alignment object dummy = cmds.group(em=True, n='dummyPlaneObj') cmds.xform(dummy, ws=True, t=cmds.xform(middle, ws=True, q=True, t=True)) cmds.delete( cmds.aimConstraint(first, dummy, offset=(0, 0, 0), aimVector=(1, 0, 0), upVector=(0, 1, 0), worldUpType='object', worldUpObject=last)) pos = cmds.xform(dummy, ws=True, q=True, t=True) rot = cmds.xform(dummy, ws=True, q=True, ro=True) plane = cmds.plane(p=pos, s=10, r=rot) cmds.delete(dummy) self.plane = plane self.planeSizeSlider() cmds.makeLive(self.plane)
def testObjectNormal(self): """ Tests that an object created interactively by dragging in the viewport has the correct orientation based on the live surface normal. """ from pxr import Gf # Load our reference assembly. UsdMaya.LoadReferenceAssemblies() # Create a new custom viewport. window = cmds.window(widthHeight=(500, 400)) cmds.paneLayout() panel = cmds.modelPanel() cmds.modelPanel(panel, edit=True, camera='persp') cmds.modelEditor(cmds.modelPanel(panel, q=True, modelEditor=True), edit=True, displayAppearance='smoothShaded', rnm='vp2Renderer') cmds.showWindow(window) # Get the viewport widget. view = OMUI.M3dView() OMUI.M3dView.getM3dViewFromModelPanel(panel, view) viewWidget = wrapInstance(long(view.widget()), QWidget) # Make our assembly live. cmds.makeLive('Block_2') # Enter interactive creation context. cmds.setToolTo('CreatePolyConeCtx') # Click in the center of the viewport widget. QTest.mouseClick(viewWidget, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier, viewWidget.rect().center()) # Find the cone (it should be called pCone1). self.assertTrue(cmds.ls('pCone1')) # Check the cone's rotation. # Because our scene is Z-axis up, the cone's Z-axis should be aligned # with Block_2's surface normal (though it might not necessarily have # the same exact rotation). rotationAngles = cmds.xform('pCone1', q=True, ro=True) rotation = (Gf.Rotation(Gf.Vec3d.XAxis(), rotationAngles[0]) * Gf.Rotation(Gf.Vec3d.YAxis(), rotationAngles[1]) * Gf.Rotation(Gf.Vec3d.ZAxis(), rotationAngles[2])) actualZAxis = rotation.TransformDir(Gf.Vec3d.ZAxis()) expectedRotation = (Gf.Rotation(Gf.Vec3d.XAxis(), 75.0) * Gf.Rotation(Gf.Vec3d.YAxis(), 90.0)) expectedZAxis = expectedRotation.TransformDir(Gf.Vec3d.ZAxis()) # Verify that the error angle between the two axes is less than # 0.1 degrees (less than ~0.0003 of a revolution, so not bad). That's # about as close as we're going to get. errorRotation = Gf.Rotation(actualZAxis, expectedZAxis) self.assertLess(errorRotation.GetAngle(), 0.1)
def setObjectAsCanvas(name): cmds.polyEvaluate(f=True) subdivSurface = cmds.polyToSubdiv(maxPolyCount=cmds.polyEvaluate(f=True), maxEdgesPerVert=32, ch=False)[0] liveSurface = cmds.subdToNurbs(subdivSurface, ot=0, ch=False) cmds.delete(subdivSurface) cmds.hide(liveSurface) cmds.makeLive(liveSurface) return liveSurface
def testObjectPosition(self): """ Tests that an object created interactively is positioned correctly on the live surface. """ # Load our reference assembly. UsdMaya.LoadReferenceAssemblies() # Create a new custom viewport. window = cmds.window(widthHeight=(500, 400)) cmds.paneLayout() panel = cmds.modelPanel() cmds.modelPanel(panel, edit=True, camera='persp') cmds.modelEditor(cmds.modelPanel(panel, q=True, modelEditor=True), edit=True, displayAppearance='smoothShaded', rnm='vp2Renderer') cmds.showWindow(window) # Force all views to re-draw. This causes us to block until the # geometry we're making live has actually been evaluated and is present # in the viewport. Otherwise execution of the test may continue and the # create tool may be invoked before there's any geometry there, in # which case the tool won't create anything. cmds.refresh() # Get the viewport widget. view = OMUI.M3dView() OMUI.M3dView.getM3dViewFromModelPanel(panel, view) viewWidget = wrapInstance(long(view.widget()), QWidget) # Make our assembly live. cmds.makeLive('Block_1') # Enter interactive creation context. cmds.setToolTo('CreatePolyTorusCtx') # Click in the center of the viewport widget. QTest.mouseClick(viewWidget, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier, viewWidget.rect().center()) # Find the torus (it should be called pTorus1). self.assertTrue(cmds.ls('pTorus1')) # Check the torus's transform. # The Block_1 is originally 1 unit deep and centered at the origin, so # its original top plane is aligned at z=0.5. # It is scaled 5x, which makes the top plane aligned at z=2.5. # Then it is translated along z by 4.0, so its top plane is finally # aligned at z=6.5. translate = cmds.xform('pTorus1', q=True, t=True) self.assertAlmostEqual(translate[2], 6.5, places=3)
def _create_drawing_plane(self, camera=None, position=None): camera = camera or self.camera self.drawing_plane = cmds.plane( name=self.name, length=self._active_view.portHeight(), width=self._active_view.portWidth(), ) if position: cmds.xform(self.drawing_plane, ws=True, t=position) cmds.connectAttr("{}.rotate".format(camera), "{}.rotate".format(self.drawing_plane)) cmds.hide(self.drawing_plane) cmds.makeLive(self.drawing_plane) self.all_group.group_nodes(self.drawing_plane) return self.drawing_plane
def onPress(self): # create newCurveatOrigin print "creating a newcurve" newGuide = self.newCurve(5) # makeSurfaceLive print "making surface live" mc.makeLive(self.surface) hitPos = mc.autoPlace(um=1) uv = self.getuv_from_world(hitPos) guideFollicle = self.new_follicle(uv) # cleanup mc.makeLive(none=1) follicleTrans = mc.listRelatives(guideFollicle, type="transform", p=1)[0] mc.parentConstraint(follicleTrans, newGuide) mc.parent(newGuide, follicleTrans) # pin base cvOfCurve curveShape = mc.listRelatives(newGuide, s=1, f=1)[0] decomposeMatrix = mc.createNode("decomposeMatrix") mc.connectAttr(follicleTrans + ".parentMatrix", decomposeMatrix + ".inputMatrix") mc.connectAttr(decomposeMatrix + ".outputTranslate", curveShape + ".controlPoints[0]")
def testObjectNormal(self): """ Tests that an object created interactively by dragging in the viewport has the correct orientation based on the live surface normal. """ # Make our proxy shape live. cmds.makeLive('Block_2') # Enter interactive creation context. cmds.setToolTo('CreatePolyConeCtx') # Click in the center of the viewport widget. QTest.mouseClick(self._viewWidget, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier, self._viewWidget.rect().center()) # Find the cone (it should be called pCone1). self.assertTrue(cmds.ls('pCone1')) # Check the cone's rotation. # Because our scene is Z-axis up, the cone's Z-axis should be aligned # with Block_2's surface normal (though it might not necessarily have # the same exact rotation). rotationAngles = cmds.xform('pCone1', q=True, ro=True) rotation = (Gf.Rotation(Gf.Vec3d.XAxis(), rotationAngles[0]) * Gf.Rotation(Gf.Vec3d.YAxis(), rotationAngles[1]) * Gf.Rotation(Gf.Vec3d.ZAxis(), rotationAngles[2])) actualZAxis = rotation.TransformDir(Gf.Vec3d.ZAxis()) expectedRotation = (Gf.Rotation(Gf.Vec3d.XAxis(), 75.0) * Gf.Rotation(Gf.Vec3d.YAxis(), 90.0)) expectedZAxis = expectedRotation.TransformDir(Gf.Vec3d.ZAxis()) # Verify that the error angle between the two axes is less than # 0.1 degrees (less than ~0.0003 of a revolution, so not bad). That's # about as close as we're going to get. errorRotation = Gf.Rotation(actualZAxis, expectedZAxis) self.assertLess(errorRotation.GetAngle(), 0.1)
def PlacementTool(): cmds.undoInfo(openChunk=True) Start = True if cmds.objExists('__Placement_Tool__'): cmds.makeLive(none=True) if cmds.objExists('__Placement_Tool_c__'): cmds.delete('__Placement_Tool_c__') if cmds.objExists('__Placement_Tool_f__'): cmds.delete('__Placement_Tool_f__') if cmds.objExists('__Placement_Tool_g__'): cmds.delete('__Placement_Tool_g__') if cmds.objExists('__Placement_Tool__'): cmds.delete('__Placement_Tool__') cmds.xform(rp=(osPivot[0],osPivot[1],osPivot[2]),os=1) Start = False PT_START_UI() if Start: global osPivot osPivot=cmds.xform(q=1,rp=1,os=1) global wsPivot wsPivot=cmds.xform(q=1,rp=1,ws=1) cmds.setToolTo('moveSuperContext') sel=cmds.ls(sl=1,l=1) cmds.InvertSelection() cmds.select(cmds.ls(sl=1,v=1)) cmds.select(cmds.filterExpand(sm=12)) selAll=cmds.ls(sl=1) cmds.duplicate() cmds.group(name=('__Placement_Tool_g__')) cmds.CombinePolygons() cmds.hyperShade(assign='lambert1') cmds.polyMapDel() cmds.DeleteHistory() cmds.rename('__Placement_Tool__') cmds.hide() # Move Pivot cmds.select(sel) for i in sel : pos = cmds.xform(i,q=1,ws=1,piv=1) dup = cmds.duplicate(i,rr=1,po=1) for attr in ['tx','ty','tz','rx','ry','rz','sx','sy','sz'] : if cmds.getAttr(dup[0]+'.'+attr,lock=True):cmds.setAttr(dup[0]+'.'+attr,lock=False) shapeNode = cmds.ls(cmds.listRelatives(i,c=1,f=1),l=1,s=1) for s in shapeNode : cmds.parent(s,dup[0],add=1,s=1) if cmds.listRelatives(dup[0],p=1) : cmds.parent(dup[0],w=1) cmds.setAttr(dup[0]+'.r',0,0,0,type="double3") bb=cmds.xform(dup[0],q=1,bb=1,ws=1) cp=cmds.objectCenter(dup[0]) xpos=cp[0];ypos=bb[1];zpos = cp[2] loc=cmds.spaceLocator() cmds.xform(loc[0],ws=1,t=(xpos,ypos,zpos)) cmds.parent(loc[0],dup[0]) cmds.delete(cmds.parentConstraint(i,dup[0])) pivPos=cmds.xform(loc[0],q=1,ws=1,t=1) cmds.xform(i,ws=1,piv=(pivPos[0],pivPos[1],pivPos[2])) cmds.delete(dup[0],loc[0]) cmds.select(sel,r=1) cmds.select('__Placement_Tool__',r=1);cmds.select(sel,add=1) cmds.normalConstraint(worldUpType="none",aimVector=(0, 1, 0),upVector=(0, 1, 0),weight=1,name='__Placement_Tool_c__') cmds.select('__Placement_Tool__',r=1);cmds.makeLive() cmds.select(selAll) cmds.createDisplayLayer(name="__Placement_Tool_f__",number=1,nr=1) import maya.mel as mel mel.eval('layerEditorLayerButtonTypeChange("__Placement_Tool_f__")') mel.eval('layerEditorLayerButtonTypeChange("__Placement_Tool_f__")') cmds.select(sel) PT_STOP_UI() cmds.undoInfo(closeChunk=True)
def deletePlaneButton(self, *args, **kwargs): '''Deletes the helper plane. Also called on window close.''' if self.plane and cmds.objExists(self.plane): cmds.delete(self.plane) self.plane = None cmds.makeLive(none=True)
test.debugPrintLists() def setObjectAsCanvas(name): cmds.polyEvaluate(f=True) subdivSurface = cmds.polyToSubdiv(maxPolyCount=cmds.polyEvaluate(f=True), maxEdgesPerVert=32, ch=False)[0] liveSurface = cmds.subdToNurbs(subdivSurface, ot=0, ch=False) cmds.delete(subdivSurface) cmds.hide(liveSurface) cmds.makeLive(liveSurface) return liveSurface liveSurface = setObjectAsCanvas(cmds.ls(sl=True)) cmds.makeLive(n=True) # This is not needed anymore # def isInteractiveMode(): # """ Returns a boolean of whether the user has enabled interactive mode in the NURBS primitive menu # """ # return bool(cmds.optionVar(q='createNurbsPrimitiveAsTool')) # #cmds.optionVar(iv=('createNurbsPrimitiveAsTool', val)) # # def setInteractiveMode(state): # """ # Enable or disable interactive mode for NURBS primitives # # state : [bool] True enables interactive mode, False disables it # """