Improved PSA import speed dramatically
This commit is contained in:
@@ -6,8 +6,9 @@ from collections import Counter
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
import numpy
|
||||||
from bpy.props import StringProperty, BoolProperty, CollectionProperty, PointerProperty, IntProperty, EnumProperty
|
from bpy.props import StringProperty, BoolProperty, CollectionProperty, PointerProperty, IntProperty, EnumProperty
|
||||||
from bpy.types import Operator, UIList, PropertyGroup, Panel
|
from bpy.types import Operator, UIList, PropertyGroup, Panel, FCurve
|
||||||
from bpy_extras.io_utils import ImportHelper
|
from bpy_extras.io_utils import ImportHelper
|
||||||
from mathutils import Vector, Quaternion
|
from mathutils import Vector, Quaternion
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ class ImportBone(object):
|
|||||||
self.orig_loc: Vector = Vector()
|
self.orig_loc: Vector = Vector()
|
||||||
self.orig_quat: Quaternion = Quaternion()
|
self.orig_quat: Quaternion = Quaternion()
|
||||||
self.post_quat: Quaternion = Quaternion()
|
self.post_quat: Quaternion = Quaternion()
|
||||||
self.fcurves = []
|
self.fcurves: List[FCurve] = []
|
||||||
|
|
||||||
|
|
||||||
def calculate_fcurve_data(import_bone: ImportBone, key_data: typing.Iterable[float]):
|
def calculate_fcurve_data(import_bone: ImportBone, key_data: typing.Iterable[float]):
|
||||||
@@ -197,13 +198,15 @@ def import_psa(psa_reader: PsaReader, armature_object: bpy.types.Object, options
|
|||||||
sequence_data_matrix[frame_index, bone_index] = calculate_fcurve_data(import_bone, key_data)
|
sequence_data_matrix[frame_index, bone_index] = calculate_fcurve_data(import_bone, key_data)
|
||||||
|
|
||||||
# Write the keyframes out.
|
# Write the keyframes out.
|
||||||
for frame_index in range(sequence.frame_count):
|
fcurve_data = numpy.zeros(2 * sequence.frame_count, dtype=float)
|
||||||
for bone_index, import_bone in enumerate(import_bones):
|
fcurve_data[0::2] = range(sequence.frame_count)
|
||||||
if import_bone is None:
|
for bone_index, import_bone in enumerate(import_bones):
|
||||||
continue
|
if import_bone is None:
|
||||||
key_data = sequence_data_matrix[frame_index, bone_index]
|
continue
|
||||||
for fcurve, datum in zip(import_bone.fcurves, key_data):
|
for fcurve_index, fcurve in enumerate(import_bone.fcurves):
|
||||||
fcurve.keyframe_points.insert(frame_index, datum, options={'FAST'})
|
fcurve_data[1::2] = sequence_data_matrix[:, bone_index, fcurve_index]
|
||||||
|
fcurve.keyframe_points.add(sequence.frame_count)
|
||||||
|
fcurve.keyframe_points.foreach_set('co', fcurve_data)
|
||||||
|
|
||||||
if options.should_convert_to_samples:
|
if options.should_convert_to_samples:
|
||||||
# Bake the curve to samples.
|
# Bake the curve to samples.
|
||||||
|
|||||||
Reference in New Issue
Block a user