Сброшены трансформации в asp_sdf_to_asset.py и унифицированы за счет freecad_to_asset.py
This commit is contained in:
parent
748fcd1351
commit
1ea7e50ecd
8 changed files with 116 additions and 121 deletions
|
@ -2,6 +2,9 @@
|
|||
# original idea from https://github.com/machin3io/MACHIN3tools
|
||||
# Copyright (C) 2023 Ilia Kurochkin <brothermechanic@gmail.com>
|
||||
#
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2023 by brothermechanic. All Rights Reserved.
|
||||
# Based on https://github.com/machin3io/MACHIN3tools/blob/master/operators/apply.py
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
|
@ -11,12 +14,12 @@
|
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
__version__ = "0.1"
|
||||
__version__ = "0.2"
|
||||
|
||||
from mathutils import Matrix, Vector, Quaternion
|
||||
|
||||
|
||||
def apply_transforms(obj):
|
||||
def apply_transforms(obj, location=False, rotation=False, scale=False):
|
||||
""" bake local object transforms """
|
||||
def get_loc_matrix(location):
|
||||
return Matrix.Translation(location)
|
||||
|
@ -25,21 +28,33 @@ def apply_transforms(obj):
|
|||
return rotation.to_matrix().to_4x4()
|
||||
|
||||
def get_sca_matrix(scale):
|
||||
scale_mx = Matrix()
|
||||
scale_martix = Matrix()
|
||||
for i in range(3):
|
||||
scale_mx[i][i] = scale[i]
|
||||
return scale_mx
|
||||
scale_martix[i][i] = scale[i]
|
||||
return scale_martix
|
||||
|
||||
mx = obj.matrix_world
|
||||
|
||||
loc, rot, sca = mx.decompose()
|
||||
if location and rotation and scale:
|
||||
loc, rot, sca = obj.matrix_world.decompose()
|
||||
mesh_martix = get_loc_matrix(loc) @ get_rot_matrix(rot) @ get_sca_matrix(sca)
|
||||
obj.data.transform(mesh_martix)
|
||||
apply_matrix = get_loc_matrix(Vector.Fill(3, 0)) @ get_rot_matrix(Quaternion()) @ get_sca_matrix(Vector.Fill(3, 1))
|
||||
obj.matrix_world = apply_matrix
|
||||
else:
|
||||
if location:
|
||||
raise Exception("Location only applies with all transformations (rotate and scale) together!")
|
||||
if rotation:
|
||||
loc, rot, sca = obj.matrix_world.decompose()
|
||||
mesh_martix = get_rot_matrix(rot)
|
||||
obj.data.transform(mesh_martix)
|
||||
apply_matrix = get_loc_matrix(loc) @ get_rot_matrix(Quaternion()) @ get_sca_matrix(sca)
|
||||
obj.matrix_world = apply_matrix
|
||||
|
||||
meshmx = get_rot_matrix(rot) @ get_sca_matrix(sca)
|
||||
|
||||
obj.data.transform(meshmx)
|
||||
|
||||
applymx = get_loc_matrix(loc) @ get_rot_matrix(Quaternion()) @ get_sca_matrix(Vector.Fill(3, 1))
|
||||
|
||||
obj.matrix_world = applymx
|
||||
if scale:
|
||||
loc, rot, sca = obj.matrix_world.decompose()
|
||||
mesh_martix = get_sca_matrix(sca)
|
||||
obj.data.transform(mesh_martix)
|
||||
apply_matrix = get_loc_matrix(loc) @ get_rot_matrix(rot) @ get_sca_matrix(Vector.Fill(3, 1))
|
||||
obj.matrix_world = apply_matrix
|
||||
|
||||
obj.rotation_mode = 'XYZ'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue