~jb55/polyadvent

ref: 4963791592f8b1f6ea91a6121bc5fc8f54cca279 polyadvent/test/test_dae.c -rw-r--r-- 3.2 KiB
49637915William Casarin lots of stuff 2 years ago
                                                                                
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
114
115
116
117
118
119
120
121
122
123
124
125
#include "animation.h"
#include "util.h"
#include "ply.h"
#include "mdl.h"
#include "vec3.h"
#include "debug.h"
#include <assert.h>
#include <stdio.h>

#include "dae.h"

static void test_load_pose()
{
    printf("test_load_pose\n");

    struct model model;
    struct make_geometry mkgeom;
    init_model(&model);
    init_make_geometry(&mkgeom);

    load_dae("data/models/pirate_officer.dae", &model, &mkgeom);

    assert(mkgeom.indices);

    assert(model.nposes == 1);
    struct pose *pose = &model.poses[0];

    debug("pose->nweights %d\n", pose->nweights);
    assert(pose->nweights == 389);
    assert(approxeq(pose->weights[0], 0.05213558));
    debug("pose last weight %f\n", pose->weights[388]);
    assert(approxeq(pose->weights[388], 0.01394611));

    assert(pose->njoints == 11);

    struct joint *joint = &pose->joints[0];
    struct node *node = get_node(&joint->node_id);
    assert(node);
    assert(approxeq(node->mat[0], 0.999897));

    joint = &pose->joints[1];
    node = get_node(&joint->node_id);
    assert(node);
    assert(approxeq(node->mat[1], -0.01434187));

    assert(pose->joints[0].n_children_ids == 3);

    free_make_geometry(&mkgeom);
}

static void test_save_mdl()
{
    printf("test_save_mdl\n");
    struct model model, model2;
    struct mdl_geometry mg, mg2;

    init_model(&model);
    init_mdl_geometry(&mg);
    init_model(&model2);
    init_mdl_geometry(&mg2);

    struct make_geometry *mk1 = &mg.mkgeom;
    struct make_geometry *mk2 = &mg.mkgeom;

    // TODO: test more models
    load_dae("data/models/pirate_officer.dae", &model, mk1);

    const char *tmpfile = "/tmp/test.mdl";
    save_mdl(tmpfile, &model, &mg);
    load_mdl(tmpfile, &model2, &mg2);

    debug("poses %d %d\n", model.nposes, model2.nposes);

    // TODO: mdl poses
    /* assert(model.nposes == model2.nposes); */

    assert(vec3_approxeq(mg.min, mg2.min));
    assert(vec3_approxeq(mg.max, mg2.max));
    assert(mk1->num_verts == mk2->num_verts);
    assert(mk1->num_indices == mk2->num_indices);
    assert(mk1->num_uv_components == mk2->num_uv_components);
    assert(mk1->num_joint_ids == mk2->num_joint_ids);

    assert(memeq(mk1->vertices, mk2->vertices,
                 mk1->num_verts * 3, mk2->num_verts * 3));

    assert(memeq(mk1->colors, mk2->colors,
                 mk1->num_verts * 3, mk2->num_verts * 3));

    assert(memeq(mk1->normals, mk2->normals,
                 mk1->num_verts * 3, mk2->num_verts * 3));

    assert(memeq(mk1->indices, mk2->indices,
                 mk1->num_indices, mk2->num_indices));

    assert(memeq(mk1->tex_coords, mk2->tex_coords,
                 mk1->num_verts * mk2->num_uv_components,
                 mk2->num_verts * mk2->num_uv_components));

    assert(memeq(mk1->joint_ids, mk2->joint_ids,
                 mk1->num_joint_ids, mk2->num_joint_ids));

    assert(memeq(mk1->joint_weights, mk2->joint_weights,
                 mk1->num_verts * 3, mk2->num_verts * 3));
}

int main(int argc, char *argv[])
{
    struct pose *pose;
    struct joint *joint;
    struct node *node;
    struct model model;
    struct make_geometry geom;
    int nposes;

    init_node_manager();
    init_model(&model);
    init_make_geometry(&geom);

    test_load_pose();
    test_save_mdl();

    return 0;
}