Two handed prop script
jsdaz_5811013940
Posts: 119
Hello,
I have been noodling writing a script that would allow a character to hold a prop with two hands. For instance the character holds a rifle. One hand would hold the stock and trigger. The other hand might hold the barrel. Usually this means parenting to the right hand, posing the character and then laboriously moving the left hand into position on the rifle with many small movement of the left arm. Grabbing the hand and moving with IK is a good start, but eventually fine tuning is required.
My idea is to parent the right hand to the trigger/stock. Then move the left hand into place. The script would calculate the spatial relationship between the left hand and the rifle. Next, change the pose. The left hand will no longer be on the rifle. The user will click a button in the script dialog and the left hand will move back into position along the rifle.
This first step has partially been done. The wonderful 3dcheapskate has published numerous scripts, some of which address this issue. But, looking at the code, it seems that the function is pretty simple. It relies on lengthening (or shortening) the arm. It also does not correctly place the second hand on the prop. (Please excuse me if I have mis-represented or mis-understood the scripts. I am in awe of what 3dcheapskate has provided the community.)
My next step would be to code a wrapping function. The idea is to manually place the second hand near the prop. The script would calculate the pose necessary to have the character literally grab the prop. Many other applications leap to mind from this base.
So before I even start I have a question. Is it possible to move the hand with a script? Natch I can rotate in three dimensions, twist, side-side and bend. What I need to do is specify an x,y,z three-coordinate and have the hand move to that position. This means engaging the IK chain from a script. In other words, I want to move the hand to a position in such a way that the forearm, shoulder and collar all move in concert automatically. Coding for three rotations for each of the body parts would be difficult and unlikely to give a good looking result. Daz has already figured the IK chains out very well. I don't want to reinvent that wheel.
Long way of asking, "Can a script move the hand to a position in space and have the rest of the arm follow?"
Thanks

Comments
Was away on a trip, so I have not pursued this yet. Starting again.
This forum is wonderful in many ways. One is that people are really knowledgeable. I think either I asked a really stupid question, or there is no good answer. Hope it is the latter.
Plan is to work on script writing. Hopefully it will become quickly apparent that two handed props can or cannot be done. Wish me luck.
Any suggestions where to find basic scripts that open boxes with control of characters would be hugely appreciated.
Don't give up on this as it would be useful!
Just chanced upon this thread while googling for one of my old posts... (and many thanks for the comment :) )
Hopefully you've already found a solution, but just in case you haven't - MJC (Casual) has done what I think you're after, in many variations. For starters check out this "Hands following props, not props following hands - how is this done?" thread - http://www.daz3d.com/forums/discussion/14828/hands-following-props-not-props-following-hands-how-is-this-done , specifically mCasual's post halfway down.
Yes, I have seen them. They come close and are good. But the hand does not orient to the prop. My hope was to have the following hand (left) on the barrel of a rifle. When the right hand moved, the would not only move in concert, but would also rotate so the palm and fingers remained in constant relation to the barrel. As good as MJC's scripts are, the hand does not rotate with prop. It does move to the proper point in space, but does not stay properly oriented. Also, the joints from the wrist to the collar move slightly un-naturally..
The notion was to have the IK chain take care of the details. For instance, if the following hand needed to move to a new point with a new orientation then the IK would figure out all the joints from the wrist to the collar.
Unfortunately, I can not find a way to engage IK inside a script. It is possible to grab and move the following hand in the UI. But moving the hand in a script fails. At least in my attempts. If you know of a way to move the hand without specifically rotating the arm joints, please let me know.
My greatest problem is that I cannot find proper documentation for the scripting languange. The online source at Daz is incomplete. Do you know how to get a full manual for the scripting language?
Thanks,
I don't know anythig about scripting, but I do have experience with firing rifles (namely the M-16), and, from my experience, the only time any part of the arms will move(side to side) when shooting is on the prone position, and then only the forearms. The elbows should remain stationary. Thus, the hand will slid up and down the grip of the rifle at least a small amount anyway. It won't remain perfectly in the exact same position. If firing from a standing or kneeling position, any side-to-side tracking movement should be with your torso, not your arms. The only arm movement should be up and down to track vertically in these cases.
Unfortunately there is no complete documentation - that is, has always been, (and probably always will be), the biggest problem.
My main reference is still the DAZ Script 2 HTML documentation from back in the days of DAZ Studio 3 (can't find the download URL at the moment - I've had it on my machine for years).
The DAZ Studio 4.x Scripting Doku , specifically the Samples / Object Index sections (under the API Reference heading) are gradually becoming more useful (and if things haven't changed in the past year or two, then that's in large part due to *Rob's free-time efforts I think)
The DAZ Script Developer Discussion Forum is the best place to ask questions specifically relating to DAZ Script. There are many people who've been writing (or cobbling together in my case! ;o) ) scripts under these less-than-favourable conditions for year, and many of those folks are very helpful. It's always a good idea to rummage through the Samples and Object Index sections mentioned above before posting, as they can now often give you a good starting point
*Rob (rbtwhiz) has always been (and continues to be) very helpful over there - it seems to me that he has forever been fighting against the odds to get proper documentation in place. Check the sticky "DAZ Studio 4.x Scripting Documentation" thread for the latest
I've asked this question again for you - it was last asked in 2012, and I've reopened the IK from DazScript? thread.
My guess is that it hasn't been added, as I can't find any reference to IK in the current documentation
I'm fairly sure that most (all?) of MJC's scripts are provided as source code,and the usage rights allow you to modify them as you wish (although you need to check in the comments at the top of each script of course to be certain).
Provided the script that comes closest to what you want has those usage rights then you could try adapting them.
Alternatively you might request MJC to add this to one of the scripts. Although he's always extremely busy (as you can see from his posts in the Freepozitory) he always seems up for a challenge! :)
Assuming that the IK chains aren't accessible from DAZ Script, then what MJC has implemented is probably,effectively a sort of DIY IK.
I know from using IK in Poser that a good result depends on having a 'good' starting position - with IK chains it's all too easy to get horrible results.
(One manual/IK-based alternative I tried way back was to parent the prop to the right hand with my script, manually adjust the right arm so the rifle/spear was horizontalabout 18" in front of the figure's chest, then manually position the left arm and hand so it was realistically holding the prop. With both hands on the prop I manually turned IK on for both hands, and off for both legs, and then translated and rotated the figure's hip. It has serious limitations, but it's an option)
Thanks so much for the suggestions. My computer has been bobbing around on the Atlantic for our intercontinental move. The computer returns to me tomorrow. Thus no activity on my part for quite a while. When I get back up and running though, this will be a project that I want to prioritize.
Engaging the IK chain in the script would be best first step. It may not be possible though. If not, then the distances and angles from the hand through to the collar could be analyzed and recalculated. It would mean applying wieghted rotations to the Collar, Shoulder, Elbow and Wrist. It might work best iteratively with successively smaller adjustments until the hand gets very close to the right position. Of course this gets pretty complicated pretty fast. I am still trying to get a really solid grasp of quaternions. They are superb in principle, I just need to get comfortable with them.
MJC's listings have been of enormous help. And funny too! Always appreciated when the write-debug-test cycle becomes tiresome.
Will dive back in the next couple of weeks.
Thanks
Interesting point (note:I have no experience with firearms) - so with a particular rifle/figure combination there is probably one basic 'correct' upper body (from the chest upwards?) firing pose (with slight variations as you mentioned). That makes a lot of sense. So I guess that would probably be a good initial pose to manually create.
And then the IK chain (or script-based) movement of the arms could be used for non-firing poses with both hands on the rifle - and probably with the finger off the trigger? (I recall an enlightening thread about that :) - edit: found the link Firearms poses (and minor rant) by Esemwy)
Sticky variable:
Making another pass at this. Having some success. The process will need to get parameters of the target figure from the initial pose and the final pose. The basic case would be a character with a rifle posed with both hands on the rifle, right hand on the trigger. (Will extend later for left handed characters.) The character pose is changed. The script run and the left hand is adjusted back into position on the rifle.
Here is the question. What is the best way to store the parameter information of the original pose. The script needs to get this information after changing the pose. Do I write to a temp file to disk? That seems cumbersome. Is there a way in scripting to have sticky variables? Those variables remains valid after the script terminates. Global variables are specifically not sticky. They might work in individual cases, but are not guaranteed.
Alternatively, is there a way to get the script to stay open while posing a character? The main screen cannot regain focus if a script dialog is opened with the standard wDlg.exec() command. But, is there a way to get the script to allow the main screen to get focus back? That way, I could have two buttons on the dialog. Press the initial button for the first pose and then press the execute button after the character is placed in the new pose. No need to store out the initial pose to disk.
Hello folks,
it's been a long time since the thread started. But I would like to re-open it.
Actually I'm having the same issues: I need to grab a weapon with the hands both. Well, is not a rifle but a spear, anyway is the same story.
Because I'm disperated, I was thinking to create a script as well. But before doing this I would like to know if there is some news, also related to the Daz script documentation: is there a good page where to start?
Thanks and have a good day.
Ennio