fix [#36995] FBX Importer does not import fbx model
[blender-addons.git] / space_view3d_math_vis / utils.py
blob318beffaeee196ca993c928f4ff741aaa7126c62
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # <pep8 compliant>
21 def console_namespace():
22 import console_python
23 get_consoles = console_python.get_console
24 consoles = getattr(get_consoles, "consoles", None)
25 if consoles:
26 for console, stdout, stderr in get_consoles.consoles.values():
27 return console.locals
28 return {}
31 def console_math_data():
32 from mathutils import Matrix, Vector, Quaternion, Euler
34 data_matrix = {}
35 data_quat = {}
36 data_euler = {}
37 data_vector = {}
38 data_vector_array = {}
40 for key, var in console_namespace().items():
41 if key[0] == "_":
42 continue
44 var_type = type(var)
46 if var_type is Matrix:
47 if len(var.col) != 4 or len(var.row) != 4:
48 if len(var.col) == len(var.row):
49 var = var.to_4x4()
50 else: # todo, support 4x3 matrix
51 continue
52 data_matrix[key] = var
53 elif var_type is Vector:
54 if len(var) < 3:
55 var = var.to_3d()
56 data_vector[key] = var
57 elif var_type is Quaternion:
58 data_quat[key] = var
59 elif var_type is Euler:
60 data_euler[key] = var
61 elif var_type in {list, tuple}:
62 if var:
63 ok = True
64 for item in var:
65 if type(item) is not Vector:
66 ok = False
67 break
68 if ok:
69 data_vector_array[key] = var
71 return data_matrix, data_quat, data_euler, data_vector, data_vector_array