c4d.python 旋转一个对象

How to Rotate an Object

第一种方法

import c4d

def main():
    selected = doc.GetActiveObject()
    if selected:
        #获取这个物体的矩阵,设置它的偏移再设置回来.
        mg = selected.GetMg()
        mg += c4d.utils.MatrixRotY(c4d.utils.DegToRad(45.))
        selected.SetMg(mg)

main()

第二种方法

import c4d

def main():
    # 获取当前文档和选中的物体
    doc = c4d.documents.GetActiveDocument()
    myObject = doc.GetActiveObject()

    # 获取当前相对旋转值
    current_rotation = myObject[c4d.ID_BASEOBJECT_REL_ROTATION]

    # 假设绕 Y 轴旋转 45 度(以弧度表示)
    current_rotation.y += c4d.utils.DegToRad(45)

    # 更新相对旋转值
    myObject[c4d.ID_BASEOBJECT_REL_ROTATION] = c4d.Vector(current_rotation.x, current_rotation.y, current_rotation.z)

    # 更新场景
    c4d.EventAdd()

main()

在0帧复位在之后一直按45度转

import c4d

def main():
    doc = c4d.documents.GetActiveDocument()
    time = doc.GetTime()
    frame =time.GetFrame(30)
    myObject = doc.GetActiveObject()
    current_rotation = c4d.Vector(0, 0, 0)
    current_rotation = myObject[c4d.ID_BASEOBJECT_ABS_ROTATION]
    if frame == 0:
        print(f"ok")
        current_rotation.y *= c4d.utils.DegToRad(0)
    else:
        current_rotation.y += c4d.utils.DegToRad(45)
    myObject[c4d.ID_BASEOBJECT_ABS_ROTATION] = c4d.Vector(current_rotation.x, current_rotation.y, current_rotation.z)
    c4d.EventAdd()
main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值