2023-12-04 13:48:52 +00:00
from bpy . types import AddonPreferences
from bpy . props import ( BoolProperty ,
IntProperty ,
StringProperty ,
EnumProperty ,
CollectionProperty
)
from . internals import ( CUSTOM_PG_sceneName )
AutoExportGltfPreferenceNames = [
' auto_export ' ,
' export_main_scene_name ' ,
' export_output_folder ' ,
' export_library_scene_name ' ,
2023-12-21 23:37:52 +00:00
2023-12-04 13:48:52 +00:00
' export_blueprints ' ,
' export_blueprints_path ' ,
2024-01-01 21:35:21 +00:00
' export_marked_assets ' ,
' collection_instances_combine_mode ' ,
feat(Save & load): new crate bevy_gltf_save_load + lots of upgrades & improvements (#95)
* feat(bevy_gltf_save_load): saving & loading implemented
* created new crate for save & load features, uses & filters out blueprints for efficient loading
* saving & loading, even with dynamically spawned nested hierarchies works
* component filter , resource filter & save path root are configurable
* for saving: added removal & cleanup logic for children component with children
that have been filtered out: ie no more invalid children getting stored in the save files !
* added sending of event once saving is done
* feat(examples/save-load): example for the new crate
* loading level static & dynamic data as blueprints
* added a bit of ui when entering saving & loading states & cleanup when exiting
* feat(bevy_gltf_blueprints): significant rewrite of how the crate works
* simplified spawning process, no more spawning children containing blueprints etc
* simplified post process : instead of copying original entity into blueprint root
we now copy blueprint root data (components & children) into the original entity ! fixes #96
* much simpler code wise
* solves issue with needing to register components that we only use on the bevy side (not gltf)
since we are not copying the bevy data into the blueprints data
* added **copyComponents** helper to copy components from one entity to another, excluding existing
components on the target entity, & some bells & whistles
* **Name** is now optional when spawning a blueprint: closes #97
* **Transform** is now optional when spawning a blueprint: closes #98
* removed transform from bundle (BREAKING change)
* added (optional) **NoInBlueprint** component to have finer control over whether to inject the **InBlueprint** component inside spawned blueprint entities
* added (optional) **Library** component, so we can override library path when we want
* added (optional) **AddToGameWorld** component for convenience to automatically add entities to the game world, if there is one
* chore(bevy_gltf_components): removed verbose output, cleaned it up a bit
* feat(tools/auto_export): added option to split out "dynamic" objects in main scenes
* ie if a collection instance (or its original collection) has a "dynamic" (aka mutable, saveable etc)
flag it can get exported to a seperate gltf file (essentially acting like an "initial save")
* the rest of the levels (the "static" data) is exported without the dynamic objects and
can be reused with save files !
2024-01-10 13:49:29 +00:00
' export_separate_dynamic_and_static_objects ' ,
2023-12-17 15:08:20 +00:00
2023-12-12 12:21:53 +00:00
' export_materials_library ' ,
' export_materials_path ' ,
2023-12-21 23:37:52 +00:00
' export_scene_settings ' ,
2023-12-12 12:21:53 +00:00
2023-12-04 13:48:52 +00:00
' main_scenes ' ,
' library_scenes ' ,
' main_scenes_index ' ,
' library_scenes_index '
]
class AutoExportGltfAddonPreferences ( AddonPreferences ) :
# this must match the add-on name, use '__package__'
# when defining this in a submodule of a python package.
bl_idname = __package__
bl_options = { ' PRESET ' }
auto_export : BoolProperty (
name = ' Auto export ' ,
description = ' Automatically export to gltf on save ' ,
default = True
)
export_main_scene_name : StringProperty (
name = ' Main scene ' ,
description = ' The name of the main scene/level/world to auto export ' ,
default = ' Scene '
)
export_output_folder : StringProperty (
name = ' Export folder (relative) ' ,
description = ' The root folder for all exports(relative to current file) Defaults to current folder ' ,
default = ' '
)
export_library_scene_name : StringProperty (
name = ' Library scene ' ,
description = ' The name of the library scene to auto export ' ,
default = ' Library '
)
2023-12-17 14:31:25 +00:00
# scene components
export_scene_settings : BoolProperty (
name = ' Export scene settings ' ,
description = ' Export scene settings ie AmbientLighting, Bloom, AO etc ' ,
2024-01-01 21:35:21 +00:00
default = False
2023-12-17 14:31:25 +00:00
)
2023-12-04 13:48:52 +00:00
# blueprint settings
export_blueprints : BoolProperty (
name = ' Export Blueprints ' ,
description = ' Replaces collection instances with an Empty with a BlueprintName custom property ' ,
default = True
)
export_blueprints_path : StringProperty (
name = ' Blueprints path ' ,
description = ' path to export the blueprints to (relative to the Export folder) ' ,
default = ' library '
)
2023-12-12 12:21:53 +00:00
export_materials_library : BoolProperty (
name = ' Export materials library ' ,
description = ' remove materials from blueprints and use the material library instead ' ,
default = False
)
export_materials_path : StringProperty (
name = ' Materials path ' ,
description = ' path to export the materials libraries to (relative to the root folder) ' ,
default = ' materials '
)
2024-01-01 21:35:21 +00:00
""" combine mode can be
- ' Split ' ( default ) : replace with an empty , creating links to sub blueprints
- ' Embed ' : treat it as an embeded object and do not replace it with an empty
- ' EmbedExternal ' : embed any instance of a non local collection ( ie external assets )
- ' Inject ' : inject components from sub collection instances into the curent object = > this is now a seperate custom property that you can apply to a collecion instance
"""
collection_instances_combine_mode : EnumProperty (
name = ' Collection instances ' ,
items = (
( ' Split ' , ' Split ' , ' replace collection instances with an empty + blueprint, creating links to sub blueprints (Default, Recomended) ' ) ,
( ' Embed ' , ' Embed ' , ' treat collection instances as embeded objects and do not replace them with an empty ' ) ,
( ' EmbedExternal ' , ' EmbedExternal ' , ' treat instances of external (not specifified in the current blend file) collections (aka assets etc) as embeded objects and do not replace them with empties ' ) ,
#('Inject', 'Inject', 'inject components from sub collection instances into the curent object')
) ,
default = ' Split '
)
export_marked_assets : BoolProperty (
name = ' Auto export marked assets ' ,
description = ' Collections that have been marked as assets will be systematically exported, even if not in use in another scene ' ,
default = True
)
feat(Save & load): new crate bevy_gltf_save_load + lots of upgrades & improvements (#95)
* feat(bevy_gltf_save_load): saving & loading implemented
* created new crate for save & load features, uses & filters out blueprints for efficient loading
* saving & loading, even with dynamically spawned nested hierarchies works
* component filter , resource filter & save path root are configurable
* for saving: added removal & cleanup logic for children component with children
that have been filtered out: ie no more invalid children getting stored in the save files !
* added sending of event once saving is done
* feat(examples/save-load): example for the new crate
* loading level static & dynamic data as blueprints
* added a bit of ui when entering saving & loading states & cleanup when exiting
* feat(bevy_gltf_blueprints): significant rewrite of how the crate works
* simplified spawning process, no more spawning children containing blueprints etc
* simplified post process : instead of copying original entity into blueprint root
we now copy blueprint root data (components & children) into the original entity ! fixes #96
* much simpler code wise
* solves issue with needing to register components that we only use on the bevy side (not gltf)
since we are not copying the bevy data into the blueprints data
* added **copyComponents** helper to copy components from one entity to another, excluding existing
components on the target entity, & some bells & whistles
* **Name** is now optional when spawning a blueprint: closes #97
* **Transform** is now optional when spawning a blueprint: closes #98
* removed transform from bundle (BREAKING change)
* added (optional) **NoInBlueprint** component to have finer control over whether to inject the **InBlueprint** component inside spawned blueprint entities
* added (optional) **Library** component, so we can override library path when we want
* added (optional) **AddToGameWorld** component for convenience to automatically add entities to the game world, if there is one
* chore(bevy_gltf_components): removed verbose output, cleaned it up a bit
* feat(tools/auto_export): added option to split out "dynamic" objects in main scenes
* ie if a collection instance (or its original collection) has a "dynamic" (aka mutable, saveable etc)
flag it can get exported to a seperate gltf file (essentially acting like an "initial save")
* the rest of the levels (the "static" data) is exported without the dynamic objects and
can be reused with save files !
2024-01-10 13:49:29 +00:00
export_separate_dynamic_and_static_objects : BoolProperty (
name = ' Export dynamic and static objects seperatly ' ,
description = """ For MAIN scenes only (aka levels), toggle this to generate 2 files per level:
- one with all dynamic data : collection or instances marked as dynamic / saveable
- one with all static data : anything else that is NOT marked as dynamic """ ,
default = True
)
2023-12-04 13:48:52 +00:00
main_scenes : CollectionProperty ( name = " main scenes " , type = CUSTOM_PG_sceneName )
main_scenes_index : IntProperty ( name = " Index for main scenes list " , default = 0 )
library_scenes : CollectionProperty ( name = " library scenes " , type = CUSTOM_PG_sceneName )
library_scenes_index : IntProperty ( name = " Index for library scenes list " , default = 0 )
#####
export_format : EnumProperty (
name = ' Format ' ,
2024-01-01 21:35:21 +00:00
items = (
( ' GLB ' , ' glTF Binary (.glb) ' ,
2023-12-04 13:48:52 +00:00
' Exports a single file, with all data packed in binary form. '
' Most efficient and portable, but more difficult to edit later ' ) ,
( ' GLTF_SEPARATE ' , ' glTF Separate (.gltf + .bin + textures) ' ,
' Exports multiple files, with separate JSON, binary and texture data. '
2024-01-01 21:35:21 +00:00
' Easiest to edit later ' )
) ,
2023-12-04 13:48:52 +00:00
description = (
' Output format and embedding options. Binary is most efficient, '
' but JSON (embedded or separate) may be easier to edit later '
) ,
default = ' GLB '
)
export_copyright : StringProperty (
name = ' Copyright ' ,
description = ' Legal rights and conditions for the model ' ,
default = ' '
)
export_image_format : EnumProperty (
name = ' Images ' ,
items = ( ( ' AUTO ' , ' Automatic ' ,
' Save PNGs as PNGs and JPEGs as JPEGs. '
' If neither one, use PNG ' ) ,
( ' JPEG ' , ' JPEG Format (.jpg) ' ,
' Save images as JPEGs. (Images that need alpha are saved as PNGs though.) '
' Be aware of a possible loss in quality ' ) ,
( ' NONE ' , ' None ' ,
' Don \' t export images ' ) ,
) ,
description = (
' Output format for images. PNG is lossless and generally preferred, but JPEG might be preferable for web '
' applications due to the smaller file size. Alternatively they can be omitted if they are not needed '
) ,
default = ' AUTO '
)
export_texture_dir : StringProperty (
name = ' Textures ' ,
description = ' Folder to place texture files in. Relative to the .gltf file ' ,
default = ' ' ,
)
"""
export_jpeg_quality : IntProperty (
name = ' JPEG quality ' ,
description = ' Quality of JPEG export ' ,
default = 75 ,
min = 0 ,
max = 100
)
"""
export_keep_originals : BoolProperty (
name = ' Keep original ' ,
description = ( ' Keep original textures files if possible. '
' WARNING: if you use more than one texture, '
' where pbr standard requires only one, only one texture will be used. '
' This can lead to unexpected results '
) ,
default = False ,
)
export_texcoords : BoolProperty (
name = ' UVs ' ,
description = ' Export UVs (texture coordinates) with meshes ' ,
default = True
)
export_normals : BoolProperty (
name = ' Normals ' ,
description = ' Export vertex normals with meshes ' ,
default = True
)
export_draco_mesh_compression_enable : BoolProperty (
name = ' Draco mesh compression ' ,
description = ' Compress mesh using Draco ' ,
default = False
)
export_draco_mesh_compression_level : IntProperty (
name = ' Compression level ' ,
description = ' Compression level (0 = most speed, 6 = most compression, higher values currently not supported) ' ,
default = 6 ,
min = 0 ,
max = 10
)
export_draco_position_quantization : IntProperty (
name = ' Position quantization bits ' ,
description = ' Quantization bits for position values (0 = no quantization) ' ,
default = 14 ,
min = 0 ,
max = 30
)
export_draco_normal_quantization : IntProperty (
name = ' Normal quantization bits ' ,
description = ' Quantization bits for normal values (0 = no quantization) ' ,
default = 10 ,
min = 0 ,
max = 30
)
export_draco_texcoord_quantization : IntProperty (
name = ' Texcoord quantization bits ' ,
description = ' Quantization bits for texture coordinate values (0 = no quantization) ' ,
default = 12 ,
min = 0 ,
max = 30
)
export_draco_color_quantization : IntProperty (
name = ' Color quantization bits ' ,
description = ' Quantization bits for color values (0 = no quantization) ' ,
default = 10 ,
min = 0 ,
max = 30
)
export_draco_generic_quantization : IntProperty (
name = ' Generic quantization bits ' ,
description = ' Quantization bits for generic coordinate values like weights or joints (0 = no quantization) ' ,
default = 12 ,
min = 0 ,
max = 30
)
export_tangents : BoolProperty (
name = ' Tangents ' ,
description = ' Export vertex tangents with meshes ' ,
default = False
)
export_materials : EnumProperty (
name = ' Materials ' ,
items = ( ( ' EXPORT ' , ' Export ' ,
' Export all materials used by included objects ' ) ,
( ' PLACEHOLDER ' , ' Placeholder ' ,
' Do not export materials, but write multiple primitive groups per mesh, keeping material slot information ' ) ,
( ' NONE ' , ' No export ' ,
' Do not export materials, and combine mesh primitive groups, losing material slot information ' ) ) ,
description = ' Export materials ' ,
default = ' EXPORT '
)
export_original_specular : BoolProperty (
name = ' Export original PBR Specular ' ,
description = (
' Export original glTF PBR Specular, instead of Blender Principled Shader Specular '
) ,
default = False ,
)
export_colors : BoolProperty (
name = ' Vertex Colors ' ,
description = ' Export vertex colors with meshes ' ,
default = True
)
export_attributes : BoolProperty (
name = ' Attributes ' ,
description = ' Export Attributes (when starting with underscore) ' ,
default = False
)
use_mesh_edges : BoolProperty (
name = ' Loose Edges ' ,
description = (
' Export loose edges as lines, using the material from the first material slot '
) ,
default = False ,
)
use_mesh_vertices : BoolProperty (
name = ' Loose Points ' ,
description = (
' Export loose points as glTF points, using the material from the first material slot '
) ,
default = False ,
)
export_cameras : BoolProperty (
name = ' Cameras ' ,
description = ' Export cameras ' ,
default = True
)
use_selection : BoolProperty (
name = ' Selected Objects ' ,
description = ' Export selected objects only ' ,
default = False
)
use_visible : BoolProperty (
name = ' Visible Objects ' ,
description = ' Export visible objects only ' ,
default = True
)
use_renderable : BoolProperty (
name = ' Renderable Objects ' ,
description = ' Export renderable objects only ' ,
default = False
)
export_apply : BoolProperty (
name = ' Export Apply Modifiers ' ,
description = ' Apply modifiers (excluding Armatures) to mesh objects - '
' WARNING: prevents exporting shape keys ' ,
default = True
)
export_yup : BoolProperty (
name = ' +Y Up ' ,
description = ' Export using glTF convention, +Y up ' ,
default = True
)
use_visible : BoolProperty (
name = ' Visible Objects ' ,
description = ' Export visible objects only ' ,
default = False
)
use_renderable : BoolProperty (
name = ' Renderable Objects ' ,
description = ' Export renderable objects only ' ,
default = False
)
export_extras : BoolProperty (
name = ' Custom Properties ' ,
description = ' Export custom properties as glTF extras ' ,
default = True
)
export_animations : BoolProperty (
name = ' Animations ' ,
description = ' Exports active actions and NLA tracks as glTF animations ' ,
default = False
)