Compare commits
No commits in common. "b92081d06ebea3ca25b32b974ef18b42e4f51e20" and "4a72ed68bf2024f014b7f3695fcd929fa66141d3" have entirely different histories.
b92081d06e
...
4a72ed68bf
2
TODO.md
2
TODO.md
|
@ -222,9 +222,7 @@ Blender side:
|
|||
- [ ] materials fixes & upgrades
|
||||
- [x] materials do not get exported again if the files are missing, until you change a material
|
||||
- [x] materials do not get exported when a material is added ?
|
||||
- [ ] if material library is toggled, then changes to materials should not change the blueprints that are using them ?
|
||||
- [ ] material assets seem to be added to list regardless of whether material exports are enabled or not
|
||||
- [ ] review & upgrade overall logic of material libraries, their names & output path
|
||||
- [ ] persist exported materials path in blueprints so that it can be read from library file users
|
||||
- [ ] just like "export_path" write it into each blueprint's collection
|
||||
- [ ] scan for used materials per blueprint !
|
||||
|
|
|
@ -49,14 +49,16 @@ impl Default for BluePrintBundle {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
/// Plugin for gltf blueprints
|
||||
pub struct BlueprintsPlugin {}
|
||||
pub struct BlueprintsPlugin {
|
||||
}
|
||||
|
||||
impl Default for BlueprintsPlugin {
|
||||
fn default() -> Self {
|
||||
Self {}
|
||||
Self { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn hot_reload(watching_for_changes: Res<WatchingForChanges>) -> bool {
|
||||
// println!("hot reload ? {}", watching_for_changes.0);
|
||||
watching_for_changes.0
|
||||
|
@ -108,8 +110,6 @@ impl Plugin for BlueprintsPlugin {
|
|||
.register_type::<Vec<String>>()
|
||||
.register_type::<BlueprintAssets>()
|
||||
.register_type::<HashMap<String, Vec<String>>>()
|
||||
.init_asset::<RawGltfAsset>()
|
||||
.init_asset_loader::<RawGltfAssetLoader>()
|
||||
.configure_sets(
|
||||
Update,
|
||||
(GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)
|
||||
|
@ -119,7 +119,6 @@ impl Plugin for BlueprintsPlugin {
|
|||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
load_raw_gltf,
|
||||
blueprints_prepare_spawn,
|
||||
blueprints_check_assets_loading,
|
||||
blueprints_assets_loaded,
|
||||
|
@ -133,14 +132,16 @@ impl Plugin for BlueprintsPlugin {
|
|||
.chain()
|
||||
.in_set(GltfBlueprintsSet::Spawn),
|
||||
)
|
||||
|
||||
// animation
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
trigger_blueprint_animation_markers_events,
|
||||
trigger_instance_animation_markers_events,
|
||||
trigger_instance_animation_markers_events
|
||||
),
|
||||
)
|
||||
|
||||
// hot reload
|
||||
.add_systems(Update, react_to_asset_changes.run_if(hot_reload));
|
||||
}
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
use std::path::Path;
|
||||
|
||||
use bevy::{
|
||||
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
|
||||
gltf::Gltf,
|
||||
prelude::*,
|
||||
scene::SceneInstance,
|
||||
utils::hashbrown::HashMap,
|
||||
};
|
||||
use bevy::{gltf::Gltf, prelude::*, scene::SceneInstance, utils::hashbrown::HashMap};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::{
|
||||
|
@ -121,59 +115,17 @@ Overview of the Blueprint Spawning process
|
|||
=> distinguish between blueprint instances inside blueprint instances vs blueprint instances inside blueprints ??
|
||||
*/
|
||||
|
||||
#[derive(Asset, TypePath, Debug)]
|
||||
pub struct RawGltfAsset(pub RawGltf);
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct RawGltfAssetLoader;
|
||||
|
||||
impl AssetLoader for RawGltfAssetLoader {
|
||||
type Asset = RawGltfAsset;
|
||||
type Settings = ();
|
||||
type Error = gltf::Error;
|
||||
|
||||
async fn load<'a>(
|
||||
&'a self,
|
||||
reader: &'a mut Reader<'_>,
|
||||
_settings: &'a (),
|
||||
_load_context: &'a mut LoadContext<'_>,
|
||||
) -> Result<Self::Asset, Self::Error> {
|
||||
let mut bytes = Vec::new();
|
||||
reader.read_to_end(&mut bytes).await?;
|
||||
let gltf = RawGltf::from_slice_without_validation(&bytes)?;
|
||||
Ok(RawGltfAsset(gltf))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Component, Deref, DerefMut)]
|
||||
#[component(storage = "SparseSet")]
|
||||
pub(super) struct AssociatedRawGltfHandle(Handle<RawGltfAsset>);
|
||||
|
||||
pub(super) fn load_raw_gltf(
|
||||
pub(crate) fn blueprints_prepare_spawn(
|
||||
blueprint_instances_to_spawn: Query<(Entity, &BlueprintInfo), Added<SpawnBlueprint>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
for (entity, blueprint_info) in blueprint_instances_to_spawn.iter() {
|
||||
let gltf_handle: Handle<RawGltfAsset> = asset_server.load(&blueprint_info.path);
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(AssociatedRawGltfHandle(gltf_handle));
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn blueprints_prepare_spawn(
|
||||
blueprint_instances_to_spawn: Query<(Entity, &BlueprintInfo, &AssociatedRawGltfHandle)>,
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
// for hot reload
|
||||
watching_for_changes: Res<WatchingForChanges>,
|
||||
mut assets_to_blueprint_instances: ResMut<AssetToBlueprintInstancesMapper>,
|
||||
raw_gltf_assets: Res<Assets<RawGltfAsset>>,
|
||||
// for debug
|
||||
// all_names: Query<&Name>
|
||||
) {
|
||||
for (entity, blueprint_info, raw_gltf_handle) in blueprint_instances_to_spawn.iter() {
|
||||
for (entity, blueprint_info) in blueprint_instances_to_spawn.iter() {
|
||||
info!(
|
||||
"BLUEPRINT: to spawn detected: {:?} path:{:?}",
|
||||
blueprint_info.name, blueprint_info.path
|
||||
|
@ -197,9 +149,7 @@ pub(super) fn blueprints_prepare_spawn(
|
|||
|
||||
// and we also add all its assets
|
||||
/* prefetch attempt */
|
||||
let Some(RawGltfAsset(gltf)) = raw_gltf_assets.get(&raw_gltf_handle.0) else {
|
||||
continue;
|
||||
};
|
||||
let gltf = RawGltf::open(format!("assets/{}", blueprint_info.path)).unwrap();
|
||||
for scene in gltf.scenes() {
|
||||
if let Some(scene_extras) = scene.extras().clone() {
|
||||
let lookup: HashMap<String, Value> =
|
||||
|
@ -304,10 +254,7 @@ pub(super) fn blueprints_prepare_spawn(
|
|||
.entity(entity)
|
||||
.insert(bevy::prelude::Name::from(blueprint_info.name.clone()));
|
||||
// add the blueprint spawning marker
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(BlueprintSpawning)
|
||||
.remove::<AssociatedRawGltfHandle>();
|
||||
commands.entity(entity).insert(BlueprintSpawning);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13340,11 +13340,11 @@
|
|||
"type": "object",
|
||||
"typeInfo": "Struct"
|
||||
},
|
||||
"blenvy::blueprints::animation::InstanceAnimations": {
|
||||
"blenvy::blueprints::animation::SceneAnimations": {
|
||||
"additionalProperties": false,
|
||||
"isComponent": true,
|
||||
"isResource": false,
|
||||
"long_name": "blenvy::blueprints::animation::InstanceAnimations",
|
||||
"long_name": "blenvy::blueprints::animation::SceneAnimations",
|
||||
"properties": {
|
||||
"graph": {
|
||||
"type": {
|
||||
|
@ -13367,7 +13367,7 @@
|
|||
"named_indices",
|
||||
"graph"
|
||||
],
|
||||
"short_name": "InstanceAnimations",
|
||||
"short_name": "SceneAnimations",
|
||||
"type": "object",
|
||||
"typeInfo": "Struct"
|
||||
},
|
||||
|
|
|
@ -12,9 +12,11 @@ def get_materials_to_export(changes_per_material, changed_export_parameters, blu
|
|||
|
||||
all_materials = bpy.data.materials
|
||||
local_materials = [material for material in all_materials if material.library is None]
|
||||
#and (changed_export_parameters or len(changes_per_material.keys()) > 0 )
|
||||
|
||||
materials_to_export = []
|
||||
if change_detection and not changed_export_parameters:
|
||||
changed_materials = [bpy.data.materials[material_name] for material_name in list(changes_per_material.keys())]
|
||||
changed_materials = []
|
||||
|
||||
# first check if all materials have already been exported before (if this is the first time the exporter is run
|
||||
# in your current Blender session for example)
|
||||
|
@ -25,4 +27,5 @@ def get_materials_to_export(changes_per_material, changed_export_parameters, blu
|
|||
materials_always_export = []
|
||||
materials_to_export = list(set(changed_materials + materials_not_on_disk + materials_always_export))
|
||||
|
||||
|
||||
return materials_to_export
|
||||
|
|
|
@ -4,24 +4,14 @@ import bpy
|
|||
from pathlib import Path
|
||||
from ..core.helpers_collections import (traverse_tree)
|
||||
|
||||
def find_materials_not_on_disk(materials, materials_path_full, extension):
|
||||
def find_materials_not_on_disk(materials, folder_path, extension):
|
||||
not_found_materials = []
|
||||
|
||||
current_project_name = Path(bpy.context.blend_data.filepath).stem
|
||||
materials_library_name = f"{current_project_name}_materials"
|
||||
materials_exported_path = os.path.join(materials_path_full, f"{materials_library_name}{extension}")
|
||||
|
||||
found = os.path.exists(materials_exported_path) and os.path.isfile(materials_exported_path)
|
||||
for material in materials:
|
||||
if not found:
|
||||
not_found_materials.append(material)
|
||||
|
||||
"""for material in materials:
|
||||
gltf_output_path = os.path.join(materials_path_full, material.name + extension)
|
||||
gltf_output_path = os.path.join(folder_path, material.name + extension)
|
||||
# print("gltf_output_path", gltf_output_path)
|
||||
found = os.path.exists(gltf_output_path) and os.path.isfile(gltf_output_path)
|
||||
if not found:
|
||||
not_found_materials.append(material)"""
|
||||
not_found_materials.append(material)
|
||||
return not_found_materials
|
||||
|
||||
def check_if_material_on_disk(scene_name, folder_path, extension):
|
||||
|
|
Loading…
Reference in New Issue