mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-26 21:37:01 +00:00
Compare commits
3 Commits
db1a15ec63
...
2d459abaf3
Author | SHA1 | Date | |
---|---|---|---|
|
2d459abaf3 | ||
|
742c5b19f0 | ||
|
7a8b91f4ec |
@ -41,7 +41,7 @@ pub struct AnimationInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Stores information about animations, to make things a bit easier api wise:
|
/// Stores information about animations, to make things a bit easier api wise:
|
||||||
/// these components are automatically inserted by gltf_auto_export on entities that have animations
|
/// these components are automatically inserted by `gltf_auto_export` on entities that have animations
|
||||||
#[derive(Component, Reflect, Default, Debug)]
|
#[derive(Component, Reflect, Default, Debug)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct AnimationInfos {
|
pub struct AnimationInfos {
|
||||||
@ -56,7 +56,7 @@ pub struct AnimationMarker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Stores information about animation markers: practical for adding things like triggering events at specific keyframes etc
|
/// Stores information about animation markers: practical for adding things like triggering events at specific keyframes etc
|
||||||
/// it is essentiall a hashmap of AnimationName => HashMap<FrameNumber, Vec of marker names>
|
/// it is essentiall a hashmap of `AnimationName` => `HashMap`<`FrameNumber`, Vec of marker names>
|
||||||
#[derive(Component, Reflect, Default, Debug)]
|
#[derive(Component, Reflect, Default, Debug)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct AnimationMarkers(pub HashMap<String, HashMap<u32, Vec<String>>>);
|
pub struct AnimationMarkers(pub HashMap<String, HashMap<u32, Vec<String>>>);
|
||||||
@ -115,23 +115,23 @@ pub fn trigger_instance_animation_markers_events(
|
|||||||
let time_in_animation = animation_player.elapsed()
|
let time_in_animation = animation_player.elapsed()
|
||||||
- (animation_player.completions() as f32) * animation_length_seconds;
|
- (animation_player.completions() as f32) * animation_length_seconds;
|
||||||
let frame_seconds =
|
let frame_seconds =
|
||||||
(animation_length_frames as f32 / animation_length_seconds) * time_in_animation;
|
(animation_length_frames / animation_length_seconds) * time_in_animation;
|
||||||
let frame = frame_seconds as u32;
|
let frame = frame_seconds as u32;
|
||||||
|
|
||||||
let matching_animation_marker = &markers.0[animation_name];
|
let matching_animation_marker = &markers.0[animation_name];
|
||||||
if matching_animation_marker.contains_key(&frame) {
|
if matching_animation_marker.contains_key(&frame) {
|
||||||
let matching_markers_per_frame = matching_animation_marker.get(&frame).unwrap();
|
let matching_markers_per_frame = matching_animation_marker.get(&frame).unwrap();
|
||||||
|
|
||||||
let foo = animation_length_seconds - time_in_animation;
|
// let timediff = animation_length_seconds - time_in_animation;
|
||||||
println!("foo {}", foo);
|
// println!("timediff {}", timediff);
|
||||||
// println!("FOUND A MARKER {:?} at frame {}", matching_markers_per_frame, frame);
|
// println!("FOUND A MARKER {:?} at frame {}", matching_markers_per_frame, frame);
|
||||||
// emit an event AnimationMarkerReached(entity, animation_name, frame, marker_name)
|
// emit an event AnimationMarkerReached(entity, animation_name, frame, marker_name)
|
||||||
// FIXME: problem, this can fire multiple times in a row, depending on animation length , speed , etc
|
// FIXME: problem, this can fire multiple times in a row, depending on animation length , speed , etc
|
||||||
for marker in matching_markers_per_frame {
|
for marker in matching_markers_per_frame {
|
||||||
animation_marker_events.send(AnimationMarkerReached {
|
animation_marker_events.send(AnimationMarkerReached {
|
||||||
entity: entity,
|
entity,
|
||||||
animation_name: animation_name.clone(),
|
animation_name: animation_name.clone(),
|
||||||
frame: frame,
|
frame,
|
||||||
marker_name: marker.clone(),
|
marker_name: marker.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -199,9 +199,9 @@ pub fn trigger_blueprint_animation_markers_events(
|
|||||||
if diff < 0.1 {
|
if diff < 0.1 {
|
||||||
for marker in matching_markers_per_frame {
|
for marker in matching_markers_per_frame {
|
||||||
animation_marker_events.send(AnimationMarkerReached {
|
animation_marker_events.send(AnimationMarkerReached {
|
||||||
entity: entity,
|
entity,
|
||||||
animation_name: animation_name.clone(),
|
animation_name: animation_name.clone(),
|
||||||
frame: frame,
|
frame,
|
||||||
marker_name: marker.clone(),
|
marker_name: marker.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use std::time::Duration;
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use bevy_gltf_blueprints::{
|
use bevy_gltf_blueprints::{
|
||||||
AnimationPlayerLink, Animations, BluePrintBundle, BlueprintName, GameWorldTag,
|
BluePrintBundle, BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintName, GameWorldTag,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{Fox, Robot};
|
use super::{Fox, Robot};
|
||||||
@ -90,7 +90,14 @@ pub fn spawn_test(
|
|||||||
// example of changing animation of entities based on proximity to the player, for "fox" entities (Tag component)
|
// example of changing animation of entities based on proximity to the player, for "fox" entities (Tag component)
|
||||||
pub fn animation_change_on_proximity_foxes(
|
pub fn animation_change_on_proximity_foxes(
|
||||||
players: Query<&GlobalTransform, With<Player>>,
|
players: Query<&GlobalTransform, With<Player>>,
|
||||||
animated_foxes: Query<(&GlobalTransform, &AnimationPlayerLink, &Animations), With<Fox>>,
|
animated_foxes: Query<
|
||||||
|
(
|
||||||
|
&GlobalTransform,
|
||||||
|
&BlueprintAnimationPlayerLink,
|
||||||
|
&BlueprintAnimations,
|
||||||
|
),
|
||||||
|
With<Fox>,
|
||||||
|
>,
|
||||||
|
|
||||||
mut animation_players: Query<&mut AnimationPlayer>,
|
mut animation_players: Query<&mut AnimationPlayer>,
|
||||||
) {
|
) {
|
||||||
@ -126,7 +133,14 @@ pub fn animation_change_on_proximity_foxes(
|
|||||||
// example of changing animation of entities based on proximity to the player, this time for the "robot" entities (Tag component)
|
// example of changing animation of entities based on proximity to the player, this time for the "robot" entities (Tag component)
|
||||||
pub fn animation_change_on_proximity_robots(
|
pub fn animation_change_on_proximity_robots(
|
||||||
players: Query<&GlobalTransform, With<Player>>,
|
players: Query<&GlobalTransform, With<Player>>,
|
||||||
animated_robots: Query<(&GlobalTransform, &AnimationPlayerLink, &Animations), With<Robot>>,
|
animated_robots: Query<
|
||||||
|
(
|
||||||
|
&GlobalTransform,
|
||||||
|
&BlueprintAnimationPlayerLink,
|
||||||
|
&BlueprintAnimations,
|
||||||
|
),
|
||||||
|
With<Robot>,
|
||||||
|
>,
|
||||||
|
|
||||||
mut animation_players: Query<&mut AnimationPlayer>,
|
mut animation_players: Query<&mut AnimationPlayer>,
|
||||||
) {
|
) {
|
||||||
@ -162,13 +176,13 @@ pub fn animation_change_on_proximity_robots(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn animation_control(
|
pub fn animation_control(
|
||||||
animated_enemies: Query<(&AnimationPlayerLink, &Animations), With<Robot>>,
|
animated_enemies: Query<(&BlueprintAnimationPlayerLink, &BlueprintAnimations), With<Robot>>,
|
||||||
animated_foxes: Query<(&AnimationPlayerLink, &Animations), With<Fox>>,
|
animated_foxes: Query<(&BlueprintAnimationPlayerLink, &BlueprintAnimations), With<Fox>>,
|
||||||
|
|
||||||
mut animation_players: Query<&mut AnimationPlayer>,
|
mut animation_players: Query<&mut AnimationPlayer>,
|
||||||
|
|
||||||
keycode: Res<ButtonInput<KeyCode>>,
|
keycode: Res<ButtonInput<KeyCode>>,
|
||||||
// mut entities_with_animations : Query<(&mut AnimationPlayer, &mut Animations)>,
|
// mut entities_with_animations : Query<(&mut AnimationPlayer, &mut BlueprintAnimations)>,
|
||||||
) {
|
) {
|
||||||
// robots
|
// robots
|
||||||
if keycode.just_pressed(KeyCode::KeyB) {
|
if keycode.just_pressed(KeyCode::KeyB) {
|
||||||
|
@ -34,6 +34,7 @@ pub fn setup_main_scene_animations(asset_server: Res<AssetServer>, mut commands:
|
|||||||
commands.insert_resource(AnimTest(asset_server.load("models/World.glb")));
|
commands.insert_resource(AnimTest(asset_server.load("models/World.glb")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
pub fn animations(
|
pub fn animations(
|
||||||
added_animation_players: Query<(Entity, &Name, &AnimationPlayer)>,
|
added_animation_players: Query<(Entity, &Name, &AnimationPlayer)>,
|
||||||
added_animation_infos: Query<(Entity, &Name, &AnimationInfos), Added<AnimationInfos>>,
|
added_animation_infos: Query<(Entity, &Name, &AnimationInfos), Added<AnimationInfos>>,
|
||||||
@ -71,10 +72,10 @@ pub fn animations(
|
|||||||
// info!("{:?} is an ancestor of {:?}", ancestor, player);
|
// info!("{:?} is an ancestor of {:?}", ancestor, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
pub fn play_animations(
|
pub fn play_animations(
|
||||||
animated_marker1: Query<
|
animated_marker1: Query<
|
||||||
(&SceneAnimationPlayerLink, &SceneAnimations),
|
(&SceneAnimationPlayerLink, &SceneAnimations),
|
||||||
|
@ -6,12 +6,12 @@ pub use in_game::*;
|
|||||||
use std::{collections::HashMap, fs, time::Duration};
|
use std::{collections::HashMap, fs, time::Duration};
|
||||||
|
|
||||||
use bevy_gltf_blueprints::{
|
use bevy_gltf_blueprints::{
|
||||||
BlueprintAnimationPlayerLink, BlueprintName, BlueprintsList,
|
BlueprintAnimationPlayerLink, BlueprintName, BlueprintsList, GltfBlueprintsSet, SceneAnimations,
|
||||||
GltfBlueprintsSet,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::*, render::view::screenshot::ScreenshotManager, time::common_conditions::on_timer, window::PrimaryWindow
|
prelude::*, render::view::screenshot::ScreenshotManager, time::common_conditions::on_timer,
|
||||||
|
window::PrimaryWindow,
|
||||||
};
|
};
|
||||||
use bevy_gltf_worlflow_examples_common_rapier::{AppState, GameState};
|
use bevy_gltf_worlflow_examples_common_rapier::{AppState, GameState};
|
||||||
|
|
||||||
@ -26,18 +26,21 @@ fn start_game(mut next_app_state: ResMut<NextState<AppState>>) {
|
|||||||
// if the export from Blender worked correctly, we should have a blueprints_list
|
// if the export from Blender worked correctly, we should have a blueprints_list
|
||||||
// if the export from Blender worked correctly, we should have the correct tree of entities
|
// if the export from Blender worked correctly, we should have the correct tree of entities
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
fn validate_export(
|
fn validate_export(
|
||||||
parents: Query<&Parent>,
|
parents: Query<&Parent>,
|
||||||
children: Query<&Children>,
|
children: Query<&Children>,
|
||||||
names: Query<&Name>,
|
names: Query<&Name>,
|
||||||
blueprints: Query<(Entity, &Name, &BlueprintName)>,
|
blueprints: Query<(Entity, &Name, &BlueprintName)>,
|
||||||
animation_player_links: Query<(Entity, &BlueprintAnimationPlayerLink)>,
|
animation_player_links: Query<(Entity, &BlueprintAnimationPlayerLink)>,
|
||||||
|
scene_animations: Query<(Entity, &SceneAnimations)>,
|
||||||
empties_candidates: Query<(Entity, &Name, &GlobalTransform)>,
|
empties_candidates: Query<(Entity, &Name, &GlobalTransform)>,
|
||||||
|
|
||||||
blueprints_list: Query<(Entity, &BlueprintsList)>,
|
blueprints_list: Query<(Entity, &BlueprintsList)>,
|
||||||
root: Query<(Entity, &Name, &Children), (Without<Parent>, With<Children>)>,
|
root: Query<(Entity, &Name, &Children), (Without<Parent>, With<Children>)>,
|
||||||
) {
|
) {
|
||||||
let animations_found = !animation_player_links.is_empty();
|
let animations_found =
|
||||||
|
!animation_player_links.is_empty() && scene_animations.into_iter().len() == 4;
|
||||||
|
|
||||||
let mut nested_blueprint_found = false;
|
let mut nested_blueprint_found = false;
|
||||||
for (entity, name, blueprint_name) in blueprints.iter() {
|
for (entity, name, blueprint_name) in blueprints.iter() {
|
||||||
|
@ -5,7 +5,6 @@ import mathutils
|
|||||||
import pytest
|
import pytest
|
||||||
import shutil
|
import shutil
|
||||||
import pathlib
|
import pathlib
|
||||||
import rna_prop_ui
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def setup_data(request):
|
def setup_data(request):
|
||||||
@ -136,12 +135,7 @@ def test_export_change_tracking_custom_properties(setup_data):
|
|||||||
print("main scene change (custom property)")
|
print("main scene change (custom property)")
|
||||||
print("----------------")
|
print("----------------")
|
||||||
|
|
||||||
bpy.context.window_manager.auto_export_tracker.enable_change_detection() # FIXME: should not be needed, but ..
|
|
||||||
bpy.data.objects["Cube"]["test_property"] = 42
|
bpy.data.objects["Cube"]["test_property"] = 42
|
||||||
|
|
||||||
#force an update
|
|
||||||
rna_prop_ui.rna_idprop_ui_create(bpy.data.objects["Cube"], "________temp", default=0)
|
|
||||||
rna_prop_ui.rna_idprop_ui_prop_clear(bpy.data.objects["Cube"], "________temp")
|
|
||||||
|
|
||||||
auto_export_operator(
|
auto_export_operator(
|
||||||
auto_export=True,
|
auto_export=True,
|
||||||
@ -162,9 +156,296 @@ def test_export_change_tracking_custom_properties(setup_data):
|
|||||||
|
|
||||||
assert modification_times[world_file_index] != modification_times_first[world_file_index]
|
assert modification_times[world_file_index] != modification_times_first[world_file_index]
|
||||||
assert other_files_modification_times == other_files_modification_times_first
|
assert other_files_modification_times == other_files_modification_times_first
|
||||||
|
|
||||||
|
def test_export_change_tracking_light_properties(setup_data):
|
||||||
|
root_path = "../../testing/bevy_example"
|
||||||
|
assets_root_path = os.path.join(root_path, "assets")
|
||||||
|
models_path = os.path.join(assets_root_path, "models")
|
||||||
|
auto_export_operator = bpy.ops.export_scenes.auto_gltf
|
||||||
|
|
||||||
|
# with change detection
|
||||||
|
# first, configure things
|
||||||
|
# we use the global settings for that
|
||||||
|
export_props = {
|
||||||
|
"main_scene_names" : ['World'],
|
||||||
|
"library_scene_names": ['Library'],
|
||||||
|
}
|
||||||
|
|
||||||
|
# store settings for the auto_export part
|
||||||
|
stored_auto_settings = bpy.data.texts[".gltf_auto_export_settings"] if ".gltf_auto_export_settings" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_settings")
|
||||||
|
stored_auto_settings.clear()
|
||||||
|
stored_auto_settings.write(json.dumps(export_props))
|
||||||
|
|
||||||
|
gltf_settings = {
|
||||||
|
"export_animations": False,
|
||||||
|
"export_optimize_animation_size": False
|
||||||
|
}
|
||||||
|
# and store settings for the gltf part
|
||||||
|
stored_gltf_settings = bpy.data.texts[".gltf_auto_export_gltf_settings"] if ".gltf_auto_export_gltf_settings" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_gltf_settings")
|
||||||
|
stored_gltf_settings.clear()
|
||||||
|
stored_gltf_settings.write(json.dumps(gltf_settings))
|
||||||
|
|
||||||
|
auto_export_operator(
|
||||||
|
auto_export=True,
|
||||||
|
direct_mode=True,
|
||||||
|
export_output_folder="./models",
|
||||||
|
export_scene_settings=True,
|
||||||
|
export_blueprints=True,
|
||||||
|
export_legacy_mode=False,
|
||||||
|
export_materials_library=False
|
||||||
|
)
|
||||||
|
|
||||||
|
world_file_path = os.path.join(models_path, "World.glb")
|
||||||
|
assert os.path.exists(world_file_path) == True
|
||||||
|
|
||||||
|
models_library_path = os.path.join(models_path, "library")
|
||||||
|
model_library_file_paths = list(map(lambda file_name: os.path.join(models_library_path, file_name), sorted(os.listdir(models_library_path))))
|
||||||
|
modification_times_first = list(map(lambda file_path: os.path.getmtime(file_path), model_library_file_paths + [world_file_path]))
|
||||||
|
|
||||||
|
mapped_files_to_timestamps_and_index = {}
|
||||||
|
for (index, file_path) in enumerate(model_library_file_paths+ [world_file_path]):
|
||||||
|
file_path = pathlib.Path(file_path).stem
|
||||||
|
mapped_files_to_timestamps_and_index[file_path] = (modification_times_first[index], index)
|
||||||
|
|
||||||
|
print("----------------")
|
||||||
|
print("main scene change (light, energy)")
|
||||||
|
print("----------------")
|
||||||
|
|
||||||
|
bpy.data.lights["Light"].energy = 100
|
||||||
|
|
||||||
|
auto_export_operator(
|
||||||
|
auto_export=True,
|
||||||
|
direct_mode=True,
|
||||||
|
export_output_folder="./models",
|
||||||
|
export_scene_settings=True,
|
||||||
|
export_blueprints=True,
|
||||||
|
export_legacy_mode=False,
|
||||||
|
export_materials_library=False
|
||||||
|
)
|
||||||
|
|
||||||
|
modification_times = list(map(lambda file_path: os.path.getmtime(file_path), model_library_file_paths + [world_file_path]))
|
||||||
|
assert modification_times != modification_times_first
|
||||||
|
# only the "world" file should have changed
|
||||||
|
world_file_index = mapped_files_to_timestamps_and_index["World"][1]
|
||||||
|
other_files_modification_times = [value for index, value in enumerate(modification_times) if index not in [world_file_index]]
|
||||||
|
other_files_modification_times_first = [value for index, value in enumerate(modification_times_first) if index not in [world_file_index]]
|
||||||
|
|
||||||
|
assert modification_times[world_file_index] != modification_times_first[world_file_index]
|
||||||
|
assert other_files_modification_times == other_files_modification_times_first
|
||||||
|
|
||||||
# reset the comparing
|
# reset the comparing
|
||||||
modification_times_first = modification_times
|
modification_times_first = modification_times
|
||||||
|
|
||||||
|
print("----------------")
|
||||||
|
print("main scene change (light, shadow_cascade_count)")
|
||||||
|
print("----------------")
|
||||||
|
|
||||||
|
bpy.data.lights["Light"].shadow_cascade_count = 2
|
||||||
|
|
||||||
|
auto_export_operator(
|
||||||
|
auto_export=True,
|
||||||
|
direct_mode=True,
|
||||||
|
export_output_folder="./models",
|
||||||
|
export_scene_settings=True,
|
||||||
|
export_blueprints=True,
|
||||||
|
export_legacy_mode=False,
|
||||||
|
export_materials_library=False
|
||||||
|
)
|
||||||
|
|
||||||
|
modification_times = list(map(lambda file_path: os.path.getmtime(file_path), model_library_file_paths + [world_file_path]))
|
||||||
|
assert modification_times != modification_times_first
|
||||||
|
# only the "world" file should have changed
|
||||||
|
world_file_index = mapped_files_to_timestamps_and_index["World"][1]
|
||||||
|
other_files_modification_times = [value for index, value in enumerate(modification_times) if index not in [world_file_index]]
|
||||||
|
other_files_modification_times_first = [value for index, value in enumerate(modification_times_first) if index not in [world_file_index]]
|
||||||
|
|
||||||
|
assert modification_times[world_file_index] != modification_times_first[world_file_index]
|
||||||
|
assert other_files_modification_times == other_files_modification_times_first
|
||||||
|
|
||||||
|
# reset the comparing
|
||||||
|
modification_times_first = modification_times
|
||||||
|
|
||||||
|
print("----------------")
|
||||||
|
print("main scene change (light, use_shadow)")
|
||||||
|
print("----------------")
|
||||||
|
|
||||||
|
bpy.data.lights["Light"].use_shadow = False
|
||||||
|
|
||||||
|
auto_export_operator(
|
||||||
|
auto_export=True,
|
||||||
|
direct_mode=True,
|
||||||
|
export_output_folder="./models",
|
||||||
|
export_scene_settings=True,
|
||||||
|
export_blueprints=True,
|
||||||
|
export_legacy_mode=False,
|
||||||
|
export_materials_library=False
|
||||||
|
)
|
||||||
|
|
||||||
|
modification_times = list(map(lambda file_path: os.path.getmtime(file_path), model_library_file_paths + [world_file_path]))
|
||||||
|
assert modification_times != modification_times_first
|
||||||
|
# only the "world" file should have changed
|
||||||
|
world_file_index = mapped_files_to_timestamps_and_index["World"][1]
|
||||||
|
other_files_modification_times = [value for index, value in enumerate(modification_times) if index not in [world_file_index]]
|
||||||
|
other_files_modification_times_first = [value for index, value in enumerate(modification_times_first) if index not in [world_file_index]]
|
||||||
|
|
||||||
|
assert modification_times[world_file_index] != modification_times_first[world_file_index]
|
||||||
|
assert other_files_modification_times == other_files_modification_times_first
|
||||||
|
|
||||||
|
|
||||||
|
def test_export_change_tracking_camera_properties(setup_data):
|
||||||
|
root_path = "../../testing/bevy_example"
|
||||||
|
assets_root_path = os.path.join(root_path, "assets")
|
||||||
|
models_path = os.path.join(assets_root_path, "models")
|
||||||
|
auto_export_operator = bpy.ops.export_scenes.auto_gltf
|
||||||
|
|
||||||
|
# with change detection
|
||||||
|
# first, configure things
|
||||||
|
# we use the global settings for that
|
||||||
|
export_props = {
|
||||||
|
"main_scene_names" : ['World'],
|
||||||
|
"library_scene_names": ['Library'],
|
||||||
|
}
|
||||||
|
|
||||||
|
# store settings for the auto_export part
|
||||||
|
stored_auto_settings = bpy.data.texts[".gltf_auto_export_settings"] if ".gltf_auto_export_settings" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_settings")
|
||||||
|
stored_auto_settings.clear()
|
||||||
|
stored_auto_settings.write(json.dumps(export_props))
|
||||||
|
|
||||||
|
gltf_settings = {
|
||||||
|
"export_animations": False,
|
||||||
|
"export_optimize_animation_size": False
|
||||||
|
}
|
||||||
|
# and store settings for the gltf part
|
||||||
|
stored_gltf_settings = bpy.data.texts[".gltf_auto_export_gltf_settings"] if ".gltf_auto_export_gltf_settings" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_gltf_settings")
|
||||||
|
stored_gltf_settings.clear()
|
||||||
|
stored_gltf_settings.write(json.dumps(gltf_settings))
|
||||||
|
|
||||||
|
auto_export_operator(
|
||||||
|
auto_export=True,
|
||||||
|
direct_mode=True,
|
||||||
|
export_output_folder="./models",
|
||||||
|
export_scene_settings=True,
|
||||||
|
export_blueprints=True,
|
||||||
|
export_legacy_mode=False,
|
||||||
|
export_materials_library=False
|
||||||
|
)
|
||||||
|
|
||||||
|
world_file_path = os.path.join(models_path, "World.glb")
|
||||||
|
assert os.path.exists(world_file_path) == True
|
||||||
|
|
||||||
|
models_library_path = os.path.join(models_path, "library")
|
||||||
|
model_library_file_paths = list(map(lambda file_name: os.path.join(models_library_path, file_name), sorted(os.listdir(models_library_path))))
|
||||||
|
modification_times_first = list(map(lambda file_path: os.path.getmtime(file_path), model_library_file_paths + [world_file_path]))
|
||||||
|
|
||||||
|
mapped_files_to_timestamps_and_index = {}
|
||||||
|
for (index, file_path) in enumerate(model_library_file_paths+ [world_file_path]):
|
||||||
|
file_path = pathlib.Path(file_path).stem
|
||||||
|
mapped_files_to_timestamps_and_index[file_path] = (modification_times_first[index], index)
|
||||||
|
|
||||||
|
print("----------------")
|
||||||
|
print("main scene change (camera)")
|
||||||
|
print("----------------")
|
||||||
|
|
||||||
|
bpy.data.cameras["Camera"].angle = 0.5
|
||||||
|
|
||||||
|
auto_export_operator(
|
||||||
|
auto_export=True,
|
||||||
|
direct_mode=True,
|
||||||
|
export_output_folder="./models",
|
||||||
|
export_scene_settings=True,
|
||||||
|
export_blueprints=True,
|
||||||
|
export_legacy_mode=False,
|
||||||
|
export_materials_library=False
|
||||||
|
)
|
||||||
|
|
||||||
|
modification_times = list(map(lambda file_path: os.path.getmtime(file_path), model_library_file_paths + [world_file_path]))
|
||||||
|
assert modification_times != modification_times_first
|
||||||
|
# only the "world" file should have changed
|
||||||
|
world_file_index = mapped_files_to_timestamps_and_index["World"][1]
|
||||||
|
other_files_modification_times = [value for index, value in enumerate(modification_times) if index not in [world_file_index]]
|
||||||
|
other_files_modification_times_first = [value for index, value in enumerate(modification_times_first) if index not in [world_file_index]]
|
||||||
|
|
||||||
|
assert modification_times[world_file_index] != modification_times_first[world_file_index]
|
||||||
|
assert other_files_modification_times == other_files_modification_times_first
|
||||||
|
|
||||||
|
|
||||||
|
def test_export_change_tracking_material_properties(setup_data):
|
||||||
|
root_path = "../../testing/bevy_example"
|
||||||
|
assets_root_path = os.path.join(root_path, "assets")
|
||||||
|
models_path = os.path.join(assets_root_path, "models")
|
||||||
|
auto_export_operator = bpy.ops.export_scenes.auto_gltf
|
||||||
|
|
||||||
|
# with change detection
|
||||||
|
# first, configure things
|
||||||
|
# we use the global settings for that
|
||||||
|
export_props = {
|
||||||
|
"main_scene_names" : ['World'],
|
||||||
|
"library_scene_names": ['Library'],
|
||||||
|
}
|
||||||
|
|
||||||
|
# store settings for the auto_export part
|
||||||
|
stored_auto_settings = bpy.data.texts[".gltf_auto_export_settings"] if ".gltf_auto_export_settings" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_settings")
|
||||||
|
stored_auto_settings.clear()
|
||||||
|
stored_auto_settings.write(json.dumps(export_props))
|
||||||
|
|
||||||
|
gltf_settings = {
|
||||||
|
"export_animations": False,
|
||||||
|
"export_optimize_animation_size": False
|
||||||
|
}
|
||||||
|
# and store settings for the gltf part
|
||||||
|
stored_gltf_settings = bpy.data.texts[".gltf_auto_export_gltf_settings"] if ".gltf_auto_export_gltf_settings" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_gltf_settings")
|
||||||
|
stored_gltf_settings.clear()
|
||||||
|
stored_gltf_settings.write(json.dumps(gltf_settings))
|
||||||
|
|
||||||
|
auto_export_operator(
|
||||||
|
auto_export=True,
|
||||||
|
direct_mode=True,
|
||||||
|
export_output_folder="./models",
|
||||||
|
export_scene_settings=True,
|
||||||
|
export_blueprints=True,
|
||||||
|
export_legacy_mode=False,
|
||||||
|
export_materials_library=False
|
||||||
|
)
|
||||||
|
|
||||||
|
world_file_path = os.path.join(models_path, "World.glb")
|
||||||
|
assert os.path.exists(world_file_path) == True
|
||||||
|
|
||||||
|
models_library_path = os.path.join(models_path, "library")
|
||||||
|
model_library_file_paths = list(map(lambda file_name: os.path.join(models_library_path, file_name), sorted(os.listdir(models_library_path))))
|
||||||
|
modification_times_first = list(map(lambda file_path: os.path.getmtime(file_path), model_library_file_paths + [world_file_path]))
|
||||||
|
|
||||||
|
mapped_files_to_timestamps_and_index = {}
|
||||||
|
for (index, file_path) in enumerate(model_library_file_paths+ [world_file_path]):
|
||||||
|
file_path = pathlib.Path(file_path).stem
|
||||||
|
mapped_files_to_timestamps_and_index[file_path] = (modification_times_first[index], index)
|
||||||
|
|
||||||
|
print("----------------")
|
||||||
|
print("main scene change (material)")
|
||||||
|
print("----------------")
|
||||||
|
|
||||||
|
bpy.data.materials["Material.001"].blend_method = 'CLIP'
|
||||||
|
|
||||||
|
auto_export_operator(
|
||||||
|
auto_export=True,
|
||||||
|
direct_mode=True,
|
||||||
|
export_output_folder="./models",
|
||||||
|
export_scene_settings=True,
|
||||||
|
export_blueprints=True,
|
||||||
|
export_legacy_mode=False,
|
||||||
|
export_materials_library=False
|
||||||
|
)
|
||||||
|
|
||||||
|
modification_times = list(map(lambda file_path: os.path.getmtime(file_path), model_library_file_paths + [world_file_path]))
|
||||||
|
assert modification_times != modification_times_first
|
||||||
|
# only the "world" file should have changed
|
||||||
|
world_file_index = mapped_files_to_timestamps_and_index["World"][1]
|
||||||
|
other_files_modification_times = [value for index, value in enumerate(modification_times) if index not in [world_file_index]]
|
||||||
|
other_files_modification_times_first = [value for index, value in enumerate(modification_times_first) if index not in [world_file_index]]
|
||||||
|
|
||||||
|
assert modification_times[world_file_index] != modification_times_first[world_file_index]
|
||||||
|
assert other_files_modification_times == other_files_modification_times_first
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
- setup gltf parameters & auto_export parameters
|
- setup gltf parameters & auto_export parameters
|
||||||
- calls exporter on the testing scene
|
- calls exporter on the testing scene
|
||||||
@ -175,7 +456,7 @@ def test_export_change_tracking_custom_properties(setup_data):
|
|||||||
- removes generated files
|
- removes generated files
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def test_export_changed_parameters(setup_data):
|
def test_export_various_changes(setup_data):
|
||||||
root_path = "../../testing/bevy_example"
|
root_path = "../../testing/bevy_example"
|
||||||
assets_root_path = os.path.join(root_path, "assets")
|
assets_root_path = os.path.join(root_path, "assets")
|
||||||
models_path = os.path.join(assets_root_path, "models")
|
models_path = os.path.join(assets_root_path, "models")
|
||||||
@ -354,7 +635,7 @@ def test_export_changed_parameters(setup_data):
|
|||||||
print("----------------")
|
print("----------------")
|
||||||
bpy.context.window_manager.auto_export_tracker.enable_change_detection() # FIXME: should not be needed, but ..
|
bpy.context.window_manager.auto_export_tracker.enable_change_detection() # FIXME: should not be needed, but ..
|
||||||
|
|
||||||
with bpy.context.temp_override(active_object=bpy.data.objects["Cube"]):
|
with bpy.context.temp_override(active_object=bpy.data.objects["Cube"], selected_objects=[bpy.data.objects["Cube"]]):
|
||||||
print("translate using operator")
|
print("translate using operator")
|
||||||
bpy.ops.transform.translate(value=mathutils.Vector((2.0, 1.0, -5.0)))
|
bpy.ops.transform.translate(value=mathutils.Vector((2.0, 1.0, -5.0)))
|
||||||
bpy.ops.transform.rotate(value=0.378874, constraint_axis=(False, False, True), mirror=False, proportional_edit_falloff='SMOOTH', proportional_size=1)
|
bpy.ops.transform.rotate(value=0.378874, constraint_axis=(False, False, True), mirror=False, proportional_edit_falloff='SMOOTH', proportional_size=1)
|
||||||
|
Loading…
Reference in New Issue
Block a user