mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-22 20:00:53 +00:00
feat(bevy_components):
* added "hack-ish" tweak to make sure component additions/delections etc are picked up correctly by the change tracker in auto_export * cleaned up a few operator names * very minor tweaks
This commit is contained in:
parent
a630494f88
commit
c2dc0324c3
6
tools/bevy_components/components/helpers.py
Normal file
6
tools/bevy_components/components/helpers.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import rna_prop_ui
|
||||||
|
|
||||||
|
# fake way to make our operator's changes be visible to the change/depsgraph update handler in gltf_auto_export
|
||||||
|
def ping_depsgraph_update(object):
|
||||||
|
rna_prop_ui.rna_idprop_ui_create(object, "________temp", default=0)
|
||||||
|
rna_prop_ui.rna_idprop_ui_prop_clear(object, "________temp")
|
@ -1,6 +1,8 @@
|
|||||||
import bpy
|
import bpy
|
||||||
from bpy.props import (StringProperty, BoolProperty, PointerProperty)
|
from bpy.props import (StringProperty, BoolProperty, PointerProperty)
|
||||||
from bpy_types import (PropertyGroup)
|
from bpy_types import (PropertyGroup)
|
||||||
|
|
||||||
|
from .helpers import ping_depsgraph_update
|
||||||
from ..propGroups.conversions_from_prop_group import property_group_value_to_custom_property_value
|
from ..propGroups.conversions_from_prop_group import property_group_value_to_custom_property_value
|
||||||
from ..propGroups.conversions_to_prop_group import property_group_value_from_custom_property_value
|
from ..propGroups.conversions_to_prop_group import property_group_value_from_custom_property_value
|
||||||
|
|
||||||
@ -128,6 +130,8 @@ def add_metadata_to_components_without_metadata(object):
|
|||||||
continue
|
continue
|
||||||
upsert_component_in_object(object, component_name, registry)
|
upsert_component_in_object(object, component_name, registry)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# adds a component to an object (including metadata) using the provided component definition & optional value
|
# adds a component to an object (including metadata) using the provided component definition & optional value
|
||||||
def add_component_to_object(object, component_definition, value=None):
|
def add_component_to_object(object, component_definition, value=None):
|
||||||
cleanup_invalid_metadata(object)
|
cleanup_invalid_metadata(object)
|
||||||
@ -149,6 +153,8 @@ def add_component_to_object(object, component_definition, value=None):
|
|||||||
del object["__disable__update"]
|
del object["__disable__update"]
|
||||||
|
|
||||||
object[short_name] = value
|
object[short_name] = value
|
||||||
|
ping_depsgraph_update(object)
|
||||||
|
|
||||||
|
|
||||||
def upsert_component_in_object(object, component_name, registry):
|
def upsert_component_in_object(object, component_name, registry):
|
||||||
# print("upsert_component_in_object", object, "component name", component_name)
|
# print("upsert_component_in_object", object, "component name", component_name)
|
||||||
@ -223,6 +229,8 @@ def copy_propertyGroup_values_to_another_object(source_object, target_object, co
|
|||||||
if field_name in source_propertyGroup:
|
if field_name in source_propertyGroup:
|
||||||
target_propertyGroup[field_name] = source_propertyGroup[field_name]
|
target_propertyGroup[field_name] = source_propertyGroup[field_name]
|
||||||
apply_propertyGroup_values_to_object_customProperties(target_object)
|
apply_propertyGroup_values_to_object_customProperties(target_object)
|
||||||
|
ping_depsgraph_update(object)
|
||||||
|
|
||||||
|
|
||||||
# TODO: move to propgroups ?
|
# TODO: move to propgroups ?
|
||||||
def apply_propertyGroup_values_to_object_customProperties(object):
|
def apply_propertyGroup_values_to_object_customProperties(object):
|
||||||
@ -295,6 +303,16 @@ def remove_component_from_object(object, component_name):
|
|||||||
break
|
break
|
||||||
for index in to_remove:
|
for index in to_remove:
|
||||||
components_metadata.remove(index)
|
components_metadata.remove(index)
|
||||||
|
ping_depsgraph_update(object)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def add_component_from_custom_property(object):
|
||||||
|
add_metadata_to_components_without_metadata(object)
|
||||||
|
apply_customProperty_values_to_object_propertyGroups(object)
|
||||||
|
ping_depsgraph_update(object)
|
||||||
|
|
||||||
|
def toggle_component(object, component_name):
|
||||||
|
components_in_object = object.components_meta.components
|
||||||
|
component_meta = next(filter(lambda component: component["name"] == component_name, components_in_object), None)
|
||||||
|
if component_meta != None:
|
||||||
|
component_meta.visible = not component_meta.visible
|
||||||
|
@ -3,12 +3,13 @@ import json
|
|||||||
import bpy
|
import bpy
|
||||||
from bpy_types import Operator
|
from bpy_types import Operator
|
||||||
from bpy.props import (StringProperty)
|
from bpy.props import (StringProperty)
|
||||||
from .metadata import add_component_to_object, add_metadata_to_components_without_metadata, apply_customProperty_values_to_object_propertyGroups, apply_propertyGroup_values_to_object_customProperties_for_component, copy_propertyGroup_values_to_another_object, find_component_definition_from_short_name, remove_component_from_object
|
|
||||||
|
from .metadata import add_component_from_custom_property, add_component_to_object, add_metadata_to_components_without_metadata, apply_customProperty_values_to_object_propertyGroups, apply_propertyGroup_values_to_object_customProperties_for_component, copy_propertyGroup_values_to_another_object, find_component_definition_from_short_name, remove_component_from_object, toggle_component
|
||||||
|
|
||||||
class AddComponentOperator(Operator):
|
class AddComponentOperator(Operator):
|
||||||
"""Add component to blueprint"""
|
"""Add Bevy component to object"""
|
||||||
bl_idname = "object.add_bevy_component"
|
bl_idname = "object.add_bevy_component"
|
||||||
bl_label = "Add component to blueprint Operator"
|
bl_label = "Add component to object Operator"
|
||||||
bl_options = {"UNDO"}
|
bl_options = {"UNDO"}
|
||||||
|
|
||||||
component_type: StringProperty(
|
component_type: StringProperty(
|
||||||
@ -29,7 +30,7 @@ class AddComponentOperator(Operator):
|
|||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class CopyComponentOperator(Operator):
|
class CopyComponentOperator(Operator):
|
||||||
"""Copy component from blueprint"""
|
"""Copy Bevy component from object"""
|
||||||
bl_idname = "object.copy_bevy_component"
|
bl_idname = "object.copy_bevy_component"
|
||||||
bl_label = "Copy component Operator"
|
bl_label = "Copy component Operator"
|
||||||
bl_options = {"UNDO"}
|
bl_options = {"UNDO"}
|
||||||
@ -66,9 +67,9 @@ class CopyComponentOperator(Operator):
|
|||||||
|
|
||||||
|
|
||||||
class PasteComponentOperator(Operator):
|
class PasteComponentOperator(Operator):
|
||||||
"""Paste component to blueprint"""
|
"""Paste Bevy component to object"""
|
||||||
bl_idname = "object.paste_bevy_component"
|
bl_idname = "object.paste_bevy_component"
|
||||||
bl_label = "Paste component to blueprint Operator"
|
bl_label = "Paste component to object Operator"
|
||||||
bl_options = {"UNDO"}
|
bl_options = {"UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
@ -91,7 +92,7 @@ class PasteComponentOperator(Operator):
|
|||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class RemoveComponentOperator(Operator):
|
class RemoveComponentOperator(Operator):
|
||||||
"""Remove component from object"""
|
"""Remove Bevy component from object"""
|
||||||
bl_idname = "object.remove_bevy_component"
|
bl_idname = "object.remove_bevy_component"
|
||||||
bl_label = "Remove component from object Operator"
|
bl_label = "Remove component from object Operator"
|
||||||
bl_options = {"UNDO"}
|
bl_options = {"UNDO"}
|
||||||
@ -117,12 +118,11 @@ class RemoveComponentOperator(Operator):
|
|||||||
remove_component_from_object(object, self.component_name)
|
remove_component_from_object(object, self.component_name)
|
||||||
else:
|
else:
|
||||||
self.report({"ERROR"}, "The object/ component to remove ("+ self.component_name +") does not exist")
|
self.report({"ERROR"}, "The object/ component to remove ("+ self.component_name +") does not exist")
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
class RemoveComponentFromAllObjectsOperator(Operator):
|
class RemoveComponentFromAllObjectsOperator(Operator):
|
||||||
"""Remove component from all object"""
|
"""Remove Bevy component from all object"""
|
||||||
bl_idname = "object.remove_bevy_component_all"
|
bl_idname = "object.remove_bevy_component_all"
|
||||||
bl_label = "Remove component from all objects Operator"
|
bl_label = "Remove component from all objects Operator"
|
||||||
bl_options = {"UNDO"}
|
bl_options = {"UNDO"}
|
||||||
@ -172,7 +172,7 @@ class RenameHelper(bpy.types.PropertyGroup):
|
|||||||
del bpy.types.WindowManager.bevy_component_rename_helper
|
del bpy.types.WindowManager.bevy_component_rename_helper
|
||||||
|
|
||||||
class OT_rename_component(Operator):
|
class OT_rename_component(Operator):
|
||||||
"""Rename component"""
|
"""Rename Bevy component"""
|
||||||
bl_idname = "object.rename_bevy_component"
|
bl_idname = "object.rename_bevy_component"
|
||||||
bl_label = "rename component"
|
bl_label = "rename component"
|
||||||
bl_options = {"UNDO"}
|
bl_options = {"UNDO"}
|
||||||
@ -270,7 +270,7 @@ class OT_rename_component(Operator):
|
|||||||
|
|
||||||
|
|
||||||
class GenerateComponent_From_custom_property_Operator(Operator):
|
class GenerateComponent_From_custom_property_Operator(Operator):
|
||||||
"""generate components from custom property"""
|
"""Generate Bevy components from custom property"""
|
||||||
bl_idname = "object.generate_bevy_component_from_custom_property"
|
bl_idname = "object.generate_bevy_component_from_custom_property"
|
||||||
bl_label = "Generate component from custom_property Operator"
|
bl_label = "Generate component from custom_property Operator"
|
||||||
bl_options = {"UNDO"}
|
bl_options = {"UNDO"}
|
||||||
@ -285,8 +285,7 @@ class GenerateComponent_From_custom_property_Operator(Operator):
|
|||||||
|
|
||||||
error = False
|
error = False
|
||||||
try:
|
try:
|
||||||
add_metadata_to_components_without_metadata(object)
|
add_component_from_custom_property(object)
|
||||||
apply_customProperty_values_to_object_propertyGroups(object)
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure
|
del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure
|
||||||
error = True
|
error = True
|
||||||
@ -297,7 +296,7 @@ class GenerateComponent_From_custom_property_Operator(Operator):
|
|||||||
|
|
||||||
|
|
||||||
class Fix_Component_Operator(Operator):
|
class Fix_Component_Operator(Operator):
|
||||||
"""attempt to fix component"""
|
"""Attempt to fix Bevy component"""
|
||||||
bl_idname = "object.fix_bevy_component"
|
bl_idname = "object.fix_bevy_component"
|
||||||
bl_label = "Fix component (attempts to)"
|
bl_label = "Fix component (attempts to)"
|
||||||
bl_options = {"UNDO"}
|
bl_options = {"UNDO"}
|
||||||
@ -322,7 +321,7 @@ class Fix_Component_Operator(Operator):
|
|||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class Toggle_ComponentVisibility(Operator):
|
class Toggle_ComponentVisibility(Operator):
|
||||||
"""toggles components visibility"""
|
"""Toggle Bevy component's visibility"""
|
||||||
bl_idname = "object.toggle_bevy_component_visibility"
|
bl_idname = "object.toggle_bevy_component_visibility"
|
||||||
bl_label = "Toggle component visibility"
|
bl_label = "Toggle component visibility"
|
||||||
bl_options = {"UNDO"}
|
bl_options = {"UNDO"}
|
||||||
@ -334,10 +333,6 @@ class Toggle_ComponentVisibility(Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
object = context.object
|
object = context.object
|
||||||
components_in_object = object.components_meta.components
|
toggle_component(object, self.component_name)
|
||||||
component_meta = next(filter(lambda component: component["name"] == self.component_name, components_in_object), None)
|
|
||||||
if component_meta != None:
|
|
||||||
component_meta.visible = not component_meta.visible
|
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user