- Home /
Fixing an imported GameObject Pivot
Following another similar question I'm attaching here the problematic FBX.
It contains objects with dislocated rotation axis / pivot. So, when I try to apply a billboard script to it, it simply doesn't work.
The simplest solution would probably be to fix it on 3DS, Maya, Blender, etc, but I wanted to do it in script for whatever reason. And I couldn't, even after a lot of research.
I do realize I could manually adjust them using an empty parent, but there are 100 leaves there and that would be way too troublesome. We could also move it using RotateAround, but I couldn't figure out a way to script it into the Billboard because we can't set it into a value (rather than moving).
Also using UnifyCommunity's SetPivot didn't work very well on the FBX - it did center the Pivot, but it moved the leaf out of its original position and into the pivot position.
So, there are 2 questions here:
How to adjust the pivot on that FBX, using scripts only?
How to do it at run time only?
If that's even possible.
Why dont you want to fix it the modeling program?? Is there a specific reason, or are you just curious? This type of coding doesnt seem practical since it takes all of 10 seconds in the modeling program VS hrs or days(research, waiting for an answer, then writing code).
Sounds like just writing this question took 3 times as long than just fixing the problem in the proper fashion. Im not sure when you would ever need this code again, other than hack-fix for a prob that shouldn't be there to begin with.
Whoa, especially since there are over 100 objects! I thought we were talking about a few that could be adjusted by hand.
@hijinxbassit as I said, for whatever reason! :P there are many little reasons I don't want to get in, but yeah, one of them is taking the challenge, learning while trying it.
Answer by Wolfram · Jun 06, 2012 at 10:37 PM
Sorry, looks to me the model is shot. The leaves don't have any useful local coordinates at all - they are all the same. So the information where each leaf is supposed to be connected is lost, and it is not contained in the .fbx.
You could still write a script that finds the center of each leaf by looping over all leaves and accessing their renderer.bounds.center, then inserting a new GameObject at the stem, setting its transform.position to that center, then reparenting the leaf to that object, which will make the leaf's center the "origin" of that parent object. You can then rotate that parent object, and this will rotate the leaf around its actual center.
But this would still be an approximation, since the leaves are not necessarily connected to the branches at their center, in fact each leaf seems to have an eintirely different (relative) place where it is connected to its branch. Most importantly, their rotation will still be wrong (which is why your billboarding script is failing, even if the center of rotation has been corrected as described above). This could also be fixed, but would require more extensive and complex scripting mathematics.
So your only chance is to fix the original model and reimporting that into Unity. If that's not possible, it will still be faster to completely remodel the trees, or find others in the web ;-)
Fixing the model might be as simple as choosing different export options (i.e., not baking/flushing/flattening/whatever-it-is-called-in-your-particular-modeling-program the local object coordinates into worldspace), if you still have the original model. If all you have is the FBX, I fear you're out of luck.
Cool. I'll try your suggestion on $$anonymous$$onday, since most of that job is already done. Using RotateAround
with the renderer.bounds.center
did work great to rotate all of them in their places... So I thought this might be a good way to go... It's only about making the rotation properly, which would be way easier with LookAt
. Thanks for your time, $$anonymous$$r $$anonymous$$resse. :-)
The idea from the second paragraph, of parenting with renderer.bounds.center
, worked perfectly! It doesn't really matter where they're connected as long as the rotating looks good enough. I'll soon update answers and scripts accordingly. Thanks again!!
Answer by crogers · Jun 08, 2012 at 10:33 PM
Realtime engines do not support the concept of a pivot point that is not at 0,0,0
to "fix" in the art package, simply move the verts of your objects to make 0,0,0 to be the pivot you want,
Thanks for the answer, but it completely missed the point.
Your answer
