Cleanup: setOrigin() (#537)

This commit is contained in:
Dragorn421
2025-06-14 15:33:33 +02:00
committed by GitHub
parent 6365e7af0b
commit d6bb836aa3
5 changed files with 19 additions and 13 deletions
+1 -1
View File
@@ -364,7 +364,7 @@ def ootDuplicateHierarchy(obj, ignoreAttr, includeEmpties, objectCategorizer) ->
for modifier in selectedObj.modifiers:
attemptModifierApply(modifier)
for selectedObj in meshObjs:
setOrigin(obj, selectedObj)
setOrigin(selectedObj, obj.location)
if ignoreAttr is not None:
for selectedObj in meshObjs:
if getattr(selectedObj, ignoreAttr):
+1 -1
View File
@@ -220,7 +220,7 @@ def ootDuplicateArmatureAndRemoveRotations(originalArmatureObj: bpy.types.Object
try:
for obj in meshObjs:
setOrigin(armatureObj, obj)
setOrigin(obj, armatureObj.location)
bpy.ops.object.select_all(action="DESELECT")
armatureObj.select_set(True)
+1 -1
View File
@@ -59,7 +59,7 @@ class OOT_AddDoor(Operator):
parentObject(cubeObj, emptyObj)
setOrigin(emptyObj, cubeObj)
setOrigin(cubeObj, emptyObj.location)
return {"FINISHED"}
@@ -298,7 +298,7 @@ def replaceDLReferenceInGeo(geoPath, pattern, replacement):
def prepareGeolayoutExport(armatureObj, obj):
# Make object and armature space the same.
setOrigin(armatureObj, obj)
setOrigin(obj, armatureObj.location)
# Apply armature scale.
bpy.ops.object.select_all(action="DESELECT")
+15 -9
View File
@@ -685,14 +685,20 @@ def checkIdentityRotation(obj, rotation, allowYaw):
)
def setOrigin(target, obj):
bpy.ops.object.select_all(action="DESELECT")
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
bpy.ops.object.transform_apply()
bpy.context.scene.cursor.location = target.location
bpy.ops.object.origin_set(type="ORIGIN_CURSOR")
bpy.ops.object.select_all(action="DESELECT")
def setOrigin(obj: bpy.types.Object, target_loc: mathutils.Vector):
if not target_loc.is_frozen:
target_loc = target_loc.copy()
with bpy.context.temp_override(
selected_objects=[obj],
active_object=obj,
):
obj.location += -target_loc
# Applying location puts the object origin at world origin
# (It is only needed to apply location to set the origin,
# but historically this function has applied all transforms
# so just keep doing that to not break anything)
bpy.ops.object.transform_apply()
obj.location = target_loc
def checkIfPathExists(filePath):
@@ -1081,7 +1087,7 @@ def combineObjects(obj, includeChildren, ignoreAttr, areaIndex):
joinedObj.select_set(True)
meshList.remove(joinedObj.data)
bpy.ops.object.join()
setOrigin(obj, joinedObj)
setOrigin(joinedObj, obj.location)
bpy.ops.object.select_all(action="DESELECT")
bpy.context.view_layer.objects.active = joinedObj