Jump to content

@numpt vs npoints (VEX vs Hscript)


Recommended Posts

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.

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

 

PS
back 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 by r-a-n-d-o-m
Link to comment
Share on other sites

@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 by f1480187
  • Like 1
Link to comment
Share on other sites

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#.

  • Like 1
Link to comment
Share on other sites

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 by r-a-n-d-o-m
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Noobini
  • Thanks 1
Link to comment
Share on other sites

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 by davpe
  • Like 1
Link to comment
Share on other sites

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 by davpe
Link to comment
Share on other sites

  • 2 months later...
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?

 

Link to comment
Share on other sites

@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

 

 

 

Link to comment
Share on other sites

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 by Noobini
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...