Wrap over Object
Wrap over Object
This is a great process for wrapping an object around a complex shape, whether that be a vellum simulation or a 3D face, this method is super versatile and very quick at delivering results. The base of this happens in the singular VEX function "uvsample". It looks complicated in VEX but with a bit of context it's a great function to use.
To start, we need two objects: the first being the object to be wrapped, and the second, the object to which we will wrap the first. From here we need to work out where on our second object we want the first object to appear. We need good UV's and a point split, using the UV's, and promoting to a point attribute. We then need a wrangle with "@P = @uv". This will give us our second mesh in uv space. We don't actually use this step but it's a great way of visualizing what we're doing.
From here we can use a transform to move our first object to the new UV layout and orientate it. It's important we have the first mesh here because now our first objects 3D coordinates are in the same space as the second object's UV coordinates.
Now we need to make use of the uvsample function. We need a wrangle with the first input being the first object and the second, the second object(but before we split the points). Now we need to add just three lines of VEX.
vector uv_p = set(@P.xm @P.z, 0);
vector pos = uvsample(1, "P", "uv", uv_p);
@P = pos;
This is working under the hood, but we're forgetting about the z axis. We can only use the x and y with "uvsample". So we need to track the local transform before so we can reimplement it after. We need to emend our code with this.
vector uv_p = set(@P.x, @P.y, 0);
vector pos = uvsample(1, "P", "uv", uv_p);
vector norm = uvsample(1, "N", "uv", uv_p);
@P = pos + (norm * (@P.y + chf("Global_Height")) * chf("scale"));
Now we have two extra variables in our wrangle, "scale", simply scales the height of our wrapped object. "Global_Height", is useful for moving the wrapped object up and down relative to the second object. What we're doing in the VEX is taking the @P.y, which is the relative height, and multiplying the normal by the relative height.
We now have our first object, wrapped over our second object. We can also move the first over the mesh by using the transform before the "uvsample" wrangle. We also have some controls for how our mesh gets wrapped around the object.