コード例 #1
0
ファイル: skeletal_model.c プロジェクト: opentomb/OpenTomb
void SSBoneFrame_FillSkinnedMeshMap(ss_bone_frame_p bf)
{
    uint32_t *ch;
    uint32_t founded_index = 0xFFFFFFFF;
    float tv[3];
    vertex_p v, founded_vertex;
    base_mesh_p mesh_base, mesh_skin;
    ss_bone_tag_p tree_tag = bf->bone_tags;

    for(uint16_t i = 0; i < bf->bone_tag_count; i++, tree_tag++)
    {
        if(!tree_tag->mesh_skin)
        {
            continue;
        }
        if(tree_tag->skin_map)
        {
            free(tree_tag->skin_map);
            tree_tag->skin_map = NULL;
        }
        mesh_base = tree_tag->mesh_base;
        mesh_skin = tree_tag->mesh_skin;
        ch = tree_tag->skin_map = (uint32_t*)malloc(mesh_skin->vertex_count * sizeof(uint32_t));
        v = mesh_skin->vertices;
        for(uint32_t k = 0; k < mesh_skin->vertex_count; k++, v++, ch++)
        {
            *ch = 0xFFFFFFFF;
            founded_index = BaseMesh_FindVertexIndex(mesh_base, v->position);
            if(founded_index != 0xFFFFFFFF)
            {
                founded_vertex = mesh_base->vertices + founded_index;
                vec3_copy(v->position, founded_vertex->position);
                vec3_copy(v->normal, founded_vertex->normal);
            }
            else if(tree_tag->parent)
            {
                vec3_add(tv, v->position, tree_tag->offset);
                founded_index = BaseMesh_FindVertexIndex(tree_tag->parent->mesh_base, tv);
                if(founded_index != 0xFFFFFFFF)
                {
                    founded_vertex = tree_tag->parent->mesh_base->vertices + founded_index;
                    *ch = founded_index;
                    vec3_sub(v->position, founded_vertex->position, tree_tag->offset);
                    vec3_copy(v->normal, founded_vertex->normal);
                }
            }
        }
    }
}
コード例 #2
0
ファイル: skeletal_model.c プロジェクト: vvs-/OpenTomb
void SkeletalModel_FillSkinnedMeshMap(skeletal_model_p model)
{
    uint32_t *ch;
    uint32_t founded_index = 0xFFFFFFFF;
    float tv[3];
    vertex_p v, founded_vertex;
    base_mesh_p mesh_base, mesh_skin;
    mesh_tree_tag_p tree_tag, prev_tree_tag;

    tree_tag = model->mesh_tree;
    for(uint16_t i = 0; i < model->mesh_count; i++, tree_tag++)
    {
        if(!tree_tag->mesh_skin)
        {
            continue;
        }
        mesh_base = tree_tag->mesh_base;
        mesh_skin = tree_tag->mesh_skin;
        ch = mesh_skin->skin_map = (uint32_t*)malloc(mesh_skin->vertex_count * sizeof(uint32_t));
        v = mesh_skin->vertices;
        for(uint32_t k = 0; k < mesh_skin->vertex_count; k++, v++, ch++)
        {
            *ch = 0xFFFFFFFF;
            founded_index = BaseMesh_FindVertexIndex(mesh_base, v->position);
            if(founded_index != 0xFFFFFFFF)
            {
                founded_vertex = mesh_base->vertices + founded_index;
                vec3_copy(v->position, founded_vertex->position);
                vec3_copy(v->normal, founded_vertex->normal);
            }
            else
            {
                vec3_add(tv, v->position, tree_tag->offset);
                prev_tree_tag = model->mesh_tree + tree_tag->parent;
                founded_index = BaseMesh_FindVertexIndex(prev_tree_tag->mesh_base, tv);
                if(founded_index != 0xFFFFFFFF)
                {
                    founded_vertex = prev_tree_tag->mesh_base->vertices + founded_index;
                    *ch = founded_index;
                    vec3_sub(v->position, founded_vertex->position, tree_tag->offset);
                    vec3_copy(v->normal, founded_vertex->normal);
                }
            }
        }
    }
}