[227] | 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 |
|
---|
[239] | 13 | nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_mesh_data* a_mesh_data )
|
---|
[231] | 14 | : animated_mesh()
|
---|
[239] | 15 | , m_mesh_data( a_mesh_data )
|
---|
[227] | 16 | , m_animation( nullptr )
|
---|
| 17 | {
|
---|
[239] | 18 | m_va = a_context->get_device()->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );
|
---|
| 19 | }
|
---|
[227] | 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;
|
---|
[230] | 26 | // TODO : INSTANCE!
|
---|
[227] | 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 );
|
---|
[239] | 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();
|
---|
[227] | 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[230] | 44 | nv::skeletal_mesh::~skeletal_mesh()
|
---|
[227] | 45 | {
|
---|
[230] | 46 | delete m_va;
|
---|
[239] | 47 | delete m_mesh_data;
|
---|
[227] | 48 | }
|
---|
| 49 |
|
---|
[230] | 50 | void nv::skeletal_mesh::run_animation( animation_entry* a_anim )
|
---|
[227] | 51 | {
|
---|
[230] | 52 | skeletal_animation_entry * anim = down_cast<skeletal_animation_entry>(a_anim);
|
---|
| 53 | // TODO : INSTANCE!
|
---|
| 54 | setup_animation( anim->m_animation );
|
---|
[227] | 55 | }
|
---|