Skip to content

Commit

Permalink
Added a "Scale Compensation" plug to both twistSpline & riderConstrai…
Browse files Browse the repository at this point in the history
…nt nodes. (#29)

* Added scale compensation plugs

Both twistSpline and riderConstraint nodes got a new plug to handle global rig scaling internally.

* Updated attribute editor templates

Also added the missing template for the TwistTangent node, along with its outliner icon.

* Fixed a typo in an attribute check macro

* Updated plug-in version

* Version bump to 1.2.0 + added new connection to script

* Added scale compensation for the globalOffset
  • Loading branch information
mdilena authored Aug 16, 2024
1 parent 9a024da commit d6b7368
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 27 deletions.
24 changes: 12 additions & 12 deletions TwistSpline.mod
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
+ PLATFORM:win64 MAYAVERSION:2022 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:win64 MAYAVERSION:2022 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: windows-2022
[r] scripts: scripts

+ PLATFORM:linux MAYAVERSION:2022 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:linux MAYAVERSION:2022 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: linux-2022
[r] scripts: scripts

+ PLATFORM:mac MAYAVERSION:2022 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:mac MAYAVERSION:2022 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: mac-2022
[r] scripts: scripts

+ PLATFORM:win64 MAYAVERSION:2023 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:win64 MAYAVERSION:2023 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: windows-2023
[r] scripts: scripts

+ PLATFORM:linux MAYAVERSION:2023 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:linux MAYAVERSION:2023 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: linux-2023
[r] scripts: scripts

+ PLATFORM:mac MAYAVERSION:2023 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:mac MAYAVERSION:2023 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: mac-2023
[r] scripts: scripts

+ PLATFORM:win64 MAYAVERSION:2024 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:win64 MAYAVERSION:2024 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: windows-2024
[r] scripts: scripts

+ PLATFORM:linux MAYAVERSION:2024 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:linux MAYAVERSION:2024 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: linux-2024
[r] scripts: scripts

+ PLATFORM:mac MAYAVERSION:2024 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:mac MAYAVERSION:2024 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: mac-2024
[r] scripts: scripts

+ PLATFORM:win64 MAYAVERSION:2025 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:win64 MAYAVERSION:2025 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: windows-2025
[r] scripts: scripts

+ PLATFORM:linux MAYAVERSION:2025 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:linux MAYAVERSION:2025 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: linux-2025
[r] scripts: scripts

+ PLATFORM:mac MAYAVERSION:2025 TwistSpline 1.1.0 TwistSpline
+ PLATFORM:mac MAYAVERSION:2025 TwistSpline 1.2.0 TwistSpline
[r] icons: icons
plug-ins: mac-2025
[r] scripts: scripts
1 change: 1 addition & 0 deletions scripts/AEriderConstraintTemplate.mel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ global proc AEriderConstraintTemplate( string $nodeName ) {
editorTemplate -beginLayout "Global Attributes" -collapse 0;
editorTemplate -label "Global Offset" -addControl "globalOffset";
editorTemplate -label "Global Spread" -addControl "globalSpread";
editorTemplate -label "Scale Compensation" -addControl "scaleCompensation";
editorTemplate -label "Rotate Order" -addControl "rotateOrder";
editorTemplate -label "Use Cycle" -addControl "useCycle";
editorTemplate -label "Normalize" -addControl "normalize";
Expand Down
1 change: 1 addition & 0 deletions scripts/AEtwistSplineTemplate.mel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ global proc AEtwistSplineTemplate( string $nodeName ) {
editorTemplate -beginScrollLayout;

editorTemplate -beginLayout "Spline Attributes" -collapse 0;
editorTemplate -label "Scale Compensation" -addControl "scaleCompensation";
editorTemplate -label "Max Vertices" -addControl "maxVertices";
editorTemplate -label "Vertex Data" -addControl "vertexData";
editorTemplate -endLayout;
Expand Down
28 changes: 28 additions & 0 deletions scripts/AEtwistTangentTemplate.mel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Attribute Editor Template for Blur Studio's 'Twist Tangent' plugin.

global proc AEtwistTangentTemplate( string $nodeName ) {
editorTemplate -beginScrollLayout;

editorTemplate -beginLayout "Input Attributes" -collapse 0;
editorTemplate -label "In Linear Target" -addControl "inLinearTarget";
editorTemplate -label "Auto" -addControl "auto";
editorTemplate -label "Smooth" -addControl "smooth";
editorTemplate -label "Weight" -addControl "weight";
editorTemplate -label "Backpoint" -addControl "backpoint";
editorTemplate -label "Endpoint" -addControl "endpoint";
editorTemplate -endLayout;

editorTemplate -beginLayout "Output Attributes" -collapse 0;
editorTemplate -label "Out" -addControl "out";
editorTemplate -label "Smooth Tan" -addControl "smoothTan";
editorTemplate -label "Out Linear Target" -addControl "outLinearTarget";
editorTemplate -label "Out Twist Up" -addControl "outTwistUp";
editorTemplate -label "Out Twist Mat" -addControl "outTwistMat";
editorTemplate -endLayout;

// Base class attributes
AEdependNodeTemplate $nodeName;

editorTemplate -addExtraControls;
editorTemplate -endScrollLayout;
}
9 changes: 7 additions & 2 deletions scripts/twistSplineBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def connectTwistSplineTangents(cvs, twBfrs, oTans, iTans, aoTans, aiTans, closed

createTwistSetup(pre, cur, post, buf, isFirst=isFirst, isLast=isLast)

def buildTwistSpline(pfx, cvs, aoTans, aiTans, tws, maxParam, closed=False):
def buildTwistSpline(pfx, cvs, aoTans, aiTans, tws, maxParam, master, closed=False):
""" Given all the controller objects, build a twist spline
Arguments:
Expand Down Expand Up @@ -445,6 +445,9 @@ def buildTwistSpline(pfx, cvs, aoTans, aiTans, tws, maxParam, closed=False):
cmds.setAttr("{}.Pin".format(cvs[0]), 1.0)
cmds.setAttr("{}.UseTwist".format(tws[0]), 1.0)

# Connect the scaleCompensation parameter
cmds.connectAttr("{}.scaleX".format(master), "{}.scaleCompensation".format(spline))

return splineTfm, spline

def buildRiders(pfx, spline, master, numJoints, closed=False):
Expand Down Expand Up @@ -478,6 +481,8 @@ def buildRiders(pfx, spline, master, numJoints, closed=False):
cnst = cmds.createNode("riderConstraint")
cmds.connectAttr("{}.Offset".format(master), "{}.globalOffset".format(cnst))
cmds.connectAttr("{}.Stretch".format(master), "{}.globalSpread".format(cnst))
# Connect the scaleCompensation from the spline's twin attribute
cmds.connectAttr("{}.scaleCompensation".format(spline), "{}.scaleCompensation".format(cnst))
if closed:
cmds.setAttr("{}.useCycle".format(cnst), 1)

Expand Down Expand Up @@ -531,7 +536,7 @@ def makeTwistSpline(pfx, numCVs, numJoints=10, maxParam=None, spread=1.0, closed

cvs, cvBfrs, oTans, iTans, aoTans, aiTans, tws, twBfrs, master = mkTwistSplineControllers(pfx, numCVs, spread, closed=closed)
connectTwistSplineTangents(cvs, twBfrs, oTans, iTans, aoTans, aiTans, closed=closed)
splineTfm, splineShape = buildTwistSpline(pfx, cvs, aoTans, aiTans, tws, maxParam, closed=closed)
splineTfm, splineShape = buildTwistSpline(pfx, cvs, aoTans, aiTans, tws, maxParam, master, closed=closed)

jPars, joints, group, cnst = None, None, None, None
if numJoints > 0:
Expand Down
2 changes: 1 addition & 1 deletion src/pluginMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SOFTWARE.

MStatus initializePlugin( MObject obj ) {
MStatus status;
MFnPlugin plugin( obj, "BlurStudio", "1.1.0", "Any");
MFnPlugin plugin( obj, "BlurStudio", "1.2.0", "Any");

status = plugin.registerData("twistSplineData", TwistSplineData::id, TwistSplineData::creator);
if (!status) {
Expand Down
24 changes: 17 additions & 7 deletions src/riderConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ MTypeId riderConstraint::id(0x001226FC);
MObject riderConstraint::aRotateOrder;
MObject riderConstraint::aGlobalOffset;
MObject riderConstraint::aGlobalSpread;
MObject riderConstraint::aScaleCompensation;
MObject riderConstraint::aUseCycle;
MObject riderConstraint::aNormalize;
MObject riderConstraint::aNormValue;
Expand Down Expand Up @@ -142,6 +143,11 @@ MStatus riderConstraint::initialize() {
status = addAttribute(aGlobalSpread);
CHECKSTAT("aGlobalSpread");

aScaleCompensation = nAttr.create("scaleCompensation", "sclcmp", MFnNumericData::kDouble, 1.0, &status);
CHECKSTAT("aScaleCompensation");
status = addAttribute(aScaleCompensation);
CHECKSTAT("aScaleCompensation");

aUseCycle = nAttr.create("useCycle", "uc", MFnNumericData::kBoolean, false, &status);
CHECKSTAT("aUseCycle");
nAttr.setKeyable(true);
Expand Down Expand Up @@ -348,7 +354,7 @@ MStatus riderConstraint::initialize() {
&aInputSplines, &aSpline, &aSplineLength, &aEndParam, &aWeight, &aParams, &aParam,
&aParentInverseMatrix, &aGlobalOffset, &aUseCycle, &aGlobalSpread, &aNormalize,
&aNormValue, &aUseMin, &aMinParam, &aUseMax, &aMaxParam,
&aUseGlobalMin, &aMinGlobalParam, &aUseGlobalMax, &aMaxGlobalParam
&aUseGlobalMin, &aMinGlobalParam, &aUseGlobalMax, &aMaxGlobalParam, &aScaleCompensation
};

std::vector<MObject *> oobjs = {
Expand Down Expand Up @@ -491,6 +497,7 @@ MStatus riderConstraint::compute(const MPlug& plug, MDataBlock& data) {
// Deal with cycling and the global offset
MDataHandle gOffsetH = data.inputValue(aGlobalOffset);
MDataHandle gSpreadH = data.inputValue(aGlobalSpread);
MDataHandle gScaleH = data.inputValue(aScaleCompensation);
MDataHandle useCycleH = data.inputValue(aUseCycle);

MDataHandle useGlobalMinH = data.inputValue(aUseGlobalMin);
Expand All @@ -501,10 +508,13 @@ MStatus riderConstraint::compute(const MPlug& plug, MDataBlock& data) {
MDataHandle normalizeH = data.inputValue(aNormalize);
MDataHandle normValueH = data.inputValue(aNormValue);

// Both the normalized value and the globalSpread have to be scaled up
// when the global rig scales.
double doNorm = normalizeH.asDouble();
double normVal = normValueH.asDouble();
double gOffset = gOffsetH.asDouble();
double gSpread = gSpreadH.asDouble();
double scaleComp = gScaleH.asDouble();
double normVal = normValueH.asDouble() * scaleComp;
double gOffset = gOffsetH.asDouble() * scaleComp;
double gSpread = gSpreadH.asDouble() * scaleComp;
bool useCycle = useCycleH.asBool();

bool useGlobalMin = useGlobalMinH.asBool();
Expand Down Expand Up @@ -532,8 +542,8 @@ MStatus riderConstraint::compute(const MPlug& plug, MDataBlock& data) {
const auto &lp = spline->getLockPositions();
mp = lp[lp.size() - 1];

const auto &rmp = spline->getRemap();
mrmp = rmp[rmp.size() - 1];
const auto &rmp = spline->getRemap();
mrmp = rmp[rmp.size() - 1];
}

std::vector<MPoint> ttrans, tscales;
Expand Down Expand Up @@ -672,4 +682,4 @@ MStatus riderConstraint::compute(const MPlug& plug, MDataBlock& data) {
void riderConstraint::postConstructor() {
MFnDependencyNode nodeFn(thisMObject());
nodeFn.setIcon("riderConstraint.png");
}
}
1 change: 1 addition & 0 deletions src/riderConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class riderConstraint : public MPxNode {
static MObject aRotateOrder;
static MObject aGlobalOffset;
static MObject aGlobalSpread;
static MObject aScaleCompensation;
static MObject aUseCycle;
static MObject aNormalize;
static MObject aNormValue;
Expand Down
23 changes: 21 additions & 2 deletions src/twistSplineNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ MObject TwistSplineNode::aTwistWeight;
MObject TwistSplineNode::aUseOrient;

MObject TwistSplineNode::aGeometryChanging;
MObject TwistSplineNode::aScaleCompensation;
MObject TwistSplineNode::aSplineDisplay;
MObject TwistSplineNode::aDebugDisplay;
MObject TwistSplineNode::aDebugScale;
Expand Down Expand Up @@ -116,6 +117,8 @@ MStatus TwistSplineNode::initialize() {

//--------------- Input -------------------

aScaleCompensation = nAttr.create("scaleCompensation", "sclcmp", MFnNumericData::kDouble, 1.0);
addAttribute(aScaleCompensation);
aSplineDisplay = nAttr.create("splineDisplay", "sd", MFnNumericData::kBoolean, true);
addAttribute(aSplineDisplay);
aDebugDisplay = nAttr.create("debugDisplay", "dd", MFnNumericData::kBoolean, false);
Expand Down Expand Up @@ -166,6 +169,7 @@ MStatus TwistSplineNode::initialize() {

addAttribute(aVertexData);

attributeAffects(aScaleCompensation, aOutputSpline);
attributeAffects(aInTangent, aOutputSpline);
attributeAffects(aControlVertex, aOutputSpline);
attributeAffects(aOutTangent, aOutputSpline);
Expand All @@ -176,6 +180,7 @@ MStatus TwistSplineNode::initialize() {
attributeAffects(aUseOrient, aOutputSpline);
attributeAffects(aMaxVertices, aOutputSpline);

attributeAffects(aScaleCompensation, aNurbsData);
attributeAffects(aInTangent, aNurbsData);
attributeAffects(aControlVertex, aNurbsData);
attributeAffects(aOutTangent, aNurbsData);
Expand All @@ -192,6 +197,7 @@ MStatus TwistSplineNode::initialize() {
attributeAffects(aMaxVertices, aSplineLength);

// Geometry changing
attributeAffects(aScaleCompensation, aGeometryChanging);
attributeAffects(aInTangent, aGeometryChanging);
attributeAffects(aControlVertex, aGeometryChanging);
attributeAffects(aOutTangent, aGeometryChanging);
Expand Down Expand Up @@ -262,9 +268,15 @@ void TwistSplineNode::getDebugDraw(bool &oDraw, double &oScale) const {
drawPlug.getValue(oDraw);
}

MPlug scaleCompPlug(mobj, aScaleCompensation);
double scaleComp = 1.0;
if (!scaleCompPlug.isNull())
scaleCompPlug.getValue(scaleComp);

MPlug scalePlug(mobj, aDebugScale);
if (!scalePlug.isNull()) {
scalePlug.getValue(oScale);
oScale *= scaleComp;
}
}

Expand All @@ -287,6 +299,9 @@ MStatus TwistSplineNode::compute(const MPlug& plug, MDataBlock& data) {
MDataHandle hMaxVertices = data.inputValue(aMaxVertices);
int maxVertices = hMaxVertices.asInt();

MDataHandle scaleCompH = data.inputValue(aScaleCompensation);
double scaleComp = scaleCompH.asDouble();

// loop over the input matrices
MArrayDataHandle inputs = data.inputArrayValue(aVertexData);
unsigned ecount = inputs.elementCount();
Expand All @@ -302,8 +317,11 @@ MStatus TwistSplineNode::compute(const MPlug& plug, MDataBlock& data) {
for (unsigned i = 0; i < ecount; ++i) {
auto group = inputs.inputValue();

lockPositions.push_back(group.child(aParamValue).asDouble());
// Ensure all parameters are scale compensated when the global rig is scaled.
lockPositions.push_back(group.child(aParamValue).asDouble() * scaleComp);

// The lock value has to be scaled up when the global rig scales, so multiply
// it by the scale compensation plug value.
double lockIt = group.child(aParamWeight).asDouble();
lockVals.push_back(lockIt);
if (lockIt > 0.0) gotLocks = true;
Expand Down Expand Up @@ -492,7 +510,8 @@ MStatus TwistSplineNode::setDependentsDirty(const MPlug& plug,
if (plug == aInTangent || plug == aOutTangent ||
plug == aControlVertex || plug == aMaxVertices ||
plug == aParamValue || plug == aParamWeight ||
plug == aTwistValue || plug == aTwistWeight || plug == aUseOrient) {
plug == aTwistValue || plug == aTwistWeight || plug == aUseOrient ||
plug == aScaleCompensation) {
MObject thisNode = thisMObject();
MPlug outputSplinePlug(thisNode, aOutputSpline);
MPlug nurbsDataPlug(thisNode, aNurbsData);
Expand Down
1 change: 1 addition & 0 deletions src/twistSplineNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class TwistSplineNode : public MPxLocatorNode
static MObject aUseOrient;

static MObject aGeometryChanging;
static MObject aScaleCompensation;
static MObject aSplineDisplay;
static MObject aDebugDisplay;
static MObject aDebugScale;
Expand Down
Loading

0 comments on commit d6b7368

Please sign in to comment.