University of Southern CaliforniaUSC
USC ICT TwitterUSC ICT FacebookUSC ICT YouTube

[OT]: Help with borrowing of retargetting algorithm | General SmartBody Discussion | Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
[OT]: Help with borrowing of retargetting algorithm
April 11, 2016
10:12 pm
Avatar
Member
Members
Forum Posts: 28
Member Since:
November 5, 2015
sp_UserOfflineSmall Offline

I still don't understand how I can re-orientate the frame of my mesh to the bvh file

I believe to take the inverse of the global transform of the bvh as this value is incorrect.

Because I have to call this function everytime I iterate the bvh motions.

I think I will have to do this once.

[code]

void initRetarget(LPCSTR tgtName, CMesh& mesh) {
    // Frame Hierarchy    
    
    FRAME* f = (FRAME*)D3DXFrameFind(mesh.GetFrameRoot(), tgtName);

    stdext::hash_map<FRAME*, Joint*, FrameHasher>::iterator itr;
    itr = mesh.m_BoneMap.find(f);

    Joint* j = (*itr).second;
    

    //// reorientate the target bone by offsetting (Don't understand)
    Quaternion gsrcTemp = j->GetGlobalRotation();
    D3DXQUATERNION gsrc;
    gsrc.x = gsrcTemp.x;
    gsrc.y = gsrcTemp.y;
    gsrc.z = gsrcTemp.z;
    gsrc.w = gsrcTemp.w;

    //// FH (world)
    D3DXQUATERNION gdst;
    D3DXMATRIX mdst = f->matCombined;
    D3DXQuaternionRotationMatrix(&gdst, &mdst);

    ///////////////////////

    //// BVH (Local) ok
    Quaternion protSrcTemp = j->GetRestRotation();
    D3DXQUATERNION protSrc;
    protSrc.x = protSrcTemp.x;
    protSrc.y = protSrcTemp.y;
    protSrc.z = protSrcTemp.z;
    protSrc.w = protSrcTemp.w;

    /// FH (Local) ok
    D3DXMATRIX mProtDst = f->TransformationMatrix;
    D3DXQUATERNION protDst;
    D3DXQuaternionRotationMatrix(&protDst, &mProtDst);

    ///////////////////////////////

    D3DXQUATERNION protSrcInv;
    D3DXQuaternionInverse(&protSrcInv, &protSrc);

    D3DXQUATERNION gsrcInv;
    D3DXQuaternionInverse(&gsrcInv, &gsrc);

    D3DXQUATERNION gdstInv;
    D3DXQuaternionInverse(&gdstInv, &gdst);

    // 1) protDst => local transform of FH
    // 2) gdstInv => inv of global transform of BVH
    // 3) gsrc    => reorientate the bone
    // 4) protSrcInv => inv of local transform of BVH
    D3DXQUATERNION preRot = protDst * gdstInv * gsrc * protSrcInv;
    D3DXQUATERNION protRot = gsrcInv * gdst;            

    //////////////////////
    stringstream oss;
    oss << "gsrc X:" << gsrc.x << " Y:" << gsrc.y << " Z:" << gsrc.z << " W:" << gsrc.w << endl;
    oss << "protSrc X:" << protSrc.x << " Y:" << protSrc.y << " Z:" << protSrc.z << " W:" << protSrc.w << endl;
    oss << "gdst X:" << gdst.x << " Y:" << gdst.y << " Z:" << gdst.z << " W:" << gdst.w << endl;
    oss << "protDst X:" << protDst.x << " Y:" << protDst.y << " Z:" << protDst.z << " W:" << protDst.w << endl;
    oss << "================" << endl;
    OutputDebugString(oss.str().c_str());                                    
 
    jointPrePostRotMap[tgtName] = QuatPair(preRot, protRot);  

    
}

[/code]

And I am calling the update functon like this

[code]

for (auto& b : mesh.m_BoneMap) {
        if (b.second->name == "RightArm") {
            initRetarget(b.first->Name, mesh);
            D3DXMATRIX m = b.first->TransformationMatrix;
            D3DXVECTOR3 s;
            D3DXVECTOR3 v;
            D3DXQUATERNION q;
            D3DXMatrixDecompose(&s, &q, &v, &m);
            D3DXQUATERNION newQ = applyRetargetJointRotation(b.first->Name, q);
            D3DXVECTOR3 newV = applyRetargetJointTranslationVec(b.first->Name, v);

            D3DXMATRIX matRot, matTrans, matOut;
            D3DXMatrixRotationQuaternion(&matRot, &newQ);

            D3DXMatrixTranslation(&matTrans, newV.x, newV.y, newV.z);

            matOut = matRot * matTrans;

            FRAME* f = (FRAME*)D3DXFrameFind(mesh.GetFrameRoot(), b.first->Name);

            f->TransformationMatrix = matOut;
        }
    }

    UpdateFrame(frame, &iden);

    // render all frames
    RenderFrame(frame);

[/code]

April 14, 2016
12:02 pm
Avatar
Admin
Forum Posts: 52
Member Since:
August 8, 2012
sp_UserOfflineSmall Offline

Hi,

I don't think you have the FH bone re-oriented to BVH bones in the code. It is the process to rotate each bone in an intermediate skeleton to the bone orientations in source skeleton ( skeleton in bvh motion ).

You may want to check the code in SkMotion::convertBoneOrientation for more detail in bone re-orientation. Once you have the bone re-oriented, both the global and local rotations you get can then be used as gdst, and protDst.

Andrew

Forum Timezone: America/Los_Angeles

Most Users Ever Online: 733

Currently Online: mondayneedle1, juhlvalenzuela2, lanp4anase, worriedutopia9579, DixieDelgado, lyinglegacy8966, eric506784
82 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

jwwalker: 80

jyambao: 51

rbaral: 47

adiaz: 30

WargnierP: 29

lucky7456969: 28

mbarros: 28

avida.matt: 26

JonathanW: 24

laguerre: 23

Member Stats:

Guest Posters: 65

Members: 52460

Moderators: 3

Admins: 4

Forum Stats:

Groups: 1

Forums: 5

Topics: 427

Posts: 2343