Navigation

    • Register
    • Login
        No matches found
    • Search
    1. Home
    2. nescis
    N

    nescis

    @nescis

    0
    Reputation
    1
    Posts
    5
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    • Profile
    • More
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    nescis Follow

    Best posts made by nescis

    This user hasn't posted anything yet.

    Latest posts made by nescis

    Tracking screen 2D coordinates of objects for each frame (convert from 3D to 2D)

    Hello,

    I'm new in C4D Development, so please give right direction to learn.

    I'm not a motion designer, I'm a professional python developer, therefore, some of the wording may be inaccurate.

    I have a simple project with 1 camera and 2 static plane objects. Camera is flying over them.

    This project is rendering to PNG sequence. On each PNG may be one or more plane objects, or maybe nothing.

    So, I need to develop a Python script, to iterate over each frame and get 2D X- and Y-coordinate of plane's vertexes.

    3D world uses inchs and centimmeters, and resulting PNG is pixels (1920x1080), I'm looking for some method to map 3D to 2D.

    I learned how to iterate over frames and get objects and camera position and rotation at each frame, but when I try to map C4D World to Screen (may be I need something other?) I have identical results for each frame.

    Here is my code:

    import json
    import c4d
    from c4d import documents, plugins, storage, gui
    from pprint import pprint
    
    obj = doc.SearchObject('holder0') # object I need to track
    
    fps = doc.GetFps()
    minFrame = doc.GetMinTime().GetFrame(fps)
    maxFrame = doc.GetMaxTime().GetFrame(fps)
    
    for frame in range(minFrame, maxFrame+1):
        time = c4d.BaseTime(frame, fps)
        doc.SetTime(time)
        doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_INTERNALRENDERER)
        c4d.EventAdd()
    
        view = doc.GetActiveBaseDraw()
    
        pprint(view.WC_V(obj.GetAbsPos()))
    
        pprint(view.WC(obj.GetAbsPos()))
    
        pprint(view.CS(view.WC(obj.GetAbsPos()), False))
    

    Output for every frame is the same:

    Vector(14.111, 11.025, 18.698)
    Vector(39.784, 12.714, 44.158)
    Vector(1720.364, -2.065, 44.158)
    Vector(14.111, 11.025, 18.698)
    Vector(39.784, 12.714, 44.158)
    Vector(1720.364, -2.065, 44.158)
    Vector(14.111, 11.025, 18.698)
    Vector(39.784, 12.714, 44.158)
    Vector(1720.364, -2.065, 44.158)
    

    Thanx!

    posted in Cinema 4D SDK •