From 9345343875d9cf8dd21f38a4bee5b4156dd1553f Mon Sep 17 00:00:00 2001 From: Redphoenix <3914410+ssnd292@users.noreply.github.com> Date: Mon, 25 Sep 2023 21:01:00 +0200 Subject: [PATCH] feat(export): Add Option to Binarize i3d file for export This adds an option to specify a path to the `i3dConverter.exe`, which can then be used to create a binary i3d file. The converter exe is NOT bundled with the release and has to be supplied by the user. It can be found as part of the official Giants I3D exporter, which is downloadable from https://gdn.giants-software.com/downloads.php. --- addon/i3dio/exporter.py | 19 +++++++++++++++---- addon/i3dio/ui/addon_preferences.py | 10 ++++++++++ addon/i3dio/ui/exporter.py | 19 ++++++++++++++++++- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/addon/i3dio/exporter.py b/addon/i3dio/exporter.py index a34e23d..9d4e13a 100644 --- a/addon/i3dio/exporter.py +++ b/addon/i3dio/exporter.py @@ -1,6 +1,7 @@ from __future__ import annotations # Enables python 4.0 annotation typehints fx. class self-referencing from typing import List import sys +import os import time import logging import bpy @@ -73,6 +74,14 @@ def export_blend_to_i3d(filepath: str, axis_forward, axis_up) -> dict: i3d.export_to_i3d_file() + if bpy.context.scene.i3dio.binarize_i3d == True: + if not bpy.context.preferences.addons['i3dio'].preferences.i3d_converter_path.find("i3dConverter.exe") == -1: + logger.info(f"Starting Binarization of {filepath}") + _binarize_i3d(filepath) + logger.info(f"Finished Binarize of {filepath}") + else: + raise ValueError("The path to the i3dConverter.exe is not set correctly!") + # Global try/catch exception handler. So that any unspecified exception will still end up in the log file except Exception: logger.exception("Exception that stopped the exporter") @@ -226,7 +235,9 @@ def _process_collection_objects(i3d: I3D, collection: bpy.types.Collection, pare _add_object_to_i3d(i3d, child, parent) logger.debug(f"[{collection.name}] no more objects to process in collection") - - - - +def _binarize_i3d(filepath: str): + i3dbinarize = bpy.context.preferences.addons['i3dio'].preferences.i3d_converter_path + gamepath = bpy.context.preferences.addons['i3dio'].preferences.fs_data_path[:-5] + if i3dbinarize != '': + input_params = (i3dbinarize+' -in "'+filepath+'" -out "'+filepath+'" -gamePath "'+gamepath+'/"') + os.system(input_params) \ No newline at end of file diff --git a/addon/i3dio/ui/addon_preferences.py b/addon/i3dio/ui/addon_preferences.py index 5dc4611..3da5625 100644 --- a/addon/i3dio/ui/addon_preferences.py +++ b/addon/i3dio/ui/addon_preferences.py @@ -40,10 +40,20 @@ class I3D_IO_AddonPreferences(AddonPreferences): update=xml_library_changed ) + i3d_converter_path: StringProperty( + name="i3dConverter.exe", + description="Path to the i3dConverter.exe", + subtype='FILE_PATH', + default="" + ) + def draw(self, context): layout = self.layout layout.prop(self, 'fs_data_path') layout.prop(self, 'xml_library') + layout.label(text="The i3dconverter.exe is not supplied with this exporter.") + layout.label(text="You need to download and extract it from the 'Blender Exporter Plugin' from Giants GDN.") + layout.prop(self, 'i3d_converter_path') def register(): diff --git a/addon/i3dio/ui/exporter.py b/addon/i3dio/ui/exporter.py index e7d2b1b..f1c2025 100644 --- a/addon/i3dio/ui/exporter.py +++ b/addon/i3dio/ui/exporter.py @@ -1,4 +1,5 @@ import bpy + from bpy.props import ( StringProperty, BoolProperty, @@ -22,6 +23,7 @@ ) + classes = [] @@ -44,6 +46,13 @@ class I3DExportUIProperties(bpy.types.PropertyGroup): default='SELECTED_OBJECTS' ) + binarize_i3d: BoolProperty( + name="Binarize i3d", + description="Binarizes i3d after Export. " + "Needs to have path to 3dConverter.exe set in Addon Preferences", + default=False + ) + keep_collections_as_transformgroups: BoolProperty( name="Keep Collections", description="Keep organisational collections as transformgroups in the i3d file. If turned off collections " @@ -178,6 +187,7 @@ class I3D_IO_OT_export(Operator, ExportHelper): def execute(self, context): status = exporter.export_blend_to_i3d(self.filepath, self.axis_forward, self.axis_up) + if status['success']: self.report({'INFO'}, f"I3D Export Successful! It took {status['time']:.3f} seconds") else: @@ -191,7 +201,7 @@ def execute(self, context): "see https://stjerneidioten.github.io/" "I3D-Blender-Addon/installation/setup/setup.html#fs-data-folder") - return {'FINISHED'} + return {'FINISHED'} def draw(self, context): pass @@ -245,6 +255,13 @@ def draw(self, context): sfile = context.space_data operator = sfile.active_operator + row = layout.row() + row.prop(bpy.context.scene.i3dio, 'binarize_i3d') + if bpy.context.preferences.addons['i3dio'].preferences.i3d_converter_path == '': + row.enabled = False + else: + row.enabled = True + row = layout.row() row.prop(bpy.context.scene.i3dio, 'keep_collections_as_transformgroups')