# bvh Rotations to C4D HPB?

 11 November 2017 Scott Ayers Kaiju Creator Scott Ayers USA bvh Rotations to C4D HPB? Hi, Does anyone know what the magic formula is for converting bvh rotation values to C4D HPB values? AFAIK bvh rotations are Euler angles expressed in degrees. And HPB are also Euler angles expressed in degrees. But they are definitely not the same values. Example: bvh rotation = 0, 0, 0 C4D HPB rotation = 0, 90, 0  <----WTF? I've tried the typical sdk functions for this: HPBToMatrix(), etc.. But so far I can't find the magic formula that will convert the bvh rotations to HPB properly. Anyone know how to do this? -ScottA __________________ My Gallery share quote
 11 November 2017 Kuroyume0161 Code Ninja   portfolio Robert Templeton Computer Programmer Kuroyume's DevelopmentZone Loveland, USA You have to employ matrix multiplication in order to go from Euler angles to C4D HPB.  First, you need to know the rotation order (which is given in BVH).   I have *old* code that I used in InterPoser Pro for loading BVH onto the IPP joints.  For HPB, it might be better to multiply rotation matrices (in rotation order).  This is typically done in reverse: for instance, if the rotation order is XYZ, you multiply the rotation matrices (based on the rotation angle for each) like this: Matrix HPB = MatrixRotZ() * MatrixRotY() * MatrixRotX().  It may also be necessary to convert from right-handed to left-handed (not sure which BVH is in but C4D uses a left-handed coordinate system).  If so, you have to use a similarity matrix to convert the handedness of the coordinate system.  See what you get without consideration of handedness.  If things look 'mirrored', I can provide code to convert from right->left. __________________ Greebler | InterPoser C4D-R16, VS2012, Xcode 4.6 share quote
 11 November 2017 Scott Ayers Kaiju Creator Scott Ayers USA Robert! How are you? You kind of vanished a while ago. It's good to see you back. I'm working in Python. But I can switch over to C++ if needed. In my bvh file I have this: CHANNELS 6 Xposition Yposition Zposition Zrotation Xrotation Yrotation So I'm guessing that means the rotation order = ZXY Here's what I have using your advice. But I'm not sure how to get the hpb vector values from the hbpMtx? ``````import c4d,math def main():          rotMtxY = c4d.utils.MatrixRotY(0)     rotMtxX = c4d.utils.MatrixRotX(0)   #These zero values are just here as simple example values from my bvh file     rotMtxZ = c4d.utils.MatrixRotZ(0)     hpbMtx = rotMtxY * rotMtxX * rotMtxZ   #<---How do I get the hpb vector values from this matrix?     print hpbMtx     #This returns vector(0,0,0)   not  vector(0,90,0) like the C4D importer does     hpb = c4d.utils.MatrixToHPB(hpbMtx, c4d.ROTATIONORDER_HPB) #<---Not sure if this is correct?     print hpb if __name__=='__main__':     main()`````` Also, In my bvh file where the MOTION values are listed. I'm assuming that the values are always listed as XYZ. That never changes regardless of the order listed in the CHANNELS right? I'm plugging in those values into my rotation matrices code accordingly. But I still can't get the correct rotation values from them. -ScottA __________________ My Gallery Last edited by Scott Ayers : 11 November 2017 at 02:57 PM. share quote
 11 November 2017 Kuroyume0161 Code Ninja   portfolio Robert Templeton Computer Programmer Kuroyume's DevelopmentZone Loveland, USA The MOTION section values use the same position and rotation orders as those given in the CHANNELS section for the JOINT hierarchy. MatrixToHPB() will give you a vector using the order (and type) as you specify in the second argument.  So,  you should be getting the actual HPB values if using 'c4d.ROTATIONORDER_HPB'.  As for why the Cinema 4D import yields (0,90,0) and you get (0,0,0) may have something to do with the axial system.  The 90 degree rotation puts the Z as up instead of the Y.  You may need to apply this 90 degree rotation to all rotation matrices (add a MatrixRotY(0.5*PI) as the first multiplication - last matrix multiplication, right to left).  __________________ Greebler | InterPoser C4D-R16, VS2012, Xcode 4.6 Last edited by Kuroyume0161 : 11 November 2017 at 01:15 AM. share quote
 11 November 2017 Scott Ayers Kaiju Creator Scott Ayers USA Originally Posted by Kuroyume0161: You may need to apply this 90 degree rotation to all rotation matrices (add a MatrixRotY(0.5*PI) as the first multiplication - last matrix multiplication, right to left).  You lost me there. I can't quite picture what you're saying. Also: I've successfully written my own fbx exporter. And the FBX sdk is also a right handed system like the bvh files are. In order to convert my fbx rotation values to c4d I needed to swap the X&Y axis values. In order to to convert the positions I needed to negate the Z axis value. I'm not sure if I will need to do the same thing when working with bvh files? -ScottA __________________ My Gallery Last edited by Scott Ayers : 11 November 2017 at 02:24 AM. share quote
 11 November 2017 Scott Ayers Kaiju Creator Scott Ayers USA I think I have it figured out. But I will need to test it some more before I'm 100% convinced. This is what I came up with that seems to work: ``````#This is how to convert the rotation values in a .bvh file to HPB values in C4D #This example uses a .bvh file that has the rotations listed as: ZXY #    EXAMPLE: CHANNELS 6 Xposition Yposition Zposition Zrotation Xrotation Yrotation #Change the code if your .bvh file uses a different order import c4d,math def main():          #First...we need to convert the bvh file's rotation values to radians     #Why?..I have no frackin' clue!!     vz = 1.45748 * math.pi / 180  #<---NOTE: This value needs to be negated from the Z value in the bvh file     vx = -11.8543 * math.pi / 180     vy = 1.15059 * math.pi / 180     #Create three rotation matrices using the above values     rotMtxZ = c4d.utils.MatrixRotZ(vz)     rotMtxX = c4d.utils.MatrixRotX(vx)        rotMtxY = c4d.utils.MatrixRotY(vy)     hpbMtx = rotMtxY * rotMtxX * rotMtxZ    #The reverse rotation order in the bvh file     #Apply the rotations to your own joint     jnt = doc.SearchObject("myJoint")     jnt.SetAbsRot(c4d.utils.MatrixToHPB(hpbMtx))     """     At this point your joint's rotations should match the rotation of the bvh file     However...The axis might be pointing in different directions     So we need to Align the joint's axis in the Z direction (as it is in the bvh file)     """     #Set the Axis option to "Z"     jnt[c4d.ID_CA_JOINT_OBJECT_BONE_AXIS] = 2          #Execute the Align button     c4d.CallButton(jnt,c4d.ID_CA_JOINT_OBJECT_ALIGN_AX IS)          c4d.EventAdd() if __name__=='__main__':     main()`````` -ScottA __________________ My Gallery share quote
 11 November 2017 Scott Ayers Kaiju Creator Scott Ayers USA Apparently this does not work. Back to the drawing board. I'm still looking for a way to turn bvh rotation values into HPB values. -ScottA __________________ My Gallery share quote
 12 December 2017 Bullit Expert Well i can say thanks    what do you mean by UA in C4D is far too primitive? UA stands for what? share quote
 12 December 2017 Scott Ayers Kaiju Creator Scott Ayers USA UA = UserArea. It's basically a canvas area where you can draw things like shapes(which can also be used like image buttons) for your C4D plugins. It's very old and very outdated in C4D. It's ok for very basic things. But we have to code everything by hand. And some things like rotating a shape are not supported. In modern frameworks like Qt and the HTML5 canvas. The shapes are full blown objects with a matrix that can be changed via built-in methods. So it's very simple to do fancier animations, collisions, parenting, drag&drop, etc. with them. And we don't need to write all of the code ourselves to do them. -ScottA __________________ My Gallery share quote
 12 December 2017 Bullit Expert But isn't C4D revamping the core? shouldn't include changing that.? With caveat that i am painful aware  as just an user of what a mess have been transitions to QT of Max, and the issues with Maya and even Houdini. share quote
 12 December 2017 Scott Ayers Kaiju Creator Scott Ayers USA Years ago I spoke to some of the support guys about how C4D partnering up with Qt would solve a lot of their prehistoric GUI limitations. And the general replies I got were that they didn't like Qt. MAXON does not talk openly about such things with it's users. So I can't say for sure what's going to happen with the new core change. But historically they have not cared enough about their ancient GUI tools to warrant updating it. I guess we'll see when the new core arrives. But I'll be surprised if the GUI tools change much. Or even at all for that matter. At this point it doesn't really matter that much to me. Because I've figured out how to write Qt apps that will work with the C4D SDK without MAXON's support. -ScottA __________________ My Gallery share quote
 12 December 2017 Bullit Expert Thanks Scott for the feedback. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.
Forum Jump
 Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Gallery     CG Awards     Featured 2D     Featured 3D     Latest Entries Main     News     General Discussion     Featured Videos     Education     Off Topic     Recruitment         Temp Job Board Challenges     CGSociety/IAMAG Beyond the Wall     The AMD RADEON PRO Challenge!     Wacom #DrawCember     Lighting Challenges     Professional Feedback GROUPS WIP ADVICE     Ask an Art Director     WIP 2D/3D & Animation         WIP/Critique: 3D         WIP/Critique: 2D             Speedpaints & Sketchbooks         WIP/Critique: Animation     Kitbash 3D Thunderdome     Collaborative Projects Autodesk     Autodesk Maya         Maya Dynamics         Maya Rendering         Maya Character Setup         Maya Programming     Autodesk Miscellaneous         Autodesk MotionBuilder         Autodesk Mudbox         Autodesk Softimage             XSI: Programming             ICE: Interactive Creative Environment     Autodesk 3ds max         3dsMax Tutorials & Tips         3dsMax Resources         3dsMax SDK and MaxScript         Plugins & Add-ons         Particle Flow     Arnold ZBrush     Featured Zbrush Gallery     Pixologic ZBrush     Keyshot     Marvelous Designer Texturing     Mari     Texturing XYZ     Marmoset Toolbag     3DCoat     Allegorithmic Substance         Substance Designer         Substance Painter Software     Maxon Cinema 4D         Cinema 4D Resources     The Foundry Modo         The Foundry Time Travel Challenge     Side Effects Houdini     Lightwave 3D         LW Resources         LW Tutorials     Blender     Photoshop / Painter     E-on Software Vue     Compositing Software         The Foundry Nuke         Adobe After Effects         Autodesk Effects and Compositing         Eyeon Software Digital Fusion Techniques     Art Techniques and Theories     Digital Matte Painting         Digital Matte Painting Mini-Challenge     Modeling         Modeling Challenge             Member Model Collection     Texturing and Surfacing     Character Rigging     Animation     Lighting and Shaders     Compositing and Editing     Anatomy and Figurative Art         SPOTLIGHT: Best of the Artistic Anatomy and Figurative Art Forum         Tutorials and Workshops         Personal Anatomy & Sketchbook Threads         References, Resources, and Supplies Technical     VR/AR     Master Virtual Reality with BrioVR     Game Engine     Graphics Programming     Technical and Hardware
Miscellaneous

All times are GMT. The time now is 03:55 AM.