Skip to content

Commit

Permalink
feat(bevy_components): qol improvements (#164)
Browse files Browse the repository at this point in the history
* closes #163 
* closes #153 
* closes #154 
* feat(bevy_components): added tools for diagnostics/ finding & replacing invalid & unregistered components
   * added ui for listing invalid & unregistered components
   * added boilerplate & functionality for component renaming/replacing
   * injection of invalid status & message in case the conversion did not work well
   * added deletion of components individual & bulk
   * added handling of wrong string for unit structs : allows detection of more wrong values for components
   * added progress bars for bulk operators
   * added docs for new features
   * added tests
   * added small "attempt to fix" button for unit struct uis in case they are invalid
* feat(bevy_components): added progress indicators for from/to custom properties
* various other minor ui tweaks for workflow improvement
  • Loading branch information
kaosat-dev committed Mar 7, 2024
1 parent 3b7b5f2 commit 1353e14
Show file tree
Hide file tree
Showing 17 changed files with 759 additions and 43 deletions.
73 changes: 64 additions & 9 deletions tools/bevy_components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ Before you can use the add-on you need to configure it

![configuration 3](./docs/configuration3.png)

#### registry file polling


* by default, the add-on will check for changes in your registry file every second, and refresh the UI accordingly
* you can set the polling frequency or turn it off if you do not want auto-refresh

![registry file polling](./docs/registry_polling.png)



## Use
Expand Down Expand Up @@ -173,27 +181,74 @@ It will add the component to the select object

![invalid component](./docs/invalid_components.png)

> important ! ```gltf_auto_export``` currently has no way of filtering out components, so you need to delete invalid components like these before exporting
this will be adress in the future
> see [here](#invalidunregistered-type-renaming--conversion) for ways to convert invalid / unregistered components to other types.

- if you are encountering this type of view: don't panic your component data is not gone ! It just means you need to reload the registry data by clicking on the relevant button

![missing registry data](./docs/missing_registry_data.png)



## advanced configuration
## Advanced Tools

### registry file polling
In this section you will find various additional more advanced tooling

### Invalid/unregistered type renaming / conversion

* by default, the add-on will check for changes in your registry file every second, and refresh the UI accordingly
* you can set the polling frequency or turn it off if you do not want auto-refresh
If you have components that are
* invalid : ie some error was diagnosed
* unregistered: a custom property is present on the object, but there is no matching type in the registry

Here you will get an overview, of ALL invalid and unregistered components in your Blender project, so you can find them, rename/convert them,
or delete them, also in bulk

![component rename overview](./docs/component_rename_overview2.png)

* you can click on the button to select the object in your outliner (this also works across scenes, so you will be taken to the scene where the
given object is located)

![update custom properties](./docs/component_rename_object_select.png)


#### Single object component renaming/ conversion

- to rename/convert a single component for a single object:

* go to the row of the object you want to convert the component of
* in the dropdown menu, choose the target component
* click on the button with the magic wand to convert the component

![single rename](./docs/component_rename_single.png)

> the tool will attempt to automatically convert the source component, including the field names/values, if the target component has the same ones
If it fails to do the conversion, you will get an error message, and you will either have to change the custom property yourself, or you can simply
change the values in the UI, which will automatically generate the custom property value

- to delete a single component for a single object:

* go to the row of the object you want to remove the component from
* click on the button with the "x" to remove the component

![single delete](./docs/component_remove_single.png)

#### Bulk component renaming/ conversion

- use this method if you want to convert ALL components of a given type of ALL objects

* click on this button to pick your source component

![bulk convert remove](./docs/component_rename_remove_bulk.png)

* for conversion: in the dropdown menu, choose the target component & click apply to convert all matching components
* for deletion: clic on the "x" to remove all matching components

![bulk convert remove](./docs/component_rename_remove_bulk2.png)

![registry file polling](./docs/registry_polling.png)

### For conversion between custom properties & components & vice-versa

### regenerate custom property values
#### regenerate custom property values

- "update custom properties of current object" : will go over **all components** that you have defined for the **currently selected object**, and re-generate the

Expand All @@ -212,7 +267,7 @@ It will add the component to the select object
You should also re-export your gltf files , otherwise you might run into issues


### regenerate UI values
#### regenerate component/ UI values

- since v0.2, you have the option to regenerate (for the selected object or all objects, as above) to regenerate your UI values from the custom property values

Expand Down
16 changes: 12 additions & 4 deletions tools/bevy_components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bl_info = {
"name": "bevy_components",
"author": "kaosigh",
"version": (0, 4, 0),
"version": (0, 4, 1),
"blender": (3, 4, 0),
"location": "VIEW_3D",
"description": "UI to help create Bevy blueprints and components",
Expand All @@ -16,11 +16,11 @@

from .helpers import load_settings
from .blueprints import CreateBlueprintOperator
from .components.operators import CopyComponentOperator, RemoveComponentOperator, GenerateComponent_From_custom_property_Operator, PasteComponentOperator, AddComponentOperator, Toggle_ComponentVisibility
from .components.operators import CopyComponentOperator, Fix_Component_Operator, OT_rename_component, RemoveComponentFromAllObjectsOperator, RemoveComponentOperator, GenerateComponent_From_custom_property_Operator, PasteComponentOperator, AddComponentOperator, RenameHelper, Toggle_ComponentVisibility

from .registry.registry import ComponentsRegistry,MissingBevyType
from .registry.operators import (COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT, ReloadRegistryOperator, OT_OpenFilebrowser)
from .registry.ui import (BEVY_COMPONENTS_PT_Configuration, BEVY_COMPONENTS_PT_MissingTypesPanel, MISSING_TYPES_UL_List)
from .registry.operators import (COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT, OT_select_component_name_to_replace, OT_select_object, ReloadRegistryOperator, OT_OpenFilebrowser)
from .registry.ui import (BEVY_COMPONENTS_PT_Configuration, BEVY_COMPONENTS_PT_AdvancedToolsPanel, BEVY_COMPONENTS_PT_MissingTypesPanel, MISSING_TYPES_UL_List)

from .components.metadata import (ComponentMetadata, ComponentsMeta, ensure_metadata_for_all_objects)
from .propGroups.prop_groups import (generate_propertyGroups_for_components)
Expand Down Expand Up @@ -87,6 +87,10 @@ def draw(self, context):
CopyComponentOperator,
PasteComponentOperator,
RemoveComponentOperator,
RemoveComponentFromAllObjectsOperator,
Fix_Component_Operator,
OT_rename_component,
RenameHelper,
GenerateComponent_From_custom_property_Operator,
Toggle_ComponentVisibility,

Expand All @@ -105,9 +109,13 @@ def draw(self, context):

COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL,
COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT,

OT_select_object,
OT_select_component_name_to_replace,

BEVY_COMPONENTS_PT_MainPanel,
BEVY_COMPONENTS_PT_ComponentsPanel,
BEVY_COMPONENTS_PT_AdvancedToolsPanel,
BEVY_COMPONENTS_PT_Configuration,
MISSING_TYPES_UL_List,
BEVY_COMPONENTS_PT_MissingTypesPanel,
Expand Down
19 changes: 19 additions & 0 deletions tools/bevy_components/components/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ def apply_propertyGroup_values_to_object_customProperties(object):
value = property_group_value_to_custom_property_value(propertyGroup, component_definition, registry, None)
object[component_name] = value

# apply component value(s) to custom property of a single component
def apply_propertyGroup_values_to_object_customProperties_for_component(object, component_name):
registry = bpy.context.window_manager.components_registry
print("yallah", component_name)
(_, propertyGroup) = upsert_component_in_object(object, component_name, registry)
component_definition = find_component_definition_from_short_name(component_name)
if component_definition != None:
print("merde")
value = property_group_value_to_custom_property_value(propertyGroup, component_definition, registry, None)
object[component_name] = value

components_metadata = object.components_meta.components
componentMeta = next(filter(lambda component: component["name"] == component_name, components_metadata), None)
if componentMeta:
print("here")
componentMeta.invalid = False
componentMeta.invalid_details = ""


def apply_customProperty_values_to_object_propertyGroups(object):
Expand All @@ -258,6 +275,8 @@ def apply_customProperty_values_to_object_propertyGroups(object):
object["__disable__update"] = True # disable update callback while we set the values of the propertyGroup "tree" (as a propertyGroup can contain other propertyGroups)
property_group_value_from_custom_property_value(propertyGroup, component_definition, registry, customProperty_value)
del object["__disable__update"]
source_componentMeta.invalid = False
source_componentMeta.invalid_details = ""

# removes the given component from the object: removes both the custom property and the matching metadata from the object
def remove_component_from_object(object, component_name):
Expand Down
Loading

0 comments on commit 1353e14

Please sign in to comment.