1 | // Copyright (C) 2011 Kornel Kisielewicz
|
---|
2 | // This file is part of NV Libraries.
|
---|
3 | // For conditions of distribution and use, see copyright notice in nv.hh
|
---|
4 |
|
---|
5 | #include "nv/gfx/skeletal_mesh.hh"
|
---|
6 |
|
---|
7 | #include <glm/gtc/matrix_access.hpp>
|
---|
8 | #include <glm/gtx/matrix_interpolation.hpp>
|
---|
9 | #include "nv/interface/context.hh"
|
---|
10 | #include "nv/interface/device.hh"
|
---|
11 |
|
---|
12 |
|
---|
13 | nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_mesh_data* a_mesh_data )
|
---|
14 | : animated_mesh()
|
---|
15 | , m_mesh_data( a_mesh_data )
|
---|
16 | , m_animation( nullptr )
|
---|
17 | {
|
---|
18 | m_va = a_context->get_device()->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );
|
---|
19 | }
|
---|
20 |
|
---|
21 |
|
---|
22 | void nv::skeletal_mesh::setup_animation( md5_animation* a_anim )
|
---|
23 | {
|
---|
24 | if ( m_animation ) m_animation->reset_animation();
|
---|
25 | m_animation = a_anim;
|
---|
26 | // TODO : INSTANCE!
|
---|
27 | m_animation->reset_animation();
|
---|
28 | }
|
---|
29 |
|
---|
30 | void nv::skeletal_mesh::update( uint32 ms )
|
---|
31 | {
|
---|
32 | if (m_animation != nullptr)
|
---|
33 | {
|
---|
34 | m_animation->update( ms * 0.001f );
|
---|
35 | m_mesh_data->apply( *m_animation );
|
---|
36 | vertex_buffer* vb = m_va->find_buffer( nv::POSITION );
|
---|
37 | const mesh_raw_channel* pch = m_mesh_data->get_channel_data()[0];
|
---|
38 | vb->bind();
|
---|
39 | vb->update( (const void*)pch->data, 0, pch->size );
|
---|
40 | vb->unbind();
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | nv::skeletal_mesh::~skeletal_mesh()
|
---|
45 | {
|
---|
46 | delete m_va;
|
---|
47 | delete m_mesh_data;
|
---|
48 | }
|
---|
49 |
|
---|
50 | void nv::skeletal_mesh::run_animation( animation_entry* a_anim )
|
---|
51 | {
|
---|
52 | skeletal_animation_entry * anim = down_cast<skeletal_animation_entry>(a_anim);
|
---|
53 | // TODO : INSTANCE!
|
---|
54 | setup_animation( anim->m_animation );
|
---|
55 | }
|
---|