Compare commits

...

2 Commits

Author SHA1 Message Date
kaosat.dev 6bc0ec0782 feat(Blenvy:Blender): added blender_manifest.toml to be compatible with Blender 4.2 extensions 2024-07-19 01:11:31 +02:00
kaosat.dev be0f4f1377 fix(Blenvy:Bevy): added safeguard against files withouth scene level metadata
* normally this should NOT happen if the blueprints to spawn are correctly generated
(by the Blender add-on) gltf files, but better safe (no unwrap!) than sorry
2024-07-19 01:09:43 +02:00
3 changed files with 104 additions and 34 deletions

View File

@ -156,41 +156,43 @@ pub(crate) fn blueprints_prepare_spawn(
/* prefetch attempt */
let gltf = RawGltf::open(format!("assets/{}", blueprint_info.path)).unwrap();
for scene in gltf.scenes() {
let scene_extras = scene.extras().clone().unwrap();
let lookup: HashMap<String, Value> = serde_json::from_str(scene_extras.get()).unwrap();
if lookup.contains_key("BlueprintAssets") {
let assets_raw = &lookup["BlueprintAssets"];
//println!("ASSETS RAW {}", assets_raw);
let all_assets: BlueprintAssets =
ron::from_str(assets_raw.as_str().unwrap()).unwrap();
// println!("all_assets {:?}", all_assets);
if let Some(scene_extras) = scene.extras().clone()
{
let lookup: HashMap<String, Value> = serde_json::from_str(scene_extras.get()).unwrap();
if lookup.contains_key("BlueprintAssets") {
let assets_raw = &lookup["BlueprintAssets"];
//println!("ASSETS RAW {}", assets_raw);
let all_assets: BlueprintAssets =
ron::from_str(assets_raw.as_str().unwrap()).unwrap();
// println!("all_assets {:?}", all_assets);
for asset in all_assets.assets.iter() {
println!("ASSET {}",asset.path);
let untyped_handle = asset_server.load_untyped(&asset.path);
let asset_id = untyped_handle.id();
let loaded = asset_server.is_loaded_with_dependencies(asset_id);
if !loaded {
asset_infos.push(AssetLoadTracker {
name: asset.name.clone(),
path: asset.path.clone(),
id: asset_id,
loaded: false,
handle: untyped_handle.clone(),
});
}
for asset in all_assets.assets.iter() {
println!("ASSET {}",asset.path);
let untyped_handle = asset_server.load_untyped(&asset.path);
let asset_id = untyped_handle.id();
let loaded = asset_server.is_loaded_with_dependencies(asset_id);
if !loaded {
asset_infos.push(AssetLoadTracker {
name: asset.name.clone(),
path: asset.path.clone(),
id: asset_id,
loaded: false,
handle: untyped_handle.clone(),
});
}
// FIXME: dang, too early, asset server has not yet started loading yet
// let path_id = asset_server.get_path_id(&asset.path).expect("we should have alread checked for this asset");
let path_id = asset.path.clone();
// TODO: make this dependant on if hot reload is enabled or not
if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids.contains_key(&path_id) {
assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids.insert(path_id.clone(), vec![]);
}
// only insert if not already present in mapping
if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids[&path_id].contains(&entity) {
println!("adding mapping between {} and entity {:?}", path_id, all_names.get(entity));
assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids.get_mut(&path_id).unwrap().push(entity);
// FIXME: dang, too early, asset server has not yet started loading yet
// let path_id = asset_server.get_path_id(&asset.path).expect("we should have alread checked for this asset");
let path_id = asset.path.clone();
// TODO: make this dependant on if hot reload is enabled or not
if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids.contains_key(&path_id) {
assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids.insert(path_id.clone(), vec![]);
}
// only insert if not already present in mapping
if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids[&path_id].contains(&entity) {
println!("adding mapping between {} and entity {:?}", path_id, all_names.get(entity));
assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids.get_mut(&path_id).unwrap().push(entity);
}
}
}
}

View File

@ -171,7 +171,6 @@ type_mappings = {
"bevy_color::linear_rgba::LinearRgba": lambda value: parse_color_rgba(value, float, "LinearRgba"),
"bevy_color::hsva::Hsva": lambda value: parse_color_hsva(value, float, "Hsva"),
'bevy_ecs::entity::Entity': lambda value: int(value),
}

View File

@ -0,0 +1,69 @@
schema_version = "1.0.0"
id = "Blenvy"
version = "0.1.0"
name = "Blenvy"
tagline = "Tools to add/edit components of objects, collections etc & create blueprints & levels for the Bevy Engine in Blender"
maintainer = "kaosat-dev <https://github.com/kaosat-dev/>"
type = "add-on"
# Optional link to documentation, support, source files, etc
# website = "https://extensions.blender.org/add-ons/my-example-package/"
website = "https://github.com/kaosat-dev/Blenvy"
# Optional list defined by Blender and server, see:
# https://docs.blender.org/manual/en/dev/advanced/extensions/tags.html
tags = ["Game Engine", "User Interface", "Import-Export"]
blender_version_min = "4.2.0"
# # Optional: Blender version that the extension does not support, earlier versions are supported.
# # This can be omitted and defined later on the extensions platform if an issue is found.
# blender_version_max = "5.1.0"
# License conforming to https://spdx.org/licenses/ (use "SPDX: prefix)
# https://docs.blender.org/manual/en/dev/advanced/extensions/licenses.html
license = [
"SPDX:MIT"
]
copyright = [
"2023-2024 kaosat-dev",
]
# Optional list of supported platforms. If omitted, the extension will be available in all operating systems.
# platforms = ["windows-x64", "macos-arm64", "linux-x64"]
# Other supported platforms: "windows-arm64", "macos-x64"
# Optional: bundle 3rd party Python modules.
# https://docs.blender.org/manual/en/dev/advanced/extensions/python_wheels.html
# wheels = [
# "./wheels/hexdump-3.3-py3-none-any.whl",
# "./wheels/jsmin-3.0.1-py3-none-any.whl",
# ]
# # Optional: add-ons can list which resources they will require:
# # * files (for access of any filesystem operations)
# # * network (for internet access)
# # * clipboard (to read and/or write the system clipboard)
# # * camera (to capture photos and videos)
# # * microphone (to capture audio)
# #
# # If using network, remember to also check `bpy.app.online_access`
# # https://docs.blender.org/manual/en/dev/advanced/extensions/addons.html#internet-access
# #
# # For each permission it is important to also specify the reason why it is required.
# # Keep this a single short sentence without a period (.) at the end.
# # For longer explanations use the documentation or detail page.
#
[permissions]
# network = "Need to sync motion-capture data to server"
files = "Export Gltf files to disk, read registry files, etc"
# clipboard = "Copy and paste bone transforms"
# Optional: build settings.
# https://docs.blender.org/manual/en/dev/advanced/extensions/command_line_arguments.html#command-line-args-extension-build
# [build]
# paths_exclude_pattern = [
# "__pycache__/",
# "/.git/",
# "/*.zip",
# ]