Skip to content

Instantly share code, notes, and snippets.

View serguei-k's full-sized avatar

Serguei Kalentchouk serguei-k

View GitHub Profile
@serguei-k
serguei-k / save_default_array_values.cpp
Created January 4, 2019 19:21
Save default array values
MStatus Node::shouldSave(const MPlug& plug, bool& result)
{
if (plug.attribute() == arrayAttribute)
{
result = true;
return MS::kSuccess;
}
return MPxNode::shouldSave(plug, result);
}
@serguei-k
serguei-k / variablefk_4.cpp
Created December 31, 2018 07:44
Variable FK 4
// ...
const int prev_sample = int(std::floor(controlParams[j] * (sampleCount - 1)));
const int next_sample = int(std::ceil(controlParams[j] * (sampleCount - 1)));
const float alpha = controlParams[j] - sampleParams[prev_sample];
const MVector tangent = curveFn.tangent(param);
const MVector up1(sampleFrames[prev_sample][1][0],
sampleFrames[prev_sample][1][1],
sampleFrames[prev_sample][1][2]);
const MVector up2(sampleFrames[next_sample][1][0],
@serguei-k
serguei-k / variablefk_3.cpp
Last active December 31, 2018 07:29
Variable FK 3
// ...
MMatrix xform = sampleFrames[i];
const MVector aim(xform[0][0], xform[0][1], xform[0][2]);
const MVector p1(xform[3][0], xform[3][1], xform[3][2]);
const MVector p2(sampleFrames[next][3][0],
sampleFrames[next][3][1],
sampleFrames[next][3][2]);
const MVector newAim = (p2 - p1).normal();
@serguei-k
serguei-k / variablefk_2.cpp
Last active April 9, 2024 02:58
Variable FK 2
// ...
const float t = float(i) / float(sampleCount - 1);
for (auto j = 0; j < controlCount; ++j)
{
const float& param = controlParams[j];
const float& falloff = controlFalloffs[j];
const MVector& scale = controlScales[j];
float weight = 1.0f - std::abs(t - param) / falloff;
@serguei-k
serguei-k / variablefk_1.cpp
Last active December 29, 2018 06:32
Variable FK 1
MMatrix localXform;
localXform[3][0] = length / double(sampleCount);
MMatrix parentXform;
for (auto i = 0; i < sampleCount; ++i)
{
MMatrix xform = i != 0 ? localXform : MMatrix::identity;
xform *= parentXform;
for (auto j = 0; j < controlCount; ++j)
@serguei-k
serguei-k / binary_parser.py
Created September 27, 2018 06:13
Parse Binary Expression
# operator precedence table
PRECEDENCE = {
'<': 10, '>': 10, '<=': 10, '>=': 10, '==': 10, '!=': 10,
'+': 20, '-': 20,
'*': 30, '/': 30, '%': 30,
}
# parse 1 + 2 * 3
def parse_binary_right(self, prec, left):
# prec starts with default 0
@serguei-k
serguei-k / lexer_ex.py
Last active September 25, 2018 20:14
Lexer Example
def read_while(self, predicate):
str = ''
while not self._data.end() and predicate(self._data.peek()):
str += self._data.next()
return str
@staticmethod
def is_string(char, strict=True):
if strict:
@serguei-k
serguei-k / project_v2.py
Created September 23, 2018 21:11
Project Vector to Plane v2
# get plane normal
normal = eval_expression('axis(plane.matrix, 1)', 'proj')
# project vector to plane
proj = eval_expression('src.translate - ({normal} * dot(src.translate, {normal}))'.format(normal=normal), 'proj')
@serguei-k
serguei-k / project_v1.py
Created September 23, 2018 21:04
Project Vector to Plane v1
# get plane normal
axis = cmds.createNode('math_AxisFromMatrix', name='proj_AXI')
cmds.connectAttr('plane.matrix', axis + '.input')
cmds.setAttr(axis + '.axis', 1)
# get dot product between vector and normal
dot = cmds.createNode('math_DotProduct', name='proj_DOT')
cmds.connectAttr('src.translate', dot + '.input1')
cmds.connectAttr(axis + '.output', dot + '.input2')
@serguei-k
serguei-k / spherical_exp_02.mel
Created May 4, 2018 08:06
Spherical Coordinates Tutorial Expression 2
float $rate = 3.14 / 2.0;
float $theta = offset.translateX * $rate + control.translateX * $rate;
float $phi = offset.translateY * $rate - control.translateY * $rate;
float $x = sin($theta) * sin($phi);
float $y = cos($phi);
float $z = cos($theta) * sin($phi);
float $px = $x / (1 - $z);
float $py = $y / (1 - $z);