Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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
    • Recent
    • Tags
    • Users
    • Login

    Recursive COFFEE function for me to modify?

    Scheduled Pinned Locked Moved SDK Help
    2 Posts 0 Posters 228 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 05/07/2011 at 08:15, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   11.5 
      Platform:   Windows  ;   Mac OSX  ; 
      Language(s) :   C.O.F.F.E.E  ;

      ---------
      Hi! 
      I am new to Coffee, but have used Cinema for a long time. I am currently working on a model of a vehcile, and I want to split the vehicle into parts and save them in a folder for importing into Unity3D. I have made a Unity script that reads a JSON string and loads whatever file indicated in the JSON file. Unity will read JSON string, detailing the (xyz and rotation values) and position the parts together. Problem is, i have to export all parts and write the JSON string by hand. Just because I dont know enough COFFEE. This has to change. 
      Basically what I am looking for is a COFFEE script that runs down the object tree looking for transforms starting with the string "Pos_" in their name. This means exporting specific nodes but leaving some alone and also writing a long JSON string with the local transform of detected each node. This way I can easily export a c4d document in as many part-files that I like, and also bring along the transforms I need to put all the parts together nicely inside Unity and other 3D programs.
      Does anyone have a recursive coffee script, that runs down the object tree? It would be perfect for me to modify. It would really give me a flying start.  I will share the results here if I get it right. Here is some pseudi. code for the recursive part of the function. 
      function readnode(node, JSON string){
      > var isPosNode = false; 
      > if Substr(node.nodeName, 0, 3) = "Pos_" then
      > > isPosNode = true;
      > >  JSON = " , "  & node.nodeName & " { fileName :"" & node.nodeName &".c4d" & ",
      >>
      >> x: " & node.pos.x & ",  
      >>
      >> y: "& node.pos.y & ",
      >>
      >> z : "& node.pos.z & ",
      >>
      >> r : node.rot.r   & ",
      >>
      >> h : node.rot.h   & ",
      >>
      >> p : node.rot.p   "
      > }  
      > for each child as c in node do
      > >  readNode (c, JSON);
      > loop
      >
      >
      >
      > if isPosNode = true then
      >
      >>   JSON = JSON & "}";  
      > >  save (node, "/nodes/" & node.nodeName & ".c4d")
      > >  deleteFromTree(node)
      > endif
      }

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 05/07/2011 at 08:24, xxxxxxxx wrote:

        Here you go, recursive function that browses the complete hierarchy:

          
        BrowseScene(op)  
        {  
          while (op)  
          {  
              // get name and print to console  
              var name = op->GetName();  
              println(name);  
          
              BrowseScene(op->GetDown());  
                
              op = op->GetNext();  
          }  
        }  
          
        main(doc,op)  
        {  
          BrowseScene(doc->GetFirstObject());  
        }  
        

        cheers,
        Matthias

        1 Reply Last reply Reply Quote 0
        • First post
          Last post