# How to calculate rotation for Mesh2 based on identical Mesh1 and its local vertices data?

I have two identical meshes. Their rotation is already applied in Blender (0,0,0). I would like to restore rotation for mesh2 based on mesh1 as a reference object.

I have a python script that finds the identical meshes (with the identical geometry data) and converts them to instances. Right now after linking mesh data, I lose the rotation.

The purpose of this is to align all meshes to their correct rotation after being converted to instances.

Thank you!

1 Like

if the objects are identical, just set their transform matrices equal…
`object1.matrix_world = object2.matrix_world`

I am stuck on the exact same routine.
I too managed to get to the point where I can replace identical meshes with the instances(links) of a “first” one, but in doing so I lose all the rotations (since every mesh got a random rotation that got baked at 0,0,0).
Did you find any way to fix this? I was think about:
1-finding a fixed element inside the identical meshes (like a vector going for the longest vertex distance inside the mesh) and get a value on how much the secondary copies are rotated when compared to the arbitrarly chosen “primary” one, via comparing these vectors
2-give to all the meshes a new pivot point aligned with the average normal, so that even if rotated, all the identical meshes get the center orientation aligned the same (but I found no way to change and bake such a change).

I am at a dead end in every way, so I’m asking you if you found anything handy

Can you post a minimal .blend file which demonstrates the problem? I have trouble understanding how it comes to be.

Actually there is not a proper problem. It comes down to finding a task such that it will allow to port a scene from blender to unreal engine making use of static mesh instances, but to achieve that I have to resolve this step in blender first. Here explaining step by step:

Initial condition, I have multiple copies of a same mesh; these copies may be rotated and translated, but such transformations are all “applied” to such meshes. Then pivot to center of mass (volume).
In this first step, through some scripts, duplicated meshes are recognized and renamed to match the blender convention (so with a primary “boat”, I got a “boat.001”, etc).

After this step, I can run a script that identifies the main mesh and the supposed copies, and “link” the copies to the main, “instancing” it.
Pictures of ther steps:

Making a linked mesh replace the “duplicated” with a linked of the original, but obviously it uses the pivot/center orientation of the original mesh.

I would like to ask for some advice on how to store the rotation of the duplicated before replacing it, so that I can iterate a corrective pass after replacing the dupes so to correctly orient them (same as op).
What I would appreciate is some idea on how to store some kind of rotation information, such that it can for ex be exported in a .txt file that can be read and processed by a python script in UE in the future.

Can you, with certainty, find two edges in each mesh which match the same two edges in the original mesh? If so, there is some definitive math to solve the problem. I don’t know what it looks like from atop of my head, but there’s something to start with.

you actually need three points since you would need to create a plane- so if you can find three points on each object that are identical you can calculate the plane for each one. since the plane is identical on both, you have everything you need to create matrices and move/scale/rotate the objects into identical positions.

Three points I can get are the two points with the longest distance between them inside the mesh and the center. Eventually I could grab the nearest and the farthest from the center. Could you propose any math that would make use of them? Or an example of a similar manipulation, that would really help.
Thanks for the reply anyway!