Skip to content

Commit

Permalink
Merge pull request #14 from SWTOR-Slicers/Blender-4.x-support
Browse files Browse the repository at this point in the history
Blender 3.6 / 4.0.2 support
  • Loading branch information
ZeroGravitasIndeed authored Jul 24, 2024
2 parents 7931fda + 6948161 commit 5750ce5
Show file tree
Hide file tree
Showing 23 changed files with 2,037 additions and 330 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.DS_Store
__pycache__
__pycache__
.archive
.history
.vscode
553 changes: 503 additions & 50 deletions README.md

Large diffs are not rendered by default.

Binary file added images/gr2_addon_010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gr2_addon_020.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gr2_addon_030.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gr2_addon_035.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gr2_addon_040.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gr2_addon_050.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gr2_addon_060.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified io_scene_gr2.zip
Binary file not shown.
141 changes: 102 additions & 39 deletions io_scene_gr2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
# <pep8 compliant>

bl_info = {
"name": "Star Wars: The Old Republic (.gr2)",
"author": "Darth Atroxa, SWTOR Slicers",
"version": (4, 0, 1),
"blender": (2, 82, 0),
"location": "File > Import-Export",
"description": "Import-Export SWTOR skeleton, or model with bone weights, UV's and materials",
"support": 'COMMUNITY',
"category": "Import-Export",
}


import importlib
import os
import sys
from typing import List

import bpy

from bpy.app import version_string
from bpy.app.handlers import depsgraph_update_post
from bpy.props import FloatVectorProperty
from bpy.types import Context, KeyMap, Menu, PropertyGroup

from .ops.export_gr2 import ExportGR2
from .ops.export_gr2_32 import ExportGR2_32
from .ops.import_cha import ImportCHA
from .ops.import_clo import ImportCLO
from .ops.import_gr2 import ImportGR2
from .ops.import_jba import ImportJBA
from .addon_prefs import Prefs, GR2PREFS_MT_presets_menu, GR2PREFS_OT_set_preset

from .ops.export_gr2 import ExportGR2
from .ops.export_gr2_32 import ExportGR2_32
from .ops.import_cha import ImportCHA
from .ops.import_clo import ImportCLO
from .ops.import_gr2 import ImportGR2
from .ops.import_jba import ImportJBA

from .types.node import ShaderNodeHeroEngine, NODE_OT_ngroup_edit

# Detect Blender version
major, minor, _ = bpy.app.version
blender_version = major + minor / 100

if blender_version >= 4.0:
from .ops.add_swtor_shaders_menu import * # classes and fn for Shader Editor's Add menu functionality in 4.x

from .types.node import ShaderNodeHeroEngine, NODE_OT_ngroup_edit

bl_info = {
"name": "Star Wars: The Old Republic (.gr2)",
"author": "Darth Atroxa, SWTOR Slicers",
"version": (3, 5, 4),
"blender": (2, 82, 0),
"location": "File > Import-Export",
"description": "Import-Export SWTOR skeleton, or model with bone weights, UV's and materials",
"support": 'COMMUNITY',
"category": "Import-Export"
}

# Python doesn't reload package sub-modules at the same time as __init__.py!
for directory in [os.path.join(os.path.dirname(os.path.realpath(__file__)), entry)
for entry in {'ops', 'types', 'utils'}]:

# reload modules in subfolder for current Blender version
addon_root_path = os.path.dirname(os.path.realpath(__file__))

directories = [os.path.join(addon_root_path, entry) for entry in {'ops','types','utils'}]

for directory in directories:
for entry in os.listdir(directory):
if entry.endswith('.py'):
module = sys.modules.get(f"{__name__}.{entry[:-3]}")

if module:
importlib.reload(module)

# …And reload common preferences module in root of add-on
module = sys.modules.get("addon_prefs")
if module:
importlib.reload(module)


# Clear out any scene update funcs hanging around, e.g. after a script reload
for func in depsgraph_update_post:
if func.__module__.startswith(__name__):
Expand All @@ -47,39 +73,39 @@
del importlib, os, sys, depsgraph_update_post


def _import_cha(self, _context):
# Import/Export functions to append to Import/Export menus in register()
def _import_gr2(self, _context):
# type: (Menu, Context) -> None
self.layout.operator(ImportCHA.bl_idname, text="SW:TOR (.json)")
self.layout.operator(ImportGR2.bl_idname, text="SWTOR 32/64-bit Objects / Skeletons (.gr2)")


def _import_clo(self, _context):
def _import_cha(self, _context):
# type: (Menu, Context) -> None
self.layout.operator(ImportCLO.bl_idname, text="SW:TOR (.clo)")
self.layout.operator(ImportCHA.bl_idname, text="SWTOR Player Characters / NPCs (.json)")


def _import_gr2(self, _context):
def _import_jba(self, _context):
# type: (Menu, Context) -> None
self.layout.operator(ImportGR2.bl_idname, text="SW:TOR (.gr2)")

self.layout.operator(ImportJBA.bl_idname, text="SWTOR 32-bit Animations (.jba)")

def _import_jba(self, _context):
def _import_clo(self, _context):
# type: (Menu, Context) -> None
self.layout.operator(ImportJBA.bl_idname, text="SW:TOR (.jba)")
self.layout.operator(ImportCLO.bl_idname, text="SWTOR 32-bit Cloth Physics (.clo)")


def _export_gr2(self, _context):
# type: (Menu, Context) -> None
self.layout.operator(ExportGR2.bl_idname, text="SW:TOR (.gr2)")
self.layout.operator(ExportGR2.bl_idname, text="SWTOR 64-bit Objects (.gr2)")

def _export_gr2_32(self, _context):
# type: (Menu, Context) -> None
self.layout.operator(ExportGR2_32.bl_idname, text="SW:TOR (.gr2 32bit)")
self.layout.operator(ExportGR2_32.bl_idname, text="SWTOR 32-bit Objects (.gr2)")


class BoneBounds(PropertyGroup):
bounds: FloatVectorProperty(default=[0.0] * 6, name="Bounds", precision=6, size=6)


classes = (
Prefs, GR2PREFS_MT_presets_menu, GR2PREFS_OT_set_preset,
BoneBounds,
ExportGR2,
ExportGR2_32,
Expand All @@ -90,20 +116,22 @@ class BoneBounds(PropertyGroup):
ShaderNodeHeroEngine,
NODE_OT_ngroup_edit,
)
if blender_version >= 4.0:
classes = classes + (NODE_MT_add_swtor_shader, NODE_MT_swtor_shaders_menu)

keymaps: List[KeyMap] = []


def register():
# type: () -> None
import bpy

from bpy.utils import register_class
for cls in classes:
register_class(cls)

from nodeitems_utils import register_node_categories
from .types import node
register_node_categories('SWTOR', node.node_categories)

# Additions to Import-Export menu
from bpy.types import TOPBAR_MT_file_export, TOPBAR_MT_file_import
TOPBAR_MT_file_import.append(_import_cha)
TOPBAR_MT_file_import.append(_import_clo)
Expand All @@ -112,11 +140,41 @@ def register():
TOPBAR_MT_file_export.append(_export_gr2)
TOPBAR_MT_file_export.append(_export_gr2_32)


from bpy.props import CollectionProperty
from bpy.types import Object
Object.bone_bounds = CollectionProperty(name="Bone Bounds", type=BoneBounds)

import bpy

from bpy.props import StringProperty
bpy.types.Scene.io_scene_gr2_last_job = StringProperty(
name="io_scene_gr2 Add-on's Last Activity",
description=".json-format info about the results of the use of this add-on\n (e.g., objects imported) that external operators can use",
default='',
)


# Additions to Shader Editor's Add menu
if blender_version < 4.0:
from .types import node

# This was the specific way to extend shader menu categories
# that has been deprecated in 4.x.
# (Oddly enough, it seems it was deprecated in 3.4
# but still it works in 3.6.x ?)
from nodeitems_utils import register_node_categories
register_node_categories('SWTOR', node.node_categories)

else:

from .types import node

# Appends fn with separator bar plus SWTOR menu to the Shader Editor's Add menu
# This is a conventional way to extend menus.
bpy.types.NODE_MT_add.append(swtor_shaders_submenu_element)


# TAB-into-Nodegroup functionality
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='Node Editor', space_type='NODE_EDITOR')
kmi = km.keymap_items.new(node.NODE_OT_ngroup_edit.bl_idname, 'TAB', 'PRESS')
Expand All @@ -127,6 +185,12 @@ def register():


def unregister():
if blender_version < 4.0:
from nodeitems_utils import unregister_node_categories
unregister_node_categories('SWTOR')
else:
bpy.types.NODE_MT_add.remove(swtor_shaders_submenu_element)

# type: () -> None
for km in keymaps:
for kmi in km.keymap_items:
Expand All @@ -141,12 +205,11 @@ def unregister():
TOPBAR_MT_file_export.remove(_export_gr2)
TOPBAR_MT_file_export.remove(_export_gr2_32)

from nodeitems_utils import unregister_node_categories
unregister_node_categories('SWTOR')

from bpy.utils import unregister_class
for cls in classes:
unregister_class(cls)

del bpy.types.Scene.io_scene_gr2_last_job


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 5750ce5

Please sign in to comment.