Skip to content

Commit

Permalink
feat(export): Add Option to Binarize i3d file for export
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ssnd292 authored Sep 25, 2023
1 parent 92e14fc commit 9345343
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
19 changes: 15 additions & 4 deletions addon/i3dio/exporter.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
10 changes: 10 additions & 0 deletions addon/i3dio/ui/addon_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
19 changes: 18 additions & 1 deletion addon/i3dio/ui/exporter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import bpy

from bpy.props import (
StringProperty,
BoolProperty,
Expand All @@ -22,6 +23,7 @@
)



classes = []


Expand All @@ -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 "
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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')

Expand Down

0 comments on commit 9345343

Please sign in to comment.