Last active
August 27, 2019 12:17
-
-
Save AJpon/53851734858051686c8b2990771044f1 to your computer and use it in GitHub Desktop.
Paste to PythonEffector
This file contains 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 c4d | |
from c4d.modules import mograph as mo | |
from c4d import utils | |
# Functions | |
def quantize(num, step): | |
return step*(num//step) | |
def vectorQuantize(vec, stepParams): | |
vecX = quantize(round(vec.x, 10), stepParams.x) | |
vecY = quantize(round(vec.y, 10), stepParams.y) | |
vecZ = quantize(round(vec.z, 10), stepParams.z) | |
return c4d.Vector(vecX, vecY, vecZ) | |
# Main function | |
def main(): | |
# Get user data --------------------------------- | |
unify = op[c4d.ID_USERDATA,8] # bool | |
posStep = op[c4d.ID_USERDATA,2] # c4d.Vector | |
sclStep = op[c4d.ID_USERDATA,4] # c4d.Vector | |
angStep = op[c4d.ID_USERDATA,6] # c4d.Vector | |
posOn = op[c4d.ID_USERDATA,3] # bool | |
sclOn = op[c4d.ID_USERDATA,5] # bool | |
angOn = op[c4d.ID_USERDATA,7] # bool | |
# ----------------------------------------------- | |
md = mo.GeGetMoData(op) # Get MoGraph data | |
if md is None: return 1.0 | |
cnt = md.GetCount() | |
marr = md.GetArray(c4d.MODATA_MATRIX) # Get MoGraph clone data | |
if unify == True: | |
posStep = c4d.Vector(posStep.x) | |
sclStep = c4d.Vector(sclStep.x) | |
angStep = c4d.Vector(angStep.x) | |
for i in xrange(cnt): | |
m = marr[i] | |
if posOn == True: | |
pos = m.off # Get position | |
m.off = vectorQuantize(pos, posStep) # Quantize and set position | |
if sclOn == True: | |
scl = c4d.Vector( m.v1.GetLength(), | |
m.v2.GetLength(), | |
m.v3.GetLength()) # Get scale | |
scl = vectorQuantize(scl, sclStep) # Quantize scale | |
# Fix zero scale ------------------------------- | |
if scl.x == 0: | |
scl.x += 0.00000001 | |
if scl.y == 0: | |
scl.y += 0.00000001 | |
if scl.z == 0: | |
scl.z += 0.00000001 | |
# Set scale ------------------------------------- | |
m.v1 = m.v1.GetNormalized()*scl.x | |
m.v2 = m.v2.GetNormalized()*scl.y | |
m.v3 = m.v3.GetNormalized()*scl.z | |
# ----------------------------------------------- | |
if angOn == True: | |
ang = utils.MatrixToHPB(m) # Get angle (HPB) | |
ang = vectorQuantize(ang, angStep) # Quantize angle | |
# Set angle ------------------------------------- | |
pos = m.off | |
scl = c4d.Vector( m.v1.GetLength(), | |
m.v2.GetLength(), | |
m.v3.GetLength()) | |
m = utils.HPBToMatrix(ang) | |
m.off = pos | |
m.v1 = m.v1.GetNormalized() * scl.x | |
m.v2 = m.v2.GetNormalized() * scl.y | |
m.v3 = m.v3.GetNormalized() * scl.z | |
# ----------------------------------------------- | |
marr[i] = m | |
md.SetArray(c4d.MODATA_MATRIX, marr, True) # Set MoGraph data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment