University of Southern CaliforniaUSC
USC ICT TwitterUSC ICT FacebookUSC ICT YouTube

Unable to correctly manage joint positions/orientations | 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
Unable to correctly manage joint positions/orientations
August 20, 2014
4:42 pm
Avatar
Paris, France
Member
Members
Forum Posts: 23
Member Since:
August 5, 2014
sp_UserOfflineSmall Offline

Hi,

I'm attempting to integrate SmartBody into Unity (without your plugin) but I get weird results when playing animation ChrBrad@Idle01 with Brad.

http://imagizer.imageshack.us/v2/280x200q90/913/xidqTU.png

I somewhat assumed the animation "Idle01" starts with a A-pose for Brad. Hence, I just needed to compute a transformation matrix D for every joint that would materialize the difference between positions/orientations computed by SmartBody on one side, and the initial A-pose of Brad in Unity once the FBX file was loaded on the other side.

So during the very first frame in Unity, I get what the user set for each joint in terms of positions and orientations in Unity inspector. I then get what SmartBody proposes for the same joints and compute transformations matrices D. Later, the matrix M in local coordinates for a joint equals to M = D x S, with S coming from a call to aJoint->getMatrixLocal().

So what am I supposed to do now? Initially I expected to play very easily animations shipped with SmartBody in Unity by setting Unity GameObjects with joint positions/orientations that SmartBody would compute. I got dumb things and finally came down to some sort of retargetting (is it the right term here?) ... But more seems to be needed and I don't know what! Any advice?

August 21, 2014
12:17 pm
Avatar
Paris, France
Member
Members
Forum Posts: 23
Member Since:
August 5, 2014
sp_UserOfflineSmall Offline

I was reading code from SmartBody, mainly in OgreFrameListener.cpp and SBOgreListener.cpp, and I have to admit that I do not understand everything.

In SBOgreListener.cpp, right after loading of character Brad for example, positions of bones are stored in a field called initialBonePositions. The positions come from calls to bone->getPosition(). According to Ogre3D documentation, we hence stored here relative positions to parents.

In OgreFrameListener.cpp, the code becomes strange:

	Ogre::Bone* bone = skel->getBone(jointName);
	if (bone)
	{						
		if (!bone->isManuallyControlled())
			bone->setManuallyControlled(true);
		Ogre::Vector3& vec = intialBonePositionMap[jointName];
		float x = joint->pos()->value(0)+ vec.x;
		float y = joint->pos()->value(1) + vec.y;
		float z = joint->pos()->value(2) + vec.z;
 		bone->setPosition(x, y, z);
		const SrQuat& q = joint->quat()->value();
		bone->setOrientation(q.w, q.x, q.y, q.z);
	}

Why is it needed to compute positions based on initial positions? What is "the translation parameterization of the joint"? Why don't you simply provide a method to access the local position of the joint (is it what getMatrixLocal() inSBJoint supposed to do? I'm confused).

For joint->quat(), documentation tells that it gives "access [to] the quaternion-based rotation of the joint" but I do not know the frame being used (local or world coordinates?)... I think it works with local coordinates when I read code of sk_joint.cpp.

Why don't you use initial rotations? Why does it work?

August 21, 2014
8:03 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

laguerre said
Hi,

I'm attempting to integrate SmartBody into Unity (without your plugin) but I get weird results when playing animation ChrBrad@Idle01 with Brad.

http://imagizer.imageshack.us/v2/280x200q90/913/xidqTU.png

I somewhat assumed the animation "Idle01" starts with a A-pose for Brad. Hence, I just needed to compute a transformation matrix D for every joint that would materialize the difference between positions/orientations computed by SmartBody on one side, and the initial A-pose of Brad in Unity once the FBX file was loaded on the other side.

So during the very first frame in Unity, I get what the user set for each joint in terms of positions and orientations in Unity inspector. I then get what SmartBody proposes for the same joints and compute transformations matrices D. Later, the matrix M in local coordinates for a joint equals to M = D x S, with S coming from a call to aJoint->getMatrixLocal().

So what am I supposed to do now? Initially I expected to play very easily animations shipped with SmartBody in Unity by setting Unity GameObjects with joint positions/orientations that SmartBody would compute. I got dumb things and finally came down to some sort of retargetting (is it the right term here?) ... But more seems to be needed and I don't know what! Any advice?

Can you post or send me a video of your results?

If you are using the ChrMaarten.fbx in data/mesh/ChrMaarten, that character starts in a a-pose, and this matches the SmartBody skeleton definition in ChrBrad.sk (Brad's name was changed to Maarten, so the skeleton is still 'Brad', but the mesh is 'Maarten')

There might be a problem related to pre-rotations that are part of that skeleton (looking at the 'prerot' line in ChrBrad.sk, the JtToeRt is flipped 180 degrees around the z axis, for example). In which case you need to call:

SBJoint::getPrerotation()

and premultiply that by the local matrix.

Ari

August 22, 2014
12:16 pm
Avatar
Paris, France
Member
Members
Forum Posts: 23
Member Since:
August 5, 2014
sp_UserOfflineSmall Offline

Here a video of Brad playing guitar. I tried to pre-multiply each joint local matrix but the result was a kind of monster...

August 25, 2014
8:00 am
Avatar
tourtravelets
Guest
Guests

Thanks for share

August 26, 2014
9:40 am
Avatar
Paris, France
Member
Members
Forum Posts: 23
Member Since:
August 5, 2014
sp_UserOfflineSmall Offline

It seems that all rotations are somewhat 'reverted': the head points towards the opposite direction and feet are turned to the inside...

Did you have to apply special transformations to skeletons when you developed your Unity plugin?

September 1, 2014
5:55 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Can you try multiplying the:

X pos by -1

Y quaternion term by -1

Z quaternion term by -1

 

In order to change the coordinate system from SmartBody->Unity

Ari

March 23, 2015
10:55 am
Avatar
Paris, France
Member
Members
Forum Posts: 23
Member Since:
August 5, 2014
sp_UserOfflineSmall Offline

I tried again and found my mistake: it was related to a wrong coordinate system. In SmartBody documentation, I did not find anything that explains what is the coordinate system so I tried several possibilities until I found the following one. Perhaps I did not pay enough attention to the documentation; otherwise could you explain the coordinate system in the documentation?

// Right-handed with the following basis:
//
//          ^ +Y
//          |
//   +X     |
//   <------+
//         /
//        /
//       < +Z
//
// +X to the left
// +Y upward
// +Z to the user

March 24, 2015
12:48 am
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

It's a right-handed coordinate system. Y-up and positive Z coming towards the viewer.

 

Ari

March 24, 2015
11:08 am
Avatar
Paris, France
Member
Members
Forum Posts: 23
Member Since:
August 5, 2014
sp_UserOfflineSmall Offline

Oops, I don't know why I wrote "right-handed"... But really, I made SB working with a left-handed system and X pointing to the left  :-/

With "reversed X", I got the result in the video. But I will try again...

Forum Timezone: America/Los_Angeles

Most Users Ever Online: 733

Currently Online: Jamesnuh, gotselyuk1987mon, koenig62ramos, krygerhagen69, coxgeorge3, doyle68bekker, ludvigsen62abbott, shortstext78, cormierhopper5
67 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

jwwalker: 80

jyambao: 52

rbaral: 47

adiaz: 30

WargnierP: 29

lucky7456969: 28

mbarros: 28

avida.matt: 26

JonathanW: 24

laguerre: 23

Member Stats:

Guest Posters: 67

Members: 100502

Moderators: 3

Admins: 4

Forum Stats:

Groups: 1

Forums: 5

Topics: 460

Posts: 2403