Skip to content

Commit

Permalink
fix example, materials generated for levels and blueprints and resolv…
Browse files Browse the repository at this point in the history
…e issue when no blueprints, put my Spawn commands behind "nesting" feature since my child parent logic was messed up, good enough for now, still dont have hotreload for scene, see bevyengine/bevy#3759
  • Loading branch information
slyedoc committed Jul 20, 2024
1 parent 18dd7e9 commit fcc3559
Show file tree
Hide file tree
Showing 12 changed files with 10,092 additions and 6,527 deletions.
483 changes: 336 additions & 147 deletions Cargo.lock

Large diffs are not rendered by default.

66 changes: 19 additions & 47 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ edition = "2021"


[features]
default = ["inspector", "registry", "physics"]
physics = [ "avian3d" ]
registry = [] # optional feature to enable the registry
default = ["inspector", "nested"]
registry = [] # will write the registry to a file if enabled
inspector = [ "bevy-inspector-egui" ]
nested = [] # testing feature to test flat vs nested
animation = [] # optional feature to enable the animation system

# testing
nested = [] # testing feature to test flat vs nested
dev = [ # Only in debug
"bevy/bevy_dev_tools",
"bevy/embedded_watcher",
"bevy/file_watcher",
"bevy/dynamic_linking",
"bevy/asset_processor",
# "bevy_registry_export",
]

[dependencies]
bevy = { version = "0.14" }
Expand All @@ -20,52 +27,17 @@ serde = "1.0.202"
serde_json = "1.0.117"
bevy-inspector-egui = { version = "0.25", optional = true }
bevy_asset_loader = { version = "0.21" }
# should match bevy_hierarchy
smallvec = { version = "1.11" }

avian3d = { version = "0.1", optional = true }


# iter utils
strum = { version = "0.26", features = ["derive"] }
strum_macros = "0.26"

[dev-dependencies]
avian3d = { version = "0.1" }

[patch.crates-io]
bevy = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_a11y = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_animation = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_app = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_asset = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_audio = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_color = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_core = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_core_pipeline = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_derive = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_diagnostic = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_ecs = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_encase_derive = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_gilrs = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_gizmos = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_gltf = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_hierarchy = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_input = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_internal = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_log = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_macro_utils = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_math = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_mikktspace = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_pbr = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_ptr = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_reflect = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_render = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_scene = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_sprite = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_state = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_tasks = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_text = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_time = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_transform = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_ui = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_utils = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_window = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
bevy_winit = { git = "https://github.com/slyedoc/bevy.git", branch = "v0.14-skybox" }
[[example]]
name = "basic"
path = "examples/basic.rs"
required-features = ["registry"] # requiering this so registy is created
36 changes: 19 additions & 17 deletions addons/bevy_sly/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def export(self): # , changes_per_scene, changed_export_parameters
# dont like deleting, but i keep getting old files
self.clear_and_create_dirs() # create the directories if they dont exist


# Figure out what to export
[level_scenes, library_scenes] = self.get_scenes()
level_scenes.sort(key = lambda a: a.name.lower())
Expand All @@ -324,8 +323,10 @@ def export(self): # , changes_per_scene, changed_export_parameters
blueprints_to_export = self.get_blueprints_to_export()
blueprints_to_export.sort(key = lambda a: a.name.lower())
blueprint_count = len(blueprints_to_export)

used_material_names = self.get_all_materials(library_scenes)

level_material_names = self.get_all_materials(level_scenes, False)
library_material_names = self.get_all_materials(library_scenes, True)
material_names = list(set(library_material_names + level_material_names))
current_project_name = Path(bpy.context.blend_data.filepath).stem

# update the list of tracked exports
Expand All @@ -334,7 +335,7 @@ def export(self): # , changes_per_scene, changed_export_parameters
#bpy.context.window_manager.auto_export_tracker.exports_count = exports_total

print("-------------------------------")
print("Materials : ", len(used_material_names))
print("Materials : ", len(material_names))
print("Levels : ", level_count)
print("Blueprints : ", len(self.data.internal_blueprints))
print("-------------------------------")
Expand All @@ -344,10 +345,10 @@ def export(self): # , changes_per_scene, changed_export_parameters
try:
# Export materials by creating scene with a cube for each material then save it
material_time = time.time()
print(f"exporting materials (1/1) - {current_project_name}")
print(f"exporting materials (all { len(material_names) }) - {current_project_name}" )
gltf_path = os.path.join(self.assets_path, MATERIALS_PATH, current_project_name + "_materials")
material_scene = bpy.data.scenes.new(name=TEMPSCENE_PREFIX + "_materials")
for index, material_name in enumerate(used_material_names):
for index, material_name in enumerate(material_names):
object = make_cube("Material_"+material_name, location=[index * 0.2,0,0], rotation=[0,0,0], scale=[1,1,1], scene=material_scene)
material = bpy.data.materials[material_name]
if material:
Expand All @@ -374,14 +375,14 @@ def export(self): # , changes_per_scene, changed_export_parameters
level_time = time.time()
level_gltf_time = 0
for index, level_scene in enumerate(level_scenes):
print(f"exporting level {index+1}/{level_count}) - {level_scene.name}")
print(f"exporting level ({index+1}/{level_count}) - {level_scene.name}")
gltf_path = os.path.join(self.assets_path, LEVELS_PATH, level_scene.name)
temp_scene = bpy.data.scenes.new(name=TEMPSCENE_PREFIX+"_"+ level_scene.name)
copy_collection(level_scene.collection, temp_scene.collection)
if EXPORT_SCENE_SETTINGS:
add_scene_settings(temp_scene)
tmp_time = time.time()
export_scene(temp_scene, {}, gltf_path)
export_scene(temp_scene, {'export_materials': 'PLACEHOLDER'}, gltf_path)
level_gltf_time += time.time() - tmp_time

delete_scene(temp_scene)
Expand Down Expand Up @@ -1707,22 +1708,21 @@ def get_blueprints_to_export(self) -> list[Blueprint]:
filtered_blueprints.append(blueprint)

return list(set(filtered_blueprints))


# set MaterialInfo for export, and returns list of used materials
def get_all_materials(self, library_scenes) -> list[str]:
def get_all_materials(self, scenes, blueprint: bool) -> list[str]:
used_material_names = []

for scene in library_scenes:
for scene in scenes:
root_collection = scene.collection
for cur_collection in traverse_tree(root_collection):
if cur_collection.name in self.data.blueprint_names:
# if we are exporting blueprints, we only want
# collection in our list, else we want all collections
if not blueprint or cur_collection.name in self.data.blueprint_names:
for object in cur_collection.all_objects:
for m in object.material_slots:
used_material_names.append(m.material.name)

used_material_names = list(set(used_material_names))
return used_material_names
return list(set(used_material_names))

# create the directories for the exported assets if they do not exist
def clear_and_create_dirs(self):
Expand All @@ -1734,7 +1734,9 @@ def clear_and_create_dirs(self):
# clear out the folder
for file in os.listdir(folder):
if file.endswith(GLTF_EXTENSION):
os.remove(os.path.join(folder, file))
f = os.path.join(folder, file)
print(f"removing {f}")
os.remove(f)


# export scene to gltf with io_scene_gltf
Expand Down
Loading

0 comments on commit fcc3559

Please sign in to comment.