MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / LoadModel_o3

Function LoadModel_o3

PanzerChasm/model.cpp:109–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109void LoadModel_o3( const Vfs::FileContent& model_file, const Vfs::FileContent& animation_file, Model& out_model )
110{
111 ClearModel( out_model );
112
113 unsigned short polygon_count;
114 unsigned short vertex_count;
115 unsigned short texture_height;
116
117 std::memcpy( &vertex_count , model_file.data() + 0x4800u, sizeof(unsigned short ) );
118 std::memcpy( &polygon_count , model_file.data() + 0x4802u, sizeof(unsigned short ) );
119 std::memcpy( &texture_height, model_file.data() + 0x4804u, sizeof(unsigned short ) );
120
121 const unsigned int v_offset_shift= texture_height & ~1023u;
122 texture_height&= 1023u;
123
124 // Texture
125 out_model.texture_size[0]= g_3o_model_texture_width;
126 out_model.texture_size[1]= texture_height;
127
128 out_model.texture_data.resize( g_3o_model_texture_width * texture_height );
129 std::memcpy(
130 out_model.texture_data.data(),
131 model_file.data() + 0x4806u,
132 out_model.texture_data.size() );
133
134
135 PC_ASSERT( model_file.size() == out_model.texture_data.size() + 0x4806u );
136
137 // Geometry
138 const Polygon_o3* const polygons= reinterpret_cast<const Polygon_o3*>( model_file.data() + 0x00u );
139
140 const unsigned char* const in_vertices_data=
141 animation_file.empty()
142 ? ( model_file.data() + 0x3200u )
143 : ( animation_file.data() + 0x02u );
144 const Vertex_o3* const vertices= reinterpret_cast<const Vertex_o3*>( in_vertices_data );
145
146 CalculateModelZ(
147 out_model,
148 reinterpret_cast<const Vertex_o3*>( model_file.data() + 0x3200u ),
149 vertex_count );
150
151 out_model.frame_count=
152 animation_file.empty()
153 ? 1u
154 : ( animation_file.size() - 2u ) / ( vertex_count * sizeof(Vertex_o3) );
155
156 out_model.animations_vertices.resize( out_model.frame_count * vertex_count );
157 for( unsigned int v= 0u; v < out_model.animations_vertices.size(); v++ )
158 {
159 for( unsigned int j= 0u; j < 3; j++ )
160 out_model.animations_vertices[v].pos[j]= vertices[v].xyz[j];
161 }
162
163 unsigned int current_vertex_index= 0u;
164
165 for( unsigned int p= 0u; p < polygon_count; p++ )
166 {

Callers 6

LoadItemsModelsFunction · 0.85
LoadWeaponsModelsFunction · 0.85
LoadRocketsModelsFunction · 0.85
LoadGibsModelsFunction · 0.85
LoadModelsMethod · 0.85
CutscenePlayerMethod · 0.85

Calls 3

ClearModelFunction · 0.85
CalculateModelZFunction · 0.85
CalculateBoundingBoxFunction · 0.85

Tested by

no test coverage detected