This script dosnt seem to be working in the latest blender, or im not using it right
I have an imported scene from an old download, i have 1000s of objects many that are duplicates
Everything is imported as if transformations have been applied so position and rotation are all 0,0,0
Position can be fixed with ‘origin to geometry’s mass’ to re-centre origins for all objects
I just need a fix for rotation, if i can get a script to rotate the local axis based on each objects data(normals or and vert data) All objects that are actually the same object would have the same vert count face count and all face normals would be the same.
Its just there local rotations that are all different or rather there all set to one global rotation. If a script can set the local axis to some sort of calculated direction based on the information of the mesh then this should produce the same result on all duplicate meshes, it should produce the same axis direction relative to the mesh regardless of its current oration in the scene.
The script could then go through and link all duplicate Objects(replace with linked duplicate)
Thus instancing the scene of 1000s of objects, ideally the script is run with nothing selected and it just processes all objects in the scene, fixing local axis and linking none linked duplicates
I have this script i found
import bpy
from bpy import context as C, data as D
from mathutils import Vector
if C.mode != 'EDIT_MESH':
raise Exception("Go to Edit Mode and select the face(s) to point towards XZ plane")
bpy.ops.object.mode_set(mode='OBJECT')
alphaape = C.object
indices = [f.index for f in alphaape.data.polygons if f.select]
def get_rot(mesh, indices):
normals = [mesh.polygons[i].normal for i in indices]
# no need to divide by len(normals) or normalize
averaged_dir = sum(normals, start=Vector())
averaged_dir.z = 0 # this way the normal is parallel to Z=0 plane and
# hopefully perpendicular to Y=0 plane
rot = averaged_dir.to_track_quat('-Y', 'Z').to_euler()
return rot
apes = (o for o in D.objects if o.name.startswith(''))
for monke in apes:
if monke is alphaape:
continue
dupmesh = monke.data
rot = get_rot(dupmesh, indices)
print(rot)
monke.data = alphaape.data
D.meshes.remove(dupmesh) # WARNING! I'm not checking for other users!
# - it's safer to not remove and make it an orphan
monke.rotation_euler = rot
Its not quite working
It dosnt really recognise same meshes and also errors out if there is a mesh thats not the same as the target mesh, It also has issues with rotations on x and y axis, duplicate objects that are rotated on the x or y is basically ignored and only z rotations are used when the linked duplicate is placed
An alternate idea is a script that takes a selected mesh looks for identical meshes and tries to place a linked copy of the selected object in all the locations of the identical meshes(removing the identical mesh a it goes). Where it tried to place the object snapping verts and rotating until all verts of the selected object match the target object
As if i was trying to place and rotate the object by hand to match another without looking at the transform numbers. So it would be a way to replace with a linked duplicate that dosnt rely on origin data to do it, just snaps the actually geometry to another