Creating a morph via script, and getting clothing to conform [SOLVED]

algovincianalgovincian Posts: 2,610

Below is the working code as a result of this thread. The thread is still there intact, but you can skip it:

var newMorphDeltas = new DzMorphDeltas();
var oNode = Scene.getPrimarySelection();
if( oNode ){
    var oObject = oNode.getObject();
    if( oObject ){
        var oShape = oObject.getCurrentShape();
        if( oShape ){
            var oGeometry = oShape.getGeometry();
            if( oGeometry ){
                var nVerts = oGeometry.getNumVertices();
                for( var i = 0; i < nVerts; i += 1 ){
                    newMorphDeltas.addDelta(i, 0, 10, 0, true);
                }
            }
        }
    }

    var newMorph = new DzMorph( newMorphDeltas );
    oObject.addModifier (newMorph, -1);
    var curModifier = oObject.getModifier(oObject.getNumModifiers()-1);
    curModifier.setName( "simpleTestMorph" );

    var curProperty = newMorph.getValueChannel();
    curProperty.setValue( 0.0 );
    curProperty.setMin( -1.0 );
    curProperty.setMax( 1.0 );
    curProperty.setIsClamped ( true );
    curProperty.setCanAutoFollow( true );
}

=======================================================

So I've been able to create new morphs for G3F via script. The dials show up under Parameters -> Morphs with the figure selected, and they dial in the morph as expected. Aces.

However, when I fit clothing to the figure, it ignores the morphs. Anybody have any experience with such things, or care to venture any guesses as to what I need to do, or might try to get this working?

Below is the snippet of code that actually creates the morph (note: newMorphDeltas has already been filled at this point):

        var newMorph = new DzMorph( newMorphDeltas );
        oObject.addModifier (newMorph, -1);
        var curModifier = oObject.getModifier(oObject.getNumModifiers()-1);
        curModifier.setName( morphPrefix + " " + partialName );
        
        var curProperty = newMorph.getValueChannel();
        curProperty.setValue( 0.0 );
        curProperty.setMin( -1.0 );
        curProperty.setMax( 1.0 );
        curProperty.setIsClamped ( true );

Thanks in advance for any ideas that anyone may have!

- Greg

 

Post edited by algovincian on

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,747

    You would need to set the morph to AutoFollow - I would assume that was a property of DzMorph but I'm not immediately seeing it in the current docs or the DS 3 docs.

  • algovincianalgovincian Posts: 2,610
    edited July 2017

    On the off chance that this interests or might help anybody else, I'm posting my findings in this thread while trying to solve this problem. Here's an analysis of a concrete example comparing 2 morphs:

    The first is a morph for George transferred to G3F using Genx2. George's shape can be dialed in on G3F with this dial, and clothes fit to the figure conform to the new shape:

    The second is a morph created programmatically using the code referenced in the previous post. George's shape can be dialed in with this dial, too, but clothes fit to the figure do not conform to the new shape:

    The differences that I can see are:

    1. The path, which I don't believe matters.

    2. Auto follow is checked for genxGeorge, but not for myGeorge. I have tried manually setting Auto Follow, but clothes fit to the figure still did not conform to the new shape.

    3. And obviously, all of those subcomponents on genxGeorge.

    After having a look in the Property Heirarchy, these look like they may be projection information on a bone-by-bone basis:

    I wonder if this information is part of what GenX2 calculates (and likewise Morph Loader Pro)? Or does the plugin API (and hopefully the scripting API) expose methods to add these properties based on the deltas? Unfortunately, I've got to go get some real work done now, so my investigation will have to stop here for now.

    - Greg

    myGeorge.jpg
    489 x 646 - 100K
    genxGeorge.jpg
    489 x 646 - 189K
    genxGeorge-property-heirarchy.jpg
    491 x 543 - 147K
    Post edited by algovincian on
  • algovincianalgovincian Posts: 2,610
    edited July 2017

    You would need to set the morph to AutoFollow - I would assume that was a property of DzMorph but I'm not immediately seeing it in the current docs or the DS 3 docs.

    As always, thanks for taking the time to respond, Richard. Didn't see your reply before - I think we may have cross-posted (took me forever to make the last post). Anyway, couldn't seem to get it working by setting Auto Follow manually. Will try again when I get home.

    - Greg

    PS - Would be great if all of those subcomponents were generated automatically!

    PPS - It occurred to me that maybe a closing and re-opening of DS might help (like can be required when working with GenX2 sometimes).

    Post edited by algovincian on
  • Richard HaseltineRichard Haseltine Posts: 100,747
    edited July 2017

    Sub-components are properties controlled by that property, so there's no way to fully automate the process (DS doesn't knwo whgich should be controlled). ERC Freeze (right-click on the controller-to-be in Edit mode)is a manual way of linking some or all of the non-zero properties.

    Post edited by Richard Haseltine on
  • algovincianalgovincian Posts: 2,610
    edited July 2017

    I've always wanted to know how to script ERC Freezes - GenX2 created them so there must be a way, but maybe it's only possible via plugins as opposed to script. After further investigation, not sure if it will help the current situation, though.

    Consider the following - George morph #3 which we'll call mlpGeorge since it was created using Morph Loader Pro. Like genxGeorge, mlpGeorge can be used to dial in George's shape on G3F, and clothes fit to the figure conform to the new shape:

    As you can see, there are no sub-components. The Parameter Settings are like myGeorge's, with the addition of Auto Follow.

    It looks like the sub-components in genxGeorge weren't the issue. I've since dialed in the morph with the Joint Editor active and it seems to confirm that the subcomponents are for adjusting the rigging to shape. The rigging adjusts as I dial in genxGeorge, but does not as I dial in mlpGeorge or myGeorge. The sub-components in genxGeorge match the parameters under the Rigging sub-heading of the Parameters Tab when bones are selected. Hurrah for learning things!

    So the problem seems to be that Auto Follow is not working on morphs created via script (at least not the way I did it). I haven't looked any further into setting Auto Follow via script, but when I set it manually from within DS on myGeorge, clothes fit to the figure do not follow the shape.

    Maybe there's something else that needs to be configured?

    Maybe it's only possible via plugins, but not via script?

    Has anybody been successful creating a morph via script and getting conforming clothes to follow the shape?

    - Greg

     

    mlpGeorge.jpg
    489 x 646 - 105K
    Post edited by algovincian on
  • Richard HaseltineRichard Haseltine Posts: 100,747

    Is your script-ctreated miorph set to have Mofifier/Shape as its type?

  • barbultbarbult Posts: 24,240

    Did you turn on Auto Follow on your morph BEFORE you loaded the clothes on the figure?

  • algovincianalgovincian Posts: 2,610

    Is your script-ctreated miorph set to have Mofifier/Shape as its type?

    Yes it is.

  • algovincianalgovincian Posts: 2,610
    barbult said:

    Did you turn on Auto Follow on your morph BEFORE you loaded the clothes on the figure?

    The morph gets created without it turned on. To be honest, I can't remember whether I turned it on before fitting the clothes or after. That's a good idea, though - I'll try making sure Auto Follow is on first.

    . . .

    Just tried deleting the clothing, making sure Auto Follow was on, and then re-loading the clothing. Still no love.

    Thanks for the idea though, Barbult.

    - Greg

  • Cris PalominoCris Palomino Posts: 11,352

    I've always wanted to know how to script ERC Freezes - GenX2 created them so there must be a way, but maybe it's only possible via plugins as opposed to script. After further investigation, not sure if it will help the current situation, though.

    Consider the following - George morph #3 which we'll call mlpGeorge since it was created using Morph Loader Pro. Like genxGeorge, mlpGeorge can be used to dial in George's shape on G3F, and clothes fit to the figure conform to the new shape:

    As you can see, there are no sub-components. The Parameter Settings are like myGeorge's, with the addition of Auto Follow.

    It looks like the sub-components in genxGeorge weren't the issue. I've since dialed in the morph with the Joint Editor active and it seems to confirm that the subcomponents are for adjusting the rigging to shape. The rigging adjusts as I dial in genxGeorge, but does not as I dial in mlpGeorge or myGeorge. The sub-components in genxGeorge match the parameters under the Rigging sub-heading of the Parameters Tab when bones are selected. Hurrah for learning things!

    So the problem seems to be that Auto Follow is not working on morphs created via script (at least not the way I did it). I haven't looked any further into setting Auto Follow via script, but when I set it manually from within DS on myGeorge, clothes fit to the figure do not follow the shape.

    Maybe there's something else that needs to be configured?

    Maybe it's only possible via plugins, but not via script?

    Has anybody been successful creating a morph via script and getting conforming clothes to follow the shape?

    - Greg

     

    http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/properties/erc_freeze/start

  • barbultbarbult Posts: 24,240

    Sometimes Daz "remembers" things you don't want it to remember. I wonder if deleting the clothes was a sufficient test. What happens if you save the morph with the Auto Follow turned on then restart Daz Studio, load the figure, dial the morph and fit the clothes?

  • Richard HaseltineRichard Haseltine Posts: 100,747

    I was expecting AutoFollow to be a modifier proerpty but it's actually on the proerpty http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/property_dz (canAutoFollow() tells you if it's on, setCanAutoFollow( true ) turns it on (or off for false).

  • algovincianalgovincian Posts: 2,610

    I've always wanted to know how to script ERC Freezes - GenX2 created them so there must be a way, but maybe it's only possible via plugins as opposed to script. After further investigation, not sure if it will help the current situation, though.

    Consider the following - George morph #3 which we'll call mlpGeorge since it was created using Morph Loader Pro. Like genxGeorge, mlpGeorge can be used to dial in George's shape on G3F, and clothes fit to the figure conform to the new shape:

    As you can see, there are no sub-components. The Parameter Settings are like myGeorge's, with the addition of Auto Follow.

    It looks like the sub-components in genxGeorge weren't the issue. I've since dialed in the morph with the Joint Editor active and it seems to confirm that the subcomponents are for adjusting the rigging to shape. The rigging adjusts as I dial in genxGeorge, but does not as I dial in mlpGeorge or myGeorge. The sub-components in genxGeorge match the parameters under the Rigging sub-heading of the Parameters Tab when bones are selected. Hurrah for learning things!

    So the problem seems to be that Auto Follow is not working on morphs created via script (at least not the way I did it). I haven't looked any further into setting Auto Follow via script, but when I set it manually from within DS on myGeorge, clothes fit to the figure do not follow the shape.

    Maybe there's something else that needs to be configured?

    Maybe it's only possible via plugins, but not via script?

    Has anybody been successful creating a morph via script and getting conforming clothes to follow the shape?

    - Greg

     

    http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/properties/erc_freeze/start

    How did I miss that?

    A while back, I scripted some dynamic cloth sims for all the joint rotations needed to make a set of JCMs for a pair of pants. A single click resulted in a pile of .obj files which was a great time saver, but I still created the properties and did the freezing manually - yuck. I think I can totally automate the process from start to finish now - woot!

    Thanks, Cris - much appreciated!

    - Greg

  • algovincianalgovincian Posts: 2,610
    barbult said:

    Sometimes Daz "remembers" things you don't want it to remember. I wonder if deleting the clothes was a sufficient test. What happens if you save the morph with the Auto Follow turned on then restart Daz Studio, load the figure, dial the morph and fit the clothes?

    Deleted clothes, made sure Auto Follow was on, saved scene, closed DS.

    Re-launched DS, loaded the scene, checked to make sure Auto Follow was on (which it was), fit some clothing, dialed in my morph, and . . . it still hates me! lol

    Thanks again to everyone for chiming in with ideas - it truly is appreciated. Sometimes it can be so hard to see the simplest/smallest thing, and it's really helpful having a place to bounce things off others. I'd buy you all a round if you were here!

    - Greg

  • barbultbarbult Posts: 24,240

    This is a puzzle. The clothes don't already have morphs of the same name, do they, preventing the autogenerated auto follow morphs from being created?

  • algovincianalgovincian Posts: 2,610

    I was expecting AutoFollow to be a modifier proerpty but it's actually on the proerpty http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/property_dz (canAutoFollow() tells you if it's on, setCanAutoFollow( true ) turns it on (or off for false).

    Thanks for digging that up. I added these 2 lines to the code in the initial post:

    MessageBox.information( curProperty.canAutoFollow(), "Auto Follow", "&OK" );
    curProperty.setCanAutoFollow( true );

    Strangely enough, the message comes back false, but the morph itself shows Auto Follow as being on in the parameter settings in DS. Progress!

    Something about the way I'm creating the modifier is making it so it can't be set to Auto Follow, though. Hmmm . . .

    - Greg

     

  • algovincianalgovincian Posts: 2,610
    barbult said:

    This is a puzzle. The clothes don't already have morphs of the same name, do they, preventing the autogenerated auto follow morphs from being created?

    Nope. The name is definitely unique.

    The issue has been narrowed down quite a bit . . . so close!

    - Greg

  • algovincianalgovincian Posts: 2,610
    edited July 2017

    OK, backing the truck up and creating the simplest test case possible:

     

    var newMorphDeltas = new DzMorphDeltas();
    var oNode = Scene.getPrimarySelection();
    if( oNode ){
        var oObject = oNode.getObject();
        if( oObject ){
            var oShape = oObject.getCurrentShape();
            if( oShape ){
                var oGeometry = oShape.getGeometry();
                if( oGeometry ){
                    var nVerts = oGeometry.getNumVertices();
                    for( var i = 0; i < nVerts; i += 1 ){
                        newMorphDeltas.addDelta(i, 0, 10, 0, true);
                    }
                }
            }
        }
        var newMorph = new DzMorph( newMorphDeltas );
        oObject.addModifier (newMorph, -1);
        var curModifier = oObject.getModifier(oObject.getNumModifiers()-1);
        curModifier.setName( "simpleTestMorph" );

        var curProperty = newMorph.getValueChannel();
        curProperty.setValue( 0.0 );
        curProperty.setMin( -1.0 );
        curProperty.setMax( 1.0 );
        curProperty.setIsClamped ( true );

        MessageBox.information( curProperty.canAutoFollow(), "Auto Follow", "&OK" );
        curProperty.setCanAutoFollow( true );
    }

     

    Running the script above with G3F selected should result in a morph labelled "simpleTestMorph" under Parameters -> Morph. The morph simply moves the entire mesh up 10 units as you dial it in.

    For me, the morph gets dialed in as expected, only any clothes fit to the figure do not follow the morph. The message box pops up with "false" ("true if the property can automatically follow a property on a following figure, otherwise false").

    I'd like nothing more than to mark this thread as [SOLVED] and add the final, corrected code to the first post!

    - Greg

    Post edited by algovincian on
  • barbultbarbult Posts: 24,240
    edited July 2017

    You said "clothes parented to the figure". Is that is a typo, and you really mean clothes fit to the figure?

    The message box reports the autofollow state before you set it. What happens if you check again after you set it?

    Post edited by barbult on
  • algovincianalgovincian Posts: 2,610
    barbult said:

    You said "clothes parented to the figure". Is that is a typo, and you really mean clothes fit to the figure?

    The message box reports the autofollow state before you set it. What happens if you check again after you set it?

    Yes - thank you. It was early and the coffee hadn't soaked in yet! lol

    - Greg

  • algovincianalgovincian Posts: 2,610

    From the docs Richard dug up:

    Boolean : canAutoFollow()

    Return Value:

    true if the property can automatically follow a property on a following figure, otherwise false.

     

    I read this to mean "if it's possible" <shrug>.

    Thanks once again for another set of eyes and another brain looking at this.

    - Greg

  • barbultbarbult Posts: 24,240

    Hmmmm. That documentation wording is pretty opaque. "follow a property on a following figure"??????

  • barbultbarbult Posts: 24,240
    edited July 2017

    Greg, I tried your script. I copied your message box line to the end to test it after setting it. It shows true the second time. And, the script works for me on G3F. The clothing did autofollow and moved with her. I did load the clothing after running  the script. What order did you do things?

    Simple Test Morph autofollow.JPG
    2205 x 1714 - 236K
    Post edited by barbult on
  • algovincianalgovincian Posts: 2,610
    barbult said:

    Greg, I tried your script. I copied your message box line to the end to test it after setting it. It shows true the second time. And, the script works for me on G3F. The clothing did autofollow and moved with her. I did load the clothing after running  the script. What order did you do things?

    That's great news! Thanks for taking the time to do so, Barbult.

    I loaded the clothing after running the script, too.

    So it looks like it may be something specific to my installation/configuration of DS . . .

    I've been away from DS for several months, and I'm currently running the latest beta I had DLed back then (4.9.4.115), though I wouldn't think it would matter. I'll try it on a different box running DS later today.

    - Greg

  • Richard HaseltineRichard Haseltine Posts: 100,747

    That was passed on by Rob rather than dug up by me, so I can't add anything as to its usability.

  • algovincianalgovincian Posts: 2,610

    That was passed on by Rob rather than dug up by me, so I can't add anything as to its usability.

    Well, thanks to Rob, and thank you, Richard, for helping to get the info. The script works for Barbult so all is good in the world!

    - Greg

  • barbultbarbult Posts: 24,240

    I ran my test on DS 4.9.4.122 Public Beta. It's what I had open at the time.

  • algovincianalgovincian Posts: 2,610

    Tried the following script on another box still running 4.9.3.166, and it worked fine. Uninstalled 4.9.4.115 Beta/ Rebooted / Re-Installed 4.9.4.115 Beta on this box, and it now works fine on this box, too. So I'm changing the title of this one to [SOLVED] and posting the code below and in the initial post. Thanks to all those who helped sort this out!

    - Greg

    Creating a morph via script, and getting clothing to conform [SOLVED]

    var newMorphDeltas = new DzMorphDeltas();
    var oNode = Scene.getPrimarySelection();
    if( oNode ){
        var oObject = oNode.getObject();
        if( oObject ){
            var oShape = oObject.getCurrentShape();
            if( oShape ){
                var oGeometry = oShape.getGeometry();
                if( oGeometry ){
                    var nVerts = oGeometry.getNumVertices();
                    for( var i = 0; i < nVerts; i += 1 ){
                        newMorphDeltas.addDelta(i, 0, 10, 0, true);
                    }
                }
            }
        }

        var newMorph = new DzMorph( newMorphDeltas );
        oObject.addModifier (newMorph, -1);
        var curModifier = oObject.getModifier(oObject.getNumModifiers()-1);
        curModifier.setName( "simpleTestMorph" );

        var curProperty = newMorph.getValueChannel();
        curProperty.setValue( 0.0 );
        curProperty.setMin( -1.0 );
        curProperty.setMax( 1.0 );
        curProperty.setIsClamped ( true );
        curProperty.setCanAutoFollow( true );
    }

Sign In or Register to comment.