How do you reset the bounding box?

Hi all,

I'm a relative newcomer to Daz Studio and to 3D rendering in general, however I have a simple question for which I can find no answer.

Is there any way to reset or zero the bounding box on a character without affecting the character itself?

That is, after rotating a character, how do I zero the bounding box so that it is correctly aligned to the world axis? I know it can be done because I have many poses where the bounding box is zeroed despite some obvious rotations to the figure (such as when lying on their side), however I have many more poses where the creator seems to have "forgotten" to reset the bounding box.

 

Comments

  • I'm not entirely sure from the description, but I think the difference is between poses that adjust the figure node and poses that adjust the hip bone - posing the hip should be used only for local adjustment and does not affect the placement and orientation of the figure node, which remains upright and at the origin; the figure node should generally be used for placement in the scene, carrying the hip with it..

  • Hi Richard,

    Thanks for responding. 

    My apologies for the description, I was looking for a solution that perhaps doesn't exist. However your answer has led me to a solution of sorts and for that I'm grateful for your input.

    It would appear that the pose creator has rotated the character instead of the character's hip, hence the bounding box has been rotated in some poses but not in others. I was actually hoping there'd be a way to zero the bounding box with the click of a button but I'm guessing there isn't one. However, I may have the beginnings of a solution myself and I think it's worth sharing here.

    It's a little difficult to explain, but if we suppose that {cx, cy, cz} is the current rotation of the character (and thus the bounding box) and {hx, hy, hz} is the current rotation of the hip (which may be zeroed, but not always), then the following will give us the correct rotation for the hip when the character rotations are zeroed:

    {cx+abs(hx), cy+abs(hy), cz+abs(hy)}

    Note that abs(n) is the absolute value of n.

    With the character rotations zeroed, the bounding box will now be "right side up" relative to the world coordinates. The only problem is that the translation will be affected depending on where the origin was located. Resetting the origin may fix this, but with the bounding box oriented correctly the translation tool now works with local coordinates (as it should) and that was the crux of the problem I was actually trying to solve.

    Thanks once again for your input Richard, your insght was very helpful.

  • mjc1016mjc1016 Posts: 15,001
     

    It's a little difficult to explain, but if we suppose that {cx, cy, cz} is the current rotation of the character (and thus the bounding box) and {hx, hy, hz} is the current rotation of the hip (which may be zeroed, but not always), then the following will give us the correct rotation for the hip when the character rotations are zeroed:

    {cx+abs(hx), cy+abs(hy), cz+abs(hy)}

    Note that abs(n) is the absolute value of n.

    With the character rotations zeroed, the bounding box will now be "right side up" relative to the world coordinates. The only problem is that the translation will be affected depending on where the origin was located. Resetting the origin may fix this, but with the bounding box oriented correctly the translation tool now works with local coordinates (as it should) and that was the crux of the problem I was actually trying to solve.

    Thanks once again for your input Richard, your insght was very helpful.

    That could probably be scripted...

  • mjc1016 said:
     

    It's a little difficult to explain, but if we suppose that {cx, cy, cz} is the current rotation of the character (and thus the bounding box) and {hx, hy, hz} is the current rotation of the hip (which may be zeroed, but not always), then the following will give us the correct rotation for the hip when the character rotations are zeroed:

    {cx+abs(hx), cy+abs(hy), cz+abs(hy)}

    Note that abs(n) is the absolute value of n.

    With the character rotations zeroed, the bounding box will now be "right side up" relative to the world coordinates. The only problem is that the translation will be affected depending on where the origin was located. Resetting the origin may fix this, but with the bounding box oriented correctly the translation tool now works with local coordinates (as it should) and that was the crux of the problem I was actually trying to solve.

    Thanks once again for your input Richard, your insght was very helpful.

    That could probably be scripted...

    Indeed it can. Ideally the figure should remain in the same position but I'm still working on that part. In the meantime, the following will suffice to reset the bounding box.

     

    var fig, hip;<br /> fig = Scene.getPrimarySelection();<br /> if (fig &amp;&amp; fig.inherits( &quot;DzBone&quot; )) {<br /> fig = fig.getSkeleton();<br /> }

    if (fig) {<br /> hip = fig.findNodeChild( &quot;hip&quot;, false );<br /> if (hip) {<br /> var fx, fy, fz, hx, hy, hz;<br /> fx = fig.getXRotControl().getValue();<br /> fy = fig.getYRotControl().getValue();<br /> fz = fig.getZRotControl().getValue();<br /> hx = hip.getXRotControl().getValue();<br /> hy = hip.getYRotControl().getValue();<br /> hz = hip.getZRotControl().getValue();<br /> hip.getXRotControl().setValue(fx + Math.abs (hx));<br /> hip.getYRotControl().setValue(fy + Math.abs (hy));<br /> hip.getZRotControl().setValue(fz + Math.abs (hz));<br /> fig.getXRotControl().setValue(0);<br /> fig.getYRotControl().setValue(0);<br /> fig.getZRotControl().setValue(0);<br /> }<br /> }

  • avmorganavmorgan Posts: 218

    See, now I know I have to learn how to use scripting in Daz Studio... how would one go about running this script? (Here's hoping the documentation has that answer, but I'll keep an eye on this thread in case someone has an answer before I find it on my own.)

  • Syrus_DanteSyrus_Dante Posts: 983

    I tried to get into scripting myself but I'm not an expert in programming. See Convert to SubD script.

     

    How to start with scripting for Daz Studio

    First you would need to know how Daz Studio works. Next you also need some basic understanding of programming. Then study the Object Index, the Action Index and methods in the API Reference.

    This thread is a good example first the issue was identifyed and they thought about what happened inside of Daz Studio. Then thinking of a solution and finaly see if there are methods doing what you want in the Scripting API Reference in the Documentation Center. Start with something simple or also have a look at the Samples list. There are a few realy good script examples pick one then read it and study what it does and how it is done.

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

    API Reference

    Other thread with references:

    What's the best way to learn Daz Scripting?

     

    Script Example by peter_71f6b13e

    The script example above by peter_71f6b13e got posted with wrong formating. With the HTML tags <br /> and all that in between it is not usable. But I try to help and translated this mess to a usable script.

    Below you see scripts can be posted inside Code Snippet blocks/containers with code highlighting that makes the text better readable. I've used "JavaScript" as code highlihting but this dosn't matter. I've called this script ConvertFigureToHipRotation_01.dsa. I've added a comment block so everyone can read where this comes from. I tested this and it works, very simple but effective will use it myself.

    /* Script Example by peter_71f6b13e 2016-12	ConvertFigureToHipRotation_01.dsa================================================================================Source: https://www.daz3d.com/forums/discussion/131436/how-do-you-reset-the-bounding-boxFunction: the script takes the selected figure "Root Node" rotaions	and converts them to hip bone rotation and fianly resetting the figure root nodeModification: by Syrus_Date 2019-06-06:	- corrected formating	- added anonymous funcion wrap around	- convert the code snipped into a usable script================================================================================*/(function ( ) {	var fig, hip;	fig = Scene.getPrimarySelection();		if (fig &amp;&amp; fig.inherits( "DzBone" )) {		fig = fig.getSkeleton();	}	if (fig) {		hip = fig.findNodeChild( "hip", false );		if (hip) {			var fx, fy, fz, hx, hy, hz;			fx = fig.getXRotControl().getValue();			fy = fig.getYRotControl().getValue();			fz = fig.getZRotControl().getValue();			hx = hip.getXRotControl().getValue();			hy = hip.getYRotControl().getValue();			hz = hip.getZRotControl().getValue();			hip.getXRotControl().setValue(fx + Math.abs (hx));			hip.getYRotControl().setValue(fy + Math.abs (hy));			hip.getZRotControl().setValue(fz + Math.abs (hz));			fig.getXRotControl().setValue(0);			fig.getYRotControl().setValue(0);			fig.getZRotControl().setValue(0);		}	}})( );

    How to run the Script

    To run this script inside of Daz Studio first you would open the Script IDE pane Window>Pane>Script IDE. This pane is simply like a text editor and opens with a blank page called Untiteled. Now copy all the code above into the empty Script IDE document. If you have a Figure loaded into the Scene (and rotated it by the root node to see the script do anything) you can now run the script with the Execute button.

    To save this script go to File>Save Script and choose maybe the Scripts folder inside your Content Library. The plain text file (ASCII formating) gets saved with the file extension .DSA. BTW you can also use a simple text editor like the Note Pad on windows to save and edit those scripts just make shure you change the file extension to DSA. Next time you can run the scriot from the Content Library by navigating to the Scripts folder, finding the icon and double click on it to execute. Alternatively you could right-click the script icon and choose Add Custom Action this will add the script to the Daz Studio Main Menu called Scripts. It is faster to run the script from there than to navigate to the right location inside the Content Library.

    See the Script IDE pane with the code in the attachment. If something is wrong with the code you get an error message at the bottom telling you in which line the script interpreter got issues to read the script. In the screenshot you see there is some code highlighting and as my text cursor was behind the last closing curly parenthesis I saw the corresponding opening curly parenthesis got highlighted behind "if (fig) {" that was the issue - I was missing a closing curly parenthesis that is corresponding to the first line "(function ( ) {". That is a typical beginner mistake and the reason why you should take care of the formating and making indents with tabs to better see where a parenthesis opens and closes wraping the code block inside.

    Otherwise good luck with scripting we can never have enougth people writing useful scripts to automate repetitive tasks or adding new functions and tools to Daz Studio.

    ConvertFigureToHipRotation_01.png
    649 x 781 - 41K
Sign In or Register to comment.