- 介绍C4D的utils模块,首先看下Rad()
c4d.utils.Rad(d)¶
Convert a degrees value into radians.
Parameters: r (number) – Input value in degrees.
Return type: number
Returns: Converted value in radians.
字面意思看是将角度转为弧度,要求输入的值是角度(如sin cos等)?
- 正巧,utils工具类里,有个SinCos()函数,该函数的作用是将任意值转为Sine和Cosine值。
c4d.utils.SinCos(w)¶
Get sine and cosine of w:
sn, cs = SinCos(80)
Parameters: w (float) – Value.
Return type: list
Returns: Sine and Cosine.
- 先撇开上面的工具函数,写一个没有用到Rad的例子,只是让物体的左边根据当前帧(用到笔记四)进行移动,代码如下:
import c4d
from c4d.utils import *
#Welcome to the world of Python
def main():
# 获取当前立方体的handle
obj = op.GetObject()
# 获取当前帧 (笔记四讲的)
current_frame = doc.GetTime().GetFrame(doc.GetFps())
# 设置物体位置,并绑定当前帧
obj.SetRelPos(c4d.Vector(current_frame,current_frame,current_frame))
print(c4d.Vector(current_frame,current_frame,current_frame))
效果如下动图所示,可以看出来动作比较僵硬哦,不够柔和。
4. 然后我们用下工具,让物体移动过程中,带有点柔美弧度的旋转,代码如下:
import c4d
from c4d.utils import *
# -*- coding: UTF-8 -*-
#Welcome to the world of Python
def main():
# 获取当前立方体的handle
obj = op.GetObject()
# 获取当前帧 (笔记四讲的)
current_frame = doc.GetTime().GetFrame(doc.GetFps())
# 设置物体位置,并绑定当前帧
obj.SetRelPos(c4d.Vector(current_frame,current_frame,current_frame))
print('current_frame: ',c4d.Vector(current_frame,current_frame,current_frame))
# -----------使用utils的 Rad-------------
# 将当前帧值转为弧度值
rcF = Rad(current_frame)
# 设置物体的旋转,并绑定弧度值
obj.SetRelRot(c4d.Vector(rcF,rcF,rcF))
print('Rad(current_frame): ',c4d.Vector(rcF,rcF,rcF))
结果:
嗯,要柔和很多,可以看出,原本很大的帧数值,转为弧度后,数值小了很多,所以用作旋转看起来要舒服很多,当然,也可以把帧值当旋转输入,但那样会旋转太快了,看着不适。