XaiJu
entagma
entagma

patreon


VEX101 - Custom Functions

Functions. We've been using them quite a lot in VEX. Basically every time you call something like rand() or nearpoint() we are using a function. That means calling a separate piece of code that SideFX created for us in order to provide easy access to intricate functionality (like finding points close by - which itself can be a non-trivial task).

However what if we'd like to create our very own functions for more specialized cases like subdividing a mesh? Fear not - we can create our own individual custom functions. Here's how it's done.


VEX101 - Custom Functions

Comments

Hi Mo, was there a reason you didn't do the loop in the wrangle? I tried but it's currently beyond my abilities. Also, we make the array called npts right at the start but don't actually use it in the code, or am i mistaken? I commented it out and nothing changed.

andrew farhall

Really great tutorial thanks so much for all the information, I'm amazed at you quality. One question, I noticed that the wrangle in the for loop can be quite slow to cook at higher iterations such as 16 as you had in the video, it makes sense that it takes a while, but on your video, it happened instantly, is there maybe a change in Houdini 18.5 that creates a delay in the for loop? I even opened up your scene to check if was my code, but it was the same. On a similar note, you said this is what you used to create the cover image, did you use a polywire to create renderable geometry? If so, doesn't that take forever to cook? Mine has been cooking for around 9 min PC specs: 128gb RAM AMD Ryzen 5950x GTX 1070 Thanks again.

Chad Stevens

i suspect something with the cutdir as when i set it to say zero (like you did at 18:25) instead of cutdir , its normal flip back to normal

mitchell tharp

haha sorry but i even tried your downloaded files and just copied your vex just in case mine was wrong and it still flipped. could it be an error in houdini. its hard to know when there a bug or error and everything is actually fine

mitchell tharp

Hey, thanks for the quick reply. float seed = chf("Seed"); int npts[] = primpoints(0, @primnum); string grp = itoa(@primnum); vector bbmin = getbbox_min(0, grp); vector bbmax = getbbox_max(0, grp); vector bbsize = getbbox_size(0, grp); int cutdir; if(bbsize.x > bbsize.z) cutdir = 0; else cutdir = 1; float cutpos = fit01(rand(@primnum + seed), 0.1, 0.9); //Subdivison vector cut = lerp(bbmin, bbmax, cutpos); vector pos; int newpt; cutdir = 1; if(cutdir == 0){ //first qaud int newprim = addprim(0,"poly"); pos = bbmin; newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = set(cut.x, bbmin.y, bbmin.z ); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = set(cut.x, bbmin.y, bbmax.z ); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = set(bbmin.x, bbmin.y, bbmax.z ); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); //second qaud newprim = addprim(0,"poly"); pos = set(cut.x, bbmin.y, bbmin.z); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = set(bbmax.x, bbmin.y, bbmin.z ); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = set(bbmax.x, bbmin.y, bbmax.z ); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = set(cut.x, bbmin.y, bbmax.z ); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); } else { //first qaud int newprim = addprim(0,"poly"); pos = bbmin; newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = set(bbmin.x, bbmin.y, cut.z ); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = set(bbmax.x, bbmin.y, cut.z ); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = set(bbmax.x, bbmin.y, bbmin.z ); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); //second qaud newprim = addprim(0,"poly"); pos = set(bbmin.x, bbmin.y, cut.z); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = set(bbmin.x, bbmin.y, bbmax.z ); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = bbmax; newpt = addpoint(0, pos); addvertex(0, newprim, newpt); pos = set(bbmax.x, bbmin.y, cut.z ); newpt = addpoint(0, pos); addvertex(0, newprim, newpt); } removeprim(0, @primnum, 1);

mitchell tharp

Heyhey, without seeing your setup, I'd suspect the winding order of those primitives is reversed. You could select the wrong primitives and use a reverse-SOP on them. Cheers, Mo

Entagma

Hi, is there a reason why at 13:45 your geo looks normal and mine flips its normals. my 0 prim is flipped and tinted and the 1 prim is normal. why did one of them flip? by the time the subdiv is made and ready to be put made into a function my geo flips all its geo so its normals are upside down.

mitchell tharp

Heyhey, the set() function creates a new vector value while simply using prentheses doesn't thus when you try using parentheses, there's nothing VEX can push into an array. Curly brackets on the other hand can only be used to define constants, so you're down to using set(). Cheers, Mo

Entagma

small question, is there a reason why set(cut.x, bbmin.y, bbmin.z) i can push into an array but without set i cant? Im trying to reduce code as much as i can and wanted to do something like quad1_points= array(bbmin,(cut.x, bbmin.y, bbmin.z),(cut.x, bbmin.y, bbmax.z),(bbmin.x, bbmin.y, bbmax.z)); but it wouldnt let me without using set before? Please let me know its super useful :D Ive loved this series ive gone back to it a couple of times now trying to minimise code as much as i can on it

Lucky Dee

Say you wanted to Mult some flownoise to the cutpos for animation. As is that would be ever changing the directional cut condition so I guess this leads me to 1 of 2 questions. If we ran the splitting function in a detail, how can we return/pass the cutpos to another wrangle to grab for the animation? (add to a group, make a channel to access, createattrib?) Or, make it run once in a single prim wrangle but retain the prims? I added if(@Time == 0 &&… to the statements [actually had to create a chf to point a var to to access the time since I didn't seem to have global var access in the function], but of course led to the geo only "existing" when the frame 0 condition was met. Or I supposed simply leave it up to the random gods for cut dir and hope for the aesthetic best ha

Eric Sanderson

He edits the videos to cut out the processing..

Thomas Roohan

Hi Paul, that's me just being lazy. Indeed you could do it purely in VEX. In general by now I prefer writing pretty much everything in VEX. One single exception might be unified noise. But that's kinda sluggish on the other hand... Cheers, Mo

Entagma

Hi Mo, In this video you suggest that you could add a vop for ramps etc ... is this because coding all of the ramp parameters in vex would take too long? And if so could you indicate which functions you recommend using in Vops rather than writing in vex? thanks

paul richards

Hi Ahmet, declaring a function with the "void" keyword means that this function once it is called will not return data. For example you could write a function which adds two integers and returns the summed integer value. This function would have a return type of integer - as it should return an integer value. In our case however the function (when called) will generate a few new pieces of geometry which will be added to our geo stream, and that's it. The function doesn't need to return any values. No ints, no floats, no vectors etc. It just creates geo. And any function that doesn't return values needs to be specified as "void" - that's why we're using this keyword here. Cheers, Mo

Entagma

Hi Mo, at around 16:30 in, when you start writing > (function void subdiv(vector bbmin, bbmax; float cutpos; int cutdir) < I don't fully understand why we specify these values and even calling function void. Could you explain a bit more please? thank you.

Ahmet Barak

Just noticed that the way you implement the "getboxmin/max" in the file linked to above is different to the video - not using getbbox_min/max. Maybe that is what makes the difference?

Kim Frederiksen

I was following this video, and noticed you crank up the loops over the subdiv function to 16 and you get almost instant result. I struggle to go beyond 10 iterations. Wondering if I missed a trick? Thanks again for all the amazing work you guys keep sharing.

Kim Frederiksen

You guys absolutely create some of the best quality learning material I have found about Houdini. Always easy to follow, presented in perfect bite sized pieces, and always providing the motivation for what i about to follow. Exemplary in the way you make sure to build a solid foundation for understanding what you are about to present.

Kim Frederiksen

Hey Nathan, these are the settings we used to generate the tut's artwork: <a href="https://www.dropbox.com/s/82e3x9846o15ozm/simple_subdivs_04.hip?dl=1" rel="nofollow noopener" target="_blank">https://www.dropbox.com/s/82e3x9846o15ozm/simple_subdivs_04.hip?dl=1</a> Cheers, Mo

Entagma

Hi there - awesome lessons! Thank you so much for sharing. I am on such an exciting adventure pushing my design skills with Houdini. I hope to continue my development and put it to use within my current design job. I also wanted to ask a question about this one here. What parameters am I suppose to adjust to get the gemotric shapes to look closer to the one in the intro. I cant figure out which things to adjust for the shape and spacing and really the animation as well. Any tips would be awesome and much appriciated but also I understand you guys are busy. Thanks for everything either way!

Nathan Eisler

No, no specific reason - just trying to be as simple as possible and going over each polygon's points separately. Of course it's a good idea to reuse the two middle points :) Cheers, Mo

Entagma

Hi! Quick question, is there a reason that you have created 8 points in total inside your function and not 6 (using the same points in the middle for the two different prim)? Thank you!

julien morneau

I’ll get in line here to also congratulate you, this was a great one Mo! This answered two big questions of mine and it makes me super eager for the next ones! I can also highly recommend “The joy of vex” to people falling a bit behind. It’s never as sexy as Entagmas examples but he has some really helpfull explanations and GIFs to make things clear.

Mr Racecar

Thank You very much!

Massimo Baita

For those above who are struggling with the VEX, I highly recommend checking out Mat Estela's "The Joy Of Vex". His lessons along with Entagma's are a great starting foundation for truly understanding the hows and whys of writing VEX.

Rob Moffett

Is there a way to do this subdividing with nodes?

reaze

That would be awesome! no rush :) thanks Mo!

Florian

Hi Florian, I think that's a good idea. But it's gonna scramble up my current schedule a bit. I'll have to postpone a few already recorded tuts and record the additional content. So expect that to drop maybe end of next week or early in two weeks. Cheers, Mo

Entagma

Hey Mo, thanks a lot for all these tutorials, they are truly helpful to connect the dots...! I was thinking how small exercises to nail down all these basic concepts would be doable in the next round before we jump to more complex things? Thanks again for everything!

Florian

Thanks for the feedback guys! When creating tutorials, we're trying to reach as broad an audience as possible. Especially when it comes to programming, there are more factors coming into play than "just" learning a programming language - which both as a tutor and as audience can be daunting. We're constantly trying to find a balance between accelerated learning and getting everyone on board. Regarding the mathy/trigonometry parts - we're planning a series on math for CG, but that might still be a bit down the road. Regarding explaining code more in detail - I'll create an additional video going over the function we created one more time while showing how to save it out externally (if you're impatient check the link Christian shared). Again thanks for the feedback! Cheers, Mo

Entagma

Fantastic course and perfectly timed for me. I would like to second the question on how to save the function to disk and be able to distribute it and include it in other hip files without having to copy and paste everywhere. For anyone else looking for this: <a href="http://www.tokeru.com/cgwiki/index.php?title=HoudiniVex" rel="nofollow noopener" target="_blank">http://www.tokeru.com/cgwiki/index.php?title=HoudiniVex#Vex_includes</a>

Christian Akesson

just to clarify. didn't mean to complain. I really learn a lot from Entigma and the quality of their content is outstanding. just meant an honest request If possible to make things easier for the brain to swallow :) when it comes to vex. just like in the AHTYA last video about noise when he explain a bit about the turbulence noise it was really helpfule now I understand all type of noise and most important what does the parameters mean. thank you again for your time.

Ash

Can you add a little addition to the topic to use and manage your own libraries?

reaze

+1 But anyway won't find better than Entagma ! Thanks a lot!!

Francois Codourey

I feel the same way too, would really like to know the choices behind why you're writing what you write in vex ... But still can't complain about the resources though. They are excellent.

Shrivas

Thank you for the great information you always provide us with. I just would like to point out to one point that I always stuck at. when you explain the theory behind any vex code I always feel like a question mark. maybe im a bit slow and others get it fast ,but for people like me it would be really helpful if you try your best to simplify the explaniation and why we write what we write in vex, what this code mean or how it would look like. it's hard to imagine what the code will do if I don't know what exactly doing. like normalise or set function or power or sin and cos . i really try to dig more when im stuck in something and I ended up in <a href="http://khanacademy.org/" rel="nofollow noopener" target="_blank">http://khanacademy.org/</a> where I stay to study algebra and victors just to understand what sin and cos means and where pi came from, it's super basics sometimes I know. and I don't expect you start algebra class here but a hit or just a few words to explain the meaning of codes and the theory behind codes would be more approachable for very biggners, im now trying to understand arrays which is also in algebra class. but I don;'t know when and how to use it... im not sure if any of what I said make sense but I wish to try to simplify the meaning of the codes as much as you can.

Ash


More Creators