Rename the main folder

This commit is contained in:
2024-05-16 22:12:11 +02:00
parent 814e158eb5
commit 9cbe89e4b8
12 changed files with 10 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import bpy
from .ui.export import GRAOU_PT_panel
from .operators.outline import ConfigBlendScene
from .operators.exports import ExportForFange
from .operators.misc import MakeBasicCollision
from .preference import GRAOU_AddonPreference
from .properties.main import FangeProperties
bl_info = {
'name': 'Fange Pipeline',
'description': 'Pipeline about the game project "Fange"',
'author': 'Graou Studio, Aurelien Vaillant',
'version': (0, 0, 1),
'blender': (4, 1, 0),
'doc_url': "",
'tracker_url': "",
'support': "COMMUNITY",
'category': 'Graou Studio',
}
modules_class = [
# Main Property
ExportForFange, MakeBasicCollision, ConfigBlendScene,
# UI
GRAOU_PT_panel,
# Preference
GRAOU_AddonPreference, FangeProperties
]
def register():
for cls in modules_class:
bpy.utils.register_class(cls)
bpy.types.Scene.graou_props = bpy.props.PointerProperty(type=FangeProperties)
def unregister():
for cls in reversed(modules_class):
bpy.utils.unregister_class(cls)
del bpy.types.Scene.graou_props
if __name__ == "__main__":
register()
+150
View File
@@ -0,0 +1,150 @@
import bpy
from ..properties.models import FangeProject
from pathlib import Path
class ExportForFange(bpy.types.Operator):
"""Export a building for fange"""
bl_idname = 'graou.building_export'
bl_label = 'Easily export a building asset'
def __init__(self):
self.coll_layout = bpy.data.collections.get('Placeholder')
self.path = FangeProject()
self.asset = self.get_asset_name()
self.category = self.get_asset_type()
self.instance_type_dict = {}
@classmethod
def poll(cls, context):
col = bpy.data.collections.get('Placeholder')
if col is not None and bpy.data.is_saved:
return True
def execute(self, context):
bpy.ops.object.select_all(action='DESELECT')
print(f'[Pipeline] Start to export the building props.')
# Make a check if the file are saved on the disk
if not bpy.data.is_saved:
self.report({'ERROR'}, 'Your blend file is not saved.')
return {'CANCELLED'}
if not self.category:
self.report({'ERROR'}, 'Can\'t find the asset category.')
return {'CANCELLED'}
if len(self.coll_layout.collection_children):
for coll in self.coll_layout.children:
print(f'[Pipeline] Update "{coll.name}" mesh')
child = bpy.data.collections.get(coll.name)
for ob in child.all_objects:
print(f'\tLook "{ob.name}", his type are "{type(ob.data)}"')
# TODO Support another type object, not only SM/SK
if ob.type == 'MESH' or 'EMPTY':
print(f'[Pipeline] Check ob {ob.name} and is type {type(ob)}')
ob.select_set(True)
if ob.type == 'EMPTY':
if ob.instance_type != 'NONE':
self.instance_type_dict[ob.name] = ob.instance_type
ob.instance_type = 'NONE'
abs_export = self.category.joinpath(self.asset, "Meshes")
if not abs_export.exists():
abs_export.mkdir(parents=True)
if coll.name != 'Socket':
asset_name = f"SM_{coll.name}.fbx"
else:
asset_name = f"{coll.name}.fbx"
# TODO Use the preset system
bpy.ops.export_scene.fbx(filepath=abs_export.joinpath(asset_name).as_posix(),
use_selection=True,
use_visible=False,
use_active_collection=False,
global_scale=1.0,
apply_unit_scale=True,
apply_scale_options='FBX_SCALE_NONE',
use_space_transform=True,
bake_space_transform=True,
object_types={'MESH', 'EMPTY'},
use_mesh_modifiers=True,
use_mesh_modifiers_render=True,
mesh_smooth_type='OFF',
colors_type='SRGB',
prioritize_active_color=False,
use_subsurf=False,
use_mesh_edges=False,
use_tspace=False,
use_triangles=False,
use_custom_props=False,
add_leaf_bones=True,
primary_bone_axis='Y',
secondary_bone_axis='X',
use_armature_deform_only=False,
armature_nodetype='NULL',
bake_anim=False,
bake_anim_use_all_bones=True,
bake_anim_use_nla_strips=True,
bake_anim_use_all_actions=True,
bake_anim_force_startend_keying=True,
bake_anim_step=1.0,
bake_anim_simplify_factor=1.0,
path_mode='AUTO',
embed_textures=False,
batch_mode='OFF',
use_batch_own_dir=True,
axis_forward='X',
axis_up='Y'
)
print(f'[Pipeline] Export here "{abs_export}"')
bpy.ops.object.select_all(action='DESELECT')
self.set_instance_type()
# for coll in coll_layout.children:
# print(f'[Pipeline] Check {coll}. Item type {type(coll)}')
self.report({'INFO'}, 'Placeholder exported')
return {'FINISHED'}
def get_asset_type(self) -> Path:
"""Look the file path, to understand if the asset are a Character, Buildings or Props"""
abs_blend_path = Path(bpy.data.filepath)
print(f'[Pipeline] Get blend file path "{abs_blend_path}"')
print(f'[Pipeline] Convert to List "{abs_blend_path.parts}"')
if 'Buildings' in abs_blend_path.parts:
print(f'[Pipeline] Export here "{self.path.buildings}"')
return self.path.buildings
elif 'Pros' in abs_blend_path.parts:
print(f'[Pipeline] Export here "{self.path.props}"')
return self.path.props
elif 'Characters' in abs_blend_path.parts:
print(f'[Pipeline] Export here "{self.path.characters}"')
return self.path.characters
else:
print(f'[Pipeline] Can\'t find asset category')
return Path()
@staticmethod
def get_asset_name():
abs_blend_path = Path(bpy.data.filepath)
return abs_blend_path.stem
def set_instance_type(self):
for key, value in self.instance_type_dict.items():
ob = bpy.data.objects.get(key)
ob.instance_type = value
self.instance_type_dict.clear()
+14
View File
@@ -0,0 +1,14 @@
import bpy
class MakeBasicCollision(bpy.types.Operator):
"""From selected mesh, make a collision object"""
bl_idname = 'graou.make_collision'
bl_label = 'Generate a collision from selected mesh'
@classmethod
def poll(cls, context):
return bpy.context.object
def execute(self, context):
return {'FINISHED'}
+90
View File
@@ -0,0 +1,90 @@
import bpy
from ..properties.models import Outline
class ConfigBlendScene(bpy.types.Operator):
"""
This operator init a news blend file, or update it.
Prepare a set of collection (from the models in `properties/models/Outline`.
Hierarchy design give that:
- Placeholder
| ${StaticMesh}
| Socket (Optional)
- Icon
- Game Object
"""
bl_idname = 'graou.build_scene'
bl_label = 'Config or update the outline'
def __init__(self):
self._outline = Outline()
# Main property
self._settings = bpy.context.scene.graou_props
self._socket = self._settings.socket_collection
def execute(self, context):
for key, value in self._outline.collections.items():
collection = bpy.data.collections.get(key)
# Make the collection if this item not exist
if collection is None:
collection = bpy.data.collections.new(value.name)
context.scene.collection.children.link(collection)
# Check if the color are correctly setup, if not update-it
if collection.color_tag is not value.color:
collection.color_tag = value.color
# Check child collection color
if collection.children:
for child in collection.children:
if isinstance(child, bpy.types.Collection):
child.color_tag = value.color
# Set or update socket collection
if self._socket:
self.set_socket_collection()
else:
self.del_socket_collection()
return {'FINISHED'}
def set_socket_collection(self):
"""Make or update the socket collection"""
col_socket = bpy.data.collections.get(self._outline.socket.name)
col_placeholder = self._outline.get_placeholder_collection
col_game_object = self._outline.get_game_object_collection
if col_socket is None:
col_socket = bpy.data.collections.new(self._outline.socket.name)
# Attach to Placeholder and Game Icon if they collection exist
if col_placeholder.children.get(self._outline.socket.name) is None:
col_placeholder.children.link(col_socket)
if col_game_object.children.get(self._outline.socket.name) is None:
col_game_object.children.link(col_socket)
# Set the COLOR Tag
col_socket.color_tag = self._outline.socket.color
def del_socket_collection(self):
"""Remove the socket collection, however, if the collection doesn't exist, terminate the function"""
socket = bpy.data.collections.get(self._outline.socket.name)
if socket is not None:
bpy.data.collections.remove(socket)
class SetCollectionSocket(bpy.types.Operator):
"""Configure a/the collection with socket param"""
bl_idname = 'graou.collection.socket_setup'
bl_label = 'Set param to be socket functional'
def __init__(self):
self.socket = bpy.data.collections.get('Socket')
def execute(self, context):
return {'FINISHED'}
+56
View File
@@ -0,0 +1,56 @@
import bpy
from pathlib import Path
def check_game_project():
"""Define the unity game project"""
unity_game_project = Path("W:\\", "Graou Studio", "Game Projects", "Fange Prototype", "Fange Prototype.sln")
if unity_game_project.exists():
return unity_game_project.parent.as_posix()
else:
return ''
class GRAOU_AddonPreference(bpy.types.AddonPreferences):
"""
Configuration about the Fange pipeline
"""
bl_idname = __package__.split(".")[0]
project_path: bpy.props.StringProperty(
name='Fange Unity project',
description='Select your Unity game project',
default=check_game_project(),
subtype='FILE_PATH',
)
subdir_graph: bpy.props.StringProperty(
name='Subdir about assets folder',
default=r'Assets\Graph',
subtype='DIR_PATH',
)
subdir_props: bpy.props.StringProperty(
name='The props subdir',
default='Props',
subtype='DIR_PATH',
)
subdir_buildings: bpy.props.StringProperty(
name='The buildings subdir',
default='Buildings',
subtype='DIR_PATH',
)
subdir_characters: bpy.props.StringProperty(
name='The characters subdir',
default='Characters',
subtype='DIR_PATH',
)
def draw(self, context):
layout = self.layout
layout.label(text='Config all setup about the pipeline.')
layout.prop(self, 'project_path')
+10
View File
@@ -0,0 +1,10 @@
import bpy
class FangeProperties(bpy.types.PropertyGroup):
socket_collection: bpy.props.BoolProperty(
name='State Socket use',
description='Use the socket collection setup',
default=False
)
+73
View File
@@ -0,0 +1,73 @@
import bpy
from pathlib import Path
from dataclasses import dataclass
class FangeProject:
"""
This object is a model to give all Unity project path.
"""
def __init__(self):
self._pref = bpy.context.preferences.addons[__name__.split(".")[0]].preferences
self._project_path = Path(self._pref.project_path)
self._subdir_path = Path(self._pref.subdir_graph)
self._building_path = Path(self._pref.subdir_buildings)
self._props_path = Path(self._pref.subdir_props)
self._characters_path = Path(self._pref.subdir_characters)
@property
def buildings(self):
"""Get the buildings project path, on absolute"""
return self._project_path.joinpath(self._subdir_path, self._building_path)
@property
def props(self):
return self._project_path.joinpath(self._subdir_path, self._props_path)
@property
def characters(self):
return self._project_path.joinpath(self._subdir_path, self._characters_path)
@dataclass
class Collection:
name: str
color: str
class Outline:
"""
Model about the Outline config.
"""
def __init__(self):
self._collections = {
'Placeholder': Collection(name='Placeholder', color='COLOR_01'),
'Icon': Collection(name='Icon', color='COLOR_04'),
'Game Object': Collection(name='Game Object', color='COLOR_05')
}
self._socket = Collection(name='Socket', color='NONE')
@property
def collections(self) -> [str]:
"""Returns all collections in a dict"""
return self._collections
@property
def get_placeholder_collection(self):
return bpy.data.collections.get(self.collections['Placeholder'].name)
@property
def get_icon_collection(self):
return bpy.data.collections.get(self.collections['Icon'].name)
@property
def get_game_object_collection(self):
return bpy.data.collections.get(self.collections['Game Object'].name)
@property
def socket(self) -> Collection:
return self._socket
View File
+39
View File
@@ -0,0 +1,39 @@
import bpy
import os
# from pathlib import Path
# icon_sauropod_path = Path(os.path.dirname(os.path.abspath(__file__)), "icons", "sauropode.png")
# print(f'[Pipeline] Get the icon sauropods {icon_sauropod_path}')
#
# if icon_sauropod_path.exists():
# print(f'[Pipeline] Icon find')
# icon_sauropod = bpy.app.icons.new_triangles_from_file(icon_sauropod_path.as_posix())
# # icon_sauropod_id = bpy.app.icons.release(icon_sauropod)
class GRAOU_PT_panel(bpy.types.Panel):
bl_idname = 'GRAOU_PT_MAIN'
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = 'Pipeline'
bl_category = 'Graou Studio'
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
col.label(text='Main Config:')
col.operator('graou.build_scene', text='Init Scene', icon='OUTLINER')
col.prop(context.scene.graou_props, 'socket_collection', text='Use socket', toggle=True)
layout.separator()
layout.label(text='Asset:')
layout.operator('graou.make_collision', text='Generate collision', icon='MOD_PHYSICS')
layout.separator()
layout.label(text='Export scene:')
box = layout.box()
box.label(text='Sanity Check')
layout.operator('graou.building_export', text='Export Placeholder', icon='EXPORT')
+28
View File
@@ -0,0 +1,28 @@
import bpy
from pathlib import Path
def get_export_preset():
"""
Select a FBX preset you want use.
"""
# TODO Subdir need to be exposed
fbx_preset_paths = bpy.utils.preset_paths(r"operator\export_scene.fbx")
# TODO Preset name need to be exposed
fbx_preset = Path(fbx_preset_paths[0], "sm-unity-building.py")
if fbx_preset_paths:
print(f'[Pipeline] Get the preset path "{fbx_preset}"')
return fbx_preset
else:
print(f'[Pipeline] Preset folder not found')
def apply_mesh_and_join():
"""
This function make a new mesh with all selected asset.
"""
pass