r-a-n-d-o-m Posted September 13, 2017 Share Posted September 13, 2017 A newbie question: Can somebody explain me when to use @numpt vs npoints. Which is actually a question VEX vs Hscript. Since Houdini 16, is it now advisable to only use VEX? Example: You lay down a LINE SOP and connect a GROUP SOP to it, in the Base Group you can type in 0 `npoints(0)-1` this results in getting the first and the last point. Can you do the same thing with the @numpt? Because that doesn't seem to work in the Base Group field of the Group node. In attribute wranglers I use @numpt. I'm getting a bit confused. Quote Link to comment Share on other sites More sharing options...
symek Posted September 13, 2017 Share Posted September 13, 2017 Whatever you put into wranglers they are VEX script statements, whatever you put into parameters they are Hscript expressions statements (or Python's ). Both can do similar things (like giving you a number of points in a SOP), but they cannot be mixed or used exchangeably. Different languages, different purposes, different places of appliance, notably with some amount of overlapping functionalities likes functions for querying geometry, generators of random numbers etc. Quote Link to comment Share on other sites More sharing options...
r-a-n-d-o-m Posted September 13, 2017 Author Share Posted September 13, 2017 That is clear. But why can I write in the base group field of the GROUP SOP the following: @P.x<0 (selects all points with a x position lower then zero) and NOT @ptnum < 5 (In my mind this should select all points whose number is lower then 5, but it doesn't) this confuses me. if I read http://www.sidefx.com/docs/houdini/vex/snippets both @P and @ptnum are Vex attribute names, yet one is accessible and the other is not. Quote Link to comment Share on other sites More sharing options...
Atom Posted September 13, 2017 Share Posted September 13, 2017 There is a spacing bug related to expression evaluation. For instance try "@ptnum<5" and then try "@ptnum < 5". They work differently. However, when I use "@ptnum < 5" I only get point 5 selected, not points 0-4 as I would expect. A better bet is to explore some of the new group offerings that H16 provides. For instance if you place that same expression in the field of a Group Expression node, it works as expected and I get all 5 elements selected. There is no general Group node anymore, and old tutorials will still try to leverage features from that old node. But moving forward it is best to get used to the new set of grouping nodes. Quote Link to comment Share on other sites More sharing options...
Popular Post f1480187 Posted September 13, 2017 Popular Post Share Posted September 13, 2017 From my personal understanding: 1. HScript is a shell-like language, the old scripting core of Houdini, mostly replaced with Python this days. Example: # Node geometryvopglobal1 (Vop/geometryvopglobal) opadd -n geometryvopglobal geometryvopglobal1 oplocate -x 1.90579 -y 1.97631 geometryvopglobal1 opspareds "" geometryvopglobal1 opparm geometryvopglobal1 chlock geometryvopglobal1 -* chautoscope geometryvopglobal1 -* opset -d on -r on -h off -f off -y off -t off -l off -s off -u off -e on -b off -L off -M off -H on geometryvopglobal1 opexprlanguage -s hscript geometryvopglobal1 Scripts typically look like sequences of commands. We still may find such scripts in old shelf tools, menu scripts, etc. Summarizing: npoints(): unavailable. Expression function can be used inside backticks. @numpt: unavailable. Where to use: in scripts and shelf tools, but better use HOM. 2. HScript Expressions is a special part of HScript used inside `backticks` to substitute contents with result of some computation. In parameter fields we use them without backticks (assumed that everything is expression), in string parameter fields we need to use backticks to evaluate contents and substitute with resulting values. # Typical expression. if(npoints(0)==0, $F, $FEND - $F) # Typical string. $HIP/render/explosion_`$F-1`.png # We can use "vex-like" @Frame instead of $F. # There is no "vex-like" equivalent for $FEND. if(npoints(0)==0, @Frame, $FEND - @Frame) When we type "@foo" in parameter field, we don't use VEX. It's like an alternate way to access something stored in "$FOO". It is not guaranteed to work for every variable that can be accessed with dollar sign. Example: before H16 Group SOP stored number of input points in variable $NPT. After @-syntax was introduced in H15, we expected logical "vex-like" equivalent with same meaning to exist: @numpt. There is no such variable, however. The feature still not implemented fully, and pretty much undocumented. New Group SOP node dropped the local var. npoints() is an expression function we can use anywhere in parameters. This is what we can use in new Group SOP to get number of input points. It accepts string path. It specially treats numbers provided as arguments (by automatically calling "opinputpath(".", number)" I guess). There is many expression functions which has no such convenient handling and will fail if we provide just 0 to them. opinputpath(".", 0) can be used instead. Expressions are widely used in Houdini. They have nice and compact syntax convenient to use inside parameters. Python is used too, but for more advanced tasks. Summarizing: npoints(): available as expression function. @numpt: unavailable. Other vex-like implicit variables may work, e.g. @Frame. $NPT: available as local variables defined on some old nodes. Where to use: in numeric parameters, in string parameters inside backticks. 3. VEX is a C-like programming language for shading and geometry processing tasks. Typical VEX program defines some context function operating over inputs and writing (exporting) some results. Sample VEX program defining SOP context function: sop restpos(export vector rest={0,0,0}) { rest = P; } There is no "@numpt"-like syntax in VEX. If we need to access some attribute, we need to use functions like attrib(). We need to compute non-attribute variable like @numpt using corresponding VEX function npoints(). Summarizing: npoints(): available as VEX function. @numpt: unavailable. Where to use: in standalone .vfl and .h files. 4. Wrangles, Snippets, VEXpressions . It is VEX extended with extra features, implemented via Snippet VOP and Attribute VOP SOP. @-style attribute bindings is one of them. Also, as we type the code inside string parameter, we can also incorporate some HScript Expressions using backticks. Typical Wrangle: @rest = @P; This will be wrapped into CVEX context function and expanded into normal VEX program automatically: void wrangle(vector rest; vector P) { rest = P; } cvex f(export vector rest={0,0,0}; export vector P={0,0,0}) { wrangle(rest, P); } @numpt is an implicit variable defined in Attribute VOP SOP and containing number of points of first input. Whenever you use VEXpressions (Snippet VOP, Wrangle SOPs, Attribute Expression SOP, Group Expression SOP, etc.), you can use @numpt. npoints() VEX function is also available, obviously. Summarizing: npoints(): available as VEX function. Also, expression function can be used inside backticks. @numpt: available. Where to use: in VEXpression parameters. 5. Grouping patterns mini-language. Specifically, an ad-hoc groups where @ also used for attribute access. You can pass a string like "@P.x<0.5" to the group parameter in many nodes, or as group argument in VEX functions. It will be processed by Houdini automatically. As we enter the group parameter string, we can use HScript Expressions inside backticks. Summarizing: npoints(): unavailable. Expression function can be used inside backticks. @numpt: unavailable. Where to use: in group parameters, in group string arguments in VEX. 6 5 Quote Link to comment Share on other sites More sharing options...
r-a-n-d-o-m Posted September 13, 2017 Author Share Posted September 13, 2017 (edited) Thanks for summarizing this clearly. This is explains why Houdini has the reputation of being difficult to learn. The use of all these different types of syntaxes is pretty daunting. Why not stick to one? (all Vex or all Phyton) This reminds me of Flash, where one could mix ActionScript 1.0, 2.0 and 3.0 all in the same file. This resulted in bad coding, unoptimized websites, draining Iphone batteries and gone was Flash. Adobe should have had the balls to dump 1.0 and 2.0 entirely with each new update. Maybe making old users angry, but then it was clear what you needed to use. I know it is not easy (backwards compatibility and such) but I believe a software company should be taken this into account because it confuses new users. That is why I want to clarify this for myself, I don't want to write bad code :-) And there is not much good reference of best practice H16 examples (yet) on that topic. Or I haven't found them yet. thanks again! PSback to my example: You lay down a LINE SOP and connect a GROUP SOP to it, in the Base Group you can type in 0 `npoints(0)-1` to get the first and last point. The follwing line does the same but all with the @ notation @ptnum = 0 @ptnum = `chs("../line3/points")-1` (channel reference to the number of points on the line, since @numpt doesn't work) So what will sideFX favour?PS2 the space issue is also something SideFX should fix Edited September 13, 2017 by r-a-n-d-o-m Quote Link to comment Share on other sites More sharing options...
f1480187 Posted September 13, 2017 Share Posted September 13, 2017 (edited) @r-a-n-d-o-m, I think it's just silently throwing away invalid tokens ("@ptnum" and "=") and reading this group like: "0 `chs("../line3/points")-1`". "0 `npoints(0)-1`" is almost same, but slightly more general, so I would stick to it. Also, chs() will return string, for numbers better use ch(). Edited September 13, 2017 by f1480187 1 Quote Link to comment Share on other sites More sharing options...
LaidlawFX Posted September 14, 2017 Share Posted September 14, 2017 19 hours ago, r-a-n-d-o-m said: Why not stick to one? (all Vex or all Phyton) The software has been actively developed for over 30 years, so while many would agree on simplifying the language choices, there are many reasons there are different languages. That is the same as asking everyone on Earth to speak one language or all of programming to use only one language. Each of them were developed for good and for worse, for their specific reasons, and depreciating stuff is actually amazingly hard. F1 did a really nice explanation of a few of them. There are even more languages and modules Houdini can use too, like HDK or opengl, and all the various hybrid languages. Houdini is a full DCC, not a program designed to do just one functionality. For instance VEX is a vector language that is C/RSL derivative language developed for fast processing on a CPU for point information and color. While python is extremely shitty for handling geometry, but really well designed for interchangeability and ease of coding, for instance having different CG programs talk to each other. OpenGL is strictly designed for GPU functionality and hardware differences. But neither of these languages would be good for building a program like C#. 1 Quote Link to comment Share on other sites More sharing options...
r-a-n-d-o-m Posted September 15, 2017 Author Share Posted September 15, 2017 (edited) I understand the complexity of it all, I read that Hscript is there only for compatibility reason, that is why I want to do as much as possible with Vex script, hence the example above to illustrate that in some places it doesn't work (like accessing @numpt for instance). If I use the Group by Expression node, where there is a field called VEX expressions and type the following: @ptnum < 5 That works@numpt-2 That doesn't work...confusing to me Edited September 15, 2017 by r-a-n-d-o-m Quote Link to comment Share on other sites More sharing options...
davpe Posted September 15, 2017 Share Posted September 15, 2017 Quote @ptnum < 5 That works@numpt-2 That doesn't work...confusing to me what are you expecting to be in the group selection in the second example (@numpt-2)? your first example has a boolean result so it can be either positive to put in the group or not. but if you have a point number, then you run "number - 2", the result may be something like 245. how do you decide if that is something that belongs to the group? it would work if you typed "@numpt-2 == 245" - then if (number-2) equals 245, it's gonna be in the group. result simply needs to be 1 or 0 to make it work as those are the only valid indicators whether to put an element in the group or not. Quote Link to comment Share on other sites More sharing options...
Noobini Posted September 15, 2017 Share Posted September 15, 2017 (edited) what I think the OP is driving at is this...in Group Expression, if you want the last point, then: @ptnum == @numpt-1 2nd last point would be @ptnum == @numpt-2...and so on.... yes, I did expect simply @numpt-1 would be the last point....but just reading stuff so far down to here...made me came up with the above answer... bonus: here's how to get 1st and last @ptnum%(@numpt-1)==0 Edited September 15, 2017 by Noobini 1 Quote Link to comment Share on other sites More sharing options...
davpe Posted September 15, 2017 Share Posted September 15, 2017 (edited) i think your initial conclusion was almost right, only you forgot that point numbers start with 0. so with expression @ptnum == @numpt-1 only the last point would be in the group. if you think about it in form of specific numbers: you have 5 points, with numbers 0-4, obviously. your @numpt = 5 and therefore @numpt-1 = 4. then VEX code iterates over each point: ptnum 0 == 4 = False ptnum 1 == 4 = False ptnum 2 == 4 = False ptnum 3 == 4 = False ptnum 4 == 4 = True edit: sorry I misread your post so i've just repeated what you said Edited September 15, 2017 by davpe 1 Quote Link to comment Share on other sites More sharing options...
Noobini Posted September 15, 2017 Share Posted September 15, 2017 no i didn't forget...and yes I was 100% clear that I want the LAST point.... Pretty sure I said "if you want the last point, then:" blah blah... Quote Link to comment Share on other sites More sharing options...
davpe Posted September 15, 2017 Share Posted September 15, 2017 (edited) 1 minute ago, Noobini said: no i didn't forget...and yes I was 100% clear that I want the LAST point.... Pretty sure I said "if you want the last point, then:" blah blah... yeah, sorry I misread your post so I just repeated whatever you said btw. nice trick with 1st AND last pt! Edited September 15, 2017 by davpe Quote Link to comment Share on other sites More sharing options...
Noobini Posted September 15, 2017 Share Posted September 15, 2017 haha...very VEXing indeed...:) and here's an even shorter way to get 1st and last: @ptnum%(@numpt-1)<1 (but that might confuse the crap out of ppl) 1 1 Quote Link to comment Share on other sites More sharing options...
r-a-n-d-o-m Posted September 15, 2017 Author Share Posted September 15, 2017 (edited) @davpe and @noobini : thanks! Edited September 15, 2017 by r-a-n-d-o-m Quote Link to comment Share on other sites More sharing options...
nakaikoi Posted December 7, 2017 Share Posted December 7, 2017 On 9/15/2017 at 5:26 AM, Noobini said: haha...very VEXing indeed...:) and here's an even shorter way to get 1st and last: @ptnum%(@numpt-1)<1 (but that might confuse the crap out of ppl) Thanks for asking this Noobini, I had the exact same question. Everyone seems to be saying USE VEX USE VEX Hscript is old... even the help documents are like HScript will probably always be available for certain jobs where it’s handier than VEX. For geometry manipulation, however, wrangling and VEX/VOPs is the way forward, and it’s worthwhile to learn the new workflow. But there have been cases where VEX doesn’t work. for example, I had a scatter sop and I wanted the total number of scatter points to be equal to the total number points of another geometry (geoB). So naturally one would think to get the @numpt from geoB and enter that into the number of points parameter. npoints(“../geoB”) in hscript works fine. For the life of me I couldn’t figure out how to use @numpt to get the same result. Is it a rule to only used hscript expressions for parameter controls? If this is true the help documents should make it point clear somewhere instead of saying we need to move toward vex vex vex. btw could you explain @ptnum%(@numpt-1)<1 looks fancy what does that % do? Quote Link to comment Share on other sites More sharing options...
acey195 Posted December 7, 2017 Share Posted December 7, 2017 @numpt is only available for the first input of the node, but there is alos a npoints(x) function in vex , where x is the input number. @ptnum%(@numpt-1)<1 does the following: it returns either 0 or 1, as at the end the left part is compared to smaller than 1 % (modulo) just returns the rest value of a fraction example: 0%3 returns 0 1%3 returns 1 2%3 returns 2 3%3 returns 0 4%3 returns 1 5%3 returns 2 etc. so @ptnum%(@numpt-1) basically returns the point number, as it will never be higher than total amount of points. so from the top of my head, that line only returns 1, if the pointnumber is 0 Quote Link to comment Share on other sites More sharing options...
f1480187 Posted December 7, 2017 Share Posted December 7, 2017 You can use @opinput1_numpt for second input's @numpt. Quote Link to comment Share on other sites More sharing options...
Noobini Posted December 7, 2017 Share Posted December 7, 2017 (edited) 8 hours ago, nakaikoi said: btw could you explain @ptnum%(@numpt-1)<1 looks fancy what does that % do? well say you have 10 points, so @numpt is 10, while your points go from 0 - 9. So @ptnum%(@numpt-1)<1 is..... 'each point number mod 9' (ie. each point number / 9, what is the remainder ?)... therefore: 0%9 = 0 1%9 = 1 2%9 = 2 3%9 = 3 . . 9%9 = 0 so if my test for remainder is < 1, I'm getting the 1st and last point with True test result (could've also tested for ==0, I guess...) Edited December 7, 2017 by Noobini Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.