University of Southern CaliforniaUSC
USC ICT TwitterUSC ICT FacebookUSC ICT YouTube

Integration problem | 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
Integration problem
May 15, 2015
3:40 pm
Avatar
Member
Members
Forum Posts: 5
Member Since:
May 15, 2015
sp_UserOfflineSmall Offline

Hello,

i am trying to integrate smartbody into a shader base framework . I want to take a transformation matrix for every joint in smartbody and use it to transform bones in our frameowork. The result is this ( http://i58.tinypic.com/f56f0z......%5B/IMG%5D ). I have tested the same process of using smartbody with irrlicht engine and it worked fine .The code is:

 

//initialize characters . . . 

//for all characters get transformation

//dae is the character instance in our framework

//j.first is joint name and j.second is the bone index

        for (std::map<std::string, unsigned int>::iterator j=dae->m_BoneMapping.begin(); j!=dae->m_BoneMapping.end(); ++j)
        {
                rotation = character->getSkeleton()->getJointByMappedName((*j).first)->getQuaternion();
                quat_rotation = quat(-position.x,position.y,position.x,-position.w);
                tranform.at((*j).second)=quat_rotation;
        }

 

and vertex shader code for tranformation:

mat4 BoneTransform = Bones[bone_map[bonesIds[0]]] * weights[0];
BoneTransform += Bones[bone_map[bonesIds[1]]] * weights[1];
BoneTransform += Bones[bone_map[bonesIds[2]]] * weights[2];
BoneTransform += Bones[bone_map[bonesIds[3]]] * weights[3];
vec4 PosL = BoneTransform * vec4(vPosition,1);

 

Many thanks in advance 

Nikos

May 18, 2015
9:24 pm
Avatar
Admin
Forum Posts: 52
Member Since:
August 8, 2012
sp_UserOfflineSmall Offline

Hi Nikos,

The bone transformations need to use joint's global transformation and bind pose matrices. The "getQuaternion" function returns only the local rotation and can't be used directly for bone transform. You can refer to "DeformableMeshInstance::updateTransformBuffer()" function in the SmartBody source code for building the BoneTransform matrices used in your shader.

Let me know if this helps answering your question.

Thanks,

Andrew

May 20, 2015
6:19 pm
Avatar
Member
Members
Forum Posts: 5
Member Since:
May 15, 2015
sp_UserOfflineSmall Offline

Hello again,

thanks for your answer it was helpfull.

I still have some problems, i can see only Chrbrad legs moving properly.

I use updatefast() instead of DeformableMeshInstance::updateTransformBuffer() because when i use this function i get unresolved external but as i saw in the implementation of updatefast the function it calls the updateTransformBuffer().

My code to get weights and tranformation matrix is: 

character->getActiveMesh()->updateFast();

sb_weights = character->dMeshInstance_p->getDeformableMesh()->skinWeights;
for(int i =0 ; i<sb_weights.size();i++)
{
        vec4 tmp_ = vec4(0,0,0,0);
        for(int j=0;j<sb_weights.at(i)->bindWeight.size();j++ )
        {
        if(j==0) tmp_.x = sb_weights.at(i)->bindWeight.at(j);
        else if(j==1) tmp_.y = sb_weights.at(i)->bindWeight.at(j);
        else if(j==2) tmp_.z = sb_weights.at(i)->bindWeight.at(j);
        else if(j==3) tmp_.w = sb_weights.at(i)->bindWeight.at(j);
}
        weights_vector.at(tranform_map.at(i))=tmp_;
}

 

vector<SrMat> tmp_tran =  character->dMeshInstance_p->transformBuffer;

for(int i = 0 ; i<tmp_tran.size();i++)
{
        SrMat curr_trans = tmp_tran.at(i);
        mat4 trans = mat4( curr_trans.e11(),curr_trans.e12(),curr_trans.e13(),curr_trans.e14(),
        curr_trans.e21(),curr_trans.e22(),curr_trans.e23(),curr_trans.e24(),
        curr_trans.e31(),curr_trans.e32(),curr_trans.e33(),curr_trans.e34(),
        curr_trans.e41(),curr_trans.e42(),curr_trans.e43(),curr_trans.e44());

transform.at(i) = trans;
}

Am i doing something wrong ?

 

Many thanks in advance 

Nikos

May 26, 2015
5:51 pm
Avatar
Admin
Forum Posts: 52
Member Since:
August 8, 2012
sp_UserOfflineSmall Offline

Hi Niko,

If part of the mesh is animated correctly, then the transformation buffer should contain the correct values. My guess is that some of vertices are not getting transformed at all. From the code segment, it seems sb_weights are not copied over correctly for each vertex as only the first 4 values are used. 

I would suggest using posBuf, boneIDBuf, and boneWeightBuf directly from DeformableMesh class to fill the skinning information into your structure. These are the arrays I feed into GPU for GPU-based skinning and should be more straightforward to use. ( You can obtain this object with "getDeformableMesh()" function. )

If this doesn't work, can you also provide me with the whole segment of code for converting SmartBody skinning information (Skin weights, influence joint index, vertex position, etc) into your structure ? We may be able to figure out the other issues from it. 

Also, I have update the SmartBody source code to export updateTransformBuffer() function as well. So now you should be able to call it directly. 

Let me know if this helps and I would be happy to look further to help your integration.

Andrew

May 30, 2015
6:37 pm
Avatar
Member
Members
Forum Posts: 5
Member Since:
May 15, 2015
sp_UserOfflineSmall Offline

Hi Andrew,

It works just fine. I am using the vertices,normals, boneids etc.. from DeformableMesh. For the render part i use getDeformableMesh()->subMeshList[i]->triBuf for indeces. 

thanks for the great help 

Nikos

Forum Timezone: America/Los_Angeles

Most Users Ever Online: 733

Currently Online: mondayneedle1, huberdavidsen3, casey29english, andersen19eaton, kristensen00leblanc, bager59mayo, eric506784, t9rrzpi307
112 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