{"id":1027,"date":"2025-09-18T15:56:10","date_gmt":"2025-09-18T22:56:10","guid":{"rendered":"http:\/\/fx-td.com\/houdiniandchill\/?p=1027"},"modified":"2025-09-18T16:00:53","modified_gmt":"2025-09-18T23:00:53","slug":"archived-post-by-toadstorm-33","status":"publish","type":"post","link":"http:\/\/fx-td.com\/houdiniandchill\/2025\/09\/18\/archived-post-by-toadstorm-33\/","title":{"rendered":"Archived post by toadstorm"},"content":{"rendered":"<div class=\"postie-post\">\n<p class=\"\">okay. i&#8217;m gonna eventually make a bloggopost about this but i&#8217;ve learned a few things about getting these shitty ass python state handles to work in the correct local space i want<\/p>\n<p class=\"\">the two main things i found are: * use `cache_previous_parms` to compute *deltas* and then add the delta value to the modified parm in onHandleToState rather than trying to set absolute values for parms in most cases * use `pivot_comp_t[xyz]` and `pivot_comp_r[xyz]` to establish the actual pivot for your handle so that you can properly transform in local space, especially if you are using a control that only exposes specific rotation axes<\/p>\n<p class=\"\">so as an example in onStateToHandle, where you need to basically set up the handle&#8217;s transform based on what&#8217;s going on under the hood \/ in the parameters window:<br \/>\n&#8220;`python elif handle == self._handles[&#8220;GUIDE_COLUMN&#8221;].name():             # set position of handle             pivot = self._skeletonCache.point(1).attribValue(&#8220;P&#8221;)             parms[&#8220;pivot_comp_tx&#8221;] = pivot[0]             parms[&#8220;pivot_comp_ty&#8221;] = pivot[1]             parms[&#8220;pivot_comp_tz&#8221;] = pivot[2]             # set rotation             prerot = self._skeletonCache.point(2).attribValue(&#8220;transform&#8221;)             prerot_m = hou.Matrix3(prerot)             prerot = prerot_m.extractRotates(rotate_order=&#8221;xyz&#8221;)             parms[&#8220;xyz_order&#8221;] = &#8220;xyz&#8221;             parms[&#8220;pivot_comp_rx&#8221;] = prerot[0]             parms[&#8220;pivot_comp_ry&#8221;] = prerot[1]             parms[&#8220;pivot_comp_rz&#8221;] = prerot[2] &#8220;`<\/p>\n<p class=\"\">the skeletonCache is a frozen reference to the skeleton geometry that&#8217;s being transformed that exists as a member of the state class, that&#8217;s so i can have a frame of reference for how the handles need to be oriented. the cache is updated onEndHandleToState<\/p>\n<p class=\"\">the equivalent code in onHandleToState: &#8220;`python elif handle == self._handles[&#8220;GUIDE_COLUMN&#8221;].name():                 # rotate only                 # self.log(prev_parms)                 prevrot = hou.Vector3(prev_parms[&#8220;rx&#8221;], prev_parms[&#8220;ry&#8221;], prev_parms[&#8220;rz&#8221;])                 rot = hou.Vector3(parms[&#8220;rx&#8221;], parms[&#8220;ry&#8221;], parms[&#8220;rz&#8221;])                 delta = rot &#8211; prevrot                 current = node.evalParm(&#8220;crane_yaw&#8221;)                 self.log(&#8220;rot: {}&#8221;.format(rot))                 self.log(&#8220;prev: {}&#8221;.format(prevrot))                 # self.log(&#8220;delta: {}&#8221;.format(delta))                 node.parm(&#8220;crane_yaw&#8221;).set(current + delta[2]) &#8220;`<\/p>\n<p class=\"\">so this way as long as the starting orientation is correct, as long as the user is dragging a handle it&#8217;s just computing the difference between prev and current, adding that to the handle, and then basically forgetting about it and resetting the handle&#8217;s position and orientation onStateToHandle, the next time the handle is activated<\/p>\n<p class=\"\">oh and in OnHandleToState i&#8217;m making sure that this shit only runs if `ui_event.reason() == hou.uiEventReason.Active`, because the prev_parms dict is always zero when you first activate the handle, which would make my delta calculation all fucked up when the user first grabs the handle (meaning `ui_event.reason()` == `hou.uiEventReason.Start`)<\/p>\n<p class=\"\">i knew it was going to be a lot of boilerplate but this amount of it feels pretty insane. dunno if there&#8217;s an easier way i&#8217;m missing but this at least works<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>okay. i&#8217;m gonna eventually make a bloggopost about this but i&#8217;ve learned a few things about getting these shitty ass python state handles to work in the correct local space i want the two main things i found are: * use `cache_previous_parms` to compute *deltas* and then add the delta value to the modified parm &hellip; <a href=\"http:\/\/fx-td.com\/houdiniandchill\/2025\/09\/18\/archived-post-by-toadstorm-33\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Archived post by toadstorm<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/posts\/1027"}],"collection":[{"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/comments?post=1027"}],"version-history":[{"count":0,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/posts\/1027\/revisions"}],"wp:attachment":[{"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/media?parent=1027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/categories?post=1027"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/tags?post=1027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}