source: trunk/src/gfx/skeletal_mesh.cc @ 239

Last change on this file since 239 was 239, checked in by epyon, 11 years ago
  • massive update of mesh handling
  • universal mesh handling routines
  • removed a lot of legacy code
  • significantly streamlined MD5 loading
  • all tests updated to new features
File size: 1.5 KB
Line 
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
13nv::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
22void 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
30void 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
44nv::skeletal_mesh::~skeletal_mesh()
45{
46        delete m_va;
47        delete m_mesh_data;
48}
49
50void 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}
Note: See TracBrowser for help on using the repository browser.