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

    RecordKey() & Memory usage

    SDK Help
    0
    19
    1.7k
    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
      Helper
      last edited by

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

      On 04/12/2008 at 09:34, xxxxxxxx wrote:

      In my case, I would just create the track and keys the more low-level way ala: Ctrack::Alloc() and CCurve->AddKey(). It's more work (adding, adding undos, and setting values) but maybe this would reduce the memory consumption you are experiencing with RecordKey().

      The consumptive results of RecordKey() could be something to do with undos. Maybe a test here would be to reduce your Undo Level setting drastically and see if there is any change in memory consumption overall.

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

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

        On 04/12/2008 at 09:48, xxxxxxxx wrote:

        Yeah, I've been suspecting that RecordKey() is doing some sort of AddUndo() internally, based on the symptoms.  Where can I change the Undo Level setting?  nm.. I found it in preferences... testing now...

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

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

          On 04/12/2008 at 10:08, xxxxxxxx wrote:

          Well, changing the Undo Depth doesn't seem to help, but I'll start looking into the lower level methods - thanks.

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

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

            On 04/12/2008 at 10:10, xxxxxxxx wrote:

            Automatic undos in the SDK can be either a blessing or a curse. I've no experience with RecordKey() so am unfamiliar with its behavior. It may be storing a full change undo (UNDO_CHANGE) which always includes the object, its children, and it branches (including tags, materials, animation) which can eat memory for breakfast as I was forced to deal with unavoidably. 🙂

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

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

              On 04/12/2008 at 10:32, xxxxxxxx wrote:

              Hmm... just to clarify...
              Say I have 50 joints, with 6 tracks each (posx, posy, posz, rotx, roty, rotz). So that's 300 total tracks.  To add a new key, I would then:

              • look up or otherwise retrieve my ptr to the CTrack (if I ultimately don't need CTrack pointers, I might just stash the CCurve pointers to start with)
              • get the CCurve from the CTrack ( pCurve = pTrack->GetCurve() )
              • either:
                • Allocate a CKey ( pKey = CKey::Alloc() ), fill it in and pCurve->InsertKey(pKey) it.
                • or:   pKey = pCurve->AddKey( time )  then just fill the key in ( pCurve->SetKeyDefault() + pKey->SetValue() )

              ...is that all?  What's this undo stuff you're talking about?  In this case, I'm creating a new document, with enirely new data / keys.  Is there any need for me to create undos?

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

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

                On 04/12/2008 at 11:10, xxxxxxxx wrote:

                Bingo!  Well, I need to figure out/fix the rotation values again (as soon as I finish my happy-dance), but I went from 277MB being used down to 3MB by just doing the CCurve/CKey thing (it's a lot faster as well).

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

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

                  On 04/12/2008 at 11:15, xxxxxxxx wrote:

                  When you create the new CTrack and CKeys, you could be adding undos (UNDO_NEW) - but it depends. In my case (IPP), the content could be being added to an existing document in which the user wants to be able to undo the addition. But if you are always creating a new document, the undos for these is probably unnecessary as there is nothing to 'undo' in a newly created document. 🙂

                  I should add, if you aren't doing this already, after filling in your document, do doc->SetChanged() so that it is marked as unsaved (you only need to do this if you don't add undos).

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

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

                    On 04/12/2008 at 11:24, xxxxxxxx wrote:

                    ...and I went from _not being able to load the full animation_ to 33MB for the entire ~190,000 keys - yay.
                    It looks like I just need to fix some gimble-lock issue with the rotations now.  Once I get it working, I'll post the updated code.

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

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

                      On 04/12/2008 at 12:18, xxxxxxxx wrote:

                      After taking time out for another happy-dance, here's the final working code (this time I'll post the rotation key section instead of the position key section.. and have removed all the memory tracking stuff for clarity) :

                          
                          
                            
                          //---------...S N I P...--- some variables setup earlier -----------------  
                          Matrix am;  
                          CKey *pCKey;  
                          LONG keyNdx;  
                          Vector hpbBase = MatrixToHPB(pJ->ml);  // 'rest' position, per joint  
                          BaseTime stime = BaseTime(i, m_animationFps);  
                          //---------...S N I P...-----------------------------------------------
                          
                          
                          
                          
                          if( (DWORD)(pMyKey->time) == i ) // pMyKey is not a CKey, it's a different structure where my data is stored  
                          {  
                              // convert to Cinema4D Matrix  
                              am = Matrix( Vector(pJ->matLocal[0][3], pJ->matLocal[1][3], pJ->matLocal[2][3]),  
                                           Vector(pJ->matLocal[0][0], pJ->matLocal[1][0], pJ->matLocal[2][0]),  
                                           Vector(pJ->matLocal[0][1], pJ->matLocal[1][1], pJ->matLocal[2][1]),  
                                           Vector(pJ->matLocal[0][2], pJ->matLocal[1][2], pJ->matLocal[2][2]));
                          
                          
                          
                          
                              Vector hpb = MatrixToHPB(am);        // get HPB angles from joint-local animation matrix  
                              hpb = GetOptimalAngle(hpbBase, hpb); // correct for gimble-lock
                          
                          
                          
                          
                              pCKey= pJ->pCurves[3]->AddKey(stime, &keyNdx); // RotX key  
                              if( pCKey) { pJ->pCurves[3]->SetKeyDefault(m_pBaseDoc, keyNdx); pCKey->SetValue(pJ->pCurves[3], hpb.x); }
                          
                          
                          
                          
                              pCKey= pJ->pCurves[4]->AddKey(stime, &keyNdx); // RotY key  
                              if( pCKey) { pJ->pCurves[4]->SetKeyDefault(m_pBaseDoc, keyNdx); pCKey->SetValue(pJ->pCurves[4], hpb.y); }
                          
                          
                          
                          
                              pCKey= pJ->pCurves[5]->AddKey(stime, &keyNdx); // RotZ key  
                              if( pCKey) { pJ->pCurves[5]->SetKeyDefault(m_pBaseDoc, keyNdx); pCKey->SetValue(pJ->pCurves[5], hpb.z); }
                          
                          
                          
                          
                          
                          
                          
                              break;  
                          }  
                          
                      

                      ...the position-key code is basically the same, but just uses am.off.x/y/z values.  Also, I just cached the CCurve pointers as an array in my joint structure (0,1,2 are the position curve pointers).
                      As a final comment for the curious, each key generated now uses ~200 bytes :).

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

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

                        On 08/12/2008 at 02:02, xxxxxxxx wrote:

                        I gather you resolved your problem then?

                        cheers,
                        Matthias

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

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

                          On 08/12/2008 at 02:21, xxxxxxxx wrote:

                          Yes - thanks.  It's apparently not a good idea to use RecordKey() :).
                          I could sure use some help with CAWeight Tags now though: https://developers.maxon.net/forum/topic/4233

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