feat: Implement initial addon
Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
This commit is contained in:
parent
12320ad285
commit
716b68313b
4 changed files with 176 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
__pycache__/
|
150
addon/bitsquid/__init__.py
Normal file
150
addon/bitsquid/__init__.py
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
# Bitsquid Blender Tools
|
||||||
|
# Copyright (C) 2021 Lucas Schwiderski
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
bl_info = {
|
||||||
|
"name": "Bitsquid Engine",
|
||||||
|
"author": "Lucas Schwiderski",
|
||||||
|
"version": (0, 0, 1),
|
||||||
|
"blender": (2, 90, 0),
|
||||||
|
"location": "File > Import-Export",
|
||||||
|
"description": "Import-Export Bitsquid related files",
|
||||||
|
"category": "Import-Export",
|
||||||
|
}
|
||||||
|
|
||||||
|
# Reload sub modules if they are already loaded
|
||||||
|
if "bpy" in locals():
|
||||||
|
import importlib
|
||||||
|
importlib.reload(unit_export)
|
||||||
|
importlib.reload(unit)
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
from bpy.types import (
|
||||||
|
Panel,
|
||||||
|
Operator,
|
||||||
|
PropertyGroup,
|
||||||
|
)
|
||||||
|
from bpy.props import (
|
||||||
|
StringProperty,
|
||||||
|
EnumProperty,
|
||||||
|
PointerProperty,
|
||||||
|
)
|
||||||
|
from bpy_extras.io_utils import (
|
||||||
|
ExportHelper,
|
||||||
|
orientation_helper,
|
||||||
|
path_reference_mode,
|
||||||
|
axis_conversion,
|
||||||
|
)
|
||||||
|
from bitsquid.unit import export as unit_export
|
||||||
|
|
||||||
|
|
||||||
|
class BitsquidSettings(PropertyGroup):
|
||||||
|
project_root: StringProperty(
|
||||||
|
name="Project Root",
|
||||||
|
description="The project directory considered as root path for all Bitsquid related operations.",
|
||||||
|
default="//",
|
||||||
|
subtype='DIR_PATH',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SCENE_PT_bitsquid(Panel):
|
||||||
|
bl_label = "Bitsquid"
|
||||||
|
bl_space_type = "PROPERTIES"
|
||||||
|
bl_region_type = "WINDOW"
|
||||||
|
bl_context = "scene"
|
||||||
|
# bl_options = {'DEFAULT_CLOSED'}
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
layout.use_property_split = False
|
||||||
|
layout.use_property_decorate = False
|
||||||
|
|
||||||
|
bitsquid = context.scene.bitsquid
|
||||||
|
layout.prop(bitsquid, "project_root", text="Project Root")
|
||||||
|
|
||||||
|
|
||||||
|
class BitsquidObjectSettings(PropertyGroup):
|
||||||
|
unit_filepath: StringProperty(
|
||||||
|
name="Unit File Path",
|
||||||
|
description="The directory to store the .unit file in. Needs to be within the project root.",
|
||||||
|
default="//",
|
||||||
|
subtype='DIR_PATH',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class OBJECT_OT_bitsquid_export(Operator):
|
||||||
|
"""Export this object into a Bitsquid Unit file"""
|
||||||
|
bl_idname = "object.bitsquid_export_unit"
|
||||||
|
bl_label = "Export .unit"
|
||||||
|
bl_options = {'REGISTER'}
|
||||||
|
|
||||||
|
filepath: StringProperty(subtype='DIR_PATH')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return bpy.data.is_saved and context.active_object is not None
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
print("Export .unit")
|
||||||
|
return unit_export.save(self, context, context.object.bitsquid.unit_filepath)
|
||||||
|
|
||||||
|
|
||||||
|
class OBJECT_PT_bitsquid(Panel):
|
||||||
|
bl_label = "Bitsquid"
|
||||||
|
bl_space_type = "PROPERTIES"
|
||||||
|
bl_region_type = "WINDOW"
|
||||||
|
bl_context = "object"
|
||||||
|
# bl_options = {'DEFAULT_CLOSED'}
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
layout.use_property_split = False
|
||||||
|
layout.use_property_decorate = False
|
||||||
|
|
||||||
|
bitsquid = context.object.bitsquid
|
||||||
|
layout.prop(bitsquid, "unit_filepath", text="Unit File Path")
|
||||||
|
layout.operator("object.bitsquid_export_unit", text="Export .unit")
|
||||||
|
|
||||||
|
|
||||||
|
# Register
|
||||||
|
classes = [
|
||||||
|
BitsquidSettings,
|
||||||
|
SCENE_PT_bitsquid,
|
||||||
|
BitsquidObjectSettings,
|
||||||
|
OBJECT_PT_bitsquid,
|
||||||
|
OBJECT_OT_bitsquid_export,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def register():
|
||||||
|
from bpy.utils import register_class
|
||||||
|
for cls in classes:
|
||||||
|
register_class(cls)
|
||||||
|
|
||||||
|
bpy.types.Scene.bitsquid = PointerProperty(type=BitsquidSettings)
|
||||||
|
bpy.types.Object.bitsquid = PointerProperty(type=BitsquidObjectSettings)
|
||||||
|
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
del bpy.types.Scene.bitsquid
|
||||||
|
|
||||||
|
from bpy.utils import unregister_class
|
||||||
|
for cls in reversed(classes):
|
||||||
|
unregister_class(cls)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
register()
|
1
addon/bitsquid/unit/__init__.py
Normal file
1
addon/bitsquid/unit/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
24
addon/bitsquid/unit/export.py
Normal file
24
addon/bitsquid/unit/export.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Bitsquid Blender Tools
|
||||||
|
# Copyright (C) 2021 Lucas Schwiderski
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
|
||||||
|
|
||||||
|
def save(self, context, unit_filepath):
|
||||||
|
filepath = bpy.path.abspath(unit_filepath)
|
||||||
|
self.report({'INFO'}, "Saving unit to " + filepath)
|
||||||
|
|
||||||
|
return {'FINISHED'}
|
Loading…
Add table
Reference in a new issue