Find, define & align transform pivot procedurally in a loop

   3441   11   0
User Avatar
Member
42 posts
Joined: Dec. 2016
Offline
Hello,

Scenario:
I have a box building with window planes on four sides. I would like to open some windows based on a noise or randomly. I would like to define the position of the hinge (maybe using a guide line). The issue I have is that I cannot figure out how to procedurally define the pivot. If I have a line can how can I tell a transform to use it as the pivot?

I figured out a method for rotating on Y (vertical hinge) but if I want to use a horizontal hinge I run into problems as Houdini doesnt know what direction each plane is facing.

I can set the position of the pivot using a point but I would also need to define the direction of the pivot, like to say always set the Z direction to point from 0 to 1 of the pivot/hinge line.

The idea would be to build a small tool that could open windows on buildings with curved facades so it should work on any orientation. Each window would still just be a 2D plane with 4pts.

See attached images and hip file

Any help or hints is much appreciated

Attachments:
Screenshot (1).png (727.7 KB)
Screenshot (2).png (789.6 KB)
Screenshot (3).png (827.9 KB)
WINDOWHINGES.hiplc (228.0 KB)

User Avatar
Member
42 posts
Joined: Dec. 2016
Offline
I found a solution. By using a Polyframe SOP on the hinge line defining N by Tangent Name I could then use a Transform Axis SOP and reference the N of the hinge line to the Direction and P of the Hinge line to the origin.

There are perhaps more elegant ways but this works for now.
User Avatar
Member
42 posts
Joined: Dec. 2016
Offline
Ok I found a better way. By calculating the cross product on the window plane and the tranferring the attribues to the hinge line, then use the cross attribute as the reference on the Transform Axis Sop I get a perfect result on all the planes.

Maybe its helpful to somebody. If anyone is interested I can post an updated hip file, as I seem to be talking to myself
User Avatar
Member
142 posts
Joined: Aug. 2009
Offline
Post file @polimpiado Thanx
User Avatar
Member
42 posts
Joined: Dec. 2016
Offline
srletak76
Post file @polimpiado Thanx

I will once I really found the answer, not there yet. turns out I shouted hi before crossing the river(Swedish saying).

I managed to do it for a horizontal hinge but now I have a problem with the vertical, I cannot figure out how to define what is outward and inward. My trigonometry / calculus is rusty to non existent. I have the cross product but it is not enough.

Plowing through quaternions and orient on cgwiki, mind boggling.

Attachments:
Screenshot (6).png (960.9 KB)
Screenshot (7).png (2.1 MB)

User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
Hi Polimpiado,

after setting continuous random values on opening angles and discrete values on hinge locations, you can define hinge positions with primuv() and open windows with rotate():

float angle = prim(0, 'angle', i@primnum);
vector nml = prim_normal(0, i@primnum, vector(0.0));
vector hinge = prim(0, 'hinge', i@primnum);
vector pos = primuv(0, 'P', i@primnum, hinge);
vector up = {0, 1, 0};
vector hor = cross(nml, up);
vector axis = hinge.z > 0.25 ? up : hor;
float amount = hinge.y > 0.25 ? angle : -angle; 
matrix3 m_rot = ident();
rotate(m_rot, amount, axis);
v@P = (v@P - pos) * m_rot + pos;
Edited by Konstantin Magnus - May 23, 2020 18:38:37

Attachments:
open_windows.hipnc (117.1 KB)
open_window.jpg (65.2 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
42 posts
Joined: Dec. 2016
Offline
Thanks Konstantin! Very interesting!

One key issue, which is what I am truly struggling with. I want to be able to make the windows set all windows to open out or inwards based on the primitive normal. Maybe its possible in your setup but at the moment they are totally random.

I am looking to set define the pivot as horizontal (top or bottom) or vertical (left or right), then set rotation as going in or out. The only randomization should be on the amount of rotation. As you can see on my screen shot the upper band of windows have a horizontal hinge and the mid band would have a vertical hinge…

Right now I am working with a basic box but I looking to apply the tool to curved facades as well.
User Avatar
Member
42 posts
Joined: Dec. 2016
Offline
Also I want to be able to move the hinge as many windows the hinge is offset from the plane… That will come later… but I think I can figure that out if I can solve this.
User Avatar
Member
42 posts
Joined: Dec. 2016
Offline
@konstantin I was able to set hinge using a attribute create in your file rather than the attribute randomize and it seems to get closer… I will import it to my main file and see what comes up, but it is promising.
User Avatar
Member
42 posts
Joined: Dec. 2016
Offline
@konstantin Here is your hip file altered a bit.

I suspect it works great when all walls are orthagonal but less so when walls are at an angle…

Attachments:
open_windows-hingeswitch.hipnc (123.5 KB)

User Avatar
Member
42 posts
Joined: Dec. 2016
Offline
It works also with non square facades

Attachments:
open_windows-hingeswitch-various-forms.hipnc (172.8 KB)

User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
polimpiado
It works also with non square facades

Nice progress! And thanks for keeping us updated live

The basic idea was to control the hinge variations solely by an attribute and rather less by hard switches but it depends on the case I guess.
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
  • Quick Links