H15.5 Transform object scale in VEX
9825 17 2- SteN
- Member
- 55 posts
- Joined: March 2015
- Offline
I have a box and I want to check if the x scale of that box is greater than its z scale, if so I want do transform the scale of another box in a certain way, otherwaise in another.
Now Im not gonna explain you why I have to do this, but I thought to use a primitive wrangle, like in the pic
Where the: `chs(“../make_brick_shape/sx”)` is the path that goes in the transfor node to look at the x and z of the first box.
Questions:
1) Is correct to use a primitive wrangle to compare the two channels of the xform node like that?
2) What function should I use to modify the scale channel of the second box? (To replace the “//transform the obj scale…”)
I tried to just reference the channel like:
`chs(“../transform2/sx”)` = 5; //To modify the obj x scale
(where `chs(“../transform2/sx”)` is the reference to the x scale of the second box)
But I get errors in the code syntax.
Thanks.
Now Im not gonna explain you why I have to do this, but I thought to use a primitive wrangle, like in the pic
Where the: `chs(“../make_brick_shape/sx”)` is the path that goes in the transfor node to look at the x and z of the first box.
Questions:
1) Is correct to use a primitive wrangle to compare the two channels of the xform node like that?
2) What function should I use to modify the scale channel of the second box? (To replace the “//transform the obj scale…”)
I tried to just reference the channel like:
`chs(“../transform2/sx”)` = 5; //To modify the obj x scale
(where `chs(“../transform2/sx”)` is the reference to the x scale of the second box)
But I get errors in the code syntax.
Thanks.
Edited by SteN - July 24, 2016 18:35:06
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
Hi
I'm not sure why this type of parameter checking only works in points mode. Any way here's a way to transform geo in vex:
Your “second box” needs to be on the first input of the wrangler or this will not work.
But it's a lot easier to modify other objects parameters with Python. Add this to a python node and make the pointer to your box 2 correct:
-b
I'm not sure why this type of parameter checking only works in points mode. Any way here's a way to transform geo in vex:
if (`chs("../box2/sizey")` < `chs("../box3/sizey")`) { //maketransform(0,0,{ TX, TY, TZ },{ RX, RY, RZ},{ SX, SY, SZ },{ CEX, CEY, CEZ }); @P *= maketransform(0,0,{ 0, 0.5, 0 },{ 0, 0, 0 },{ 1, 1, 1 },{ 0, 0, 0 }); }
But it's a lot easier to modify other objects parameters with Python. Add this to a python node and make the pointer to your box 2 correct:
box2 = hou.node('/obj/box_object1/box2') if box2.parm('sizey').eval() < box2.parm('sizex').eval(): box2.parm('sizey').set(2)
-b
Edited by bonsak - July 24, 2016 19:24:52
- SteN
- Member
- 55 posts
- Joined: March 2015
- Offline
Thanks for the reply
Now this is what I have so far:
I get an error that says “ unexpected ‘;’ expecting ‘,’ or ‘)’ ”
Basically:
I created the “xscale” float variable to calculate the xscale, so I dont have to put that long expression in the maketransfor function.
Basically the xscale of the second box must be equal to the bounding box of another object less a certain value (the rest of the expression.)
Then in the else statement I pnt 5,5,5 in the scale just as a test, once the if will work ill write the else properly.
Why I get that error?
Thanks
Now this is what I have so far:
if (`chs("../make_brick_shape/sz")` > `chs("../make_brick_shape/sx")`/2) { //maketransform(0,0,{ TX, TY, TZ },{ RX, RY, RZ},{ SX, SY, SZ },{ CEX, CEY, CEZ }); float xscale = bbox("../overall_scale", D_XSIZE) - ( `chs("../make_brick_shape/sz")` - ((`chs("../make_brick_shape/sx")`/2) ); @P *= maketransform(0,0,{ 0, 0, 0 },{ 0, 0, 0 },{ xscale, 1, 1 },{ 0, 0, 0 }); } else { @P *= maketransform(0,0,{ 0, 0, 0 },{ 0, 0, 0 },{ 5, 5, 5 },{ 0, 0, 0 }); }
I get an error that says “ unexpected ‘;’ expecting ‘,’ or ‘)’ ”
Basically:
I created the “xscale” float variable to calculate the xscale, so I dont have to put that long expression in the maketransfor function.
Basically the xscale of the second box must be equal to the bounding box of another object less a certain value (the rest of the expression.)
Then in the else statement I pnt 5,5,5 in the scale just as a test, once the if will work ill write the else properly.
Why I get that error?
Thanks
Edited by SteN - July 25, 2016 07:06:52
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- neil_math_comp
- Member
- 1743 posts
- Joined: March 2012
- Offline
I don't know exactly what you're trying to do, but this should work better:
Things I changed, (in addition to following bonsak's advice):
* You had mismatched parentheses on the line defining xscale.
* You don't need to use backticks to evaluate parameters from VEX, you can use the chs (for strings), chf (for floats), or chi (for integers) VEX functions.
* You would need to use backticks around bbox, but there's a getbbox VEX function that you can use in a slightly different way. Avoiding backtick expressions entirely means that the VEX code doesn't have to be recompiled whenever one of these expressions changes.
* If you're just scaling, makeinstance is overkill, and a lot easier to use incorrectly than just scaling directly. Also, VEX (unfortunately) only allows constants to be in the vector syntax using curly braces, so you'd need to use set(xscale,1,1), instead of {xscale,1,1).
float sx = chf("../make_brick_shape/sx"); float sz = chf("../make_brick_shape/sz"); if (sz > sx/2) { vector minpos; vector maxpos; getbbox("../overall_scale", minpos, maxpos); float xscale = (maxpos.x - minpos.x) - (sz - (sx/2)); @P.x *= xscale; } else { @P *= 5; }
* You had mismatched parentheses on the line defining xscale.
* You don't need to use backticks to evaluate parameters from VEX, you can use the chs (for strings), chf (for floats), or chi (for integers) VEX functions.
* You would need to use backticks around bbox, but there's a getbbox VEX function that you can use in a slightly different way. Avoiding backtick expressions entirely means that the VEX code doesn't have to be recompiled whenever one of these expressions changes.
* If you're just scaling, makeinstance is overkill, and a lot easier to use incorrectly than just scaling directly. Also, VEX (unfortunately) only allows constants to be in the vector syntax using curly braces, so you'd need to use set(xscale,1,1), instead of {xscale,1,1).
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- SteN
- Member
- 55 posts
- Joined: March 2015
- Offline
Thanks for clearing a lot of things out ndickson.
I used your code and now no error, and the expressions are correct, but the second box is far away to be as large in x to the object, see picture.
So I tried to set thisAnd from this (If I correctly understood what do the function does) I would expect the second box to be as large as the object's bounding box, but if I do so the box just flattens on the x…woundering why.
I used your code and now no error, and the expressions are correct, but the second box is far away to be as large in x to the object, see picture.
So I tried to set this
@P.x *= maxpos.x;
Edited by SteN - July 25, 2016 14:32:46
- SteN
- Member
- 55 posts
- Joined: March 2015
- Offline
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- SteN
- Member
- 55 posts
- Joined: March 2015
- Offline
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
Hi
I think i understand what your trying to do. Here's a file that adjusts the outside of the brick wall to the perimeter of the bounding box.
-b
I think i understand what your trying to do. Here's a file that adjusts the outside of the brick wall to the perimeter of the bounding box.
vector minpos, maxpos; // BB object connected to port 1 of the wrangle getbbox(1, minpos, maxpos); v@bug_min = minpos; v@bug_max_pos = maxpos; if(@P.x > maxpos.x){ @P.x = maxpos.x; } if(@P.z > maxpos.z){ @P.z = maxpos.z; } if(@P.x < minpos.x){ @P.x = minpos.x; } if(@P.z < minpos.z){ @P.z = minpos.z; }
-b
- SteN
- Member
- 55 posts
- Joined: March 2015
- Offline
Thanks thats kind of what I want, but not totally.
Ill try to break it down once more:
1-Just get a box to be as large as the bbox of the bricks model
2-Decrease that scale by a certain amount
The second step should be pretty easy, for now please focus on the first step.
All this is because later Ill use the second box as the “cut shape” in a cookie sop with the bricks model, to cut out the extra part of the bricks.
In the file thers also an idea I had.
Ill try to break it down once more:
1-Just get a box to be as large as the bbox of the bricks model
2-Decrease that scale by a certain amount
The second step should be pretty easy, for now please focus on the first step.
All this is because later Ill use the second box as the “cut shape” in a cookie sop with the bricks model, to cut out the extra part of the bricks.
In the file thers also an idea I had.
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- SteN
- Member
- 55 posts
- Joined: March 2015
- Offline
Yes exactly, we are getting closer!
Of course you have to multiply by a number wich is less than 0 to scale down…silly me.
But what about If I want to scale down of lets say 1.5 units in x?
I mean I cant just multiply the x for 1.5 cause it will increase its size (ofcourse).
Like I have a 4x4x4 (x,y,z) cube and I want to scale it down by 1.5 in x (both sides from the center)so it will become 1x4x4.
How can I do this?
All I could do is this, see pic. (the if is false the else takes action)
Ass you can see the red box is in the right spont in the left and bottom side but not the other ones.
Of course you have to multiply by a number wich is less than 0 to scale down…silly me.
But what about If I want to scale down of lets say 1.5 units in x?
I mean I cant just multiply the x for 1.5 cause it will increase its size (ofcourse).
Like I have a 4x4x4 (x,y,z) cube and I want to scale it down by 1.5 in x (both sides from the center)so it will become 1x4x4.
How can I do this?
All I could do is this, see pic. (the if is false the else takes action)
Ass you can see the red box is in the right spont in the left and bottom side but not the other ones.
Edited by SteN - July 27, 2016 15:13:24
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
Hi
I don't think i understand exactly.
1.5 / “your bbox side length” will give you the scaling factor.
If your BBOX x is 2.1 and you want it to become 1.5, then you first have to calculate 1.5 / 2.1 = 0,7142857142857143 and then scale by that factor to make your object 1.5
If you have a something measuring 4x4x4 and you want to decrease it to 1x4x4 then you need to multiply the first value by 0.25
-b
I don't think i understand exactly.
1.5 / “your bbox side length” will give you the scaling factor.
If your BBOX x is 2.1 and you want it to become 1.5, then you first have to calculate 1.5 / 2.1 = 0,7142857142857143 and then scale by that factor to make your object 1.5
If you have a something measuring 4x4x4 and you want to decrease it to 1x4x4 then you need to multiply the first value by 0.25
-b
- SteN
- Member
- 55 posts
- Joined: March 2015
- Offline
Yea kind of, but what I really want is the same thing as taking a transform node and write in the x channel:
Got it?
Like you sad you have to perform some calculations to find out the % to scale down, not the actual value in units, but I cant figure out that calcualtion step.
1 - my value
Got it?
Like you sad you have to perform some calculations to find out the % to scale down, not the actual value in units, but I cant figure out that calcualtion step.
Edited by SteN - July 28, 2016 07:14:16
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- SteN
- Member
- 55 posts
- Joined: March 2015
- Offline
-
- Quick Links