1
$\begingroup$

I have two monkeys with exactly the same meshes. They have same objects rotations, but different vertices rotations.

How I can link their meshes with saving rotations?

I think I need to convert the rotation somehow

I also found a script that can revert monkey's rotation (Script). Maybe I should somehow get the rotation delta after executing the script and apply it to the rotation of the object.

There is a first monkey transforms

First monkey

And there is a second Second monkey

This happens when I link second monkey's mesh to first enter image description here

$\endgroup$
2
  • $\begingroup$ Hello, what do you mean by "How I can link their meshes with saving rotations"? If you want the second object to be exactly the same you can copy the Object Data of the first one $\endgroup$
    – moonboots
    Nov 4, 2021 at 19:03
  • 1
    $\begingroup$ Yes, I want to copy the Object Data, but second monkey was rotated in edit mode and their meshes are different. When I'm trying to copy Object Data then rotation resets $\endgroup$
    – Vovan675
    Nov 4, 2021 at 19:06

1 Answer 1

0
$\begingroup$

Ohhh, I think I got it. Here is the script. Not best solution I sure, but it works.

You just need to select the face that will look up at zero rotation. Then just execute the script and it will convert rotations)

import bpy
import bmesh
from mathutils import Vector, Matrix
import logging

context = bpy.context
ob = context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)


face = bm.select_history.active
o = face.calc_center_median()
face.normal_update()
norm = face.normal
edges = sorted((e for e in face.edges), key=lambda e: abs((e.verts[1].co - e.verts[0].co).dot(face.normal)))
e = edges[0]
# if this value is 0 then edge and normal orthogonal should test
print((e.verts[1].co - e.verts[0].co).dot(face.normal))
T = Matrix.Translation(-o)
up = Vector((0, 0, 1))
R = face.normal.rotation_difference(up).to_matrix()

R_inv = R.inverted().to_4x4()

loc = ob.location.copy()

bmesh.ops.transform(bm, verts=bm.verts, matrix=R, space=T)
forward = Vector((0, 1, 0))
R = (e.verts[1].co - e.verts[0].co).rotation_difference(forward).to_matrix()

#bmesh.ops.transform(bm, verts=bm.verts, matrix=R, space=T)
T = Matrix.Translation(face.calc_center_median() - o)
bmesh.ops.transform(bm, verts=bm.verts, matrix=T)
bmesh.update_edit_mesh(me)

bpy.ops.object.editmode_toggle()
bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN')

ob.matrix_world = R_inv
ob.location = loc
$\endgroup$

You must log in to answer this question.

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