Changeset 502

Show
Ignore:
Timestamp:
02/12/08 17:03:35 (11 months ago)
Author:
phill
Message:

o X42_VER_V6 write code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/morph-targets/libx42.net/Enums.h

    r469 r502  
    5555{ 
    5656        Version5                                = X42_VER_V5, 
     57        Version6                                = X42_VER_V6, 
    5758 
    5859        CurrentVersion                  = X42_CURRENT_VERSION, 
  • branches/morph-targets/libx42/include/x42.h

    r501 r502  
    369369} x42outStream_t; 
    370370 
    371 #define X42_SAVE_VER X42_VER_V5 
     371#define X42_SAVE_VER X42_VER_V6 
    372372 
    373373/* 
  • branches/morph-targets/libx42/write.c

    r501 r502  
    2222 
    2323#include "local.h" 
    24  
    25 static void fix_persist_flags( uint *pf, const x42data_t *x42 ); 
    26  
    27 X42_EXPORT size_t X42_CALL x42_GetFileSize( const x42data_t *x42, uint persistFlags ) 
    28 { 
    29         uint i; 
    30  
    31         size_t ret = 0; 
    32         const x42header_t *h; 
    33  
    34 #ifndef LIBX42_NO_PARAM_VALIDATION 
    35         demand_rz( x42 != NULL, X42_ERR_BADPTR, "Expected valid x42data_t pointer, got NULL instead." ); 
    36         demand_rz( x42_ValidateHeader( &x42->header ), X42_ERR_BADDATA, "Invalid x42 file header." ); 
    37 #endif 
    38  
    39         h = &x42->header; 
    40  
    41         switch( h->ident.version ) 
    42         { 
    43         case X42_VER_V5: 
    44                 ret += sizeof( x42Header_v5_t ); 
    45                 break; 
    46  
    47         default: 
    48                 return 0; 
    49         } 
    50  
    51         fix_persist_flags( &persistFlags, x42 ); 
    52  
    53         ret = align( ret, 8 ); 
    54         ret += sizeof( x42Bone_v5_t ) * h->numBones; 
    55         ret = align( ret, 8 ); 
    56         ret += sizeof( x42AnimGroup_v5_t ) * h->numAnimGroups; 
    57  
    58         ret += sizeof( u16[3] ) * h->numPosValues; 
    59         if( h->modelFlags & X42_MF_UNIFORM_SCALE ) 
    60                 ret += sizeof( u16 ) * h->numScaleValues; 
    61         else 
    62                 ret += sizeof( u16[3] ) * h->numScaleValues; 
    63         ret += sizeof( s16[4] ) * h->numRotValues; 
    64  
    65         ret = align( ret, 8 ); 
    66         ret += sizeof( x42KeyStreamEntry_v5_t ) * h->keyStreamLength; 
    67         ret = align( ret, 8 ); 
    68         ret += sizeof( x42Animation_v5_t ) * h->numAnims; 
    69  
    70         ret = align( ret, 8 ); 
    71         ret += sizeof( x42Tag_v5_t ) * h->numTags; 
    72         ret = align( ret, 8 ); 
    73         ret += sizeof( x42Influence_v5_t ) * h->numInfluences; 
    74  
    75         ret = align( ret, 8 ); 
    76         ret += sizeof( x42LodRange_v5_t ) * h->numLods; 
    77         ret = align( ret, 8 ); 
    78         ret += sizeof( x42Group_v5_t ) * h->numGroups; 
    79  
    80         ret = align( ret, 2 ); 
    81         ret += sizeof( u16[3] ) * h->numVerts; 
    82         for( i = 0; i < h->numGroups; i++ ) 
    83         { 
    84                 if( x42->groups[i].maxVertInfluences ) 
    85                         ret += sizeof( u8 ) * ((x42->groups[i].maxVertInfluences - 1) * 2 + 1); 
    86         } 
    87  
    88         if( persistFlags & X42_PERSIST_NORMALS ) 
    89                 ret += sizeof( s8[3] ) * h->numVerts; 
    90  
    91         if( persistFlags & X42_PERSIST_TANGENT_BASIS ) 
    92                 ret += sizeof( s8[7] ) * h->numVerts; 
    93  
    94         if( persistFlags & X42_PERSIST_TEXTURE_COORDINATES ) 
    95         { 
    96                 ret = align( ret, 2 ); 
    97                 ret += sizeof( u16[2] ) * h->numVerts; 
    98         }                                                 
    99  
    100         if( persistFlags & X42_PERSIST_COLORS ) 
    101         { 
    102                 ret = align( ret, 4 ); 
    103                 ret += sizeof( rgba_t ) * h->numVerts; 
    104         } 
    105          
    106         ret = align( ret, 4 ); 
    107         ret += sizeof( x42index_t ) * h->numIndices; 
    108  
    109         return ret; 
    110 } 
    11124 
    11225static void fix_persist_flags( uint *pf, const x42data_t *x42 ) 
     
    12235} 
    12336 
    124 static void translate_header( x42Header_v5_t *out, const x42data_t *x42, uint persistFlags ) 
     37X42_EXPORT size_t X42_CALL x42_GetFileSize( const x42data_t *x42, uint persistFlags ) 
     38
     39        uint i; 
     40 
     41        size_t ret = 0; 
     42        const x42header_t *h; 
     43 
     44#ifndef LIBX42_NO_PARAM_VALIDATION 
     45        demand_rz( x42 != NULL, X42_ERR_BADPTR, "Expected valid x42data_t pointer, got NULL instead." ); 
     46        demand_rz( x42_ValidateHeader( &x42->header ), X42_ERR_BADDATA, "Invalid x42 file header." ); 
     47#endif 
     48 
     49        h = &x42->header; 
     50 
     51        ret += sizeof( x42Header_v6_t ); 
     52        ret += sizeof( x42PackHeader_v6_t ); 
     53 
     54        fix_persist_flags( &persistFlags, x42 ); 
     55 
     56        ret = align( ret, 8 ); 
     57        ret += sizeof( x42Bone_v5_t ) * h->numBones; 
     58        ret = align( ret, 8 ); 
     59        ret += sizeof( x42AnimGroup_v5_t ) * h->numAnimGroups; 
     60 
     61        ret += sizeof( u16[3] ) * h->numPosValues; 
     62        if( h->modelFlags & X42_MF_UNIFORM_SCALE ) 
     63                ret += sizeof( u16 ) * h->numScaleValues; 
     64        else 
     65                ret += sizeof( u16[3] ) * h->numScaleValues; 
     66        ret += sizeof( s16[4] ) * h->numRotValues; 
     67 
     68        ret = align( ret, 8 ); 
     69        ret += sizeof( x42KeyStreamEntry_v5_t ) * h->keyStreamLength; 
     70        ret = align( ret, 8 ); 
     71        ret += sizeof( x42Animation_v5_t ) * h->numAnims; 
     72 
     73        ret = align( ret, 8 ); 
     74        ret += sizeof( x42Tag_v5_t ) * h->numTags; 
     75        ret = align( ret, 8 ); 
     76        ret += sizeof( x42Influence_v5_t ) * h->numInfluences; 
     77 
     78        ret = align( ret, 8 ); 
     79        ret += sizeof( x42LodRange_v5_t ) * h->numLods; 
     80        ret = align( ret, 8 ); 
     81        ret += sizeof( x42Group_v5_t ) * h->numGroups; 
     82 
     83        ret = align( ret, 2 ); 
     84        ret += sizeof( u16[3] ) * h->numVerts; 
     85        for( i = 0; i < h->numGroups; i++ ) 
     86        { 
     87                if( x42->groups[i].maxVertInfluences ) 
     88                        ret += sizeof( u8 ) * ((x42->groups[i].maxVertInfluences - 1) * 2 + 1); 
     89        } 
     90 
     91        if( persistFlags & X42_PERSIST_NORMALS ) 
     92                ret += sizeof( s8[3] ) * h->numVerts; 
     93 
     94        if( persistFlags & X42_PERSIST_TANGENT_BASIS ) 
     95                ret += sizeof( s8[7] ) * h->numVerts; 
     96 
     97        if( persistFlags & X42_PERSIST_TEXTURE_COORDINATES ) 
     98        { 
     99                ret = align( ret, 2 ); 
     100                ret += sizeof( u16[2] ) * h->numVerts; 
     101        }                                                 
     102 
     103        if( persistFlags & X42_PERSIST_COLORS ) 
     104        { 
     105                ret = align( ret, 4 ); 
     106                ret += sizeof( rgba_t ) * h->numVerts; 
     107        } 
     108         
     109        ret = align( ret, 4 ); 
     110        ret += sizeof( x42index_t ) * h->numIndices; 
     111 
     112        return ret; 
     113
     114 
     115static void translate_header( x42Header_v6_t *out, const x42data_t *x42, uint persistFlags ) 
    125116{ 
    126117        const x42header_t *in = &x42->header; 
     
    157148        out->numLods = in->numLods; 
    158149        out->numGroups = in->numGroups; 
     150        out->numMorphTargets = in->numMorphTargets; 
    159151 
    160152        out->numVerts = in->numVerts; 
    161153        out->numIndices = in->numIndices; 
     154        out->numMorphDeltas = in->numMorphDeltas; 
    162155 
    163156        out->boundingSphere = in->boundingSphere; 
     
    213206} 
    214207 
    215 static void get_pack_header( x42PackHeader_v5_t *pack, 
    216         const x42Header_v5_t *h, const x42data_t *x42 ) 
     208static void get_pack_header( x42PackHeader_v6_t *pack, 
     209        const x42Header_v6_t *h, const x42data_t *x42 ) 
    217210{ 
    218211        vec2_t bounds[3]; 
     
    232225        if( x42->vertTc ) 
    233226                get_stream_bounds( pack->vertTcPack, 2, (float*)x42->vertTc, h->numVerts, sizeof( vec2_t ) ); 
     227 
     228        get_stream_bounds( pack->morphPosPack, 3, (float*)x42->morphPos, h->numMorphDeltas, sizeof( vec4_t ) ); 
    234229} 
    235230 
     
    414409 
    415410        x42Header_ident_t ident; 
    416         x42Header_v5_t wh; 
    417         x42PackHeader_v5_t pack; 
     411        x42Header_v6_t wh; 
     412        x42PackHeader_v6_t pack; 
    418413 
    419414#ifndef LIBX42_NO_PARAM_VALIDATION 
     
    426421 
    427422        ident = h->ident; 
    428         ident.version = X42_VER_V5
     423        ident.version = X42_VER_V6
    429424 
    430425        fix_persist_flags( &persist_flags, x42 ); 
     
    508503        checked_write_a( x42->lods, sizeof( x42LodRange_v5_t ) * h->numLods, 8 ); 
    509504        checked_write_a( x42->groups, sizeof( x42Group_v5_t ) * h->numGroups, 8 ); 
     505        checked_write_a( x42->morphTargets, sizeof( x42morphTarget_t ) * h->numMorphTargets, 8 ); 
    510506 
    511507        checked_align( 2 ); 
     
    572568        checked_write_a( x42->indices, sizeof( x42index_t ) * h->numIndices, 4 ); 
    573569 
     570        checked_write_a( x42->morphIndices, sizeof( x42index_t ) * h->numIndices, 4 ); 
     571 
     572        checked_align( 2 ); 
     573        stat = write_packed_floats( file_stream, &outPos, pack.morphPosPack, 3, 
     574                (float*)x42->morphPos, h->numMorphDeltas, sizeof( vec4_t ) ); 
     575        write_check(); 
     576 
     577        if( persist_flags & X42_PERSIST_NORMALS ) 
     578        { 
     579                stat = write_packed_floats_s8n( file_stream, &outPos, 3, 
     580                        (float*)&x42->morphNorm[0].norm, h->numMorphDeltas, sizeof( x42morphNormal_t ) ); 
     581                write_check(); 
     582        } 
     583 
     584        if( persist_flags & X42_PERSIST_TANGENT_BASIS ) 
     585        { 
     586                stat = write_packed_floats_s8n( file_stream, &outPos, 7, 
     587                        (float*)&x42->morphTan[0].tan, h->numMorphDeltas, sizeof( x42morphTangent_t ) ); 
     588                write_check(); 
     589        } 
     590 
    574591        checked_write( x42->strings, sizeof( u8 ) * h->nameBlobLen ); 
    575592