Created
March 13, 2018 05:50
-
-
Save anonymous/32a3d9e876927ded84ffeceb1cded4b2 to your computer and use it in GitHub Desktop.
Simple Mover C4D Python Expression Tag
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
"""Name-US: Simple Mover | |
Description-US: Expression Tag that Moves and Object Over Time | |
Version History | |
=============== | |
v0.0.1 - Initial Version | |
Copyright (C) 2018 Maxon Computer Inc. | |
Written for Cineversity.com | |
Written by Donovan Keith <donovanskeith@gmail.com> | |
""" | |
import c4d | |
def GetValueAtTime(start, rate, time, offset=0.0): | |
"""Calculates PSR for rate at time. If vector is 0 | |
for a given channel (XYZ, HPB), then start will be returned.""" | |
value_at_time = start | |
if rate.x: | |
value_at_time.x = rate.x * time + offset | |
if rate.y: | |
value_at_time.y = rate.y * time + offset | |
if rate.z: | |
value_at_time.z = rate.z * time + offset | |
return value_at_time | |
def main(): | |
obj = op.GetObject() | |
if obj is None: | |
return | |
# Get a direction/trajectory from the user | |
move = op[c4d.ID_USERDATA,1] | |
rotate = op[c4d.ID_USERDATA,2] | |
scale = op[c4d.ID_USERDATA,3] | |
# Get the time in seconds | |
time = doc.GetTime().Get() | |
# Position | |
start_pos = obj.GetRelPos() | |
new_pos = GetValueAtTime(start_pos, move, time) | |
obj.SetRelPos(new_pos) | |
# Scale | |
start_scale = obj.GetRelScale() | |
default_scale = 1.0 #Don't start from 0 scale. | |
new_scale = GetValueAtTime(start_scale, scale, time, offset=default_scale) | |
obj.SetRelScale(new_scale) | |
# Rotation | |
start_rot = obj.GetRelRot() | |
new_rot = GetValueAtTime(start_rot, rotate, time) | |
obj.SetRelRot(new_rot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment