pymel.core.modeling.angleBetween¶
- angleBetween(*args, **kwargs)¶
Returns the axis and angle required to rotate one vector onto another. If the construction history (ch) flag is ON, then the name of the new dependency node is returned.
Flags:
Long Name / Short Name Argument Types Properties caching / cch bool Toggle caching for all attributes so that no recomputation is needed constructionHistory / ch bool Turn the construction history on or off. euler / er bool return the rotation as 3 Euler angles instead of axis + angle frozen / fzn bool name / n unicode nodeState / nds int Maya dependency nodes have 6 possible states. The Normal (0), HasNoEffect (1), and Blocking (2)states can be used to alter how the graph is evaluated. The Waiting-Normal (3), Waiting-HasNoEffect (4), Waiting-Blocking (5)are for internal use only. They temporarily shut off parts of the graph during interaction (e.g., manipulation). The understanding is that once the operation is done, the state will be reset appropriately, e.g. Waiting-Blockingwill reset back to Blocking. The Normaland Blockingcases apply to all nodes, while HasNoEffectis node specific; many nodes do not support this option. Plug-ins store state in the MPxNode::stateattribute. Anyone can set it or check this attribute. Additional details about each of these 3 states follow. StateDescriptionNormalThe normal node state. This is the default.HasNoEffectThe HasNoEffectoption (a.k.a. pass-through), is used in cases where there is an operation on an input producing an output of the same data type. Nearly all deformers support this state, as do a few other nodes. As stated earlier, it is not supported by all nodes. Its typical to implement support for the HasNoEffectstate in the nodes compute method and to perform appropriate operations. Plug-ins can also support HasNoEffect. The usual implementation of this state is to copy the input directly to the matching output without applying the algorithm in the node. For deformers, applying this state leaves the input geometry undeformed on the output. BlockingThis is implemented in the depend node base class and applies to all nodes. Blockingis applied during the evaluation phase to connections. An evaluation request to a blocked connection will return as failures, causing the destination plug to retain its current value. Dirty propagation is indirectly affected by this state since blocked connections are never cleaned. When a node is set to Blockingthe behavior is supposed to be the same as if all outgoing connections were broken. As long as nobody requests evaluation of the blocked node directly it wont evaluate after that. Note that a blocked node will still respond to getAttrrequests but a getAttron a downstream node will not reevaluate the blocked node. Setting the root transform of a hierarchy to Blockingwont automatically influence child transforms in the hierarchy. To do this, youd need to explicitly set all child nodes to the Blockingstate. For example, to set all child transforms to Blocking, you could use the following script. import maya.cmds as cmds def blockTree(root): nodesToBlock = [] for node in {child:1 for child in cmds.listRelatives( root, path=True, allDescendents=True )}.keys(): nodesToBlock += cmds.listConnections(node, source=True, destination=True ) for node in {source:1 for source in nodesToBlock}.keys(): cmds.setAttr( ‘%s.nodeState’ % node, 2 ) Applying this script would continue to draw objects but things would not be animated. Default:kdnNormal vector1 / v1 float, float, float vector from which to compute the rotation vector1X / v1x float X coordinate of the vector from which to compute the rotation vector1Y / v1y float Y coordinate of the vector from which to compute the rotation vector1Z / v1z float Z coordinate of the vector from which to compute the rotation vector2 / v2 float, float, float vector to which to compute the rotation vector2X / v2x float X coordinate of the vector to which to compute the rotation vector2Y / v2y float Y coordinate of the vector to which to compute the rotation vector2Z / v2z float Z coordinate of the vector to which to compute the rotation Flag can have multiple arguments, passed either as a tuple or a list. Derived from mel command maya.cmds.angleBetween
Example:
import pymel.core as pm # To find the euler angle between these two vectors. The result is three # angles in the current angular unit. In this example, the first vector # must be rotated -63.434949 degrees about the X axis, 16.60155 degrees # about the Y axis and -26.565051 degrees about the Z axis to achieve # the second vector. pm.angleBetween( euler=True, v1=(0.0, 1.0, 2.0), v2=(1.0, 2.0, 0.0) ) # Result: [-63.43494882292202, 16.601549599020235, -26.565051177077994] # # To find the angle between these two vectors. The result is an axis and # an angle (in the current angular unit). In this example, the first # vector must be rotated 66.421822 degrees about the axis # (-0.8728716, 0.4364358, -0.2182179) to achieve the second vector. pm.angleBetween( v1=(0.0, 1.0, 2.0), v2=(1.0, 2.0, 0.0) ) # Result: [-0.8728715609439698, 0.4364357804719849, -0.21821789023599245, 66.42182152179817] # # How to create a dependency node that calculates the angle between two # vectors. This example shows how the (x,z) position of a sphere # can be used to control the rotate factors (about y) of a cone shape. angleBtwnNode = pm.angleBetween(v1=(1, 0, 0), v2=(1, 0, 0), ch=True) sphere = pm.sphere() pm.move( 5, 0, 5, sphere[0] ) pm.connectAttr( sphere[0]+'.translateX', angleBtwnNode+'.vector2X' ) pm.connectAttr( sphere[0]+'.translateZ', angleBtwnNode+'.vector2Z' ) cone = pm.cone( ch=False ) convert = pm.createNode( 'unitConversion' ) pm.connectAttr( angleBtwnNode+'.eulerY', convert+'.input' ) pm.connectAttr( convert+'.output', cone[0]+'.rotateY' )