简体   繁体   English

修复帧上的 object position 以对其进行动画处理

[英]Fix object position on frames to animate it

I would like to fix an object (for example an Ocube) at different positions depending of the frame number.我想根据帧号在不同位置修复 object(例如 Ocube)。

Here is my code, inspired by tutorials I've found ( https://github.com/PluginCafe/cinema4d_py_sdk_extended )这是我的代码,灵感来自我找到的教程( https://github.com/PluginCafe/cinema4d_py_sdk_extended


    # Creates the object in memory
    obj = c4d.BaseObject(c4d.Ocube)
    
    # Retrieves BaseTime of frame 0, 20
    start = 0
    end = 20

    # Loops through the frames
    for frame in range(start, end + 1):
    
        # Move the cube to some position
        obj.SetRelPos(c4d.Vector(20+frame*20))

        # Creates the track in memory. Defined by it's DescID
        trackY = c4d.CTrack(obj, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_REL_POSITION, c4d.DTYPE_VECTOR, 0),
                                            c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0)))
                                           
        # Inserts the track 
        obj.InsertTrackSorted(trackY)

    # Inserts the object in document
    doc.InsertObject(obj)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()

Problem :问题

This code doesn't fix object in frames.此代码无法修复帧中的 object。 The cube change position at each loop iteration but it's not fixed frame by frame.立方体在每次循环迭代时更改 position 但它不是逐帧固定的。 I guess I need to associated the track to a frame but I haven't found documentation to do this.我想我需要将轨道与框架相关联,但我还没有找到执行此操作的文档。

What I want我想要的是

At each loop iteration, I want to reccord a object position as the "Reccord Active Objects" do.在每次循环迭代中,我想记录一个 object position 作为“记录活动对象”。

录制按钮

And automatically create a track as it appears on the timeline:并自动创建出现在时间线上的轨道:

按时间线追踪

Questions :问题

  • How to link a track to a frame number?如何将轨道链接到帧号?
  • Is it a good way to animate the cube frame by frame?这是逐帧动画立方体的好方法吗?
  • Have you a link with examples that could guide me to animate an object frame by frame in python?您是否有示例链接可以指导我在 python 中逐帧为 object 设置动画?

Thanks谢谢

I was missing something when I read the documentation but I finally found an answer that fit my need at this link:我在阅读文档时遗漏了一些东西,但我终于在此链接上找到了适合我需要的答案:

https://github.com/PluginCafe/cinema4d_py_sdk_extended/blob/master/scripts/04_3d_concepts/scene_elements/animation/ctrack_create_keys_r13.py https://github.com/PluginCafe/cinema4d_py_sdk_extended/blob/master/scripts/04_3d_concepts/scene_elements/animation/ctrack_create_keys_r13.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python-Tkinter修复对象位置 - Python - Tkinter fix object position 用两帧动画 matplotlib 散点图 - Animate a matplotlib scatterplot with two frames 如何在 Pygame 中为对象或精灵的位置设置动画并将其移动到预定义的位置或沿定义的路径移动? - How to animate the position of an object or sprite in Pygame and move it towards predefined positions or along a defined path? 试图固定按钮的位置 - Trying to fix the position of Buttons 修复 KMeans 集群 position - Fix KMeans cluster position 如何修复 Tkinter 帧控制器密钥错误? - How to fix Tkinter frames controller key error? 仅对MatPlotLib绘图进行动画处理,然后为帧选择不同的范围 - Animate MatPlotLib Plot just once and choose different range for frames 是否可以为 tkinter 中的网格管理器布局的帧设置动画? - Is it possible to animate frames that are layed out with the grid manager in tkinter? 3D Object Position 估计相对于使用两个非静态相机的固定点 - 3D Object Position Estimation Relative to Fix Points Using Two Non-static Cameras 'tuple' 对象在我的 Python 代码中没有属性 'position'。 我该如何解决? - 'tuple' object has no attribute 'position' in my Python code. How can I fix it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM