[Bf-extensions-cvs] [4dacb21] master: FBX export: split huge export_fbx_bin.py in two.

Bastien Montagne noreply at git.blender.org
Fri May 9 15:18:10 CEST 2014


Commit: 4dacb21127a6da84ac4f52bbcd5ac36dfbf3d88e
Author: Bastien Montagne
Date:   Fri May 9 15:07:57 2014 +0200
https://developer.blender.org/rBA4dacb21127a6da84ac4f52bbcd5ac36dfbf3d88e

FBX export: split huge export_fbx_bin.py in two.

Separate all utils and constants definitions into a new export_fbx_bin_utils.py file,
helps (a bit :/) to navigate in insanely big export_fbx_bin.py itself!

===================================================================

M	io_scene_fbx/export_fbx_bin.py
A	io_scene_fbx/export_fbx_bin_utils.py

===================================================================

diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index 7bc11eb..44a7eff 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -27,582 +27,61 @@ import math
 import os
 import time
 
-import collections
-from collections import namedtuple, OrderedDict
-from collections.abc import Iterable
-import itertools
+from collections import OrderedDict
 from itertools import zip_longest, chain
 
 import bpy
 import bpy_extras
-from bpy.types import Object, Bone, PoseBone, DupliObject
 from mathutils import Vector, Matrix
 
 from . import encode_bin, data_types
-
-
-# "Constants"
-FBX_VERSION = 7400
-FBX_HEADER_VERSION = 1003
-FBX_SCENEINFO_VERSION = 100
-FBX_TEMPLATES_VERSION = 100
-
-FBX_MODELS_VERSION = 232
-
-FBX_GEOMETRY_VERSION = 124
-# Revert back normals to 101 (simple 3D values) for now, 102 (4D + weights) seems not well supported by most apps
-# currently, apart from some AD products.
-FBX_GEOMETRY_NORMAL_VERSION = 101
-FBX_GEOMETRY_BINORMAL_VERSION = 101
-FBX_GEOMETRY_TANGENT_VERSION = 101
-FBX_GEOMETRY_SMOOTHING_VERSION = 102
-FBX_GEOMETRY_VCOLOR_VERSION = 101
-FBX_GEOMETRY_UV_VERSION = 101
-FBX_GEOMETRY_MATERIAL_VERSION = 101
-FBX_GEOMETRY_LAYER_VERSION = 100
-FBX_POSE_BIND_VERSION = 100
-FBX_DEFORMER_SKIN_VERSION = 101
-FBX_DEFORMER_CLUSTER_VERSION = 100
-FBX_MATERIAL_VERSION = 102
-FBX_TEXTURE_VERSION = 202
-FBX_ANIM_KEY_VERSION = 4008
-
-FBX_NAME_CLASS_SEP = b"\x00\x01"
-
-FBX_KTIME = 46186158000  # This is the number of "ktimes" in one second (yep, precision over the nanosecond...)
-
-
-MAT_CONVERT_LAMP = Matrix.Rotation(math.pi / 2.0, 4, 'X')  # Blender is -Z, FBX is -Y.
-MAT_CONVERT_CAMERA = Matrix.Rotation(math.pi / 2.0, 4, 'Y')  # Blender is -Z, FBX is +X.
-#MAT_CONVERT_BONE = Matrix.Rotation(math.pi / -2.0, 4, 'X')  # Blender is +Y, FBX is +Z.
-MAT_CONVERT_BONE = Matrix()
-
-
-BLENDER_OTHER_OBJECT_TYPES = {'CURVE', 'SURFACE', 'FONT', 'META'}
-BLENDER_OBJECT_TYPES_MESHLIKE = {'MESH'} | BLENDER_OTHER_OBJECT_TYPES
-
-
-# Lamps.
-FBX_LIGHT_TYPES = {
-    'POINT': 0,  # Point.
-    'SUN': 1,    # Directional.
-    'SPOT': 2,   # Spot.
-    'HEMI': 1,   # Directional.
-    'AREA': 3,   # Area.
-}
-FBX_LIGHT_DECAY_TYPES = {
-    'CONSTANT': 0,                   # None.
-    'INVERSE_LINEAR': 1,             # Linear.
-    'INVERSE_SQUARE': 2,             # Quadratic.
-    'CUSTOM_CURVE': 2,               # Quadratic.
-    'LINEAR_QUADRATIC_WEIGHTED': 2,  # Quadratic.
-}
-
-
-##### Misc utilities #####
-
-# Note: this could be in a utility (math.units e.g.)...
-
-UNITS = {
-    "meter": 1.0,  # Ref unit!
-    "kilometer": 0.001,
-    "millimeter": 1000.0,
-    "foot": 1.0 / 0.3048,
-    "inch": 1.0 / 0.0254,
-    "turn": 1.0,  # Ref unit!
-    "degree": 360.0,
-    "radian": math.pi * 2.0,
-    "second": 1.0,  # Ref unit!
-    "ktime": FBX_KTIME,
-}
-
-
-def units_convert(val, u_from, u_to):
-    """Convert value."""
-    conv = UNITS[u_to] / UNITS[u_from]
-    return val * conv
-
-
-def units_convert_iter(it, u_from, u_to):
-    """Convert value."""
-    conv = UNITS[u_to] / UNITS[u_from]
-    return (v * conv for v in it)
-
-
-def matrix_to_array(mat):
-    """Concatenate matrix's columns into a single, flat tuple"""
-    # blender matrix is row major, fbx is col major so transpose on write
-    return tuple(f for v in mat.transposed() for f in v)
-
-
-def similar_values(v1, v2, e=1e-6):
-    """Return True if v1 and v2 are nearly the same."""
-    if v1 == v2:
-        return True
-    return ((abs(v1 - v2) / max(abs(v1), abs(v2))) <= e)
-
-
-RIGHT_HAND_AXES = {
-    # Up, Front -> FBX values (tuples of (axis, sign), Up, Front, Coord).
-    # Note: Since we always stay in right-handed system, third coord sign is always positive!
-    ('X',  'Y'):  ((0, 1),  (1, -1),  (2, 1)),
-    ('X',  '-Y'): ((0, 1),  (1, 1), (2, 1)),
-    ('X',  'Z'):  ((0, 1),  (2, -1),  (1, 1)),
-    ('X',  '-Z'): ((0, 1),  (2, 1), (1, 1)),
-    ('-X', 'Y'):  ((0, -1), (1, -1),  (2, 1)),
-    ('-X', '-Y'): ((0, -1), (1, 1), (2, 1)),
-    ('-X', 'Z'):  ((0, -1), (2, -1),  (1, 1)),
-    ('-X', '-Z'): ((0, -1), (2, 1), (1, 1)),
-    ('Y',  'X'):  ((1, 1),  (0, -1),  (2, 1)),
-    ('Y',  '-X'): ((1, 1),  (0, 1), (2, 1)),
-    ('Y',  'Z'):  ((1, 1),  (2, -1),  (0, 1)),
-    ('Y',  '-Z'): ((1, 1),  (2, 1), (0, 1)),
-    ('-Y', 'X'):  ((1, -1), (0, -1),  (2, 1)),
-    ('-Y', '-X'): ((1, -1), (0, 1), (2, 1)),
-    ('-Y', 'Z'):  ((1, -1), (2, -1),  (0, 1)),
-    ('-Y', '-Z'): ((1, -1), (2, 1), (0, 1)),
-    ('Z',  'X'):  ((2, 1),  (0, -1),  (1, 1)),
-    ('Z',  '-X'): ((2, 1),  (0, 1), (1, 1)),
-    ('Z',  'Y'):  ((2, 1),  (1, -1),  (0, 1)),  # Blender system!
-    ('Z',  '-Y'): ((2, 1),  (1, 1), (0, 1)),
-    ('-Z', 'X'):  ((2, -1), (0, -1),  (1, 1)),
-    ('-Z', '-X'): ((2, -1), (0, 1), (1, 1)),
-    ('-Z', 'Y'):  ((2, -1), (1, -1),  (0, 1)),
-    ('-Z', '-Y'): ((2, -1), (1, 1), (0, 1)),
-}
-
-
-FBX_FRAMERATES = (
-    (-1.0, 14),  # Custom framerate.
-    (120.0, 1),
-    (100.0, 2),
-    (60.0, 3),
-    (50.0, 4),
-    (48.0, 5),
-    (30.0, 6),  # BW NTSC.
-    (30.0 / 1.001, 9),  # Color NTSC.
-    (25.0, 10),
-    (24.0, 11),
-    (24.0 / 1.001, 13),
-    (96.0, 15),
-    (72.0, 16),
-    (60.0 / 1.001, 17),
+from .export_fbx_bin_utils import (
+    # Constants.
+    FBX_VERSION, FBX_HEADER_VERSION, FBX_SCENEINFO_VERSION, FBX_TEMPLATES_VERSION,
+    FBX_MODELS_VERSION,
+    FBX_GEOMETRY_VERSION, FBX_GEOMETRY_NORMAL_VERSION, FBX_GEOMETRY_BINORMAL_VERSION, FBX_GEOMETRY_TANGENT_VERSION,
+    FBX_GEOMETRY_SMOOTHING_VERSION, FBX_GEOMETRY_VCOLOR_VERSION, FBX_GEOMETRY_UV_VERSION,
+    FBX_GEOMETRY_MATERIAL_VERSION, FBX_GEOMETRY_LAYER_VERSION,
+    FBX_POSE_BIND_VERSION, FBX_DEFORMER_SKIN_VERSION, FBX_DEFORMER_CLUSTER_VERSION,
+    FBX_MATERIAL_VERSION, FBX_TEXTURE_VERSION,
+    FBX_ANIM_KEY_VERSION,
+    FBX_KTIME,
+    BLENDER_OTHER_OBJECT_TYPES, BLENDER_OBJECT_TYPES_MESHLIKE,
+    FBX_LIGHT_TYPES, FBX_LIGHT_DECAY_TYPES,
+    RIGHT_HAND_AXES, FBX_FRAMERATES,
+    # Miscellaneous utils.
+    units_convert, units_convert_iter, matrix_to_array, similar_values,
+    # UUID from key.
+    get_fbx_uuid_from_key,
+    # Key generators.
+    get_blenderID_key, get_blenderID_name,
+    get_blender_empty_key, get_blender_bone_key,
+    get_blender_armature_bindpose_key, get_blender_armature_skin_key, get_blender_bone_cluster_key,
+    get_blender_anim_id_base, get_blender_anim_stack_key, get_blender_anim_layer_key,
+    get_blender_anim_curve_node_key, get_blender_anim_curve_key,
+    # FBX element data.
+    elem_empty,
+    elem_data_single_bool, elem_data_single_int16, elem_data_single_int32, elem_data_single_int64,
+    elem_data_single_float32, elem_data_single_float64,
+    elem_data_single_bytes, elem_data_single_string, elem_data_single_string_unicode,
+    elem_data_single_bool_array, elem_data_single_int32_array, elem_data_single_int64_array,
+    elem_data_single_float32_array, elem_data_single_float64_array,
+    elem_data_single_byte_array, elem_data_vec_float64,
+    # FBX element properties.
+    elem_properties, elem_props_set, elem_props_compound,
+    # FBX element properties handling templates.
+    elem_props_template_init, elem_props_template_set, elem_props_template_finalize,
+    # Templates.
+    FBXTemplate, fbx_templates_generate,
+    # Objects.
+    ObjectWrapper, fbx_name_class,
+    # Top level.
+    FBXSettingsMedia, FBXSettings, FBXData,
 )
 
-
-##### UIDs code. #####
-
-# ID class (mere int).
-class UID(int):
-    pass
-
-
-# UIDs storage.
-_keys_to_uids = {}
-_uids_to_keys = {}
-
-
-def _key_to_uid(uids, key):
-    # TODO: Check this is robust enough for our needs!
-    # Note: We assume we have already checked the related key wasn't yet in _keys_to_uids!
-    #       As int64 is signed in FBX, we keep uids below 2**63...
-    if isinstance(key, int) and 0 <= key < 2**63:
-        # We can use value directly as id!
-        uid = key
-    else:
-        uid = hash(key)
-        if uid < 0:
-            uid = -uid
-        if uid >= 2**63:
-            uid //= 2
-    # Try to make our uid shorter!
-    if uid > int(1e9):
-        t_uid = uid % int(1e9)
-        if t_uid not in uids:
-            uid = t_uid
-    # Make sure our uid *is* unique.
-    if uid in uids:
-        inc = 1 if uid < 2**62 else -1
-        while uid in uids:
-            uid += inc
-            if 0 > uid >= 2**63:
-                # Note that this is more that unlikely, but does not harm anyway...
-                raise ValueError("Unable to generate an UID for key {}".format(key))
-    return UID(uid)
-
-
-def get_fbxuid_from_key(key):
-    """
-    Return an UID for given key, which is assumed hasable.
-    """
-    uid = _keys_to_uids.get(key, None)
-    if uid is None:
-        uid = _key_to_uid(_uids_to_keys, key)
-        _keys_to_uids[key] = uid
-        _uids_to_keys[uid] = key
-    return uid
-
-
-# XXX Not sure we'll actually need this one?
-def get_key_from_fbxuid(uid):
-    """
-    Return the key which generated this uid.
-    """
-    assert(uid.__class__ == UID)
-    return _uids_to_keys.get(uid, None)
-
-
-# Blender-specific key generators
-def get_blenderID_key(bid):
-    if isinstance(bid, Iterable):
-        return "|".join("B" + e.rna_type.name + "#" + e.name for e in bid)
-    else:
-        return "B" + bid.rna_type.name + "#" + bid.name
-
-
-def get_blenderID_name(bid):
-    if isinstance(bid, Iterable):
-        return "|".join(e.name for e in bid)
-    else:
-        return bid.name
-
-
-def get_blender_empty_key(obj):
-    """Return bone's keys (Model and NodeAttribute)."""
-    return "|".join((get_blenderID_key(obj), "Empty"))
-
-
-def get_blender_dupli_key(dup):
-    """Return dupli's key (Model only)."""
-    return "|".join((get_blenderID_key(dup.id_data), get_blenderID_key(dup.object), "Dupli",
-           "".join(str(i) for i in dup.persistent_id)))
-
-
-def get_blender_bone_key(armature, bone):
-    """Return bone's keys (Model and NodeAttribute)."""
-    return "|".join((get_blenderID_key((armature, bone)), "Data"))
-
-
-def get_blender_armature_bindpose_key(armature, mesh):
-    """Return armature's bindpose key."""
-    return "|".join((get_blenderID_key(armature), get_blenderID_key(me

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list