Bifrost pose reader

barycentric gif


Barycentric coordinate system

The barycentric coordinates are a way of expressing the location of a point within a triangle using proportions based on areas. It’s like dividing the triangle into smaller areas and using those areas to describe where the point is in relation to them. This is known as areal coordinates and it’s a simple way to understand how a point is positioned within a triangle using only area ratios.

So once we have 3 points (ABC) and a point (P) we can calculate the area of ABC, PAB, PBC and PCA.

triangles ABCP

Once you have the area of each triangle, you can then use these values to determine the barycentric coordinates of P.


INPUTS


STEPS

  1. Find the projected point (P) on the geometry using a vector
  2. Determine the face on which point P is located
  3. Extract the vertices of the face where we are ABC
  4. Calculate the areas of ABC, PBC, PCA, PAB
  5. Output


Find the projected point (P) on the geometry using a vector

In order to find point P, we’ll need our driver, which is placed in the geometry’s center and a direction vector. This vector can be passed as value (1, 0, 0) if we want to use the X axis or we can have an input in our bifrost node so we can decide which axis we want to use.

vector gif

To project p onto the geometry, we’ll use the node get_raycast_locations. This node needs to be given the inputs as lists. Therefore, we’ll use build_array to turn our data into lists.

Once our get_raycast_locations is working, we’ll need to access the point p. To do this, we must use the node sample_property. The sample_data is the output we’re looking for.

raycast bifrost graph


Determine the face on which point P is located

To determine the closest face, we’ll use the get_closest_locations node. This node provides us valuable information, such as the closest vertex or the closest face. To extract this information, we’ll create a value node and set its type as GeoLocation.

geoLocation value node

The output is a list, so we’ll use the first_in_array node to get the first value.

closest face graph


Extract the vertices of the face where we are ABC

To obtain the 3 vertices that form our face, we need to use the get_mesh_structure node.

face vertex graph


Calculate the areas of ABC, PBC, PCA, PAB

This step may seem very complex, but it’ss as simple as looking for the formula on the internet and applying it with bifrost nodes. The area formula for a triangle is the following:

| (B - A) x (C - A) | / 2

We need to calculate the area of ABC, PBC, PCA, PAB

area graph


Output

As we said at the beginning of the post, once we have all the areas, the only thing we need to do is to divide the areas by the area of ABC. So, for example, the weight of A = Area(PBC) / Area(ABC).

Apart from that, in the image you can see the way I’ve found to create an empty array and fill it only with the values of the vertex of the face we are on.

output


The sum of all our weights must be equal to 1 and, since they are values between 0 and 1, we can use them to trigger our blendshapes directly.


I am providing the example scene for download, you can find all the weights connected in the driver, so if you rotate the locator, you’ll see the output.

Download

Iván Cuenca Ruiz - 12 / 04 / 2023