skeleton.cpp 3.39 KB
Newer Older
TheNumbat's avatar
TheNumbat committed
1
2
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

#include "../scene/skeleton.h"

Vec3 closest_on_line_segment(Vec3 start, Vec3 end, Vec3 point) {

    // TODO(Animation): Task 3

    // Return the closest point to 'point' on the line segment from start to end
    return Vec3{};
}

Mat4 Joint::joint_to_bind() const {
    
    // TODO(Animation): Task 2

    // Return a matrix transforming points in the space of this joint
    // to points in mesh space in bind position.

    // Bind position implies that all joints have pose = Vec3{0.0f}

    // You will need to traverse the joint heirarchy. This should
    // not take into account Skeleton::base_pos
    return Mat4::I;
}

Mat4 Joint::joint_to_posed() const {

    // TODO(Animation): Task 2

    // Return a matrix transforming points in the space of this joint
    // to points in mesh space, taking into account joint poses.

    // You will need to traverse the joint heirarchy. This should
    // not take into account Skeleton::base_pos
    return Mat4::I;
}

Vec3 Skeleton::end_of(Joint* j) {

    // TODO(Animation): Task 2
    
    // Return the position of the endpoint of joint j in mesh space in bind position.
    // This should take into account Skeleton::base_pos.
    return Vec3{};
}

Vec3 Skeleton::posed_end_of(Joint* j) {

    // TODO(Animation): Task 2
    
    // Return the position of the endpoint of joint j in mesh space with poses.
    // This should take into account Skeleton::base_pos.
    return Vec3{};
}

Mat4 Skeleton::joint_to_bind(const Joint* j) const {

    // TODO(Animation): Task 2
    
    // Return a matrix transforming points in joint j's space to mesh space in
    // bind position. This should take into account Skeleton::base_pos.
    return Mat4::I;
}

Mat4 Skeleton::joint_to_posed(const Joint* j) const {

    // TODO(Animation): Task 2
    
    // Return a matrix transforming points in joint j's space to mesh space with
    // poses. This should take into account Skeleton::base_pos.
    return Mat4::I;
}

void Skeleton::find_joints(const GL::Mesh& mesh, std::unordered_map<unsigned int, std::vector<Joint*>>& map) {

    // TODO(Animation): Task 3

    // Construct a mapping from vertex indices in 'mesh' to lists of joints in this skeleton
    // that should effect the vertex. A joint should effect a vertex if it is within Joint::radius
    // distance of the bone segment in bind position.

    const std::vector<GL::Mesh::Vert>& verts = mesh.verts();

    for_joints([&](Joint* j) {
    
        // What vertices does joint j effect?
    });

    // For each i in [0,verts.size()), map[i] should contain the list of joints that effect vertex i 
    (void)verts;
}

void Skeleton::skin(const GL::Mesh& input, GL::Mesh& output, 
                    const std::unordered_map<unsigned int, std::vector<Joint*>>& map) {

    // TODO(Animation): Task 3

    // Apply bone poses & weights to the vertices of the input (bind position) mesh
    // and store the result in the output mesh. See the task description for details.
    // map was computed by find_joints, hence gives a mapping from vertex index to
    // the list of bones the vertex should be effected by. 
    
    // Currently, this just copies the input to the output without modification.

	std::vector<GL::Mesh::Vert> verts = input.verts();
    for(size_t i = 0; i < verts.size(); i++) {
        
        // Skin vertex i.
    }

	std::vector<GL::Mesh::Index> idxs = input.indices();
	output.recreate(std::move(verts), std::move(idxs));
}