wrangle and snippet question.

   3195   5   1
User Avatar
Member
383 posts
Joined:
Offline
Hello,

I am trying to understand the difference and relation between wrangle and snippet.

I have 1000 points at {0,0,0} and I want to organize them in cube shape (10x10x10).
I wrote this code in point wrangle SOp:

int i, j, k;
i=0;
j=0;
k=0;
for ( k; k<11; k++){
for ( j; j<11; j++){
for ( i; i<11; i++){
@P.z = @ptnum%10;
}
@P.x = (@ptnum/10)%10;
}
@P.y @ptnum/100)%10;
}


It works as excepted even If I assume it should better way to do this.

When I paste it to a Snippet VOP inside an Attribute VOP, it gives me an error if the Global Parameters node is present :
Read only expression for read/write parameter. (1,35)

When I erase the Gobal Parameters node, the error disappear but the code doesn't seems to do anything ( all points remains at {0,0,0}).

I don't understand this behavior inside the snippet in my VOP.
I would like to make my snippet to work exactly like the wrangle. How can I do that ?

Thanks for your help,

Vincent

PS : well … I just see the smiley.
I add space in the code and it works


Edited by vbk!!! - Sept. 8, 2016 05:18:18
http://vimeo.com/vbkstudio [vimeo.com]
User Avatar
Member
383 posts
Joined:
Offline
New question !

I am now trying to reproduce my cube shape distribution with a Point Replicate Procedural.

But my code return an error :
pid redeclared with different type float previously declared as int (48,1)

I joint the screenshot of my little setup.

What did I forget to make it to work as the snippet in SOP level ?

Vincent




Attachments:
snippet.png (27.7 KB)

http://vimeo.com/vbkstudio [vimeo.com]
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
Hi vbk!!

I've been doing similar work with vex but directly and only in a point wrangler so far.

I don't know why yours is not working because of my limited contexual experience plus it may be better if you provided a hip file.

However I think there might be a few things to look at:

Create new points based on the old ones with the point function, then do your work to set their position.

{This is the method I have been doing)

I have created functions whereby I used the incoming points(the ones coming into the point wrangler) as arguments
and inadvertly tried to change them but got similar error messages like “…read only”.

The thing is that in my case I don't want to change the incoming points…only use them as reference.

This is why I really don't know if you can do what you want or not.( Just change the position without making duplicate)

You may want to look at the list of vex functions in the docs that might give you a clue to do what you want.

Maybe one of the ‘set’ functions might be able to allow you to work on those points to new positions?
User Avatar
Member
383 posts
Joined:
Offline
I read the vex code generated again and again.

And it works now :
I don't use @pid anymore since the vex code declare it as float.
I use i@pid instead forcing vex to declare pid at integer.

No more conflict !
http://vimeo.com/vbkstudio [vimeo.com]
User Avatar
Member
606 posts
Joined: July 2013
Online
It works as excepted even If I assume it should better way to do this.

There is a better way.

A Point Wrangle is executed in parallel automagically….you dont have to manually loop over the Context elements.

So…you can replace you're entire vex code that has the for loop with a single line:

@P = set( (@ptnum/10)%10, (@ptnum/100)%10, @ptnum%10);

A Wrangle has a Context (Point, Vertex, Primitive, or Detail). The Wrangle context determines how many times the Vex code is evaluated.

A Detail Wrangle is only evaluated (1) time, since Detail context is singular. A Primitive Wrangle is evaluated for (n) number of Primitives on the object, same with the Vertex and Point context…it depends on how many there are.

So, in your example, you have 1000 Points, and you've created a Point Wrangle. So, the Vex code you write inside the Point Wrangle is evaluated per-point, which in your case, this is what is happening with your current code that has the for loop:

Vex code is evaluated for Point #1
@ptnum value is 1
Vex code sets the value of @P for Point #1 1000 times inside a For Loop

Vex code is evaluated for Point #2
@ptnum value is 2
Vex code sets the value of @P for Point #2 1000 times inside a For Loop

What this code
@P = set( (@ptnum/10)%10, (@ptnum/100)%10, @ptnum%10);
does instead is:


Vex code is evaluated for Point #1
@ptnum value is 1
Vex code sets the value of @P for Point #1

Vex code is evaluated for Point #2
@ptnum value is 2
Vex code sets the value of @P for Point #2

Hope that makes sense.
Houdini Indie
Karma/Redshift 3D
User Avatar
Member
383 posts
Joined:
Offline
It makes perfect sense !
You just make my day !

Thanks a lot.

Vincent
http://vimeo.com/vbkstudio [vimeo.com]
  • Quick Links