Update the outline operators.

Make a setup to generate the socket collection
This commit is contained in:
2024-05-14 00:04:10 +02:00
parent 61e3bcaaf3
commit 9758304066
3 changed files with 83 additions and 1 deletions
+1
View File
@@ -5,6 +5,7 @@ from .operators.outline import ConfigBlendScene
from .operators.exports import ExportForFange from .operators.exports import ExportForFange
from .operators.misc import MakeBasicCollision from .operators.misc import MakeBasicCollision
from .preference import GRAOU_AddonPreference from .preference import GRAOU_AddonPreference
from .properties.main import FangeProperties
bl_info = { bl_info = {
'name': 'Fange Pipeline', 'name': 'Fange Pipeline',
+64 -1
View File
@@ -4,13 +4,28 @@ from ..properties.models import Outline
class ConfigBlendScene(bpy.types.Operator): class ConfigBlendScene(bpy.types.Operator):
"""Init the opened blend scene""" """
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_idname = 'graou.build_scene'
bl_label = 'Config or update the outline' bl_label = 'Config or update the outline'
def __init__(self): def __init__(self):
self._outline = Outline() self._outline = Outline()
# Main property
self._settings = bpy.context.scene.graou_props
self._socket = self._settings.socket_collection
def execute(self, context): def execute(self, context):
for key, value in self._outline.collections.items(): for key, value in self._outline.collections.items():
collection = bpy.data.collections.get(key) collection = bpy.data.collections.get(key)
@@ -24,4 +39,52 @@ class ConfigBlendScene(bpy.types.Operator):
if collection.color_tag is not value.color: if collection.color_tag is not value.color:
collection.color_tag = 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'} return {'FINISHED'}
+18
View File
@@ -49,7 +49,25 @@ class Outline:
'Game Object': Collection(name='Game Object', color='COLOR_05') 'Game Object': Collection(name='Game Object', color='COLOR_05')
} }
self._socket = Collection(name='Socket', color='NONE')
@property @property
def collections(self) -> [str]: def collections(self) -> [str]:
"""Returns all collections in a dict""" """Returns all collections in a dict"""
return self._collections 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