- Timestamp:
- 09/17/15 17:19:14 (10 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/formats/nmd_loader.hh
r431 r470 65 65 { 66 66 uint16 frame_rate; 67 float duration;67 uint16 frame_count; 68 68 bool flat; 69 69 }; -
trunk/nv/gfx/animation.hh
r454 r470 117 117 return keyfresult; 118 118 } 119 index0 = math::clamp( int( time ), 0, int( channel.size() ) - 2);119 index0 = math::clamp( int( time ), 0, int( channel.size() ) - 1 ); 120 120 index1 = index0 + 1; 121 if ( index1 == int( channel.size() ) ) index1 = 0; 121 122 factor = math::clamp( time - index0, 0.0f, 1.0f ); 122 123 } -
trunk/nv/gfx/keyframed_mesh.hh
r430 r470 26 26 virtual transform get_node_transform( uint32 node_id ) const; 27 27 virtual mat4 get_node_matrix( uint32 node_id ) const; 28 virtual void update_animation( animation_entry*, uint32 a_ anim_time );28 virtual void update_animation( animation_entry*, uint32 a_ms_anim_time ); 29 29 virtual void update( program a_program ); 30 30 virtual ~keyframed_mesh(); -
trunk/nv/gfx/skeletal_mesh.hh
r467 r470 21 21 public: 22 22 skeletal_animation_entry( shash64 name, const mesh_nodes_data* anim, bool a_looping ) 23 : animation_entry( name, a_looping, anim->get_f rame_rate(), 0.0f, anim->get_duration() )23 : animation_entry( name, a_looping, anim->get_fps(), 0, anim->get_frame_count() ) 24 24 , m_node_data( anim ) 25 25 { … … 27 27 } 28 28 29 skeletal_animation_entry( shash64 name, const mesh_nodes_data* anim, float time_start, floattime_end, bool a_looping )30 : animation_entry( name, a_looping, anim->get_f rame_rate(), time_start, time_end )29 skeletal_animation_entry( shash64 name, const mesh_nodes_data* anim, uint32 time_start, uint32 time_end, bool a_looping ) 30 : animation_entry( name, a_looping, anim->get_fps(), time_start, time_end ) 31 31 , m_node_data( anim ) 32 32 { … … 35 35 36 36 void prepare( const mesh_nodes_data* bones ); 37 void update_skeleton( mat4* tr, uint32 time ) const;37 void update_skeleton( mat4* tr, uint32 a_ms_time ) const; 38 38 ~skeletal_animation_entry(); 39 39 40 protected: 40 41 void initialize(); … … 46 47 sint16* m_bone_ids; 47 48 mat4* m_offsets; 49 uint32 m_root; 48 50 bool m_prepared; 49 51 data_descriptor m_interpolation_key; … … 65 67 virtual transform get_node_transform( uint32 node_id ) const; 66 68 virtual mat4 get_node_matrix( uint32 node_id ) const; 69 virtual sint16 get_parent_id() const { return m_parent_id; } 70 virtual uint32 get_node_count() const { return m_bone_data ? m_bone_data->size() : 0; } 67 71 ~skeletal_mesh() 68 72 { … … 77 81 uint32 m_index_count; 78 82 mat4* m_transform; 83 sint16 m_parent_id; 79 84 }; 80 85 -
trunk/nv/interface/animated_mesh.hh
r468 r470 25 25 { 26 26 public: 27 animation_entry( shash64 name, bool looping, uint32 frame_rate, float a_start, float a_end ) : m_name( name ), m_looping( looping ), m_frame_rate( frame_rate ),28 m_ start( a_start ), m_end( a_end ), m_duration( m_end - m_start) {}27 animation_entry( shash64 name, bool looping, uint32 frame_rate, uint32 a_start, uint32 a_end ) : m_name( name ), m_looping( looping ), m_fps( frame_rate ), 28 m_fstart( a_start ), m_fend( a_end ) {} 29 29 shash64 get_name() const { return m_name; } 30 uint32 get_frame_rate() const { return m_frame_rate; } 31 float get_duration() const { return m_duration; } 32 float get_start() const { return m_start; } 33 float get_end() const { return m_end; } 30 uint32 get_fps() const { return m_fps; } 31 // TODO : if loop +1? 32 uint32 get_frame_count() const { int todo; return m_fend - m_fstart; } 33 uint32 get_start_frame() const { return m_fstart; } 34 uint32 get_end_frame() const { return m_fend; } 34 35 bool is_looping() const { return m_looping; } 35 void set_ range( float a_start, floata_end )36 void set_frame_range( uint32 a_start, uint32 a_end ) 36 37 { 37 m_start = a_start; 38 m_end = a_end; 39 m_duration = m_end - m_start; 38 m_fstart = a_start; 39 m_fend = a_end; 40 40 } 41 void set_f rame_rate( uint32 rate )41 void set_fps( uint32 rate ) 42 42 { 43 m_f rame_rate= rate;43 m_fps = rate; 44 44 } 45 45 virtual ~animation_entry() {} 46 46 protected: 47 shash64 m_name; 48 bool m_looping; 49 uint32 m_frame_rate; 50 float m_start; 51 float m_end; 52 float m_duration; 47 shash64 m_name; /// string hash of name 48 bool m_looping; /// does the animation loop 49 uint32 m_fps; /// frames per second 50 uint32 m_fstart; /// start time (in frames) 51 uint32 m_fend; /// end time (in frames) 53 52 }; 54 53 … … 61 60 virtual transform get_node_transform( uint32 ) const { return transform(); } 62 61 virtual mat4 get_node_matrix( uint32 ) const { return mat4(); } 62 virtual uint32 get_node_count() const { return 0; } 63 virtual sint16 get_parent_id() const { return -1; } 64 63 65 }; 64 66 -
trunk/nv/interface/mesh_data.hh
r457 r470 33 33 34 34 explicit mesh_nodes_data( shash64 name ) 35 : m_name( name ), m_frame_rate(0), m_ duration(0.0f), m_flat( false )35 : m_name( name ), m_frame_rate(0), m_frame_count(0), m_flat( false ) 36 36 { 37 37 } 38 38 39 explicit mesh_nodes_data( shash64 name, uint16 a_fps, floata_frames, bool a_flat )40 : m_name( name ), m_frame_rate(a_fps), m_ duration(a_frames), m_flat( a_flat )39 explicit mesh_nodes_data( shash64 name, uint16 a_fps, uint16 a_frames, bool a_flat ) 40 : m_name( name ), m_frame_rate(a_fps), m_frame_count(a_frames), m_flat( a_flat ) 41 41 { 42 42 } … … 84 84 85 85 bool is_flat() const { return m_flat; } 86 uint16 get_f rame_rate() const { return m_frame_rate; }87 float get_duration() const { return m_duration; }86 uint16 get_fps() const { return m_frame_rate; } 87 uint16 get_frame_count() const { return m_frame_count; } 88 88 shash64 get_name() const { return m_name; } 89 89 … … 97 97 shash64 m_name; 98 98 uint16 m_frame_rate; 99 float m_duration;99 uint16 m_frame_count; 100 100 bool m_flat; 101 101 }; -
trunk/src/formats/assimp_loader.cc
r454 r470 350 350 351 351 uint16 frame_rate = static_cast<uint16>( anim->mTicksPerSecond ); 352 float duration = static_cast<float>( anim->mDuration ); 352 int check_this; 353 uint16 duration = static_cast<uint16>( anim->mDuration ); 353 354 bool flat = false; 354 355 -
trunk/src/formats/nmd_loader.cc
r442 r470 98 98 nmd_animation_header animation_header; 99 99 source.read( &animation_header, sizeof( animation_header ), 1 ); 100 m_node_data = new mesh_nodes_data( e.name, animation_header.frame_rate, animation_header. duration, animation_header.flat );100 m_node_data = new mesh_nodes_data( e.name, animation_header.frame_rate, animation_header.frame_count, animation_header.flat ); 101 101 for ( uint32 i = 0; i < e.children; ++i ) 102 102 { … … 215 215 216 216 nmd_animation_header aheader; 217 aheader.frame_rate = nodes.get_frame_rate();218 aheader. duration = nodes.get_duration();217 aheader.frame_rate = nodes.get_fps(); 218 aheader.frame_count = nodes.get_frame_count(); 219 219 aheader.flat = nodes.is_flat(); 220 220 stream_out.write( &aheader, sizeof( aheader ), 1 ); -
trunk/src/gfx/keyframed_mesh.cc
r454 r470 72 72 } 73 73 74 void nv::keyframed_mesh::update_animation( animation_entry* anim, uint32 a_ anim_time )74 void nv::keyframed_mesh::update_animation( animation_entry* anim, uint32 a_ms_anim_time ) 75 75 { 76 76 if ( m_active ) 77 77 { 78 float tick_time = ( static_cast<float>( a_anim_time ) * 0.001f ) * anim->get_frame_rate(); 79 float duration = anim->is_looping() ? anim->get_duration() + 1.0f : anim->get_duration(); 80 if ( tick_time >= duration ) 78 float fframe = ( static_cast<float>( a_ms_anim_time ) * 0.001f ) * anim->get_fps(); 79 uint32 frame = uint32( fframe ); 80 float reminder = fframe - static_cast<float>( frame ); 81 uint32 duration = anim->is_looping() ? anim->get_frame_count() + 1 : anim->get_frame_count(); 82 83 if ( frame >= duration ) 81 84 { 82 85 if ( anim->is_looping() ) 83 86 { 84 tick_time = fmodf( tick_time, duration ); 87 frame = frame % duration; 88 fframe = static_cast<float>( frame ) + reminder; 85 89 } 86 90 else 87 91 { 88 m_active = false;89 m_last_frame = static_cast<uint32>( anim->get_end());90 m_next_frame = m_last_frame;92 m_active = false; 93 m_last_frame = anim->get_end_frame(); 94 m_next_frame = m_last_frame; 91 95 m_interpolation = 0.0f; 92 96 return; 93 97 } 94 98 } 95 m_last_frame = static_cast<uint32>( math::floor( tick_time ) + anim->get_start());99 m_last_frame = frame + anim->get_start_frame(); 96 100 m_next_frame = m_last_frame + 1; 97 if ( m_next_frame > static_cast<uint32>( anim->get_end() ) ) m_next_frame = static_cast<uint32>( anim->get_start());98 m_interpolation = tick_time - math::floor( tick_time );101 if ( m_next_frame > anim->get_end_frame() ) m_next_frame = anim->get_start_frame(); 102 m_interpolation = reminder; 99 103 } 100 104 } -
trunk/src/gfx/mesh_creator.cc
r458 r470 9 9 #include "nv/interface/data_channel_access.hh" 10 10 11 #include "nv/core/logging.hh" 12 11 13 struct nv_key_transform { nv::transform tform; }; 12 14 … … 16 18 merge_keys(); 17 19 uint32 max_frames = 0; 18 for ( auto keys : m_data->m_data ) 19 { 20 21 nv::vector< sint16 > ids; 22 { 23 // TODO: simplify this shit! 24 // The complexity here is that we cannot pre-transform in any order 25 // as the bones depend on previous bones, but ARE NOT IN ORDER 26 // 27 // Either rewrite this a lot nicer, or sort the bones on creation 28 // by tree-order. 29 30 ids.reserve( m_data->m_data.size() ); 31 { 32 nv::vector< sint16 > ids_next; 33 ids_next.reserve( m_data->m_data.size() ); 34 ids_next.push_back( -1 ); 35 while ( !ids_next.empty() ) 36 { 37 sint16 pid = ids_next.back(); 38 ids_next.pop_back(); 39 for ( sint16 i = 0; i < sint16(m_data->m_data.size()); ++i ) 40 if ( m_data->m_data[i]->get_parent_id() == pid ) 41 { 42 sint16* it = nv::find( ids.begin(), ids.end(), i ); 43 if ( it == ids.end() ) 44 { 45 ids.push_back( i ); 46 ids_next.push_back( i ); 47 } 48 } 49 } 50 } 51 52 if ( ids.size() != m_data->m_data.size() ) 53 { 54 NV_LOG_WARNING( "Bad skeleton!" ); 55 } 56 } 57 58 NV_LOG_DEBUG( "ID/PID" ); 59 for ( auto id : ids ) 60 { 61 data_channel_set* keys = m_data->m_data[id]; 20 62 sint16 parent_id = keys->get_parent_id(); 21 data_channel_set* pkeys = ( parent_id != -1 ? m_data->m_data[parent_id] : nullptr ); 63 NV_LOG_DEBUG( "Id : ", id, " PID", parent_id ); 64 data_channel_set* pkeys = ( parent_id != -1 ? m_data->m_data[parent_id] : nullptr ); 22 65 size_t count = ( keys ? keys->get_channel_size(0) : 0 ); 23 66 size_t pcount = ( pkeys ? pkeys->get_channel_size(0) : 0 ); … … 26 69 { 27 70 data_channel_access< nv_key_transform > channel_creator( keys, 0 ); 71 28 72 nv_key_transform* channel = channel_creator.data(); 29 73 const nv_key_transform* pchannel = pkeys->get_channel(0)->data_cast< nv_key_transform >(); … … 38 82 if ( m_data->m_frame_rate == 1 ) 39 83 { 40 m_data->m_frame_rate = 32;41 m_data->m_ duration = static_cast<float>( max_frames );84 m_data->m_frame_rate = 32; 85 m_data->m_frame_count = max_frames; 42 86 } 43 87 -
trunk/src/gfx/skeletal_mesh.cc
r467 r470 13 13 void nv::skeletal_animation_entry::initialize() 14 14 { 15 m_root = uint32(-1); 15 16 m_prepared = false; 16 17 m_children = nullptr; … … 30 31 m_children[ node->get_parent_id()].push_back( n ); 31 32 } 32 } 33 } 34 } 35 36 void nv::skeletal_animation_entry::update_skeleton( mat4* data, uint32 time ) const 37 { 38 float tick_time = ( time * 0.001f ) * m_frame_rate; 39 float anim_time = m_start; 40 if ( m_duration > 0.0f ) anim_time += fmodf( tick_time, m_duration ); 33 else 34 { 35 if ( m_root >= 0 ) 36 { 37 m_root = uint32( -2 ); 38 } 39 else 40 m_root = n; 41 } 42 } 43 NV_ASSERT( m_root != uint32( -1 ), "Animation without root!" ); 44 } 45 } 46 47 void nv::skeletal_animation_entry::update_skeleton( mat4* data, uint32 a_ms_time ) const 48 { 49 float fframe = ( a_ms_time * 0.001f ) * m_fps; 50 uint32 frame = math::floor( fframe ); 51 float reminder = fframe - static_cast<float>( frame ); 52 uint32 duration = get_frame_count(); 53 if ( duration == 0 ) 54 { 55 frame = get_start_frame(); 56 fframe = static_cast<float>( frame ); 57 } 58 else if ( frame >= duration ) 59 { 60 if ( is_looping() ) 61 { 62 frame = frame % duration; 63 fframe = static_cast<float>( frame ) + reminder; 64 } 65 else 66 { 67 frame = get_end_frame(); 68 fframe = static_cast<float>( frame ); 69 } 70 } 41 71 42 72 if ( !m_node_data->is_flat() ) 43 73 { 44 animate_rec( data, anim_time, 0, mat4() ); 74 if ( m_root == uint32( -2 ) ) // multi-root 75 { 76 for ( uint32 n = 0; n < m_node_data->size(); ++n ) 77 if ( ( *m_node_data )[n]->get_parent_id() == -1 ) 78 animate_rec( data, fframe, n, mat4() ); 79 } 80 else 81 animate_rec( data, fframe, m_root, mat4() ); 45 82 return; 46 83 } … … 55 92 { 56 93 raw_channel_interpolator interpolator( node, m_interpolation_key ); 57 node_mat = interpolator.get< mat4 >( anim_time );94 node_mat = interpolator.get< mat4 >( fframe ); 58 95 } 59 96 … … 66 103 { 67 104 if ( m_prepared ) return; 68 unordered_map< uint64, uint16 > bone_names;105 nv::hash_store< shash64, uint16 > bone_names; 69 106 m_offsets = new mat4[ bones->size() ]; 70 107 for ( nv::uint16 bi = 0; bi < bones->size(); ++bi ) 71 108 { 72 109 const data_channel_set* bone = (*bones)[ bi ]; 73 bone_names[ bone->get_name() .value()] = bi;110 bone_names[ bone->get_name() ] = bi; 74 111 m_offsets[bi] = bone->get_transform(); 75 112 } … … 80 117 sint16 bone_id = -1; 81 118 82 auto bi = bone_names.find( node->get_name() .value());119 auto bi = bone_names.find( node->get_name() ); 83 120 if ( bi != bone_names.end() ) 84 121 { … … 129 166 130 167 nv::skeletal_mesh::skeletal_mesh( context* a_context, const data_channel_set* a_mesh, const mesh_nodes_data* a_bone_data ) 131 : m_context( a_context ), m_bone_data( a_bone_data ), m_index_count( 0 ), m_transform( nullptr ) 168 : m_context( a_context ), m_bone_data( a_bone_data ), m_index_count( 0 ), m_transform( nullptr ), m_parent_id(-1) 132 169 { 133 170 if ( a_mesh ) … … 135 172 m_va = a_context->create_vertex_array( a_mesh, nv::STATIC_DRAW ); 136 173 m_index_count = a_mesh->get_channel_size( slot::INDEX ); 174 m_parent_id = a_mesh->get_parent_id(); 137 175 } 138 176 if ( m_bone_data ) -
trunk/src/wx/wx_canvas.cc
r467 r470 6 6 7 7 #include <nv/wx/wx_canvas.hh> 8 9 #include <nv/core/time.hh> 8 10 9 11 wxBEGIN_EVENT_TABLE( nv::wx_gl_canvas, wxWindow ) … … 51 53 void nv::wx_gl_canvas::on_idle( wxIdleEvent& evt ) 52 54 { 55 nv::sleep( 10 ); 53 56 if ( m_render ) 54 57 {
Note: See TracChangeset
for help on using the changeset viewer.