[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4661] contrib/py/scripts/addons/ io_import_fbx.py: remove ascii fbx importer, never worked well, now we have one in trunk.

Campbell Barton ideasman42 at gmail.com
Fri Aug 9 09:51:38 CEST 2013


Revision: 4661
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4661
Author:   campbellbarton
Date:     2013-08-09 07:51:37 +0000 (Fri, 09 Aug 2013)
Log Message:
-----------
remove ascii fbx importer, never worked well, now we have one in trunk.

Removed Paths:
-------------
    contrib/py/scripts/addons/io_import_fbx.py

Deleted: contrib/py/scripts/addons/io_import_fbx.py
===================================================================
--- contrib/py/scripts/addons/io_import_fbx.py	2013-08-09 06:11:12 UTC (rev 4660)
+++ contrib/py/scripts/addons/io_import_fbx.py	2013-08-09 07:51:37 UTC (rev 4661)
@@ -1,508 +0,0 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-#  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 2
-#  of the License, or (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  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.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, write to the Free Software Foundation,
-#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-# <pep8 compliant>
-
-bl_info = {
-    "name": "Import: Autodesk FBX",
-    "author": "Campbell Barton",
-    "version": (0, 0, 1),
-    "blender": (2, 56, 0),
-    "location": "File > Import ",
-    "description": "This script is WIP and not intended for general use yet!",
-    "warning": "Work in progress",
-    "wiki_url": "",
-    "tracker_url": "",
-    "category": "Import-Export"}
-
-
-def parse_fbx(path, fbx_data):
-    DEBUG = False
-
-    f = open(path, "rU", encoding="utf-8")
-    lines = f.readlines()
-
-    # remove comments and \n
-    lines = [l[:-1].rstrip() for l in lines if not l.lstrip().startswith(";")]
-
-    # remove whitespace
-    lines = [l for l in lines if l]
-
-    # remove multiline float lists
-    def unmultiline(i):
-        lines[i - 1] = lines[i - 1] + lines.pop(i).lstrip()
-
-    # Multiline floats, used for verts and matricies, this is harderto read so detect and make into 1 line.
-    i = 0
-    while i < len(lines):
-        l = lines[i].strip()
-        if l.startswith(","):
-            unmultiline(i)
-            i -= 1
-        try:
-            float(l.split(",", 1)[0])
-            unmultiline(i)
-            i -= 1
-        except:
-            pass
-
-        i += 1
-
-    CONTAINER = [None]
-
-    def is_int(val):
-        try:
-            CONTAINER[0] = int(val)
-            return True
-        except:
-            return False
-
-    def is_int_array(val):
-        try:
-            CONTAINER[0] = tuple([int(v) for v in val.split(",")])
-            return True
-        except:
-            return False
-
-    def is_float(val):
-        try:
-            CONTAINER[0] = float(val)
-            return True
-        except:
-            return False
-
-    def is_float_array(val):
-        try:
-            CONTAINER[0] = tuple([float(v) for v in val.split(",")])
-            return True
-        except:
-            return False
-
-    def read_fbx(i, ls):
-        if DEBUG:
-            print("LINE:", lines[i])
-
-        tag, val = lines[i].split(":", 1)
-        tag = tag.lstrip()
-        val = val.strip()
-
-        if val == "":
-            ls.append((tag, None, None))
-        if val.endswith("{"):
-            name = val[:-1].strip()  # remove the trailing {
-            if name == "":
-                name = None
-
-            sub_ls = []
-            ls.append((tag, name, sub_ls))
-
-            i += 1
-            while lines[i].strip() != "}":
-                i = read_fbx(i, sub_ls)
-
-        elif val.startswith('"') and val.endswith('"'):
-            ls.append((tag, None, val[1:-1]))  # remove quotes
-        elif is_int(val):
-            ls.append((tag, None, CONTAINER[0]))
-        elif is_float(val):
-            ls.append((tag, None, CONTAINER[0]))
-        elif is_int_array(val):
-            ls.append((tag, None, CONTAINER[0]))
-        elif is_float_array(val):
-            ls.append((tag, None, CONTAINER[0]))
-        elif tag == 'Property':
-            ptag, ptype, punknown, pval = val.split(",", 3)
-            ptag = ptag.strip().strip("\"")
-            ptype = ptype.strip().strip("\"")
-            punknown = punknown.strip().strip("\"")
-            pval = pval.strip()
-
-            if val.startswith('"') and val.endswith('"'):
-                pval = pval[1:-1]
-            elif is_int(pval):
-                pval = CONTAINER[0]
-            elif is_float(pval):
-                pval = CONTAINER[0]
-            elif is_int_array(pval):
-                pval = CONTAINER[0]
-            elif is_float_array(pval):
-                pval = CONTAINER[0]
-
-            ls.append((tag, None, (ptag, ptype, punknown, pval)))
-        else:
-            # IGNORING ('Property', None, '"Lcl Scaling", "Lcl Scaling", "A+",1.000000000000000,1.000000000000000,1.000000000000000')
-            print("\tParser Skipping:", (tag, None, val))
-
-        # name = .lstrip()[0]
-        if DEBUG:
-            print("TAG:", tag)
-            print("VAL:", val)
-        return i + 1
-
-    i = 0
-    while i < len(lines):
-        i = read_fbx(i, fbx_data)
-
-
-def parse_connections(fbx_data):
-    c = {}
-    for tag, name, value in fbx_data:
-        type, child, parent = [i.strip() for i in value.replace('"', '').split(',')]
-        if type == "OO":
-            parent = parent.replace('Model::', '').replace('Material::', '')
-            child = child.replace('Model::', '').replace('Material::', '')
-
-            c[child] = parent
-
-    return c
-
-# Blender code starts here:
-import bpy
-
-
-def import_fbx(path):
-    import math
-    import mathutils
-
-    mtx_x90 = mathutils.Matrix.Rotation(math.pi / 2.0, 3, 'X')
-
-    fbx_data = []
-    objects = {}
-    materials = {}
-    parse_fbx(path, fbx_data)
-    # Now lets get in the mesh data for fun.
-
-    def tag_get_iter(data, tag):
-        for tag_iter, name, value in data:
-            if tag_iter == tag:
-                yield (name, value)
-
-    def tag_get_single(data, tag):
-        for tag_iter, name, value in data:
-            if tag_iter == tag:
-                return (name, value)
-        return (None, None)
-
-    def tag_get_prop(data, prop):
-        for tag_iter, name, value in data:
-            if tag_iter == "Property":
-                if value[0] == prop:
-                    return value[3]
-        return None
-
-    scene = bpy.context.scene
-
-    connections = parse_connections(tag_get_single(fbx_data, "Connections")[1])
-
-    for tag1, name1, value1 in fbx_data:
-        if tag1 == "Objects":
-            for tag2, name2, value2 in value1:
-                if tag2 == "Model":
-                    '''
-                    print("")
-                    print(tag2)
-                    print(name2)
-                    print(value2)
-                    '''
-
-                    # check we import an object
-                    obj = None
-
-                    # "Model::MyCamera", "Camera"  -->  MyCamera
-                    fbx_name = name2.split(',')[0].strip()[1:-1].split("::", 1)[-1]
-                    # we dont parse this part properly
-                    # the name2 can be somtrhing like
-                    # Model "Model::kimiko", "Mesh"
-                    if name2.endswith(" \"Mesh\""):
-
-                        verts = tag_get_single(value2, "Vertices")[1]
-                        faces = tag_get_single(value2, "PolygonVertexIndex")[1]
-                        edges = tag_get_single(value2, "Edges")[1]
-                        if edges is None:
-                            edges = []
-
-                        # convert odd fbx verts and faces to a blender mesh.
-                        if verts and faces:
-                            me = bpy.data.meshes.new(name=fbx_name)
-                            # get a list of floats as triples
-                            blen_verts = [verts[i - 3:i] for i in range(3, len(verts) + 3, 3)]
-
-                            # get weirdo face indices and proper edge indexs
-                            # edge_points Collects faces index, first and last verts.
-
-                            face = []
-                            edge_points = {}
-                            blen_faces = [face]
-                            blen_faces_edges = []  # faces that have a length of 2
-                            blen_poly_mapping = {}
-                            poly_idx = 0
-
-                            for idx, f in enumerate(faces):
-
-                                if f < 0:
-                                    face.append(f ^ -1)
-                                    edge_points[idx] = [face[-1], face[0]]
-                                    face = []
-
-                                    if len(blen_faces[-1]) == 2:
-                                        blen_faces_edges.append(blen_faces.pop())
-                                    else:
-                                        blen_poly_mapping[poly_idx] = len(blen_faces) - 1
-
-                                    blen_faces.append(face)
-                                    poly_idx += 1
-                                else:
-                                    face.append(f)
-
-                            edge_final = []
-
-                            if len(faces) == 2:  # Special case if there is only one edge in scene.
-                                edge1 = faces[0]
-                                if edge1 < 0:
-                                    edge1 ^= -1
-                                edge2 = faces[1]
-                                if edge2 < 0:
-                                    edge2 ^= -1
-                                edge_final.append((edge1, edge2))
-
-                            else:  # More than one edges
-                                for idx, e in enumerate(edges):
-
-                                    if faces[e] < 0:  # If this is the faces last point, use edge_points to create edge between last and first points of face
-                                        edge1 = edge_points[e][0]
-                                        edge2 = edge_points[e][1]
-                                    else:
-                                        edge1 = faces[e]
-                                        edge2 = faces[e + 1]
-                                        if edge2 < 0:
-                                            edge2 ^= -1
-

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list