FBX Import: Base patch for numpy and foreach_set speedup #104499

Merged
Bastien Montagne merged 1 commits from Mysteryem/blender-addons:fbx_import_numpy_foreach_base_pr into main 2023-04-03 14:40:58 +02:00
2 changed files with 12 additions and 0 deletions

View File

@ -244,6 +244,11 @@ def array_to_matrix4(arr):
return Matrix(tuple(zip(*[iter(arr)]*4))).transposed()
def parray_as_ndarray(arr):
"""Convert an array.array into an np.ndarray that shares the same memory"""
return np.frombuffer(arr, dtype=arr.typecode)
def similar_values(v1, v2, e=1e-6):
"""Return True if v1 and v2 are nearly the same."""
if v1 == v2:

View File

@ -18,6 +18,9 @@ import bpy
from bpy.app.translations import pgettext_tip as tip_
from mathutils import Matrix, Euler, Vector
# Also imported in .fbx_utils, so importing here is unlikely to further affect Blender startup time.
import numpy as np
# -----
# Utils
from . import parse_fbx, fbx_utils
@ -34,6 +37,10 @@ from .fbx_utils import (
similar_values,
similar_values_iter,
FBXImportSettings,
vcos_transformed,
nors_transformed,
parray_as_ndarray,
astype_view_signedness,
)
# global singleton, assign on execution