Rotation Flipping NormalConstraint PYTHON

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

 
Thread Tools Display Modes
  05 May 2018
Rotation Flipping NormalConstraint PYTHON

Hey !

I am making a script , where you can click 2 points on your mesh and it will make an Arealight between those 2 points and looks to my sphere.
But I have some flipping in my rotation when I add the light at the other side of my sphere.


See video :https://www.youtube.com/watch?v=LGIE7hgg52I

If someonecan help me would be amazing !



Here is my code :

import maya.cmds as cmds






cmds.polySphere()
cmds.scale(5,5,5,)
cmds.rename('PainterObject')

draggerContextName = "myDragger"
lights=[]






def dragger_onPress2():
pos = cmds.draggerContext(draggerContextName, query = True, anchorPoint = True)



#make locator for distance
cmds.spaceLocator(name=('DistnaceLoc'))
cmds.move(pos[0],pos[1],pos[2])

if cmds.objExists('DistnaceLoc') and cmds.objExists('DistnaceLoc1'):
posLoc1_X = cmds.getAttr('DistnaceLoc.translateX')
posLoc1_Y = cmds.getAttr('DistnaceLoc.translateY')
posLoc1_Z = cmds.getAttr('DistnaceLoc.translateZ')

posLoc2_X = cmds.getAttr('DistnaceLoc1.translateX')
posLoc2_Y = cmds.getAttr('DistnaceLoc1.translateY')
posLoc2_Z = cmds.getAttr('DistnaceLoc1.translateZ')




Distance = cmds.distanceDimension(startPoint=[posLoc1_X,posLoc1_Y,posLoc1_Z],endPoint=[posLoc2_X,posLoc2_Y,posLoc2_Z])
#cmds.rename(Distance,'DistanceLocators')

DistanceValue = cmds.getAttr(Distance + '.distance')
print(DistanceValue)

averagePosX = (posLoc1_X+posLoc2_X)/2
averagePosY = (posLoc1_Y+posLoc2_Y)/2
averagePosZ = (posLoc1_Z+posLoc2_Z)/2






#create light
lights.append(cmds.shadingNode('aiAreaLight', asLight=True))
cmds.move(averagePosX,averagePosY,averagePosZ)
cmds.scale((DistanceValue/2),0.1,1)

cmds.rename(lights[len(lights)-1],'PainterLight_aiArealight'+'1')

LastLight = len(lights) #hier returnt hij gewoon antaal lichten dat ik hem , kan ik dan gebruiken in mijn aim , zodat hij altijd mijn niuew licht constraint.




LastSelectLight = 'PainterLight_aiArealight'+str(LastLight)


# Aimconstrain the light between the targets
# mo=False so no offset
ConstrainToLocator = cmds.aimConstraint('DistnaceLoc1', LastSelectLight, worldUpVector = (0,1,0), aimVector=(1,0,0), upVector = (0,1,0), mo = False)
#cmds.delete(ConstrainToLocator)

cmds.delete('DistnaceLoc','DistnaceLoc1')




RotlightX = cmds.getAttr(LastSelectLight+".rotateX")
RotlightY = cmds.getAttr(LastSelectLight+".rotateY")
RotlightZ = cmds.getAttr(LastSelectLight+".rotateZ")


myNormalConstrain = cmds.normalConstraint('PainterObject','PainterLigh t_aiArealight'+str(LastLight), aimVector = (0,0,1), worldUpType = 'scene',name='NormalConstrainToPainterObject')
cmds.move(0,0,1,objectSpace=True, relative=True)
cmds.delete(myNormalConstrain)


cmds.rotate(0,0,RotlightZ,objectSpace=True,relativ e=True)



def makeLightStripe():

if cmds.objExists ('PainterObject'):
cmds.select('PainterObject')

# for getting the mousepoitionww
if (cmds.contextInfo(draggerContextName, exists = True)):
cmds.deleteUI(draggerContextName, toolContext = True )

cmds.draggerContext(draggerContextName, pressCommand = dragger_onPress2,cursor = "crossHair", space="world",snapping=True)
cmds.setToolTo(draggerContextName)


#settting snapmode to points
cmds.snapMode(point = True)


makeLightStripe()






 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:25 AM.


Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.