Jump to content
r-a-n-d-o-m

@numpt vs npoints (VEX vs Hscript)

Recommended Posts

r-a-n-d-o-m    0

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.

 

Share this post


Link to post
Share on other sites
symek    266

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. 

Share this post


Link to post
Share on other sites
r-a-n-d-o-m    0

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.

 

 

Share this post


Link to post
Share on other sites
Atom    516

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.

Share this post


Link to post
Share on other sites
f1480187    454

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.

  • Like 2
  • Thanks 2

Share this post


Link to post
Share on other sites
r-a-n-d-o-m    0

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

Share this post


Link to post
Share on other sites
f1480187    454

@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

Share this post


Link to post
Share on other sites
LaidlawFX    139
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

Share this post


Link to post
Share on other sites
r-a-n-d-o-m    0

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

Share this post


Link to post
Share on other sites
davpe    54
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.

Share this post


Link to post
Share on other sites
Noobini    82

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

Share this post


Link to post
Share on other sites
davpe    54

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

Share this post


Link to post
Share on other sites
Noobini    82

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

Share this post


Link to post
Share on other sites
davpe    54
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

Share this post


Link to post
Share on other sites
Noobini    82

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)

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×