The Big Rotation / Orientation Quest in Unity - rotation

I'm working on a custom blender to unity exporter/importer(school project), and I have a bigger problem: The Rotation.
I can get the Euler rotations and/or quaternions from blender, but when I want them to apply in one of Unity's objects, it just totally messes up the rotation.
I've already tried to swap Y and Z coordinates, but it doesn't seems to work either.
I tried but applying a rotation matrix isn't possible in unity... but if somehow we can figure it out, maybe that would be the solution?
I need to find a universal solution as soon as possible.
Thanks.
... for a further description, please read the comments bellow.

Related

three.js filling gaps between edges

I created a model in Blender of a block with a hole in it:
I export it as an .obj file, and import it in ThreeJS with the OBJLoader add-on.
When I use it in my app, it appears to draw a face over the sides of the hole:
Is there a setting I need to use in ThreeJS to avoid having it close over gaps like this? Or is the problem in how I'm creating the model? I'm totally lost here, any guidance appreciated.
EDIT: I discovered through trial-and-error that the problem is having irregularly-shaped faces, like the ones adjacent to the hole. I "solved" my problem by triangulating the model; while this changes its shape slightly, it ensures that every vertex in the hole is part of a triangle face, which seems to be the magic answer.
I'm still very curious about why this is, especially since the triangulation has made the corners of the box a bit weird.
EDIT 2: Sorry for the delay. Here's the blender file: https://gofile.io/?c=EoxH1r
The problem you are having is because of ngons (polygons with more than 4 sides).
Modelling for three.js is just like modelling for games, so it is best to avoid polygons with more than 4 sides because when the renderer (or video card, I dunno) tries to render the model, it has to apply triangulation and may do it in an unexpected way.
As you said, applying triangulation to the model fixed the issue, but automatically applying triangulation in your modelling app may also yield unexpected results. So your best bet is to alter the model so you get the results you expect.
Here is a youtube video I found that seems to explain a lot about ngons.
https://www.youtube.com/watch?v=BjnCV2PIkKA
(though I only watched the first minute or so)
Here is an example of how I would do it, red lines representing added edges. Remember to do it all the way around on both sides and apply your smoothing groups before exporting.

Using "broken" option in animation curves doesn't work for rotation

I'm making a game using sprite sheets, but I was curious to see if I could animate other sprites into the animation. Indeed, it is possible, however the animation's curve has to be dealt with, or else you have one part choppy, and the other very smooth. I found this resource which helped: http://answers.unity3d.com/questions/893479/how-to-make-not-smooth-multi-sprite-animation.html
While the "broken" curve works for translation, it seems to be without effect on rotation.
This is what happens instead:
As you can see the curves are straight, but the animation does not reflect that.
I'm wondering if this is a bug?
I haven't found any other resources mentioning it. I realize I can simply create another sprite sheet, but it'd be efficient if I could do it in this manner, I believe.
Try setting different interpolation modes from context menu of rotation property. Eeuler angles( Quaternion Approximation ) should be suitable for you

Compose two rotations in D3 geo projection?

Having fun with D3 geo orthographic projection to build an interactive globe, based on all the great examples I found.
You can see my simple mockup at http://bl.ocks.org/patricksurry/5721459
I want the user to manipulate the globe like a trackball (http://www.opengl.org/wiki/Trackball). I started with one of Mike's examples (http://mbostock.github.io/d3/talk/20111018/azimuthal.html), and improved slightly to use canvas coordinates and express the mouse locations in 'trackball coordinates' (i.e. rotation around canvas horizontal and vertical axes) so that a fixed mouse movement gives more rotation near the edges of the globe (and works outside the globe if you use the hyberbolic extension explained above), rather than Mike's one:one correspondence.
It works nicely when the globe starts at an unrotated position (north pole vertical), but when the globe is already rotated (manipulate the example so the north pole is facing out of the page) then the trackball controls become non-intuitive because you can't simply express a change in trackball coordinates as a delta in the d3.geo.rotate lat/lon coordinates. D3's 3-axis rotation involves applying a longitude rotation (spin around north pole), then a latitude rotation (spin around a horizontal axis in the canvas plane), and then a 'yaw' rotation (spin around an axis perpendicular to the plane) - see http://bl.ocks.org/mbostock/4282586.
I guess what I need is a method for composing my two rotation matrices (the one currently in the projection, with a new one to rotate the trackball slightly), but I can't see a way to do that in D3, other than digging into the source (https://github.com/mbostock/d3/blob/master/src/geo/rotation.js) and trying to do the math to define the rotation matrix. The code looks elegant but comment-free and I'm not sure I can correctly decipher the closures with the orthographic projection instance.
On the last point, if someone knows the rotation matrix form of d3.geo.projection that would probably solve my problem too.
Any ideas?
There is an alternative solution to patricksurry's answer, by using quaternion representations, as inspired by Jason Davies. I, too, thought D3 would've already supported this composition natively! And hoped Jason Davies posted his code...
Took sometime to figure out the math. A demo is uploaded here, with an attempt to explain the math too. http://bl.ocks.org/ivyywang/7c94cb5a3accd9913263
With my limited math knowledge, I think, one of the advantages quaternion over Euler is the ability to compound multiple rotations over and over, without worrying about coordinate references. So it would always work, no matter where your north pole faces, and no matter how many rotations you'll have. (Someone please correct me, if I got this wrong).
I decided that solving for the combined rotation matrix might not be so hard. I got http://sagemath.org to do most of the hard work, so that I could express the composition of the original projection rotate() orientation plus a trackball rotation as a single equivalent rotate().
This gives much more natural behavior regardless of the orientation of the globe.
I updated the mockup so that it has the improved version - see http://bl.ocks.org/patricksurry/5721459
The sources are at http://bl.ocks.org/patricksurry/5721459 which include an explanation of the math - cool that you can use proper greek letters in javascript for almost readable math sourcecode!
It would still be good if D3 supported composition of rotate operations natively (or maybe it does already?!)

Blender to Unity rotations screwed up

I managed to get rotations on the console in blender, but when I try to apply it in Unity, it is just very wrong. I am using Quaternion.Set
to set the desired rotation. I know that blender uses (WXYZ) quaternion, but when I got these values and set properly it in to Unity3D (XYZW), it gives me nonsense rotations.
http://pastebin.com/bKzUVCih
here is the link to my script. Please help me point out what is wrong there.
P.S.: Euler rotations are not an option, because they're lossy as far as I know...
I have solved this problem to my satisfaction. The problem is that the XYZ rotations of Unity are different from those of Blender. If you wish to convert positioning and rotation of an object perfectly from Blender to Unity, use the following steps:
Rotate the object -90 degrees on the X axis.
Calculate the Blender quaternion. Remember that the Blender quaternion is going to come out in a WXYZ matrix, and a Unity quaternion is going to use a XYZW order.
Rotate your object back 90 degrees on the X axis, export to FBX using the experimental, "apply transform," check box.
Translate your object in Unity using the translation in Blender, BUT use the equivalent of (-X, Z, -Y) for your translation.
If you're looking for a Python script to get the quaternion out of Blender, I've put together one and put most of it here
I might as well put a YouTube clip together on this, it's simplistic but ridiculously hard to figure out.

Are there any C++ libraries for real-time animation of a 3D model using changing x,y coordinates of feature key points

I am working on a project where I am to use the Kinect to track facial expressions and animate a 3D model (.ply) accordingly.
So far I have managed to track a human face with a finite number of key-points on the face. I am able to get the coordinates of each key-point at every frame.
I am not very adept with animating techniques and general concepts of Mesh deformation and would really appreciate if one could provide a library which provides a high-level API so as to do said animation using x,y coordinates of key-points.
I am aware of CUBICA but unsure whether it can be used for what I want. Please excuse me as I am not very adept with this and would appreciate any help.
I too am looking for something that would do this (with .NET if possible), so I could hook Kinect up, set the position of each joint and see the character animate - without needing to set the position and angle of each bone which quickly gets very complex when you take into account the X,Y and Z positions.
So far my research has lead me to believe I will need a 3D engine that supports inverse kinematics - if anyone else had any better advice I'd be keen to hear it.

Resources