This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.api.OpenMaya as om | |
from math import * | |
def T(z): | |
return 0.5 * z | |
for i, p in enumerate(cmds.ls('unit.vtx[*]', fl=True)): | |
x, y, z = cmds.xform(p, q=True, t=True) | |
x = T(x) | |
y = T(y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.api.OpenMaya as om | |
from math import * | |
for i, p in enumerate(cmds.ls('unit.vtx[*]', fl=True)): | |
x, y, z = cmds.xform(p, q=True, t=True) | |
proj = om.MVector(x / (1 - z), y / (1 - z), 0) | |
cmds.xform('unit.vtx[{0}]'.format(i), t=proj) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float $rate = 3.14 / 2.0; | |
float $theta = offset.translateX * $rate + control.translateX * $rate; | |
float $phi = offset.translateY * $rate - control.translateY * $rate; | |
constraint.translateX = sin($theta) * sin($phi); | |
constraint.translateY = cos($phi); | |
constraint.translateZ = cos($theta) * sin($phi); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MEulerRotation rotationAverage(const std::vector<MQuaternion>& values) | |
{ | |
if (values.empty()) return MEulerRotation::identity; | |
const MQuaternion sum = std::accumulate(values.begin(), values.end(), MQuaternion::identity, | |
[](const MQuaternion& a, const MQuaternion& b) | |
{ | |
return a + b.log(); | |
}); | |
const MQuaternion average(sum.x / values.size(), sum.y / values.size(), sum.z / values.size(), sum.w / values.size()); | |
return average.exp().asEulerRotation(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MVector scaleAverage(const std::vector<MVector>& values) | |
{ | |
if (values.empty()) return MVector::zero; | |
const MVector sum = std::accumulate(values.begin(), values.end(), MVector::zero, | |
[](const MVector& a, const MVector& b) | |
{ | |
// assumes [Vx, Vy, Vz] > 0 | |
return MVector(a.x + std::log(b.x), a.y + std::log(b.y), a.z + std::log(b.z)); | |
}); | |
const MVector average = sum / values.length(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MVector translationAverage(const std::vector<MVector>& values) | |
{ | |
if (values.empty()) return MVector::zero; | |
const MVector sum = std::accumulate(values.begin(), values.end(), MVector::zero); | |
return sum / values.size(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global proc CreateCustomControl(string $attrName) | |
{ | |
expressionControl -a $attrName -l "Expression" "expressionControl"; | |
} | |
global proc UpdateCustomControl(string $attrName) | |
{ | |
expressionControl -e -a $attrName "expressionControl"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ExpressionControlCommand.h | |
#pragma once | |
#include <maya/MPxCommand.h> | |
class ExpressionControlCommand : public MPxCommand | |
{ | |
public: | |
MStatus doIt(const MArgList& argList) override; | |
bool isUndoable() const override; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global proc AEFastExpression(string $nodeName) | |
{ | |
editorTemplate -callCustom "CreateCustomControl" "UpdateCustomControl" "expression"; | |
} | |
global proc CreateCustomControl(string $attrName) | |
{ | |
// command to create custom control | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global proc AEFastExpression(string $nodeName) | |
{ | |
editorTemplate -addControl "expression"; | |
} |