Changeset 593

Show
Ignore:
Timestamp:
07/03/08 17:12:32 (5 months ago)
Author:
phill
Message:

o Root offset fixes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/morph-targets/libx42/anim-skin.c

    r500 r593  
    191191        const x42data_t *x42, uint groupNum, const affine_t *boneMats ) 
    192192{ 
    193         uint i
     193        uint i, maxInfs
    194194        const x42group_t *grp; 
    195195        affine_t infs[X42_MAX_INFLUENCES_PER_BATCH_V5]; 
     
    206206                        affine_cpy( infs + i, &inf->meshToBone ); 
    207207        } 
     208 
     209        maxInfs = grp->maxVertInfluences > 0 ? grp->maxVertInfluences : 1; 
    208210 
    209211        if( oTan || oBin || !x42->vertNorm ) 
     
    223225                        oTan = &nullStream; 
    224226 
    225                 skin_verts_pntb( infs, grp->numInfluences, grp->maxVertInfluences, 
     227                skin_verts_pntb( infs, grp->numInfluences, maxInfs, 
    226228                        iPos, x42->vertPos + grp->firstVert, iTan, grp->numVerts, oPos, oNorm, oTan, oBin ); 
    227229        } 
    228230        else if( oNorm ) 
    229231        { 
    230                 skin_verts_pn( infs, grp->numInfluences, grp->maxVertInfluences, 
     232                skin_verts_pn( infs, grp->numInfluences, maxInfs, 
    231233                        iPos, x42->vertPos + grp->firstVert,  iNorm, grp->numVerts, oPos, oNorm ); 
    232234        } 
    233235        else 
    234236        { 
    235                 skin_verts_p( infs, grp->numInfluences, grp->maxVertInfluences, 
     237                skin_verts_p( infs, grp->numInfluences, maxInfs, 
    236238                        iPos, x42->vertPos + grp->firstVert, grp->numVerts, oPos ); 
    237239        } 
  • branches/morph-targets/libx42/anim.c

    r501 r593  
    127127        grp = x42->groups + groupNum; 
    128128 
    129         copy_verts = !boneMats || grp->maxVertInfluences == 0
     129        copy_verts = !boneMats || (grp->maxVertInfluences == 0 && (x42->header.runFlags & X42_RF_ROOT_MATRIX_BAKED))
    130130        applied_opts = opts ? x42_ApplyOpts( opts ) : false; 
    131131 
  • branches/morph-targets/libx42/include/x42.h

    r563 r593  
    132132        x42tag_t                        *tags;                  //may be null 
    133133 
     134        affine_t                        rootMatrix;             //usually identity, X42_RF_ROOT_MATRIX will be set otherwise 
     135 
    134136        /* 
    135137                Geometry data. 
     
    341343X42_EXPORT x42data_t* X42_CALL x42_LoadDataFromStream( void *out_buffer, const x42header_t *h, uint persist_flags, x42inStream_t *file_stream ); 
    342344 
     345/* 
     346        Apply a runtime root offset to the model. This stores a matrix in the x42data_t struct 
     347        to append onto the root of all animation heirarchies and (optionally) bakes the matrix 
     348        into the vertices of any static animation groups. 
     349 
     350        Leave bake_into_static_verts set to true unless you're going to manually skin the vertices 
     351        with their (identity) influence. 
     352*/ 
     353X42_EXPORT bool X42_CALL x42_ApplyRootOffset( x42data_t *x42, const affine_t *rootMatrix, bool bake_into_static_verts ); 
     354 
    343355/*********************************** 
    344356 
     
    435447 
    436448X42_EXPORT affine_t* X42_CALL x42_GetAnimBoneMatrices( void *out_buffer, const x42data_t *x42, 
    437         const x42animLerp_t *lerp, const affine_t *rootMatrix, x42opts_t *opts ); 
     449        const x42animLerp_t *lerp, x42opts_t *opts ); 
    438450X42_EXPORT affine_t* X42_CALL x42_GetAnimTagMatrices( void *out_buffer, const x42data_t *x42, 
    439451        const affine_t *boneMats, x42opts_t *opts ); 
  • branches/morph-targets/libx42/local.h

    r560 r593  
    4343 
    4444#define X42_RF_LOAD_SWAPPED                     0x0001 
     45#define X42_RF_ROOT_MATRIX                      0x1000 
     46#define X42_RF_ROOT_MATRIX_BAKED        0x2000 
    4547 
    4648#ifdef __cplusplus 
  • branches/morph-targets/libx42/platform/x86-64/anim-skin.c

    r500 r593  
    759759        const x42data_t *x42, uint groupNum, const affine_t *boneMats, x42opts_t *opts ) 
    760760{ 
    761         uint i
     761        uint i, maxInfs
    762762        x42group_t *g; 
    763763 
     
    784784        g = x42->groups + groupNum; 
    785785 
    786         if( !g->maxVertInfluences ) 
    787                 //bother with a fast path for this? 
    788                 return false; 
     786        maxInfs = g->maxVertInfluences > 0 ? g->maxVertInfluences : 1; 
    789787 
    790788        for( i = 0; i < g->numInfluences; i++ ) 
     
    826824                        oNorm = &nullStream; 
    827825 
    828                 opt_skin_verts_pntb( infs, g->maxVertInfluences, iPos, x42->vertPos + g->firstVert, 
     826                opt_skin_verts_pntb( infs, maxInfs, iPos, x42->vertPos + g->firstVert, 
    829827                        iTan, g->numVerts, oPos, oNorm, oTan, oBin ); 
    830828        } 
    831829        else if( oNorm ) 
    832830        { 
    833                 switch( g->maxVertInfluences ) 
     831                switch( maxInfs ) 
    834832                { 
    835833                case 1: 
  • branches/morph-targets/libx42/pose.c

    r563 r593  
    504504*/ 
    505505 
     506X42_EXPORT bool X42_CALL x42_ApplyRootOffset( x42data_t *x42, const affine_t *rootMatrix, bool bake_into_static_verts ) 
     507{ 
     508#ifndef LIBX42_NO_PARAM_VALIDATION 
     509        demand_rf( x42 != NULL, X42_ERR_BADPTR, "x42 is NULL" ); 
     510        demand_rf( x42_ValidateHeader( &x42->header ), X42_ERR_BADDATA, "invalid x42 header data" ); 
     511        demand_rf( rootMatrix != NULL, X42_ERR_BADPTR, "rootMatrix is NULL" ); 
     512 
     513        if( x42->header.runFlags & X42_RF_ROOT_MATRIX ) 
     514        { 
     515                demand_rf( bake_into_static_verts ? true : false == 
     516                        (x42->header.runFlags & X42_RF_ROOT_MATRIX_BAKED) ? true : false , X42_ERR_INVALIDOP, "cannot mix baked/unbaked root offsets" ); 
     517        } 
     518#endif 
     519 
     520        //from the left 
     521        if( (x42->header.runFlags & X42_RF_ROOT_MATRIX) == 0 ) 
     522        { 
     523                affine_cpy( &x42->rootMatrix, rootMatrix ); 
     524                x42->header.runFlags |= X42_RF_ROOT_MATRIX; 
     525        } 
     526        else 
     527        { 
     528                affine_mul( &x42->rootMatrix, rootMatrix, &x42->rootMatrix ); 
     529        } 
     530 
     531        if( bake_into_static_verts ) 
     532        { 
     533                uint g, v, lv; 
     534 
     535                x42->header.runFlags |= X42_RF_ROOT_MATRIX_BAKED; 
     536 
     537                for( g = 0; g < x42->header.numVerts; g++ ) 
     538                { 
     539                        const x42group_t *grp = x42->groups + g; 
     540                         
     541                        if( grp->maxVertInfluences ) 
     542                                //not static 
     543                                continue; 
     544 
     545                        lv = grp->firstVert + grp->numVerts; 
     546                        for( v = grp->firstVert; v < lv; v++ ) 
     547                                affine_mul_pos( x42->vertPos[v].pos, rootMatrix, x42->vertPos[v].pos ); 
     548 
     549                        if( x42->vertNorm ) 
     550                        { 
     551                                for( v = grp->firstVert; v < lv; v++ ) 
     552                                        affine_mul_vec( x42->vertNorm[v].norm, rootMatrix, x42->vertNorm[v].norm ); 
     553                        } 
     554 
     555                        if( x42->vertTan ) 
     556                        { 
     557                                for( v = grp->firstVert; v < lv; v++ ) 
     558                                { 
     559                                        affine_mul_vec( x42->vertTan[v].tan, rootMatrix, x42->vertTan[v].tan ); 
     560                                        affine_mul_vec( x42->vertTan[v].bit, rootMatrix, x42->vertTan[v].bit ); 
     561                                } 
     562                        } 
     563                } 
     564 
     565                for( g = 0; g < x42->header.numMorphTargets; g++ ) 
     566                { 
     567                        const x42morphTarget_t *tar = x42->morphTargets + g; 
     568                         
     569                        if( x42->groups[tar->targetGroup].maxVertInfluences ) 
     570                                //not static 
     571                                continue; 
     572 
     573                        lv = tar->numDeltas; 
     574 
     575                        for( v = tar->firstDelta; v < lv; v++ ) 
     576                                affine_mul_vec( x42->morphPos[v], rootMatrix, x42->morphPos[v] ); 
     577 
     578                        if( x42->morphNorm ) 
     579                        { 
     580                                for( v = tar->firstDelta; v < lv; v++ ) 
     581                                        affine_mul_vec( x42->morphNorm[v].norm, rootMatrix, x42->morphNorm[v].norm ); 
     582                        } 
     583 
     584                        if( x42->morphTan ) 
     585                        { 
     586                                for( v = tar->firstDelta; v < lv; v++ ) 
     587                                { 
     588                                        affine_mul_vec( x42->morphTan[v].tan, rootMatrix, x42->morphTan[v].tan ); 
     589                                        affine_mul_vec( x42->morphTan[v].bit, rootMatrix, x42->morphTan[v].bit ); 
     590                                } 
     591                        } 
     592                } 
     593        } 
     594 
     595        return true; 
     596} 
     597 
    506598X42_EXPORT size_t X42_CALL x42_GetAnimBoneMatricesSize( const x42data_t *x42 ) 
    507599{ 
     
    515607 
    516608X42_EXPORT affine_t* X42_CALL x42_GetAnimBoneMatrices( void *out_buffer, const x42data_t *x42, 
    517         const x42animLerp_t *lerp, const affine_t *rootMatrix, x42opts_t *opts ) 
     609        const x42animLerp_t *lerp, x42opts_t *opts ) 
    518610{ 
    519611        uint i; 
     
    583675                if( b->parentIdx != X42_MODEL_BONE ) 
    584676                        affine_mul( ret + i, ret + b->parentIdx, ret + i ); 
    585                 else if( rootMatrix
    586                         affine_mul( ret + i, rootMatrix, ret + i );            
     677                else if( x42->header.runFlags & X42_RF_ROOT_MATRIX
     678                        affine_mul( ret + i, &x42->rootMatrix, ret + i );              
    587679        } 
    588680 
  • branches/morph-targets/libx42/write.c

    r502 r593  
    218218        get_stream_bounds( bounds, 3, (float*)x42->scaleValues, h->numScaleValues, sizeof( vec3_t ) ); 
    219219 
    220         pack->animScalePack[0] = min( bounds[0][0], bounds[1][0] ); 
    221         pack->animScalePack[1] = max( bounds[0][1], bounds[1][1] ); 
     220        pack->animScalePack[0] = min3( bounds[0][0], bounds[1][0], bounds[2][0] ); 
     221        pack->animScalePack[1] = max3( bounds[0][1], bounds[1][1], bounds[2][1] ); 
    222222 
    223223        get_stream_bounds( pack->vertPosPack, 3, (float*)&x42->vertPos[0].pos, h->numVerts, sizeof( x42vertAnim_t ) ); 
  • branches/morph-targets/x42maya/modelexporter-gather.cpp

    r568 r593  
    359359} 
    360360 
    361 std::vector< mesh_part model_exporter::import_mesh_geometry( MObject &mesh_obj ) 
     361std::vector< model_exporter::mesh_part > model_exporter::import_mesh_geometry( MObject &mesh_obj ) 
    362362{ 
    363363        MStatus stat;