Caffeine Abuse - The Blog

Automatic weightmaps for the left and right side of a head using ICE

Start by downloading and opening the scene ICE_Weightmaps.scn from: https://dl.dropboxusercontent.com/u/3834689/CaffeineAbuse/LeftAndRight_Weightmap.zip

Before you can assign any weights use ICE you need an actual weightmap to assign them to. Select the Head object and from the Get > Property menu choose Weight Map. In the PPG, click the Rename button and rename it to Weight_Map_Left. Create a second WeightMap and rename it Weight_Map_Right. With the head still selected, press [Alt] + 9 to open an ICE Tree and from the Create menu choose ICE Tree. Get a Get Data node and enter self.PointPosition as the reference. To assign the proper weights to the weightmap you need to find where along the x-axis each of the points is located. If it’s higher a certain value (zero in this case) it’s part of the left side of the head, and if it’s lower (a negative number in this case) it’s part of the right side. While the get PointPosition node does get the position of the points on the geometry, it outputs them as a 3D vector (the X, Y and Z position and direction per point). So you’ll need to convert the 3D Vector to output the X, Y and Z component separately.

ICE_Sym_Weightmap_01

Since your calculating the distance between the points at the furthers left and right side, it doesn’t matter if the object is placed at the center of the scene or not. The distance between the minimum and maximum is always the same either way.

Get a 3D Vector to Scalar node and connect the Get PointPosition node to its input. By getting the position at the furthest right (maximum) and furthest left (minimum) and interpolate between the two you can assign a value to each point based on where it is located within that range. Sort of a percentage or gradient from furthest left to right if you will. Get a Get Array Maximum and a Get Array Minimum node and connect the X output of 3D Vector to Scalar node to their respective Array input. Get a Linear Interpolate node and connect the Array Minimum to the First input and the Array Maximum to the Second input. The weights in the weightmap ranges from 0 to 1 so you need to rescale the current values which spans from -3.230 to 3.230 (their global x positions) to fit this range. Get a Rescale node and connect the Linear Interpolation node to its input. While you could enter the current minimum and maximum positions manually as the Source Start and End, your ICE Tree would only work on this specific model which really isn’t that useful. However, you already know the position of all the points so you can automatically get the highest and lowest number and plug that into the Rescale node. To do so, get a Get Maximum in Set and a Get Minimum in Set node and connect the X output of the 3D Vector to Scalar node to their respective Value inputs. Then connect the Maximum in Set to the Source End of the Rescale node and the Minimum in Set to the Source Start.

ICE_Sym_Weightmap_02
The FCurve node does not only enables you to create a smooth transition between the left and right weightmap, it also defines where each side start and ends. If your head is asymmetrical, simply nudge the keyframes to the left or right to aligned them with the geometry.

Get an FCurve node and connect the output of the Rescale node to its In input. Open the Fcurve PPG and select the Key at the left. Right-click on the Key and from the menu, choose Key Properties. Set the Frame value to 0.49. Click the Next Key button and change the Frame value to 0.51. This will create a smooth transition between the points of the left (with a value of 0) and right side (with a value of 1) of the head. Get a Set Data node, enter self.MyWeights as the reference and connect the output of the FCurve to its input. Then connect the Set Data node to the Port1 of the ICETree.

ICE_Sym_Weightmap_03

Get a Get Data node and enter self.MyWeights as the reference. Get a Set Data node, open its PPG and click the Explore button. Expand the tree in the explorer Head > Polygon Mesh > Clusters > WeightMap Cls > Weight_Map_Left and choose weights. Close the PPG and connect the Get self.MyWeights node the weights input of the Set Data node. Connect the Set Data node to the New (Port2)… input of the ICETree. To assign the weights for the right side weight map, all you have to do is to reverse the values. Get a Rescale node and connect the output of the self.MyWeights node to its Value input. Open the PPG and change the Target Start to 1 and Target End to 0. Get a Set Data node and repute the previous step but select the Weights for the Weight_Map_Right. Connect the Set Data node to New (Port3)… of the ICETree.

Quick tip

Whenever modifying or assign weights to weightmaps using ICE, you should always use a custom “buffer attribute” to do all your calculations. Then get the custom attribute and set the actual weights of the weightmap at the bottom of your ICETree.<br /><br />Once you’re happy with the weightmaps it’s a good idea to freeze the geometry to avoid accidentally changing the weights. Please note that this will delete your ICE Tree so you might want to save the scene under a separate name for future reference.