Skip to content

Commit

Permalink
Merge branch 'bugfixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-g committed Mar 5, 2021
2 parents 7b41ef0 + 0146709 commit 364800c
Show file tree
Hide file tree
Showing 9 changed files with 2,054 additions and 1,858 deletions.
73 changes: 39 additions & 34 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""
IO PDX Mesh Python module.
Supports Maya 2015 and up, supports Blender 2.80 and up.
Supports Maya 2018 and up, supports Blender 2.83 and up.
author : ross-g
"""

from __future__ import unicode_literals

import sys
import site
import json
Expand All @@ -20,21 +22,21 @@


bl_info = {
'author': 'ross-g',
'name': 'IO PDX Mesh',
'description': 'Import/Export Paradox asset files for the Clausewitz game engine.',
'location': '3D View > Toolbox',
'category': 'Import-Export',
'support': 'COMMUNITY',
'blender': (2, 80, 0),
'maya': (2015),
'version': (0, 72),
'warning': 'this add-on is beta',
'project_name': 'io_pdx_mesh',
'project_url': 'https://github.com/ross-g/io_pdx_mesh',
'wiki_url': 'https://github.com/ross-g/io_pdx_mesh/wiki',
'tracker_url': 'https://github.com/ross-g/io_pdx_mesh/issues',
'forum_url': 'https://forum.paradoxplaza.com/forum/index.php?forums/clausewitz-maya-exporter-modding-tool.935/',
"author": "ross-g",
"name": "IO PDX Mesh",
"description": "Import/Export Paradox asset files for the Clausewitz game engine.",
"location": "3D View > Toolbox",
"category": "Import-Export",
"support": "COMMUNITY",
"blender": (2, 83, 0),
"maya": (2018),
"version": (0, 8),
"warning": "this add-on is beta",
"project_name": "io_pdx_mesh",
"project_url": "https://github.com/ross-g/io_pdx_mesh",
"wiki_url": "https://github.com/ross-g/io_pdx_mesh/wiki",
"tracker_url": "https://github.com/ross-g/io_pdx_mesh/issues",
"forum_url": "https://forum.paradoxplaza.com/forum/index.php?forums/clausewitz-maya-exporter-modding-tool.935/",
}


Expand All @@ -43,31 +45,31 @@
========================================================================================================================
"""

app = path.split(sys.executable)[1]
environment = sys.executable.lower()
root_path = path.abspath(path.dirname(inspect.getfile(inspect.currentframe())))

# setup module logging
log_name = bl_info['project_name']
log_format = '[%(name)s] %(levelname)s: %(message)s'
log_name = bl_info["project_name"]
log_format = "[%(name)s] %(levelname)s: %(message)s"

# setup module preferences
site.addsitedir(path.join(root_path, 'external'))
site.addsitedir(path.join(root_path, "external"))
from appdirs import user_data_dir # noqa

config_path = path.join(user_data_dir(bl_info['project_name'], False), 'settings.json')
config_path = path.join(user_data_dir(bl_info["project_name"], False), "settings.json")
IO_PDX_SETTINGS = PDXsettings(config_path)

# setup engine/export settings
export_settings = path.join(root_path, 'clausewitz.json')
export_settings = path.join(root_path, "clausewitz.json")
ENGINE_SETTINGS = {}
try:
if '.zip' in export_settings:
zipped = export_settings.split('.zip')[0] + '.zip'
with zipfile.ZipFile(zipped, 'r') as z:
f = z.open('io_pdx_mesh/clausewitz.json')
if ".zip" in export_settings:
zipped = export_settings.split(".zip")[0] + ".zip"
with zipfile.ZipFile(zipped, "r") as z:
f = z.open("io_pdx_mesh/clausewitz.json")
ENGINE_SETTINGS = json.loads(f.read(), object_pairs_hook=OrderedDict)
else:
with open(export_settings, 'rt') as f:
with open(export_settings, "rt") as f:
ENGINE_SETTINGS = json.load(f, object_pairs_hook=OrderedDict)
except Exception as err:
print(err)
Expand All @@ -83,14 +85,14 @@
========================================================================================================================
"""

# check if running in Blender
if 'blender' in app.lower():
# check if running from Blender
if "blender" in environment:
import bpy # noqa

logging.basicConfig(level=logging.DEBUG, format=log_format)
IO_PDX_LOG = logging.getLogger(log_name)

IO_PDX_LOG.info("Running from {0}".format(app))
IO_PDX_LOG.info("Running from {0}".format(bpy.app.binary_path.lower()))
IO_PDX_LOG.info(root_path)

try:
Expand All @@ -100,8 +102,8 @@
traceback.print_exc()
raise e

# otherwise running in Maya
if 'maya' in app.lower():
# or running from Maya
elif "maya" in environment:
import maya.cmds # noqa

IO_PDX_LOG = logging.getLogger(log_name)
Expand All @@ -112,15 +114,18 @@
console.setFormatter(logging.Formatter(log_format))
IO_PDX_LOG.addHandler(console)

IO_PDX_LOG.info("Running from {0}".format(app))
IO_PDX_LOG.info("Running from {0}".format(environment))
IO_PDX_LOG.info(root_path)

try:
# launch the Maya UI
from .pdx_maya import maya_ui

reload(maya_ui)
maya_ui.main()
except Exception as e:
traceback.print_exc()
raise e

# otherwise, we don't support running elsewhere
else:
raise NotImplementedError('Running from unknown environment "{0}"'.format(environment))
57 changes: 31 additions & 26 deletions pdx_blender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

import inspect
import importlib

import bpy
from bpy.types import PropertyGroup
from bpy.props import PointerProperty, CollectionProperty, StringProperty, BoolProperty, EnumProperty, IntProperty

from .. import IO_PDX_LOG
from .. import IO_PDX_LOG, IO_PDX_SETTINGS, ENGINE_SETTINGS

from . import blender_import_export, blender_ui

importlib.reload(blender_import_export)
importlib.reload(blender_ui)

Expand All @@ -23,49 +25,51 @@
"""


# fmt:off
class PDXBlender_settings(PropertyGroup):
setup_engine : EnumProperty(
name='Engine',
description='Engine',
items=blender_ui.get_engine_list,
)
setup_fps : IntProperty(
name='Animation fps',
description='Animation fps',
min=1,
default=15,
update=blender_ui.set_animation_fps,
setup_engine: EnumProperty(
name="Engine",
description="Engine",
items=((engine, engine, engine) for engine in ENGINE_SETTINGS.keys()),
default=IO_PDX_SETTINGS.last_set_engine or list(ENGINE_SETTINGS.keys())[0],
update=blender_ui.set_engine,
)


class PDXMaterial_settings(PropertyGroup):
mat_name : StringProperty(
name='Material name',
description='Material name',
default='',
mat_name: StringProperty(
name="Material name",
description="Material name",
default="",
)
mat_type : StringProperty(
name='Shader type',
description='Shader type',
default='',
mat_type: StringProperty(
name="Material type",
description="Material type",
default="",
)


class PDXObject_Pointer(PropertyGroup):
ref : PointerProperty(name='pdx pointer', type=bpy.types.Object)
ref: PointerProperty(
name='pdx pointer',
type=bpy.types.Object,
)


class PDXObject_Group(PropertyGroup):
coll : CollectionProperty(type=PDXObject_Pointer)
idx : IntProperty() # index for the collection
coll: CollectionProperty(
type=PDXObject_Pointer,
)
idx: IntProperty() # index for the collection


class PDXExport_settings(PropertyGroup):
custom_range : BoolProperty(
custom_range: BoolProperty(
name='Custom range',
description='Custom range',
default=False,
)
# fmt:on


""" ====================================================================================================================
Expand All @@ -78,11 +82,11 @@ class PDXExport_settings(PropertyGroup):

# Append classes dynamically from submodules
for name, obj in inspect.getmembers(blender_ui, inspect.isclass):
if obj.__module__.startswith(__name__) and hasattr(obj, 'bl_rna'):
if obj.__module__.startswith(__name__) and hasattr(obj, "bl_rna"):
classes.append(obj)

# Sort based on possible class attribute panel_order so we can set UI rollout order in the tool panel
classes.sort(key=lambda cls: cls.panel_order if hasattr(cls, 'panel_order') else 0)
classes.sort(key=lambda cls: cls.panel_order if hasattr(cls, "panel_order") else 0)


""" ====================================================================================================================
Expand All @@ -94,6 +98,7 @@ class PDXExport_settings(PropertyGroup):
def register():
IO_PDX_LOG.info("Loading Blender UI.")
import importlib

importlib.reload(blender_import_export)
importlib.reload(blender_ui)

Expand Down
Loading

0 comments on commit 364800c

Please sign in to comment.