2
$\begingroup$

I have created a large set of individual objects by splitting an icosphere along its edges. I am currently trying to import these objects into unity, along with their appropriate transforms, relative to the origin in blender. I have been successful in importing the positions using the experimental transform functionality, however all of the newly created objects' rotation transforms are set to (0,0,0), i.e. the original parent icosphere's rotation. How could I go about recalculating the rotation of the new child objects prior to exporting to a .fbx format?

Thank you for your help, any assistance is greatly appreciated :)

$\endgroup$
3
  • $\begingroup$ Hey :). I'm pretty sure there is a very similar thread here somewhere, including a nice python script... Just can't seem to find it right now. $\endgroup$ Commented May 11, 2020 at 6:46
  • $\begingroup$ Got it! blender.stackexchange.com/q/118763 $\endgroup$ Commented May 11, 2020 at 6:52
  • $\begingroup$ @JachymMichal thanks for the link! $\endgroup$
    – lh1395
    Commented May 11, 2020 at 16:23

1 Answer 1

2
$\begingroup$

A script to do this

enter image description here Shows origin and local orientation of one split off face

  • Adds an icosphere, edge splits, separates and returns to object mode

  • Selected objects are the result of separate modifier.

  • For each face object get its lone face and calculate the global center and normal. See how far the normal is rotated from default quaternion.

    • Use this to create the global matrix aligned to normal, origin at center. The object space inverse is applied to the mesh with transfrom (makes origin (0, 0, 0).
  • The global transform is given to the object by way of world matrix.

Script.

import bpy
from mathutils import Quaternion

context = bpy.context
bpy.ops.mesh.primitive_ico_sphere_add(enter_editmode=True)
bpy.ops.mesh.edge_split()
bpy.ops.mesh.separate(type='LOOSE')

bpy.ops.object.mode_set()
z = Quaternion()
for ob in context.selected_objects:
    print(ob)
    me = ob.data
    mw = ob.matrix_world
    mwi = mw.inverted()
    f = ob.data.polygons[0]
    c = mw @ f.center
    n = mw @ f.normal

    q = z.rotation_difference(n.to_track_quat())
    M =  q.to_matrix().to_4x4()
    M.translation = c
    me.transform(mwi @ M.inverted())
    ob.matrix_world = M

Related. Another example of making a matrix based on known orthogonals.

https://blender.stackexchange.com/a/177331/15543

$\endgroup$
3
  • $\begingroup$ Thank you very much for sharing this! It worked perfectly :) $\endgroup$
    – lh1395
    Commented May 11, 2020 at 16:23
  • $\begingroup$ Note, the above script seems to only produce correct results if the objects are at the world origin... (unless I'm missing something). $\endgroup$
    – eobet
    Commented Mar 8, 2021 at 22:05
  • $\begingroup$ Oh, and the above script also only works if the original object has no previous rotation... trying to figure out why now, but... quaternions... $\endgroup$
    – eobet
    Commented Mar 13, 2021 at 21:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .