RESOLVED: Curiosity Regarding The 'inPlace' Parameter For Add/RemoveNodeChild()

3dcheapskate3dcheapskate Posts: 2,719

RESOLVED - EVERYTHING WORKS AS IT SHOULD DO. THE ONLY REAL CURIOUSITY IS MY MIND!:cheese:

I have a simple proxy prop (oProxy, a DzNode) and the target, a figure's hand (oHand, a DzNode) already defined.
The proxy will usually have one direct child (possibly more), and may (or may not) already be parented to a DIFFERENT figure's hand (or the same figure's other hand)

If the proxy has no children I simply want to move and parent it to the target hand.
If the proxy has children then I want to end up with the children parented to the target hand and the proxy deleted.

Here's the relevant DAZ Script 2 extract that I'm using:

// If the proxy's parented then unparent it.
var oParent=oProxy.getNodeParent();
if (oParent)
oParent.
removeNodeChild(oProxy);

// Set the proxy's x/y/z rotations/translations to the
// world-coordinate orientation/position for the zeroed target figure's hand

...

// Parent the proxy to the selected hand of the selected figure
oHand.addNodeChild(oProxy); // as per the original (which works!), no second parameter given (so inPlace=false)

// If the proxy has children then do the necessary
var kids = oProxy.getNodeChildren();
if (kids.length>0){
for(i=0;i var oChild = kids;
oProxy.
removeNodeChild(oChild,true); // Unparent each child of the proxy...
oHand.addNodeChild(oChild,true); // ...then reparent it to the hand
oHand.removeNodeChild(oProxy); // ...and finally delete the proxy
if (!Scene.removeNode(oProxy))
MessageBox.information("Failed to delete proxy.","Proxy Not Deleted","OK");
}
}


I'm rather puzzled that I need the 'inPlace' flag set for unparenting/reparenting the child (without it the child prop ends up in the wrong place), but I mustn't set it for the proxy (if I do the proxy ends up in the wrong place).

Any explanation?

P.S. where's the 'font selection' option gone? all I see is 'size' and 'colour' but no 'font family'?

Post edited by 3dcheapskate on

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,842
    edited December 1969

    I'm having some trouble picturing this - could you post some screenshots of your scene before/after the scripts?

    I don't think either the old or the current fiorum have ever had the ability to select a font type from a list. There are code tags for code, if needed.

  • millighostmillighost Posts: 261
    edited December 1969

    I have a simple proxy prop (oProxy, a DzNode) and the target, a figure's hand (oHand, a DzNode) already defined.
    The proxy will usually have one direct child (possibly more), and may (or may not) already be parented to a DIFFERENT figure's hand (or the same figure's other hand)

    If the proxy has no children I simply want to move and parent it to the target hand.
    If the proxy has children then I want to end up with the children parented to the target hand and the proxy deleted.

    Here's the relevant DAZ Script 2 extract that I'm using:

    // If the proxy's parented then unparent it.
    var oParent=oProxy.getNodeParent();
    if (oParent)
    oParent.
    removeNodeChild(oProxy);

    // Set the proxy's x/y/z rotations/translations to the
    // world-coordinate orientation/position for the zeroed target figure's hand

    ...

    // Parent the proxy to the selected hand of the selected figure
    oHand.addNodeChild(oProxy); // as per the original (which works!), no second parameter given (so inPlace=false)

    // If the proxy has children then do the necessary
    var kids = oProxy.getNodeChildren();
    if (kids.length>0){
    for(i=0;i var oChild = kids;
    oProxy.
    removeNodeChild(oChild,true); // Unparent each child of the proxy...
    oHand.addNodeChild(oChild,true); // ...then reparent it to the hand
    oHand.removeNodeChild(oProxy); // ...and finally delete the proxy
    if (!Scene.removeNode(oProxy))
    MessageBox.information("Failed to delete proxy.","Proxy Not Deleted","OK");
    }
    }


    I'm rather puzzled that I need the 'inPlace' flag set for unparenting/reparenting the child (without it the child prop ends up in the wrong place), but I mustn't set it for the proxy (if I do the proxy ends up in the wrong place).

    Hard to tell without knowing what the "right" or "wrong" place should be. But this script most likely will not do what you want if the proxy has more than one child: in the for-loop the proxy is removed from the scene for every iteration instead of only once at the end.

    Any explanation?

    P.S. where's the 'font selection' option gone? all I see is 'size' and 'colour' but no 'font family'?


    use the code marker like this
    
      
    
      [ /code] <- without the space after the left bracket.
    
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited April 2014

    ...I don't think either the old or the current fiorum have ever had the ability to select a font type from a list. There are code tags for code, if needed.

    ...use the code marker like this
    <pre><code> [ /code] <- without the space after the left bracket.

    I must be harking back to the good old days with the font selection then! ;-)

    Re 'code' markers - tried them and they didn't do what I wanted. Great for syntax highlighting, but I wanted to highlight the four lines of code in question and you can't use bold/italic/color within a code' block. I love courier and manual colour-coding!

    Edit: and long lines aren't wrapped inside 'code' markers, which can really b****r up a forum thread page!

    Post edited by 3dcheapskate on
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited December 1969

    I'm having some trouble picturing this - could you post some screenshots of your scene before/after the scripts?...

    quote author="millighost" date="1396612530"]...Hard to tell without knowing what the "right" or "wrong" place should be. But this script most likely will not do what you want if the proxy has more than one child: in the for-loop the proxy is removed from the scene for every iteration instead of only once at the end.

    Point taken about the proxy deletion - I'd have spotted that when I tested with a second child!

    I'll do a couple of screenshots to hopefully explain it better and post asap...

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited December 1969

    Okay, here's what it does - first the very basic version:

    1 - the initial setup.
    - Behemoth is in zeroed pose with forearms twisted 90deg to put palms forward.
    - The clubs are from Valandars Bashers and Bludgeons.
    - The orange blobs are 'DummyHand' proxies.
    - Each club was manually positioned/oriented into their respective proxy when it was at the origin, and then manually parented to it.
    - The proxies were then moved,spun to random-ish positions/orientations.

    2 - After the "Set the proxy’s x/y/z rotations/translations to the world-coordinate orientation/position for the zeroed target figure’s hand" bit of my script.
    - The proxy and proxied club is correctly positioned/oriented for the zeroed Behemoth.

    3 - After the script parents the proxy to the hand (correctly positioned in the hand now)
    - No change to position/orientation after 'oProxy.removeNodeChild(oChild,true)' which is correct
    - No change to position/orientation after 'oHand.addNodeChild(oChild,true); ' which is correct

    4 - After the proxy's been unparented and then deleted (the script also applies a hand pose

    a.jpg
    993 x 498 - 60K
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited April 2014

    Ah! I've answered my own question - it's doing exactly what it should, and it all makes sense now!

    1 - proxy already parented to GG3.1's right hand
    2 - proxy unparented (and thus positioned correctly for a zeroed GG3.1's right hand)
    3 - proxy repositioned (now in correct position for a zeroed GG3.1's left hand)
    4 - proxy parented to GG3.1's left hand.
    5 - after unparenting and deleting the proxy and applying the hand pose.

    And of course, it's only between (4) and (5) that I want to do things 'inPlace'.

    (and I've just realized that this will allow any figure to snatch Vicky's smartprops from her! Load the Smart+ DummyHand proxy (the orange blob) to Vicky's hand that's holding the smartprop, manually reparent the prop to the proxy, then run the script)

    b.jpg
    904 x 500 - 69K
    Post edited by 3dcheapskate on
Sign In or Register to comment.