How to change Blender 2.76 fbx-export addon to libgdx g3dj, g3db export addon.

2,3日前にリリースされた最新版Blender 3D 2.76のfbx-exporterをlibgdx-g3dのコンバーターへ変更する方法をpatch.txtで記述した。このバージョン2.76からOption指定Windowが大きく変わったので注意してほしい。 改造はAddonの中でfbx-convをシンプルに実行しているだけなので、当たり前だが非常にstableでメンテナンスも簡単である。
注意点はfbxファイルはコンバート成功後、自動に消されるので、消したくない場合はos.remove(keywords["filepath"])を削除する。


詳細:
  1. 以下のpatch.txtをblender-2.76-linux-glibc211-x86_64/2.76/scripts/addons/io_scene_fbx/の__init__.pyに当てるとlibgdxのg3dファイルのコンバートをしてくれるようになる。BinaryかJsonかのオプションも追加される。
  2. https://github.com/libgdx/fbx-convからfbx-convをDownload & installする。ソースだけではなくBinaryのダウンロードも可能だ。
  3. Linux(Ubuntu15.04でテスト)ではfbx-conv-lin64を実行できるようにPATH環境変数に設定しなければならない。
  4. BlenderでFbx-exportを実行すればよい。メニュー名などは自分の作業効率アップのため変えてみるのもよいだろう。

尚、fbx-conv-lin64をWindows用、MacOS用のコマンド名に変更し、PATHを設定すれば各OSで動作するハズ(未確認)。
Tips:さらに自作のaddonを自動に呼びたければos.remove(keywords["filepath"])の下に他のフォルダーのaddonの関数を書けばよい(importを忘れずに)。私はそうしている。


下図ではlibgdxのoutput optionが追加になっている。defaultでg3djを出力


P.S.1
I'm sorry for English guys! May be, English version coming soon;-)

P.S.2
I can not up load this code to github yet... so much to do, so little time.

P.S.3
I'm using libgdx version1.7.0

--------------------------------------------- patch.txt-----------------------------------------------------------
--- __init__original.py 2015-09-02 16:50:54.000000000 +0900
+++ __init__.py 2015-10-13 10:00:23.434418638 +0900
@@ -294,6 +294,13 @@
             default=False,
             )

+    libgdx_binary = BoolProperty(
+            name="LibGDX Outputs g3db",
+            description="If chechked output binary g3d file. *.g3db."
+                        "uncheked meaning outputs json file. *.g3dj.",
+            default=False,
+            )
+
     object_types = EnumProperty(
             name="Object Types",
             options={'ENUM_FLAG'},
@@ -494,6 +501,7 @@
                 layout.prop(self, "object_types")
                 layout.prop(self, "bake_space_transform")
                 layout.prop(self, "use_custom_props")
+                layout.prop(self, "libgdx_binary")

                 layout.separator()
                 row = layout.row(align=True)
@@ -562,6 +570,7 @@

     def execute(self, context):
         from mathutils import Matrix
+        import os
         if not self.filepath:
             raise Exception("filepath not set")

@@ -578,13 +587,25 @@

         keywords["global_matrix"] = global_matrix

+        ret = {''}
         if self.version == 'BIN7400':
             from . import export_fbx_bin
-            return export_fbx_bin.save(self, context, **keywords)
+            ret = export_fbx_bin.save(self, context, **keywords)
         else:
             from . import export_fbx
-            return export_fbx.save(self, context, **keywords)
+            ret = export_fbx.save(self, context, **keywords)

+        if self.libgdx_binary is True:
+            command = "fbx-conv-lin64 -f -o G3DB %s" % keywords["filepath"]
+        else:
+            command = "fbx-conv-lin64 -f -o G3DJ %s" % keywords["filepath"]
+        print(">>>%s" % command)
+        if os.system(command) != 0:
+            print("ERROR: fbx-conv failed")
+        else:
+            # delete fbx file.
+            os.remove(keywords["filepath"])
+        return ret

 def menu_func_import(self, context):
     self.layout.operator(ImportFBX.bl_idname, text="FBX (.fbx)")
--------------------------------------------- patch.txt-----------------------------------------------------------

コメント

このブログの人気の投稿

日本でコンピュータサイエンスを学ぶ難しさ

How to preview nif file on the ubuntu.