Skip to content

linear_blend_skinning

linear_blend_skinning(V, Ws, Rs, Ts)

Deform a mesh using linear blend skinning, given a list of weights, rotations and translations.

Parameters:

Name Type Description Default
V (n,3) numpy array

vertex list of a triangle mesh

required
Ws (n,m) numpy array

weights for each vertex and each handle

required
Rs (m,3,3) numpy array

rotations for each handle

required
Ts (m,3) numpy array

translations for each handle

required
Returns required
U (n,3) numpy array

deformed vertex list of a triangle mesh

required

Examples:

import numpy as np
import gpytoolbox as gpt
# Create a mesh
V = np.array([[0,0,0],[1,0,0],[0,1,0],[1,1,0]])
F = np.array([[0,1,2],[1,2,3]])
# Create a set of handles
Rs = np.array([np.eye(3),np.eye(3)])
Ts = np.array([[0,0,0],[1,0,0]])
# Create a set of weights
Ws = np.array([[1,0],[0,1],[0,1],[1,0]])
# Deform the mesh
U = gpt.linear_blend_skinning(V,Ws,Rs,Ts)
# Check the result
assert np.allclose(U,np.array([[0,0,0],[2,0,0],[1,1,0],[1,1,0]]))
Source code in src/gpytoolbox/linear_blend_skinning.py
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def linear_blend_skinning(V,Ws,Rs,Ts):
    """
    Deform a mesh using linear blend skinning, given a list of weights, rotations and translations.

    Parameters
    ----------
    V : (n,3) numpy array
        vertex list of a triangle mesh
    Ws : (n,m) numpy array
        weights for each vertex and each handle
    Rs : (m,3,3) numpy array
        rotations for each handle
    Ts : (m,3) numpy array
        translations for each handle

    Returns
    -------
    U : (n,3) numpy array
        deformed vertex list of a triangle mesh

    Examples
    --------
    ```python
    import numpy as np
    import gpytoolbox as gpt
    # Create a mesh
    V = np.array([[0,0,0],[1,0,0],[0,1,0],[1,1,0]])
    F = np.array([[0,1,2],[1,2,3]])
    # Create a set of handles
    Rs = np.array([np.eye(3),np.eye(3)])
    Ts = np.array([[0,0,0],[1,0,0]])
    # Create a set of weights
    Ws = np.array([[1,0],[0,1],[0,1],[1,0]])
    # Deform the mesh
    U = gpt.linear_blend_skinning(V,Ws,Rs,Ts)
    # Check the result
    assert np.allclose(U,np.array([[0,0,0],[2,0,0],[1,1,0],[1,1,0]]))
    ```
    """

    U = np.zeros_like(V,dtype=float)
    # print(Ws.shape[1])
    for i in range(Ws.shape[1]):
        rotations = np.dot(V,Rs[i].T)
        rep_weights = np.repeat(Ws[:,i,None],V.shape[1],axis=1)
        rep_translations = np.repeat(Ts[i][None,:],V.shape[0],axis=0)
        U += rep_weights*(rotations + rep_translations)
        # print(U)
    return U