generated from stilobique/BlenderTemplate
Update the outline operators.
Make a setup to generate the socket collection
This commit is contained in:
@@ -5,6 +5,7 @@ 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',
|
||||
|
||||
@@ -4,13 +4,28 @@ from ..properties.models import Outline
|
||||
|
||||
|
||||
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_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)
|
||||
@@ -24,4 +39,52 @@ class ConfigBlendScene(bpy.types.Operator):
|
||||
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'}
|
||||
|
||||
@@ -49,7 +49,25 @@ class Outline:
|
||||
'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
|
||||
|
||||
Reference in New Issue
Block a user