eMath#

_images/as_eMath.jpg

eMath Features

:Advanced Math Module:

The eMath module, specifically developed for Autodesk Maya and VFX applications, focuses on enhancing mathematical functionalities in rigging scripts. Here’s a simplified overview with four key points:

  1. Complex Mathematical Functions: eMath provides advanced mathematical operations essential for intricate rigging and animation tasks in Maya.

  2. Geometry and Spatial Calculations: The module includes algorithms for precise geometry calculations, crucial for accurate modeling and rigging in 3D space.

  3. Optimized Vector and Matrix Operations: eMath offers efficient support for vector and matrix operations, fundamental in 3D animation and rig manipulation.

  4. Scripting Support for Rigging Calculations: The module integrates complex mathematical calculations into rigging scripts, streamlining the rigging process in Maya.

eMath.__init__(self)#

To Support main auto rig scripts via “eMath”

as_eMathMain_v1.2

About

Author: (Subbaiah) Subbu Addanki
Character Supervisor (Rigging) & Programmer

Visit

http://www.pythonscripting.com
http://subbuadd.blogspot.com

Contact

Mail Id: subbu.add@gmail.com
Mobile No: +91-9741454400 / +91-9949005359

Copyright (c) as_eMathMain

** (Subbaiah) Subbu Addanki. All Rights Reserved. **
eMath.as_eMath(self)#

To Support main scripts with repetitive tasks via eMath

eMath.buildMatrix(self, translate=(0, 0, 0), xAxis=(1, 0, 0), yAxis=(0, 1, 0), zAxis=(0, 0, 1), **shArgs)#

[shArgs : t=translate, xa=xAxis, ya=yAxis, za=zAxis]

Purpose:

:: Constructs a transformation matrix from translation and axis vectors. This function builds a transformation matrix given translation values and vectors defining the X, Y, and Z axes.

Parameters:
  • translate – <tuple/list> #Translation values for the matrix.

  • xAxis – <tuple/list> #Vector defining the X-axis of the matrix.

  • yAxis – <tuple/list> #Vector defining the Y-axis of the matrix.

  • zAxis – <tuple/list> #Vector defining the Z-axis of the matrix.

Returns:

<MMatrix> #The constructed transformation matrix.

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateTranslate["/fas:fa-edit Update Translate"] UpdateTranslate --> UpdateXAxis["/fas:fa-edit Update XAxis"] UpdateXAxis --> UpdateYAxis["/fas:fa-edit Update YAxis"] UpdateYAxis --> UpdateZAxis["/fas:fa-edit Update ZAxis"] UpdateZAxis --> CreateMatrix["/fas:fa-th Create Transformation Matrix"] CheckShArgs --"If shArgs not provided" --> CreateMatrix CreateMatrix --> SetXAxisValues["/fas:fa-arrows-alt-h Set XAxis Values"] SetXAxisValues --> SetYAxisValues["/fas:fa-arrows-alt-h Set YAxis Values"] SetYAxisValues --> SetZAxisValues["/fas:fa-arrows-alt-h Set ZAxis Values"] SetZAxisValues --> SetTranslateValues["/fas:fa-arrows-alt Set Translate Values"] SetTranslateValues --> ReturnMatrix["/fas:fa-check Return Matrix"] ReturnMatrix --> End[("fas:fa-stop End")] style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateTranslate fill:#ff9999,stroke:#000,stroke-width:2px style UpdateXAxis fill:#99ccff,stroke:#000,stroke-width:2px style UpdateYAxis fill:#cc99ff,stroke:#000,stroke-width:2px style UpdateZAxis fill:#99ff99,stroke:#000,stroke-width:2px style CreateMatrix fill:#ff9999,stroke:#000,stroke-width:2px style SetXAxisValues fill:#99ccff,stroke:#000,stroke-width:2px style SetYAxisValues fill:#cc99ff,stroke:#000,stroke-width:2px style SetZAxisValues fill:#99ff99,stroke:#000,stroke-width:2px style SetTranslateValues fill:#ff9999,stroke:#000,stroke-width:2px style ReturnMatrix fill:#99ccff,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the buildMatrix function:

  • Checks if shArgs exist, and if so, updates the translate, xAxis, yAxis, and zAxis values from it.

  • If shArgs do not exist, initializes parameters with default values.

  • Creates a transformation matrix based on the input vectors translate, xAxis, yAxis, and zAxis.

eMath.closestPointOnLine(self, pnt, lineA, lineB, clampSegment=False, **shArgs)#

[shArgs : pnt=p, lineA=la, lineB=lb, clampSegment=cs]

Purpose:

:: Identifies the closest point on a line segment to a given point. This function determines the nearest point on a line, defined by two points, to a third point. It optionally allows clamping to the segment between the two defining points.

Parameters:
  • pnt – (<type list>) # The point to find the closest position to, represented as a list of three numbers.

  • lineA – (<type list>) # Start point of the line segment.

  • lineB – (<type list>) # End point of the line segment.

  • clampSegment – (<type bool>, optional) # Whether to clamp the closest point to the segment defined by lineA and lineB.

Returns:

(<type list>) # The closest point on the line to pnt, returned as a list of three numbers.

Code Examples:

```python >>> # Usage examples can be added here if needed >>> closest_point = closestPointOnLine([1.0, 2.0, 3.0], [0.0, 0.0, 0.0], [2.0, 2.0, 2.0], True) >>> print(closest_point) [1.0, 1.0, 1.0]

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdatePnt["/fas:fa-edit Update Pnt"] UpdatePnt --> UpdateLineA["/fas:fa-edit Update LineA"] UpdateLineA --> UpdateLineB["/fas:fa-edit Update LineB"] UpdateLineB --> UpdateClampSegment["/fas:fa-edit Update Clamp Segment"] UpdateClampSegment --> CalculateVectorOffsets["/fas:fa-arrows-alt Calculate Vector Offsets"] CheckShArgs --"If shArgs not provided" --> CalculateVectorOffsets CalculateVectorOffsets --> PerformVectorComparison["/fas:fa-balance-scale Perform Vector Comparison"] PerformVectorComparison --> CheckClampSegment{{"/fas:fa-question Check Clamp Segment"}} CheckClampSegment --"If Clamp Segment" --> ClampDotProduct["/fas:fa-compress-arrows-alt Clamp Dot Product"] ClampDotProduct --> CheckDotProduct{{"/fas:fa-question Check Dot Product"}} CheckDotProduct --"If dot < 0.0" --> ReturnLineA["/fas:fa-arrow-left Return LineA"] CheckDotProduct --"If dot > 1.0" --> ReturnLineB["/fas:fa-arrow-right Return LineB"] CheckClampSegment --"If Not Clamp Segment" --> ProjectVector["/fas:fa-project-diagram Project Vector"] ProjectVector --> ReturnClosestPoint["/fas:fa-map-pin Return Closest Point"] ReturnLineA --> End[("fas:fa-stop End")] ReturnLineB --> End ReturnClosestPoint --> End style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdatePnt fill:#ff9999,stroke:#000,stroke-width:2px style UpdateLineA fill:#99ccff,stroke:#000,stroke-width:2px style UpdateLineB fill:#cc99ff,stroke:#000,stroke-width:2px style UpdateClampSegment fill:#99ff99,stroke:#000,stroke-width:2px style CalculateVectorOffsets fill:#ff9999,stroke:#000,stroke-width:2px style PerformVectorComparison fill:#99ccff,stroke:#000,stroke-width:2px style CheckClampSegment fill:#cc99ff,stroke:#000,stroke-width:2px style ClampDotProduct fill:#99ff99,stroke:#000,stroke-width:2px style CheckDotProduct fill:#ff9999,stroke:#000,stroke-width:2px style ReturnLineA fill:#99ccff,stroke:#000,stroke-width:2px style ReturnLineB fill:#cc99ff,stroke:#000,stroke-width:2px style ProjectVector fill:#99ff99,stroke:#000,stroke-width:2px style ReturnClosestPoint fill:#ff9999,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the closestPointOnLine function:

  • Checks if shArgs exist, and if so, updates the pnt, lineA, lineB, and clampSegment values from it.

  • If shArgs do not exist, uses the provided parameters.

  • Calculates vector offsets.

  • Performs a vector comparison and calculates the dot product.

  • Checks if the segment needs to be clamped.

  • Projects the vector if not clamped and returns the closest point on the line.

eMath.dotProduct(self, vector1=[0, 0, 0], vector2=[0, 0, 0], **shArgs)#

[shArgs : vector1=v1, vector2=v2]

Purpose:

:: Calculates the dot product of two vectors. This function computes the dot product, a scalar value, of two vectors. It’s a measure of the extent to which two vectors are parallel.

Parameters:
  • vector1 – (<type list>) # The first vector for the dot product operation, represented as a list of three numbers.

  • vector2 – (<type list>) # The second vector for the dot product operation, similar in format to vector1.

Returns:

(<type float>) # Returns the scalar dot product of the two vectors.

Code Examples:

```python >>> # Usage examples can be added here if needed >>> result = dotProduct([1.0, 2.0, 3.0], [2.0, 3.0, 4.0]) >>> print(result) 20.0

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateVector1["/fas:fa-edit Update Vector1"] UpdateVector1 --> UpdateVector2["/fas:fa-edit Update Vector2"] UpdateVector2 --> ConvertVector1["/fas:fa-exchange-alt Convert Vector1 to MVector"] CheckShArgs --"If shArgs not provided" --> ConvertVector1 ConvertVector1 --> ConvertVector2["/fas:fa-exchange-alt Convert Vector2 to MVector"] ConvertVector2 --> CalculateDotProduct["/fas:fa-tachometer-alt-fast Calculate Dot Product"] CalculateDotProduct --> ReturnDotProduct["/fas:fa-check-circle Return Dot Product"] ReturnDotProduct --> End[("fas:fa-stop End")] style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateVector1 fill:#ff9999,stroke:#000,stroke-width:2px style UpdateVector2 fill:#99ccff,stroke:#000,stroke-width:2px style ConvertVector1 fill:#cc99ff,stroke:#000,stroke-width:2px style ConvertVector2 fill:#99ff99,stroke:#000,stroke-width:2px style CalculateDotProduct fill:#ff9999,stroke:#000,stroke-width:2px style ReturnDotProduct fill:#99ccff,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the dotProduct function:

  • Checks if shArgs exist, and if so, updates the vector1 and vector2 values from it.

  • If shArgs do not exist, uses the provided parameters.

  • Converts the input vectors to MVector objects.

  • Calculates the dot product of the two vectors and returns the result as a float.

eMath.getMatrix(self, transform, local=False, time=None, **shArgs)#

[shArgs : t=transform, l=local, tm=time]

Purpose:

:: Retrieves the transformation matrix of a given object, with options for local space and specific time. This function extracts the transformation matrix of a specified object, either in world or local space, and optionally at a specific time frame.

Parameters:
  • transform – <str> #The transform object from which to get the matrix.

  • local – <bool, optional> #Determines whether to retrieve the local space matrix instead of the world space matrix. Defaults to False.

  • time – <int/float, optional> #The specific frame to get the matrix for. If not provided, the current frame is used.

Returns:

<MMatrix> #The transformation matrix of the specified object.

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateTransform["/fas:fa-edit Update Transform"] UpdateTransform --> UpdateLocal["/fas:fa-edit Update Local"] UpdateLocal --> UpdateTime["/fas:fa-edit Update Time"] UpdateTime --> CheckTransformExists["/fas:fa-search-plus Check Transform Exists"] CheckShArgs --"If shArgs not provided" --> CheckTransformExists CheckTransformExists --"If Transform Exists" --> DefineMatrixAttr["/fas:fa-th Define Matrix Attribute"] DefineMatrixAttr --> CheckTime{{"/fas:fa-question Check Time"}} CheckTime --"If Time Specified" --> GetMatrixAtTime["/fas:fa-clock Get Matrix At Time"] CheckTime --"If Time Not Specified" --> GetMatrix["/fas:fa-th Get Matrix"] GetMatrixAtTime --> BuildMatrix["/fas:fa-cogs Build Matrix"] GetMatrix --> BuildMatrix CheckTransformExists --"If Transform Does Not Exist" --> RaiseException["/fas:fa-exclamation-triangle Raise Exception"] BuildMatrix --> ReturnMatrix["/fas:fa-arrow-right Return Matrix"] RaiseException --> End[("fas:fa-stop End")] ReturnMatrix --> End style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateTransform fill:#ff9999,stroke:#000,stroke-width:2px style UpdateLocal fill:#99ccff,stroke:#000,stroke-width:2px style UpdateTime fill:#cc99ff,stroke:#000,stroke-width:2px style CheckTransformExists fill:#99ff99,stroke:#000,stroke-width:2px style DefineMatrixAttr fill:#ff9999,stroke:#000,stroke-width:2px style CheckTime fill:#99ccff,stroke:#000,stroke-width:2px style GetMatrixAtTime fill:#cc99ff,stroke:#000,stroke-width:2px style GetMatrix fill:#99ff99,stroke:#000,stroke-width:2px style BuildMatrix fill:#ff9999,stroke:#000,stroke-width:2px style RaiseException fill:#99ccff,stroke:#000,stroke-width:2px style ReturnMatrix fill:#cc99ff,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the getMatrix function:

  1. Checks if shArgs exist and, if so, updates transform, local, and time based on the provided arguments.

  2. Checks if the specified transform object exists.

  3. Defines the matrix attribute as either ‘worldMatrix[0]’ or ‘matrix’ based on the local parameter.

  4. Checks if a specific time frame is specified.

  5. Retrieves the transformation matrix based on the defined matrix attribute and time (if specified).

  6. Builds the transformation matrix.

  7. Returns the transformation matrix.

eMath.getRotationMx(self, matrix, rotationOrder='xyz', **shArgs)#

[shArgs : matrix=m, rotationOrder=ro]

Purpose:

:: Extracts the rotation component from a transformation matrix. This function calculates the Euler rotation values from a given transformation matrix, considering the specified rotation order.

Parameters:
  • matrix – (<type MMatrix>): # The transformation matrix to extract the rotation from.

  • rotationOrder – (<type str/int, optional>): # The rotation order for the Euler rotation. Can be a string like ‘xyz’ or an integer representing the order. Defaults to ‘xyz’.

Returns:

(<type tuple>): # A tuple of three values representing the XYZ Euler rotation extracted from the matrix.

Code Examples:

```python >>> # Usage examples can be added here if needed >>> import maya.OpenMaya as om >>> matrix = om.MMatrix() >>> result = getRotationMx(matrix, rotationOrder=’xyz’) >>> print(result) # Returns the XYZ Euler rotation values extracted from the matrix.

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateMatrix["/fas:fa-edit Update Matrix"] UpdateMatrix --> UpdateRotationOrder["/fas:fa-sync-alt Update Rotation Order"] UpdateRotationOrder --> CalculateRadianConstant["/fas:fa-ruler-combined Calculate Radian Constant"] CheckShArgs --"If shArgs not provided" --> CalculateRadianConstant CalculateRadianConstant --> CheckRotationOrderType{{"/fas:fa-question Check Rotation Order Type"}} CheckRotationOrderType --"If Rotation Order is String" --> ValidateRotationOrderString["/fas:fa-check-square Validate Rotation Order (String)"] CheckRotationOrderType --"If Rotation Order is Int" --> ConvertRotationOrderToInt["/fas:fa-sort-numeric-up Convert Rotation Order (Int)"] ValidateRotationOrderString --> GetTransformationMatrix["/fas:fa-th Get Transformation Matrix"] ConvertRotationOrderToInt --> GetTransformationMatrix GetTransformationMatrix --> GetEulerRotation["/fas:fa-sync-alt Get Euler Rotation"] GetEulerRotation --> ReorderRotation["/fas:fa-random Reorder Rotation"] ReorderRotation --> ReturnXYZRotation["/fas:fa-arrows-alt Return XYZ Rotation"] ReturnXYZRotation --> End[("fas:fa-stop End")] style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateMatrix fill:#ff9999,stroke:#000,stroke-width:2px style UpdateRotationOrder fill:#99ccff,stroke:#000,stroke-width:2px style CalculateRadianConstant fill:#cc99ff,stroke:#000,stroke-width:2px style CheckRotationOrderType fill:#99ff99,stroke:#000,stroke-width:2px style ValidateRotationOrderString fill:#ff9999,stroke:#000,stroke-width:2px style ConvertRotationOrderToInt fill:#99ccff,stroke:#000,stroke-width:2px style GetTransformationMatrix fill:#cc99ff,stroke:#000,stroke-width:2px style GetEulerRotation fill:#99ff99,stroke:#000,stroke-width:2px style ReorderRotation fill:#ff9999,stroke:#000,stroke-width:2px style ReturnXYZRotation fill:#99ccff,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the getRotationMx function:

  1. Checks if shArgs exist, and if so, updates matrix and rotationOrder based on the provided arguments.

  2. If shArgs do not exist, calculates the radian constant.

  3. Checks the type of rotationOrder (string or int).

  4. If rotationOrder is a string, validates it and converts it to an integer representation.

  5. Gets the transformation matrix from the input matrix.

  6. Extracts Euler rotation from the matrix.

  7. Reorders the rotation based on the specified rotation order.

  8. Returns the XYZ Euler rotation values.

eMath.get_2PosExtn(self, srcObj, dirObj, extnRatio=None, locName='Extn_Loc', getLoc=True, extnDist=None, getSpot=False, **shArgs)#

[shArgs : srcObj=so, dirObj=do, extnRatio=er, locName=n, getLoc=gl, extnDist=ed, getSpot=gs]

Purpose:

:: Calculates an extended position or locator based on a directional vector between two objects. This function extends a position in the direction from one object (source) to another (direction object), either by a ratio of the distance between them or by a specified distance.

Parameters:
  • srcObj – (<type str>) # Source object for the directional vector.

  • dirObj – (<type str>) # Direction object for the directional vector.

  • extnRatio – (<type float>, optional) # Ratio value for extended position calculation. # 0 => at dirObj, 1.0 => at srcObj->dirObj distance away from dirObj # -1.0 => at srcObj, -0.5 in the middle of srcObj and dirObj

  • locName – (<type str>, optional) # Name for the locator if created. Defaults to ‘Extn_Loc’.

  • getLoc – (<type bool>, optional) # Whether to return a locator or only the position of the extension point.

  • extnDist – (<type float>, optional) # If provided, the extension distance, overriding the extnRatio. # plusValue -> distance away from dirObj # negValue -> distance from dirObj to towards srcObj

  • getSpot – (<type bool>, optional) # Determines whether to return a specific spot along the extension.

Returns:

# Either a locator or a position list, depending on ‘getLoc’ and ‘getSpot’ parameters.

Code Examples:

```python >>> # Usage examples can be added here if needed >>> result = get_2PosExtn(“sourceObject”, “directionObject”, extnRatio=0.5, locName=”MyLocator”, getLoc=True, extnDist=None, getSpot=False) >>> print(result) # Returns a locator if getLoc is True, or a position list if getSpot is False

Usage:#

eMath.get_2PosExtn(selected()[0], selected()[1], 0.5)

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateSrcObj["/fas:fa-edit Update SrcObj"] UpdateSrcObj --> UpdateDirObj["/fas:fa-edit Update DirObj"] UpdateDirObj --> UpdateExtnRatio["/fas:fa-edit Update ExtnRatio"] UpdateExtnRatio --> UpdateLocName["/fas:fa-edit Update LocName"] UpdateLocName --> UpdateGetLoc["/fas:fa-edit Update GetLoc"] UpdateGetLoc --> UpdateExtnDist["/fas:fa-edit Update ExtnDist"] UpdateExtnDist --> UpdateGetSpot["/fas:fa-edit Update GetSpot"] UpdateGetSpot --> CheckGetSpot{{"/fas:fa-question Check GetSpot"}} CheckShArgs --"If shArgs not provided" --> CheckGetSpot CheckGetSpot --"If GetSpot" --> SetGetLocFalse["/fas:fa-times Set GetLoc False"] SetGetLocFalse --> GetDirectionVector["/fas:fa-location-arrow Get Direction Vector"] CheckGetSpot --"If Not GetSpot" --> GetDirectionVector GetDirectionVector --> CheckExtnDist{{"/fas:fa-question Check ExtnDist"}} CheckExtnDist --"If ExtnDist" --> CalculateWithExtnDist["/fas:fa-arrows-alt-h Calculate With ExtnDist"] CheckExtnDist --"If Not ExtnDist" --> CalculateWithExtnRatio["/fas:fa-expand-arrows-alt Calculate With ExtnRatio"] CalculateWithExtnDist --> CreateLocator["/fas:fa-map-pin Create Locator"] CalculateWithExtnRatio --> CreateLocator CreateLocator --> SnapLocatorToSrcObj["/fas:fa-magnet Snap Locator to SrcObj"] SnapLocatorToSrcObj --> CenterPivotAndUnfreeze["/fas:fa-crosshairs Center Pivot and Unfreeze"] CenterPivotAndUnfreeze --> CheckGetLoc{{"/fas:fa-question Check GetLoc"}} CheckGetLoc --"If GetLoc" --> ReturnLocator["/fas:fa-location-arrow Return Locator"] CheckGetLoc --"If Not GetLoc" --> CheckGetSpotPostProcess{{"/fas:fa-question Check GetSpot Post-Process"}} CheckGetSpotPostProcess --"If GetSpot" --> GetSpotPosition["/fas:fa-dot-circle Get Spot Position"] CheckGetSpotPostProcess --"If Not GetSpot" --> GetLocatorPosition["/fas:fa-map-marker-alt Get Locator Position"] GetSpotPosition --> DeleteLocatorAndGetSpot["/fas:fa-trash-alt Delete Locator and Get Spot"] GetLocatorPosition --> DeleteLocatorAndGetPosition["/fas:fa-trash-alt Delete Locator and Get Position"] ReturnLocator --> End[("fas:fa-stop End")] DeleteLocatorAndGetSpot --> End DeleteLocatorAndGetPosition --> End style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateSrcObj fill:#ff9999,stroke:#000,stroke-width:2px style UpdateDirObj fill:#99ccff,stroke:#000,stroke-width:2px style UpdateExtnRatio fill:#cc99ff,stroke:#000,stroke-width:2px style UpdateLocName fill:#99ff99,stroke:#000,stroke-width:2px style UpdateGetLoc fill:#ff9999,stroke:#000,stroke-width:2px style UpdateExtnDist fill:#99ccff,stroke:#000,stroke-width:2px style UpdateGetSpot fill:#cc99ff,stroke:#000,stroke-width:2px style CheckGetSpot fill:#99ff99,stroke:#000,stroke-width:2px style SetGetLocFalse fill:#ff9999,stroke:#000,stroke-width:2px style GetDirectionVector fill:#99ccff,stroke:#000,stroke-width:2px style CheckExtnDist fill:#cc99ff,stroke:#000,stroke-width:2px style CalculateWithExtnDist fill:#99ff99,stroke:#000,stroke-width:2px style CalculateWithExtnRatio fill:#ff9999,stroke:#000,stroke-width:2px style CreateLocator fill:#99ccff,stroke:#000,stroke-width:2px style SnapLocatorToSrcObj fill:#cc99ff,stroke:#000,stroke-width:2px style CenterPivotAndUnfreeze fill:#99ff99,stroke:#000,stroke-width:2px style CheckGetLoc fill:#ff9999,stroke:#000,stroke-width:2px style ReturnLocator fill:#99ccff,stroke:#000,stroke-width:2px style CheckGetSpotPostProcess fill:#cc99ff,stroke:#000,stroke-width:2px style GetSpotPosition fill:#99ff99,stroke:#000,stroke-width:2px style GetLocatorPosition fill:#ff9999,stroke:#000,stroke-width:2px style DeleteLocatorAndGetSpot fill:#99ccff,stroke:#000,stroke-width:2px style DeleteLocatorAndGetPosition fill:#cc99ff,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the get_2PosExtn function:

  • Checks if shArgs exist and updates various parameters from it.

  • Calculates the direction vector between srcObj and dirObj.

  • Extends the position based on the provided extnRatio or extnDist.

  • Creates a locator and positions it based on the extension.

  • Snap the locator to srcObj, centers its pivot, and unfreezes its transformations.

  • Returns either the locator or a position list, depending on getLoc and getSpot parameters.

eMath.get_2PosExtn_Old(self, srcObj, dirObj, extnRatio=None, locName=None, getLoc=True, extnDist=None, getSpot=False, **shArgs)#

Args: [**shArgs : srcObj =so, dirObj =do, extnRatio =er, locName =n, getLoc =gl, extnDist =ed]#

srcObj = node(str) #_ Source Object for direction vector dirObj = node(str) #_ Direction Object for direction vector extnRatio = int | float #_ Ration Value for Direction Extended Position

#_ 0 => at dirObj, 1.0 => at srcObj->dirObj distance away from dirObj #_ -1.0 => at srcObj, -0.5 in the middle of srcObj and dirObj

locName =name(str) #_ Name of returning locator getLoc = True | False #_ Whether to return locator or only position of extn point extnDist = int | Float #_ if extnDist is given, extnRatio is neglected.

#_ plusValue -> distance away from dirObj #_ negValue -> distance from dirObj to towards srcObj

Usage:#

eMath.get_2PosExtn(selected()[0], selected()[1], 0.5)

eMath.get_2PosVect(self, srcObj, destObj, **shArgs)#

[shArgs : srcObj=so, destObj=do]

Purpose:

:: Calculates the vector between two given positions in 3D space. This function computes a vector representing the directional and distance difference between two points in a 3D space. It handles both node objects and list representations of positions.

Parameters:
  • srcObj – (<type str/list>) # Source object or position in 3D space. If a string is provided, it is assumed to be a node from which the position will be extracted.

  • destObj – (<type str/list>) # Destination object or position in 3D space. Similar to srcObj, this can be either a node name or a position list.

Returns:

(<type MVector>) # Returns an MVector object representing the directional vector from srcObj to destObj.

Code Examples:

```python >>> # Usage examples can be added here if needed >>> result = get_2PosVect(“sourceObject”, “destinationObject”) >>> print(result) # Returns an MVector object representing the directional vector between the two positions.

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateSrcObj["/fas:fa-edit Update SrcObj"] UpdateSrcObj --> UpdateDestObj["/fas:fa-edit Update DestObj"] UpdateDestObj --> DetermineDestType{{"/fas:fa-question Determine Dest Type"}} CheckShArgs --"If shArgs not provided" --> DetermineDestType DetermineDestType --"If DestObj is List" --> SetDestPosList["/fas:fa-list-ol Set DestPos as List"] DetermineDestType --"If DestObj is Node" --> GetDestPosNode["/fas:fa-map-marker-alt Get DestPos from Node"] SetDestPosList --> DetermineSrcType{{"/fas:fa-question Determine Src Type"}} GetDestPosNode --> DetermineSrcType DetermineSrcType --"If SrcObj is List" --> SetSrcPosList["/fas:fa-list-ol Set SrcPos as List"] DetermineSrcType --"If SrcObj is Node" --> GetSrcPosNode["/fas:fa-map-marker-alt Get SrcPos from Node"] SetSrcPosList --> CalculateVector["/fas:fa-arrows-alt Calculate Vector"] GetSrcPosNode --> CalculateVector CalculateVector --> ReturnMVector["/fas:fa-arrow-right Return MVector"] ReturnMVector --> End[("fas:fa-stop End")] style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateSrcObj fill:#ff9999,stroke:#000,stroke-width:2px style UpdateDestObj fill:#99ccff,stroke:#000,stroke-width:2px style DetermineDestType fill:#cc99ff,stroke:#000,stroke-width:2px style SetDestPosList fill:#99ff99,stroke:#000,stroke-width:2px style GetDestPosNode fill:#ff9999,stroke:#000,stroke-width:2px style DetermineSrcType fill:#99ccff,stroke:#000,stroke-width:2px style SetSrcPosList fill:#cc99ff,stroke:#000,stroke-width:2px style GetSrcPosNode fill:#99ff99,stroke:#000,stroke-width:2px style CalculateVector fill:#ff9999,stroke:#000,stroke-width:2px style ReturnMVector fill:#99ccff,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the get_2PosVect function:

  1. Checks if shArgs exist and, if so, updates srcObj and destObj based on shArgs[‘so’] and shArgs[‘do’].

  2. Gets the destination position. If destObj is not a list, it retrieves the position from the specified node using asNode(destObj). If it’s a list, it takes it as-is.

  3. Gets the source position. Similarly, it retrieves the source position from the specified node or list.

  4. Calculates the vector between the two positions in 3D space by finding the differences in X, Y, and Z coordinates.

  5. Returns the calculated vector as an MVector object.

eMath.get_2PosVect_Old(self, srcObj, destObj)#
eMath.get_ClosestGeoLoc(self, loc, mesh, locName='Geo_Loc', giveLoc=True, **shArgs)#

[shArgs : loc=l, mesh=m, locName=n, giveLoc=gl]

Purpose:

:: Finds the closest point on a geometry mesh to a given locator. This function calculates the nearest point on a specified mesh to a locator and can return either the position or a locator at that position. Note: Mesh should be freezed for correct snapping

Parameters:
  • loc – (<type str>) # The locator from which the closest point on the mesh is calculated.

  • mesh – (<type str>) # The mesh object to find the closest point on.

  • locName – (<type str, optional>) # Name for the locator if created. Defaults to ‘Geo_Loc’.

  • giveLoc – (<type bool, optional>) # Determines whether to return the locator itself or its position.

Returns:

# Either a locator or its position on the closest point on the mesh.

Code Examples:

```python >>> # Usage examples can be added here if needed >>> result = get_ClosestGeoLoc(“locator1”, “mesh1”, locName=”MyGeoLocator”, giveLoc=True) >>> print(result) # Returns the created locator named “MyGeoLocator” positioned at the closest point on the mesh.

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateLoc["/fas:fa-edit Update Loc"] UpdateLoc --> UpdateMesh["/fas:fa-edit Update Mesh"] UpdateMesh --> UpdateLocName["/fas:fa-edit Update LocName"] UpdateLocName --> UpdateGiveLoc["/fas:fa-edit Update GiveLoc"] UpdateGiveLoc --> CreateCPOMNode["/fas:fa-plus Create CPOM Node"] CheckShArgs --"If shArgs not provided" --> CreateCPOMNode CreateCPOMNode --> GetLocatorPosition["/fas:fa-map-marker-alt Get Locator Position"] GetLocatorPosition --> SetCPOMPosition["/fas:fa-arrows-alt Set CPOM Position"] SetCPOMPosition --> ConnectCPOMToMesh["/fas:fa-link Connect CPOM to Mesh"] ConnectCPOMToMesh --> GetTargetPosition["/fas:fa-crosshairs Get Target Position"] GetTargetPosition --> CreateGeoLocator["/fas:fa-map-pin Create Geo Locator"] CreateGeoLocator --> MoveGeoLocator["/fas:fa-arrows-alt Move Geo Locator"] MoveGeoLocator --> CheckGiveLoc{{"/fas:fa-question Check GiveLoc"}} CheckGiveLoc --"If GiveLoc" --> ReturnGeoLocator["/fas:fa-location-arrow Return Geo Locator"] CheckGiveLoc --"If Not GiveLoc" --> GetGeoLocatorPosition["/fas:fa-map-marker-alt Get Geo Locator Position"] GetGeoLocatorPosition --> DeleteGeoLocator["/fas:fa-trash-alt Delete Geo Locator"] DeleteGeoLocator --> ReturnPosition["/fas:fa-arrow-right Return Position"] ReturnGeoLocator --> End[("fas:fa-stop End")] ReturnPosition --> End style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateLoc fill:#ff9999,stroke:#000,stroke-width:2px style UpdateMesh fill:#99ccff,stroke:#000,stroke-width:2px style UpdateLocName fill:#cc99ff,stroke:#000,stroke-width:2px style UpdateGiveLoc fill:#99ff99,stroke:#000,stroke-width:2px style CreateCPOMNode fill:#ff9999,stroke:#000,stroke-width:2px style GetLocatorPosition fill:#99ccff,stroke:#000,stroke-width:2px style SetCPOMPosition fill:#cc99ff,stroke:#000,stroke-width:2px style ConnectCPOMToMesh fill:#99ff99,stroke:#000,stroke-width:2px style GetTargetPosition fill:#ff9999,stroke:#000,stroke-width:2px style CreateGeoLocator fill:#99ccff,stroke:#000,stroke-width:2px style MoveGeoLocator fill:#cc99ff,stroke:#000,stroke-width:2px style CheckGiveLoc fill:#99ff99,stroke:#000,stroke-width:2px style ReturnGeoLocator fill:#ff9999,stroke:#000,stroke-width:2px style GetGeoLocatorPosition fill:#99ccff,stroke:#000,stroke-width:2px style DeleteGeoLocator fill:#cc99ff,stroke:#000,stroke-width:2px style ReturnPosition fill:#99ff99,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the get_ClosestGeoLoc function:

  1. Checks if shArgs exist and, if so, updates loc, mesh, locName, and giveLoc based on the provided arguments.

  2. Creates a closestPointOnMesh node named closestPoint and gets the position of the locator.

  3. Sets the initial position of closestPoint to the locator’s position.

  4. Connects the closestPoint node to the specified mesh.

  5. Gets the position details from closestPoint.

  6. Creates a locator named Geo_Loc or as specified by locName at the calculated position.

  7. If giveLoc is True, it returns the created locator. Otherwise, it returns the position and deletes the locator.

  8. Cleanup by deleting the closestPoint node if giveLoc is True.

eMath.get_GCLoc(self, baseLoc, baseGeo, giveLoc=True, **shArgs)#

[shArgs : baseLoc=bl, baseGeo=bg, giveLoc=gl]

Purpose:

:: Calculates a geometric central locator between two closest points on a geometry from a base location. This function identifies two closest points on a geometry from a base locator, extends the position, finds another set of closest points, and finally calculates a central position or locator.

Parameters:
  • baseLoc – (<type str>) # The base locator to start the calculation.

  • baseGeo – (<type str>) # The geometry on which closest points are calculated.

  • giveLoc – (<type bool, optional>) # Determines whether to return the locator itself or its position. Defaults to True.

Returns:

# Either a locator or its position, representing the geometric central location.

Code Examples:

```python >>> # Usage examples can be added here if needed >>> result = get_GCLoc(“baseLocator”, “geometryMesh”, giveLoc=True) >>> print(result) # Returns the central locator positioned between two closest points on the geometry.

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateBaseLoc["/fas:fa-edit Update BaseLoc"] UpdateBaseLoc --> UpdateBaseGeo["/fas:fa-edit Update BaseGeo"] UpdateBaseGeo --> UpdateGiveLoc["/fas:fa-edit Update GiveLoc"] UpdateGiveLoc --> GetClosestGeoLoc1["/fas:fa-map-pin Get Closest GeoLoc 1"] CheckShArgs --"If shArgs not provided" --> GetClosestGeoLoc1 GetClosestGeoLoc1 --> Get2PosExtn["/fas:fa-expand-arrows-alt Get 2Pos Extn"] Get2PosExtn --> GetClosestGeoLoc2["/fas:fa-map-pin Get Closest GeoLoc 2"] GetClosestGeoLoc2 --> Get2PosExtnCenter["/fas:fa-compress-arrows-alt Get 2Pos Extn Center"] Get2PosExtnCenter --> DeleteIntermediateLocators["/fas:fa-trash-alt Delete Intermediate Locators"] DeleteIntermediateLocators --> CheckGiveLoc{{"/fas:fa-question Check GiveLoc"}} CheckGiveLoc --"If GiveLoc" --> ReturnCenterLoc["/fas:fa-location-arrow Return Center Loc"] CheckGiveLoc --"If Not GiveLoc" --> GetCenterLocPosition["/fas:fa-map-marker-alt Get Center Loc Position"] GetCenterLocPosition --> DeleteCenterLoc["/fas:fa-trash-alt Delete Center Loc"] DeleteCenterLoc --> ReturnPosition["/fas:fa-arrow-right Return Position"] ReturnCenterLoc --> End[("fas:fa-stop End")] ReturnPosition --> End style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateBaseLoc fill:#ff9999,stroke:#000,stroke-width:2px style UpdateBaseGeo fill:#99ccff,stroke:#000,stroke-width:2px style UpdateGiveLoc fill:#cc99ff,stroke:#000,stroke-width:2px style GetClosestGeoLoc1 fill:#99ff99,stroke:#000,stroke-width:2px style Get2PosExtn fill:#ff9999,stroke:#000,stroke-width:2px style GetClosestGeoLoc2 fill:#99ccff,stroke:#000,stroke-width:2px style Get2PosExtnCenter fill:#cc99ff,stroke:#000,stroke-width:2px style DeleteIntermediateLocators fill:#99ff99,stroke:#000,stroke-width:2px style CheckGiveLoc fill:#ff9999,stroke:#000,stroke-width:2px style ReturnCenterLoc fill:#99ccff,stroke:#000,stroke-width:2px style GetCenterLocPosition fill:#cc99ff,stroke:#000,stroke-width:2px style DeleteCenterLoc fill:#99ff99,stroke:#000,stroke-width:2px style ReturnPosition fill:#ff9999,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the get_GCLoc function:

  1. Checks if shArgs exist and, if so, updates baseLoc, baseGeo, and giveLoc based on the provided arguments.

  2. Calculates the first closest geometric locator using get_ClosestGeoLoc.

  3. Extends the position to find another set of closest points using get_2PosExtn.

  4. Calculates the second closest geometric locator using get_ClosestGeoLoc.

  5. Calculates the central position between the two locators using get_2PosExtn.

  6. Deletes intermediate locators created during the process.

  7. If giveLoc is True, it returns the central locator. Otherwise, it returns the central locator’s position and deletes the locator.

  8. Cleanup by deleting intermediate locators if giveLoc is True.

eMath.get_GeoCentricLoc(self, baseLoc, baseGeo, giveLoc=True, **shArgs)#

[shArgs : baseLoc=bl, baseGeo=bg, giveLoc=gl]

Purpose:

:: Calculates a geocentric locator or position based on a given base location and geometry. This function computes a geocentric locator or position, considering the closest points on a geometry to a base location and additional geometric calculations based on joints and normal vectors.

Parameters:
  • baseLoc – (<type str>) # The base locator or joint from which the calculation starts.

  • baseGeo – (<type str>) # The geometry used for calculating closest points and extensions.

  • giveLoc – (<type bool, optional>) # Determines whether to return a locator or just the position. Defaults to True.

Returns:

# Either a locator or a position, representing the geocentric location relative to the baseLoc and baseGeo. eMath.get_GeoCentricLoc(selected()[0], ‘baseGeo’)

Usage:

```python >>> # Example usage: >>> result = get_GeoCentricLoc(“baseLocator”, “geometryMesh”, giveLoc=True) >>> print(result) # Returns the geocentric locator or position based on the base locator and geometry.

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateBaseLoc["/fas:fa-edit Update BaseLoc"] UpdateBaseLoc --> UpdateBaseGeo["/fas:fa-edit Update BaseGeo"] UpdateBaseGeo --> UpdateGiveLoc["/fas:fa-edit Update GiveLoc"] UpdateGiveLoc --> ConvertBaseLoc["/fas:fa-exchange-alt Convert BaseLoc to PyNode"] CheckShArgs --"If shArgs not provided" --> ConvertBaseLoc ConvertBaseLoc --> GetClosestGeoLoc1["/fas:fa-map-pin Get Closest GeoLoc 1"] GetClosestGeoLoc1 --> Get2PosExtn1["/fas:fa-expand-arrows-alt Get 2Pos Extn 1"] Get2PosExtn1 --> GetClosestGeoLoc2["/fas:fa-map-pin Get Closest GeoLoc 2"] GetClosestGeoLoc2 --> Get2PosExtnCenter["/fas:fa-compress-arrows-alt Get 2Pos Extn Center"] Get2PosExtnCenter --> CheckBaseLocType{{"/fas:fa-question Check BaseLoc Type"}} CheckBaseLocType --"If BaseLoc is Joint" --> ProcessJointType["/fas:fa-link Process Joint Type"] CheckBaseLocType --"If BaseLoc is Not Joint" --> ProcessNonJointType["/fas:fa-link Process Non-Joint Type"] ProcessJointType --> GetNormLoc["/fas:fa-map-marker-alt Get Norm Loc"] GetNormLoc --> GetClosestGeoLocNorm1["/fas:fa-map-pin Get Closest GeoLoc Norm 1"] GetClosestGeoLocNorm1 --> Get2PosExtnNorm["/fas:fa-expand-arrows-alt Get 2Pos Extn Norm"] Get2PosExtnNorm --> GetClosestGeoLocNorm2["/fas:fa-map-pin Get Closest GeoLoc Norm 2"] GetClosestGeoLocNorm2 --> CalculateFinalCenterLoc["/fas:fa-balance-scale Calculate Final Center Loc"] CalculateFinalCenterLoc --> DeleteIntermediateLocatorsJoint["/fas:fa-trash-alt Delete Intermediate Locators (Joint)"] DeleteIntermediateLocatorsJoint --> FinalCenterLocJoint["/fas:fa-location-arrow Final Center Loc (Joint)"] ProcessNonJointType --> DeleteIntermediateLocatorsNonJoint["/fas:fa-trash-alt Delete Intermediate Locators (Non-Joint)"] DeleteIntermediateLocatorsNonJoint --> FinalCenterLocNonJoint["/fas:fa-location-arrow Final Center Loc (Non-Joint)"] FinalCenterLocJoint --> CheckGiveLoc{{"/fas:fa-question Check GiveLoc"}} FinalCenterLocNonJoint --> CheckGiveLoc CheckGiveLoc --"If GiveLoc" --> ReturnCenterLoc["/fas:fa-location-arrow Return Center Loc"] CheckGiveLoc --"If Not GiveLoc" --> GetCenterLocPosition["/fas:fa-map-marker-alt Get Center Loc Position"] GetCenterLocPosition --> DeleteCenterLoc["/fas:fa-trash-alt Delete Center Loc"] DeleteCenterLoc --> ReturnPosition["/fas:fa-arrow-right Return Position"] ReturnCenterLoc --> End[("fas:fa-stop End")] ReturnPosition --> End style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateBaseLoc fill:#ff9999,stroke:#000,stroke-width:2px style UpdateBaseGeo fill:#99ccff,stroke:#000,stroke-width:2px style UpdateGiveLoc fill:#cc99ff,stroke:#000,stroke-width:2px style ConvertBaseLoc fill:#99ff99,stroke:#000,stroke-width:2px style GetClosestGeoLoc1 fill:#ff9999,stroke:#000,stroke-width:2px style Get2PosExtn1 fill:#99ccff,stroke:#000,stroke-width:2px style GetClosestGeoLoc2 fill:#cc99ff,stroke:#000,stroke-width:2px style Get2PosExtnCenter fill:#99ff99,stroke:#000,stroke-width:2px style CheckBaseLocType fill:#ff9999,stroke:#000,stroke-width:2px style ProcessJointType fill:#99ccff,stroke:#000,stroke-width:2px style ProcessNonJointType fill:#cc99ff,stroke:#000,stroke-width:2px style GetNormLoc fill:#99ff99,stroke:#000,stroke-width:2px style GetClosestGeoLocNorm1 fill:#ff9999,stroke:#000,stroke-width:2px style Get2PosExtnNorm fill:#99ccff,stroke:#000,stroke-width:2px style GetClosestGeoLocNorm2 fill:#cc99ff,stroke:#000,stroke-width:2px style CalculateFinalCenterLoc fill:#99ff99,stroke:#000,stroke-width:2px style DeleteIntermediateLocatorsJoint fill:#ff9999,stroke:#000,stroke-width:2px style FinalCenterLocJoint fill:#99ccff,stroke:#000,stroke-width:2px style DeleteIntermediateLocatorsNonJoint fill:#cc99ff,stroke:#000,stroke-width:2px style FinalCenterLocNonJoint fill:#99ff99,stroke:#000,stroke-width:2px style CheckGiveLoc fill:#ff9999,stroke:#000,stroke-width:2px style ReturnCenterLoc fill:#99ccff,stroke:#000,stroke-width:2px style GetCenterLocPosition fill:#cc99ff,stroke:#000,stroke-width:2px style DeleteCenterLoc fill:#99ff99,stroke:#000,stroke-width:2px style ReturnPosition fill:#ff9999,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the get_GeoCentricLoc function:

  1. Checks if shArgs exist and, if so, updates baseLoc, baseGeo, and giveLoc based on the provided arguments.

  2. Converts baseLoc to a PyNode object.

  3. Calculates the first closest geometric locator using get_ClosestGeoLoc.

  4. Extends the position to find another set of closest points using get_2PosExtn.

  5. Calculates the second closest geometric locator using get_ClosestGeoLoc.

  6. Calculates the central position based on whether baseLoc is a joint or not.

  7. If baseLoc is a joint, additional calculations involving normals and joints

eMath.get_NewDirLoc(self, oldSt, oldEnd, newSt, newEnd, giveLoc=True, **shArgs)#

[shArgs : os=oldSt, oe=oldEnd, ns=newSt, ne=newEnd, gl=giveLoc]

Purpose:

:: Calculates a new direction locator based on the difference in distance between two pairs of points.

Parameters:
  • oldSt – <asNode/position> #Starting point of the old direction.

  • oldEnd – <asNode/position> #Ending point of the old direction.

  • newSt – <asNode/position> #Starting point of the new direction.

  • newEnd – <asNode/position> #Ending point of the new direction.

  • giveLoc – <bool, optional> #If True, returns a locator at the new position. Default is True.

Returns:

<asNode/position> #New position or locator based on the calculated direction and distance difference.

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateOldSt["/fas:fa-edit Update OldSt"] UpdateOldSt --> UpdateOldEnd["/fas:fa-edit Update OldEnd"] UpdateOldEnd --> UpdateNewSt["/fas:fa-edit Update NewSt"] UpdateNewSt --> UpdateNewEnd["/fas:fa-edit Update NewEnd"] UpdateNewEnd --> UpdateGiveLoc["/fas:fa-edit Update GiveLoc"] UpdateGiveLoc --> CalculateOldDistance["/fas:fa-ruler Calculate Old Distance"] CheckShArgs --"If shArgs not provided" --> CalculateOldDistance CalculateOldDistance --> CalculateNewDistance["/fas:fa-ruler Calculate New Distance"] CalculateNewDistance --> ComputeDiffPercent["/fas:fa-calculator Compute Difference Percentage"] ComputeDiffPercent --> CalculateNewPosition["/fas:fa-location-arrow Calculate New Position"] CalculateNewPosition --> CheckGiveLoc{{"/fas:fa-question Check GiveLoc"}} CheckGiveLoc --"If GiveLoc" --> ReturnNewLocator["/fas:fa-map-marker-alt Return New Locator"] CheckGiveLoc --"If Not GiveLoc" --> ReturnNewPosition["/fas:fa-arrow-right Return New Position"] ReturnNewLocator --> End[("fas:fa-stop End")] ReturnNewPosition --> End style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateOldSt fill:#ff9999,stroke:#000,stroke-width:2px style UpdateOldEnd fill:#99ccff,stroke:#000,stroke-width:2px style UpdateNewSt fill:#cc99ff,stroke:#000,stroke-width:2px style UpdateNewEnd fill:#99ff99,stroke:#000,stroke-width:2px style UpdateGiveLoc fill:#ff9999,stroke:#000,stroke-width:2px style CalculateOldDistance fill:#99ccff,stroke:#000,stroke-width:2px style CalculateNewDistance fill:#cc99ff,stroke:#000,stroke-width:2px style ComputeDiffPercent fill:#99ff99,stroke:#000,stroke-width:2px style CalculateNewPosition fill:#ff9999,stroke:#000,stroke-width:2px style CheckGiveLoc fill:#99ccff,stroke:#000,stroke-width:2px style ReturnNewLocator fill:#cc99ff,stroke:#000,stroke-width:2px style ReturnNewPosition fill:#99ff99,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the get_NewDirLoc function:

  1. Checks if shArgs exist and, if so, updates oldSt, oldEnd, newSt, newEnd, and giveLoc based on the provided arguments.

  2. Calculates the old distance between oldSt and oldEnd.

  3. Calculates the new distance between newSt and newEnd.

  4. Computes the difference percentage between old and new distances.

  5. Calculates the new position based on the difference percentage and whether to return a locator.

  6. Returns either the new locator or the new position.

eMath.get_NormLoc(self, obj_Piv, obj_Vec1, obj_Vec2, locName='Norm_Loc', giveLoc=True, **shArgs)#

[shArgs : obj_Piv=op, obj_Vec1=ov1, obj_Vec2=ov2, locName=n, giveLoc=gl]

Purpose:

:: Calculates the normal locator position based on two vector positions from a pivot object. This function generates a locator at the normal vector position relative to two directional vectors originating from a pivot object.

Parameters:
  • <str> (obj_Vec2) – #The pivot object from which the vectors originate.

  • <str> – #The first directional vector object.

  • <str> – #The second directional vector object.

  • optional) (giveLoc (bool,) – #Name for the created locator. Defaults to ‘Norm_Loc’.

  • optional) – #Determines whether to return the locator itself or its position. Defaults to True.

Returns:

#Returns either the locator or its position based on the ‘giveLoc’ parameter.

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateObjPiv["/fas:fa-edit Update Obj_Piv"] UpdateObjPiv --> UpdateObjVec1["/fas:fa-edit Update Obj_Vec1"] UpdateObjVec1 --> UpdateObjVec2["/fas:fa-edit Update Obj_Vec2"] UpdateObjVec2 --> UpdateLocName["/fas:fa-edit Update LocName"] UpdateLocName --> UpdateGiveLoc["/fas:fa-edit Update GiveLoc"] UpdateGiveLoc --> GetVector1["/fas:fa-location-arrow Get Vector 1"] CheckShArgs --"If shArgs not provided" --> GetVector1 GetVector1 --> GetVector2["/fas:fa-location-arrow Get Vector 2"] GetVector2 --> CalculateNormalVector["/fas:fa-calculator Calculate Normal Vector"] CalculateNormalVector --> CreateNormLoc["/fas:fa-map-pin Create Norm Loc"] CreateNormLoc --> CreateJoints["/fas:fa-bone Create Joints"] CreateJoints --> SnapEndJointToNormLoc["/fas:fa-magnet Snap End Joint to Norm Loc"] SnapEndJointToNormLoc --> SnapStartJointToObjPiv["/fas:fa-magnet Snap Start Joint to Obj_Piv"] SnapStartJointToObjPiv --> SnapNormLocToEndJoint["/fas:fa-magnet Snap Norm Loc to End Joint"] SnapNormLocToEndJoint --> DeleteStartJoint["/fas:fa-trash-alt Delete Start Joint"] DeleteStartJoint --> CheckGiveLoc{{"/fas:fa-question Check GiveLoc"}} CheckGiveLoc --"If GiveLoc" --> ReturnNormLoc["/fas:fa-location-arrow Return Norm Loc"] CheckGiveLoc --"If Not GiveLoc" --> GetNormLocPosition["/fas:fa-map-marker-alt Get Norm Loc Position"] GetNormLocPosition --> DeleteNormLoc["/fas:fa-trash-alt Delete Norm Loc"] DeleteNormLoc --> ReturnPosition["/fas:fa-arrow-right Return Position"] ReturnNormLoc --> End[("fas:fa-stop End")] ReturnPosition --> End style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateObjPiv fill:#ff9999,stroke:#000,stroke-width:2px style UpdateObjVec1 fill:#99ccff,stroke:#000,stroke-width:2px style UpdateObjVec2 fill:#cc99ff,stroke:#000,stroke-width:2px style UpdateLocName fill:#99ff99,stroke:#000,stroke-width:2px style UpdateGiveLoc fill:#ff9999,stroke:#000,stroke-width:2px style GetVector1 fill:#99ccff,stroke:#000,stroke-width:2px style GetVector2 fill:#cc99ff,stroke:#000,stroke-width:2px style CalculateNormalVector fill:#99ff99,stroke:#000,stroke-width:2px style CreateNormLoc fill:#ff9999,stroke:#000,stroke-width:2px style CreateJoints fill:#99ccff,stroke:#000,stroke-width:2px style SnapEndJointToNormLoc fill:#cc99ff,stroke:#000,stroke-width:2px style SnapStartJointToObjPiv fill:#99ff99,stroke:#000,stroke-width:2px style SnapNormLocToEndJoint fill:#ff9999,stroke:#000,stroke-width:2px style DeleteStartJoint fill:#99ccff,stroke:#000,stroke-width:2px style CheckGiveLoc fill:#cc99ff,stroke:#000,stroke-width:2px style ReturnNormLoc fill:#99ff99,stroke:#000,stroke-width:2px style GetNormLocPosition fill:#ff9999,stroke:#000,stroke-width:2px style DeleteNormLoc fill:#99ccff,stroke:#000,stroke-width:2px style ReturnPosition fill:#cc99ff,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the get_NormLoc function:

  1. Checks if shArgs exist and, if so, updates obj_Piv, obj_Vec1, obj_Vec2, locName, and giveLoc based on the provided arguments.

  2. Calculates the normal vector based on two directional vectors originating from obj_Piv.

  3. Creates a locator at the calculated normal vector position.

  4. Creates joints and snaps them to the locator and objects.

  5. Deletes the temporary joints.

  6. Returns either the locator or its position based on the giveLoc parameter.

eMath.mapRange(self, inputVal, minIN, maxIN, minOUT, maxOUT, **shArgs)#

[shArgs : inputVal=iv, minIN=minI, maxIN=maxI, minOUT=minO, maxOUT=maxO]

Purpose:

:: Remaps a value from one range to another range, optionally supporting inverted output ranges. This function takes an input value within a specified input range and maps it to a new value within a specified output range. It also handles cases where the output range is inverted. Now Supports inverted / reverse out put range where maxOUT is less than minOUT

Parameters:
  • inputVal – (<type float>): # The value to be remapped.

  • minIN – (<type float>): # The minimum of the input range.

  • maxIN – (<type float>): # The maximum of the input range.

  • minOUT – (<type float>): # The minimum of the output range.

  • maxOUT – (<type float>): # The maximum of the output range.

Returns:

(<type float>): # The remapped value within the output range.

Code Examples:

```python >>> # Usage examples can be added here if needed >>> result = mapRange(0.5, 0.0, 1.0, 0.0, 100.0) >>> print(result) # Returns the remapped value within the specified output range.

graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateInputVal["/fas:fa-edit Update InputVal"] UpdateInputVal --> UpdateMinIN["/fas:fa-edit Update MinIN"] UpdateMinIN --> UpdateMaxIN["/fas:fa-edit Update MaxIN"] UpdateMaxIN --> UpdateMinOUT["/fas:fa-edit Update MinOUT"] UpdateMinOUT --> UpdateMaxOUT["/fas:fa-edit Update MaxOUT"] UpdateMaxOUT --> CheckOutputRange{{"/fas:fa-balance-scale Check Output Range"}} CheckShArgs --"If shArgs not provided" --> CheckOutputRange CheckOutputRange --"If MaxOUT > MinOUT" --> CalculateOutRange["/fas:fa-ruler-horizontal Calculate OutRange"] CheckOutputRange --"If MaxOUT <= MinOUT" --> CalculateInvertedOutRange["/fas:fa-ruler-horizontal Calculate Inverted OutRange"] CalculateOutRange --> CheckInputRange{{"/fas:fa-balance-scale Check Input Range"}} CalculateInvertedOutRange --> CheckInputRange CheckInputRange --"If Input Range Not Zero" --> ScaleValue["/fas:fa-arrows-alt-h Scale Value"] CheckInputRange --"If Input Range Zero" --> ScaleValueZero["/fas:fa-arrows-alt-h Scale Value (Zero Input Range)"] ScaleValue --> CalculateOutputValue["/fas:fa-calculator Calculate Output Value"] ScaleValueZero --> CalculateOutputValue CalculateOutputValue --> ClampOutputValue["/fas:fa-compress-arrows-alt Clamp Output Value"] ClampOutputValue --> ReturnMappedValue["/fas:fa-check-circle Return Mapped Value"] ReturnMappedValue --> End[("fas:fa-stop End")] style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateInputVal fill:#ff9999,stroke:#000,stroke-width:2px style UpdateMinIN fill:#99ccff,stroke:#000,stroke-width:2px style UpdateMaxIN fill:#cc99ff,stroke:#000,stroke-width:2px style UpdateMinOUT fill:#99ff99,stroke:#000,stroke-width:2px style UpdateMaxOUT fill:#ff9999,stroke:#000,stroke-width:2px style CheckOutputRange fill:#99ccff,stroke:#000,stroke-width:2px style CalculateOutRange fill:#cc99ff,stroke:#000,stroke-width:2px style CalculateInvertedOutRange fill:#99ff99,stroke:#000,stroke-width:2px style CheckInputRange fill:#ff9999,stroke:#000,stroke-width:2px style ScaleValue fill:#99ccff,stroke:#000,stroke-width:2px style ScaleValueZero fill:#cc99ff,stroke:#000,stroke-width:2px style CalculateOutputValue fill:#99ff99,stroke:#000,stroke-width:2px style ClampOutputValue fill:#ff9999,stroke:#000,stroke-width:2px style ReturnMappedValue fill:#99ccff,stroke:#000,stroke-width:2px style End fill:#ff6666,stroke:#000,stroke-width:3px
Flow Chart Description:

This flowchart illustrates the mapRange function:

  1. Checks if shArgs exist, and if so, updates the function parameters based on the provided arguments.

  2. Calculates the output range based on whether maxOUT is greater than minOUT.

  3. Checks the input range.

  4. Scales the input value within the input range.

  5. Calculates the output value based on the scaled input value and output range.

  6. Clamps the output value to ensure it falls within the specified output range.

  7. Returns the mapped value.

eMath.old_mapRange(self, inputVal, minIN, maxIN, minOUT, maxOUT)#
eMath.orientTo(self, jointList, target, **shArgs)#

[shArgs : jointList=jl, target=tg]

Purpose:

:: Matches the orientation of a list of joints to a target transform. This function aligns the orientation of each joint in a given list to match that of a specified target transform.

Parameters:
  • (list) (jointList) – # A list of joints to orient.

  • (str) (target) – # The target transform to match the joint orientations to.

Returns:

# None. The function modifies the joint orientations directly.

Code Examples:

>>> # Usage examples can be added here if needed
>>> jointList = ["joint1", "joint2", "joint3"]
>>> target = "target_transform"
>>> orientTo(jointList, target)
# Aligns the orientation of the specified joints to match the target transform.
graph TB Start[("(fa:fa-play Start)")] --> CheckShArgs{{"/fas:fa-question Check shArgs"}} CheckShArgs --"If shArgs provided" --> UpdateJointList["/fas:fa-edit Update Joint List"] UpdateJointList --> UpdateTarget["/fas:fa-edit Update Target"] CheckShArgs --"If shArgs not provided" --> UpdateTarget UpdateTarget --> ProcessJointList{{"/fas:fa-list-ol Process Joint List"}} ProcessJointList --> LoopJoints{{"/fas:fa-repeat Loop Through Joints"}} LoopJoints --> UnparentChildren["/fas:fa-level-up-alt Unparent Children"] UnparentChildren --> GetParentMatrix["/fas:fa-arrows-alt Get Parent Matrix"] GetParentMatrix --> GetTargetMatrix["/fas:fa-crosshairs Get Target Matrix"] GetTargetMatrix --> CalculateOrientMatrix["/fas:fa-cogs Calculate Orient Matrix"] CalculateOrientMatrix --> ExtractJointOrient["/fas:fa-sync-alt Extract Joint Orient"] ExtractJointOrient --> ResetJointRotation["/fas:fa-undo Reset Joint Rotation"] ResetJointRotation --> SetJointOrient["/fas:fa-redo Set Joint Orient"] SetJointOrient --> ReparentChildren["/fas:fa-level-down-alt Reparent Children"] ReparentChildren --> EndLoop{{"/fas:fa-repeat End Loop"}} EndLoop --"If More Joints" --> LoopJoints EndLoop --"If No More Joints" --> SelectJointList["/fas:fa-hand-pointer Select Joint List"] SelectJointList --> End[("fas:fa-stop End")] style Start fill:#00cc00,stroke:#000,stroke-width:3px style CheckShArgs fill:#ffcc00,stroke:#000,stroke-width:2px style UpdateJointList fill:#ff9999,stroke:#000,stroke-width:2px style UpdateTarget fill:#99ccff,stroke:#000,stroke-width:2px style ProcessJointList fill:#cc99ff,stroke:#000,stroke-width:2px style LoopJoints fill:#99ff99,stroke:#000,stroke-width:2px style UnparentChildren fill:#ff9999,stroke:#000,stroke-width:2px style GetParentMatrix fill:#99ccff,stroke:#000,stroke-width:2px style GetTargetMatrix fill:#cc99ff,stroke:#000,stroke-width:2px style CalculateOrientMatrix fill:#99ff99,stroke:#000,stroke-width:2px style ExtractJointOrient fill:#ff9999,stroke:#000,stroke-width:2px style ResetJointRotation fill:#99ccff,stroke:#000,stroke-width:2px style SetJointOrient fill:#cc99ff,stroke:#000,stroke-width:2px style ReparentChildren fill:#99ff99,stroke:#000,stroke-width:2px style EndLoop fill:#ff9999,stroke:#000,stroke-width:2px style SelectJointList fill:#99ccff,stroke:#000,stroke-width:2px style End fill:#cc99ff,stroke:#000,stroke-width:2px
Flow Chart Description:

This flowchart illustrates the orientTo function:

  1. Checks if shArgs exist, and if so, updates the function parameters based on the provided arguments.

  2. Loops through the list of joints.

  3. Unparents children of the current joint.

  4. Gets the parent joint matrix.

  5. Gets the target matrix.

  6. Calculates the orient matrix.

  7. Extracts joint orient values.

  8. Resets joint rotation and orientation.

  9. Reparents children to the current joint.

  10. Repeats the process for the next joint or ends the loop.

  11. Selects the joint list.

  12. Ends the process.