CAMorphNode->SetPoint [SOLVED]



  • On 04/06/2015 at 02:19, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R16 
    Platform:      Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    Hi,

    I'm working on an objectData plugin.
    Inside my plugin I need a morph tag with some morphs.
    Adding the morph tag and the morphs was no problem, editing the morphs was.
    I have my morphtag on an object with 12 points. I used the following method:

      
    myFirstMorphNode->SetPoint(6, myFirstMorphNode->GetPoint(7));  
    

    As far as I know this should set the point with index 6 to the position of the point with index 7.
    But, it doesn't :s
    Here is my full code about the morph tag:

      
    CAPoseMorphTag* myMorphTag = CAPoseMorphTag::Alloc();  
    if (!myMorphTag) return false;  
    myMorphTag->SetParameter(DescID(ID_CA_POSE_POINTS), GeData(true), DESCFLAGS_SET_0);  
    myMorphTag->SetParameter(DescID(ID_CA_POSE_ADDMORPH), GeData(true), DESCFLAGS_SET_0);  
    myCube->InsertTag(myMorphTag);  
    myMorphTag->AddMorph();  
    CAMorph* myBaseMorph = myMorphTag->GetMorphBase();  
    if (!myBaseMorph) return false;  
    myMorphTag->AddMorph();  
    CAMorph* myFirstMorph = myMorphTag->GetMorph(1);  
    if (!myFirstMorph) return false;  
    CAMorphNode* myFirstMorphNode = myFirstMorph->GetFirst();  
    myFirstMorph->SetMode(doc, leftThighMorphTag, CAMORPH_MODE_FLAGS_ALL | CAMORPH_MODE_FLAGS_EXPAND, CAMORPH_MODE_ABS);  
    myFirstMorphNode->GetInfo() & CAMORPH_DATA_FLAGS_POINTS;  
    myFirstMorphNode->SetPoint(6, myFirstMorphNode->GetPoint(7));  
    myFirstMorph->SetMode(doc, leftThighMorphTag, CAMORPH_MODE_FLAGS_ALL | CAMORPH_MODE_FLAGS_COLLAPSE, CAMORPH_MODE_AUTO);  
    myMorphTag->UpdateMorphs();  
    

    Does anybody know what could be the problem here?
    Thanks in advance for your help and time!

    With kind regards,
    Casimir Smets



  • On 08/06/2015 at 04:45, xxxxxxxx wrote:

    Hi Casimir,

    I played around a bit with the PoseMorph tag.
    Before suggesting a solution, I'd like to add a few notes on your code:

    Beginning, after Alloc:
    There calls missing to InitMorphs() and ExitEdit(). The later may not be that important in this situation, but I'd add it anyway.
    Also I'd rather use MakeTag(), which not only allocates but also inserts the newly created tag in one step.

    Line 4:

      
    myMorphTag->SetParameter(DescID(ID_CA_POSE_ADDMORPH), GeData(true), DESCFLAGS_SET_0);
    

    Here, you are trying to push a button.
    a) I'm wondering why, because you are setting up the PoseMorph yourself anyway.
    b) The line doesn't work. To push a button, you'd rather send a MSG_DESCRIPTION_COMMAND.

    Line 6 and following:
    Why not use the return value from AddMorph(), instead of using AddMorph() -> GetMorph() combinations.

    Line 14:

    myFirstMorphNode->GetInfo() & CAMORPH_DATA_FLAGS_POINTS;
    

    You seem to have copied this line from the docs... The way you use it, this line does nothing. I'm wondering your compiler doesn't warn about this. It was thought as a parameter for an "if" statement.

    Then there's a general problem, you forgot to store the data of your object into the pose morphs.

    Adding all this together, I came up with the following code, which works nicely in a Command Plugin:

    BaseDocument* doc = GetActiveDocument();
    if (!doc)
      return false;
      
    BaseObject* op = doc->GetActiveObject();
    if (!op)
      return false;
      
    CAPoseMorphTag* myMorphTag = static_cast<CAPoseMorphTag*>(op->GetTag(Tposemorph));
    if (!myMorphTag)
    {
      myMorphTag = static_cast<CAPoseMorphTag*>(op->MakeTag(Tposemorph));
      if (!myMorphTag)
        return false;
      myMorphTag->InitMorphs();
      
      myMorphTag->ExitEdit(doc, true);
      
      myMorphTag->SetParameter(DescID(ID_CA_POSE_POINTS), GeData(true), DESCFLAGS_SET_0);
      
      CAMorph* myBaseMorph = myMorphTag->AddMorph();
      if (!myBaseMorph)
        return false;
      myBaseMorph->Store(doc, myMorphTag, CAMORPH_DATA_FLAGS_POINTS);
      
      CAMorph* myFirstMorph = myMorphTag->AddMorph();
      if (!myFirstMorph)
        return false;
      myFirstMorph->Store(doc, myMorphTag, CAMORPH_DATA_FLAGS_POINTS);
      
      CAMorphNode* myFirstMorphNode = myFirstMorph->GetFirst();
      myFirstMorph->SetMode(doc, myMorphTag, CAMORPH_MODE_FLAGS_ALL | CAMORPH_MODE_FLAGS_EXPAND, CAMORPH_MODE_ABS);
      if (myFirstMorphNode->GetInfo() & CAMORPH_DATA_FLAGS_POINTS)
      {
        myFirstMorphNode->SetPoint(6, myFirstMorphNode->GetPoint(7));
      }
      myFirstMorph->SetMode(doc, myMorphTag, CAMORPH_MODE_FLAGS_ALL | CAMORPH_MODE_FLAGS_COLLAPSE, CAMORPH_MODE_AUTO);
      myMorphTag->UpdateMorphs();
      EventAdd();
    }
    

    Having said this, I have not been able to get this to work in a ObjectData generator plugin in GetVirtualObjects(), yet. I'm not sure, if this can work at all.



  • On 08/06/2015 at 09:21, xxxxxxxx wrote:

    Hi Andreas,

    About line 4 with the button push: I was testing some description elements for the morph tag, and I simply forgot to delete it.
    On line 14 I get no warning at all.

    Also, thanks for your tips in general! I'll try to implement them all.

    And indeed, I forgot to store the data. I will look into your example and make sure I understand it fully before implementing it in my own plugin.

    Thanks again for your help and time, I greatly appreciate it!!

    With kind regards,
    Casimir Smets



  • On 08/06/2015 at 11:27, xxxxxxxx wrote:

    Hi Andreas,

    I've implemented your code in my objectData plugin, and everything works fine!
    I should note that my previous code wasn't inside GetVirtualObjects(), neither is my code now.
    I call it inside Message inside MSG_DESCRIPTION_COMMAND.

    The problems that it could give in GVO(), are those the same as the problems for XPresso inside GVO()? (I'm trying to understand everything! :D)

    Also, I won't post my code, since it's exactly the same as yours, with other names.

    Thanks for your help and time!
    Greetings,
    Casimir Smets



  • On 09/06/2015 at 04:11, xxxxxxxx wrote:

    Hi Casimir,

    I'm not sure, how I came to the idea, you'd want to do this in GVO. Glad you don't 😉
    Actually I'm not sure, what is happening, if I try to use this in GVO. Yes, it may be similar to Xpresso nodes (causing problems, when called from a threaded context). As I'm a little bit short on time, I'd opt to not further investigate, as your problem seems solved.



  • On 09/06/2015 at 04:26, xxxxxxxx wrote:

    Hi Andreas,

    Thanks for your answer! And you don't have to further investigate it, it seems like the same kind of problem.
    And you probably came by the idea of GVO, because of my other posts where I mostly talk about GVO :D

    Greetings,
    Casimir Smets


Log in to reply