Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login
    1. Maxon Developers Forum
    2. nescis
    N
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 1
    • Best 0
    • Controversial 0
    • Groups 0

    nescis

    @nescis

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

    nescis Unfollow Follow

    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
      N
      nescis