# JoyOfVex6

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

### Day 6

point wrangle vs prim wrangle vs detail wrangle

Set colour from a sine wave based distance as we've been doing:

```float d = length(@P);
d *= ch('scale');
@Cd = 0;
@Cd.r = sin(d);
```

Now on the 'run over' drop down, change it from points to primitives.

Note how the result looks sharper, more 8 bit. Also notice that @Cd has gone from the geo spreadsheet. Click the primitives button on the geo spreadsheet, ah, thats where colour went.

Why does it look sharper? Because the points are shared between the primitives, the colour is blended across the prims. But if we colour the primitives directly, there's no blending the result is crisp. Read the point verts prims page for more info.

Can we do other tricks like moving @P on prims?

```float d = length(@P);
d *= ch('scale');
@P.y = sin(d);
```

Swap between point and prim mode. No, it only works on points. Look in the geo spreadsheet, can see that points have a @P attribute, so they can be modified, but prims don't, so they can't. Prim position is driven by the points that make it up, again refer to the points/verts/prims page for more info.

But wait... why did colour work then? That's somehow reading @P from the prims, but they have no @P according to the spreadsheet!?

This is a convenience helper of vex; its likely that you'll do operations based on prim location, so vex will temporarily make a read-only @P for each prim, but you can't write back to it.

### How to know about attributes like ptnum, P, N numpt etc

A lot of it comes down to experience, but houdini comes with a built in cheat sheet. Create a point vop, dive in side, look at the global parameter node. They're the usual ones that either Houdini expects to find, or provides for you, or both. Similarly for the output vop node.

Put list of what they are and what they do here.

### Other modes on a wrangle, vertex and detail

Vertex wrangle makes sense, it lets you run over every vert in your geo. Like prims, they don't let you set many interesting things, vert wrangles are rarely used outside of uvs, yet again, refer to the point/vert/prim page for details.

Speaking of details (SEGUE), whats a detail wrangle? This simply means 'run once'. This is handy for situations where you're referring to the entire object in one hit, like calculating its bounding box, or setting a single text variable somewhere. You can do more with this, to come in a later chapter.

You can also set attributes at this high level on the entire geometry, click the 'details' button on the geo spreadsheet to see this level of data.

### Moving beyond P N Cd ptnum

All the demos so far have written results directly to position or colour. What if you want to store it as something else? Say you want to store each points distance to the origin, to be used in another wrangle later on?

You can make up your own attributes, just prefix it with @.

```float d = length(@P);
@mydistance = d;
```

In fact its common to not use local variables at all, and just directly assign and read from your own attributes:

```@d = length(@P);
@d *= ch('scale');
@Cd = 0;
@Cd.r = sin(@d);
```

Exercise

1. set normals per prims
2. set a d attribute on prims in one wrangle, and use it to create a sine wave in another