@@ -11,10 +11,7 @@ use binrw::BinReaderExt;
11
11
use binrw:: { binrw, BinWrite , BinWriterExt } ;
12
12
13
13
use crate :: common_file_operations:: { read_bool_from, write_bool_as} ;
14
- use crate :: model_vertex_declarations:: {
15
- vertex_element_parser, vertex_element_writer, VertexDeclaration , VertexType , VertexUsage ,
16
- VERTEX_ELEMENT_SIZE ,
17
- } ;
14
+ use crate :: model_vertex_declarations:: { vertex_element_parser, vertex_element_writer, VertexDeclaration , VertexType , VertexUsage , VERTEX_ELEMENT_SIZE } ;
18
15
use crate :: { ByteBuffer , ByteSpan } ;
19
16
20
17
pub const NUM_VERTICES : u32 = 17 ;
@@ -290,9 +287,9 @@ struct ShapeValue {
290
287
#[ allow( dead_code) ]
291
288
#[ br( import { file_header: & ModelFileHeader } ) ]
292
289
#[ brw( little) ]
293
- struct ModelData {
290
+ pub struct ModelData {
294
291
#[ br( args { vertex_declaration_count: file_header. vertex_declaration_count } ) ]
295
- header : ModelHeader ,
292
+ pub header : ModelHeader ,
296
293
297
294
#[ br( count = header. element_id_count) ]
298
295
element_ids : Vec < ElementId > ,
@@ -373,7 +370,7 @@ struct ElementId {
373
370
rotate : [ f32 ; 3 ] ,
374
371
}
375
372
376
- #[ derive( Clone , Copy , PartialEq ) ]
373
+ #[ derive( Clone , Copy , PartialEq , Debug ) ]
377
374
#[ repr( C ) ]
378
375
pub struct Vertex {
379
376
pub position : [ f32 ; 3 ] ,
@@ -403,47 +400,50 @@ impl Default for Vertex {
403
400
}
404
401
}
405
402
406
- #[ derive( Clone , Copy ) ]
403
+ #[ derive( Debug , Clone , Copy ) ]
407
404
#[ repr( C ) ]
408
405
pub struct NewShapeValue {
409
406
pub base_index : u32 ,
410
407
pub replacing_vertex : Vertex ,
411
408
}
412
409
413
- #[ derive( Clone , Copy ) ]
410
+ #[ derive( Debug , Clone , Copy ) ]
414
411
#[ repr( C ) ]
415
412
pub struct SubMesh {
416
413
submesh_index : usize ,
417
414
pub index_count : u32 ,
418
415
pub index_offset : u32 ,
419
416
}
420
417
421
- #[ derive( Clone ) ]
418
+ #[ derive( Debug , Clone ) ]
422
419
pub struct Shape {
423
420
pub name : String ,
424
421
pub morphed_vertices : Vec < Vertex > ,
425
422
}
426
423
427
424
/// Corresponds to a "Mesh" in an LOD
428
- #[ derive( Clone ) ]
425
+ #[ derive( Debug , Clone ) ]
429
426
pub struct Part {
430
427
mesh_index : u16 ,
431
428
pub vertices : Vec < Vertex > ,
429
+ /// Indexed by VertexElement::stream
430
+ pub vertex_streams : Vec < Vec < u8 > > ,
431
+ pub vertex_stream_strides : Vec < usize > ,
432
432
pub indices : Vec < u16 > ,
433
433
pub material_index : u16 ,
434
434
pub submeshes : Vec < SubMesh > ,
435
435
pub shapes : Vec < Shape > ,
436
436
}
437
437
438
- #[ derive( Clone ) ]
438
+ #[ derive( Debug , Clone ) ]
439
439
pub struct Lod {
440
440
pub parts : Vec < Part > ,
441
441
}
442
442
443
- #[ derive( Clone ) ]
443
+ #[ derive( Debug , Clone ) ]
444
444
pub struct MDL {
445
445
file_header : ModelFileHeader ,
446
- model_data : ModelData ,
446
+ pub model_data : ModelData ,
447
447
448
448
pub lods : Vec < Lod > ,
449
449
pub affected_bone_names : Vec < String > ,
@@ -551,13 +551,7 @@ impl MDL {
551
551
MDL :: read_byte_float4 ( & mut cursor) . unwrap ( ) ;
552
552
}
553
553
VertexType :: Byte4 => {
554
- let bytes = MDL :: read_byte4 ( & mut cursor) . unwrap ( ) ;
555
- vertices[ k as usize ] . bone_weight = [
556
- f32:: from ( bytes[ 0 ] ) ,
557
- f32:: from ( bytes[ 1 ] ) ,
558
- f32:: from ( bytes[ 2 ] ) ,
559
- f32:: from ( bytes[ 3 ] ) ,
560
- ] ;
554
+ vertices[ k as usize ] . bone_weight = MDL :: read_tangent ( & mut cursor) . unwrap ( ) ;
561
555
}
562
556
VertexType :: UnsignedShort4 => {
563
557
let bytes = MDL :: read_unsigned_short4 ( & mut cursor) . unwrap ( ) ;
@@ -779,13 +773,42 @@ impl MDL {
779
773
}
780
774
}
781
775
776
+ let mut vertex_streams = vec ! [ ] ;
777
+ let mut vertex_stream_strides = vec ! [ ] ;
778
+ let mesh = & model. meshes [ j as usize ] ;
779
+ for stream in 0 ..mesh. vertex_stream_count {
780
+ let mut vertex_data = vec ! [ ] ;
781
+ let stride = mesh. vertex_buffer_strides [ stream as usize ] ;
782
+ for z in 0 ..mesh. vertex_count {
783
+ // TODO: read the entire vertex data into a buffer
784
+ // Handle the offsets within Novus itself
785
+ cursor
786
+ . seek ( SeekFrom :: Start (
787
+ ( model. lods [ i as usize ] . vertex_data_offset
788
+ + model. meshes [ j as usize ] . vertex_buffer_offsets
789
+ [ stream as usize ]
790
+ + ( z as u32 * stride as u32 ) ) as u64 ,
791
+ ) )
792
+ . ok ( ) ?;
793
+
794
+ for _ in 0 ..stride {
795
+ vertex_data. push ( cursor. read_le :: < u8 > ( ) . ok ( ) ?) ;
796
+ }
797
+ }
798
+
799
+ vertex_streams. push ( vertex_data) ;
800
+ vertex_stream_strides. push ( mesh. vertex_buffer_strides [ stream as usize ] as usize ) ;
801
+ }
802
+
782
803
parts. push ( Part {
783
804
mesh_index : j,
784
805
vertices,
785
806
indices,
786
807
material_index,
787
808
submeshes,
788
809
shapes,
810
+ vertex_streams,
811
+ vertex_stream_strides
789
812
} ) ;
790
813
}
791
814
@@ -1019,6 +1042,13 @@ impl MDL {
1019
1042
1020
1043
match element. vertex_usage {
1021
1044
VertexUsage :: Position => match element. vertex_type {
1045
+ VertexType :: Single4 => {
1046
+ MDL :: write_single4 (
1047
+ & mut cursor,
1048
+ & MDL :: pad_slice ( & vert. position , 1.0 ) ,
1049
+ )
1050
+ . ok ( ) ?;
1051
+ }
1022
1052
VertexType :: Half4 => {
1023
1053
MDL :: write_half4 (
1024
1054
& mut cursor,
@@ -1041,6 +1071,10 @@ impl MDL {
1041
1071
MDL :: write_byte_float4 ( & mut cursor, & vert. bone_weight )
1042
1072
. ok ( ) ?;
1043
1073
}
1074
+ VertexType :: Byte4 => {
1075
+ MDL :: write_byte_float42 ( & mut cursor, & vert. bone_weight )
1076
+ . ok ( ) ?; // TODO: WRONG!
1077
+ }
1044
1078
_ => {
1045
1079
panic ! (
1046
1080
"Unexpected vertex type for blendweight: {:#?}" ,
0 commit comments