Undo with Skeleton.addJoint()?

Help
Pete
2016-02-29
2016-03-01
  • Pete

    Pete - 2016-02-29

    HI!

    How do I use undo, when I add new bones into a skeleton by script?

    So far I have something like:

    UndoRecord undo = new UndoRecord(window, false);
    
    for(as many as needed){
        // creating 'newJoint'
        // getting 'parentID'
    
        skeleton.addJoint(newJoint, parentID);
    
        // Then what?
    }
    
    window.setUndoRecord(undo);
    

    I suppose it takes undo.addCommad() but how do I generate the command number and the data object?

    -P-

     
    Last edit: Pete 2016-03-01
  • Luke S

    Luke S - 2016-02-29

    I'm not quite clear on what the undo.addCommand() etc. are for, but if you just want to be able to undo what the script did, you don't have to do anything else. In fact, window.setUndoRecord(undo) can be placed up at the top, right after you create the record, or you can create the record inline, like so:

    window.setUndoRecord(new undoRecord(window, false));
    
     
  • Pete

    Pete - 2016-03-01

    Nope. That is not doing anything. :(

    When I add objects to the scene, the procedure seems to be:

    UndoRecord undo = new UndoRecord(window, false);
    
    for(as many as needed){
        // creating 'newObject'
        window.addObject(newObject, undo); // This is recording the events
    }
    window.setUndoRecord(undo);
    

    For adding bones to a skeleton there is no method that'd automatically record the event into 'undo'. Though, when using the skeleton editor, undo does work inside the editor.

    I guess I'll go studying the code....

     
  • Pete

    Pete - 2016-03-01

    Got it:

    ...
    // 'selMesh' is the object inside the selected ObjectInfo
    Skeleton skeleton = selMesh.getSkeleton();
    
    window.setUndoRecord(new UndoRecord(window, true, UndoRecord.COPY_SKELETON, new Object[] {skeleton, skeleton.duplicate()}));
    
    for (many times){
        //add joints to skeleton
    }
    
    return;
    

    The command number is one of those integers defined in the UndoRecord, in this case the COPY_SKELETON and the data object is simply a note to make a 'safecopy' of the skeleton.

    The SkeletonTool uses COPY_OBJECT and makes a duplicate of the mesh but the COPY_SKELETON was used somewhere too.

    The creation and setting of the UndoRecord could just as well be split into:

    UndoRecord undo = new UndoRecord(window, true);
    undo.addCommand(UndoRecord.COPY_SKELETON, new Object[] {skeleton, skeleton.duplicate()});
    window.setUndoRecord(undo);
    

    The setUndoRecord can in this case be either before or after the for-loop.

    If I put the addCommand inside the for loop then (I think) the setUndoRecord needs to be after the loop and the result is somewhat different.

    -P-

     
    Last edit: Pete 2016-03-01

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks