fixed reshape and rebuild to update on modifications.
This commit is contained in:
parent
63b49c70c7
commit
53e85dbcd0
|
@ -37,6 +37,7 @@ pub struct GridEditData {
|
||||||
pub struct StructureEditData {
|
pub struct StructureEditData {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub id: Handle<StructureAsset>,
|
pub id: Handle<StructureAsset>,
|
||||||
|
pub edit_entity: Entity, //which instance of this structure is representing the one we can edit in the structure editor. other instances will exist which will be tricky (seperate store?)
|
||||||
pub has_changed_since_last_save: bool,
|
pub has_changed_since_last_save: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,12 +210,6 @@ pub fn startup_system_edit_ui(
|
||||||
spawn_camera(&mut commands);
|
spawn_camera(&mut commands);
|
||||||
let str = "test.vvs";
|
let str = "test.vvs";
|
||||||
let handle = asset_server.load::<StructureAsset>(str);
|
let handle = asset_server.load::<StructureAsset>(str);
|
||||||
let data = StructureEditData {
|
|
||||||
path: str.into(),
|
|
||||||
id: handle.clone(),
|
|
||||||
has_changed_since_last_save: false,
|
|
||||||
};
|
|
||||||
shared_ui_state.structures.push(data);
|
|
||||||
|
|
||||||
//let id = OctTreeAsset::load(&mut pairs, asset_server.into(), mesh_assets, "test.vvg".into());
|
//let id = OctTreeAsset::load(&mut pairs, asset_server.into(), mesh_assets, "test.vvg".into());
|
||||||
let parent = commands
|
let parent = commands
|
||||||
|
@ -223,6 +218,17 @@ pub fn startup_system_edit_ui(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.id();
|
.id();
|
||||||
|
let id = commands.spawn((SpatialBundle::from_transform(Transform::IDENTITY), StructureComponent {
|
||||||
|
asset: handle.clone(),
|
||||||
|
nodes: Default::default(),
|
||||||
|
})).id();
|
||||||
|
let data = StructureEditData {
|
||||||
|
path: str.into(),
|
||||||
|
id: handle.clone(),
|
||||||
|
has_changed_since_last_save: false,
|
||||||
|
edit_entity: id.clone(),
|
||||||
|
};
|
||||||
|
shared_ui_state.structures.push(data);
|
||||||
/*let child = commands
|
/*let child = commands
|
||||||
.spawn((
|
.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
|
@ -237,16 +243,12 @@ pub fn startup_system_edit_ui(
|
||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
commands.entity(parent).add_child(child);*/
|
commands.entity(parent).add_child(child);*/
|
||||||
let id = commands.spawn((SpatialBundle::INHERITED_IDENTITY, StructureComponent {
|
|
||||||
asset: handle,
|
|
||||||
nodes: Default::default(),
|
|
||||||
})).id();
|
|
||||||
commands.entity(parent).add_child(id.clone());
|
commands.entity(parent).add_child(id.clone());
|
||||||
event_writer.send(StructureUpdateMessage {
|
event_writer.send(StructureUpdateMessage {
|
||||||
update_type: StructureUpdateType::Build,
|
update_type: StructureUpdateType::Rebuild,
|
||||||
entity: id,
|
entity: id,
|
||||||
});
|
});
|
||||||
let light_transform = Transform::from_xyz(7f32, 7f32, 7f32).looking_at(Vec3::ZERO, Vec3::Y);
|
let light_transform = Transform::from_xyz(4f32, 4f32, 4f32).looking_at(Vec3::ZERO, Vec3::Y);
|
||||||
|
|
||||||
commands.spawn(PointLightBundle {
|
commands.spawn(PointLightBundle {
|
||||||
point_light: PointLight {
|
point_light: PointLight {
|
||||||
|
@ -417,6 +419,7 @@ pub fn edit_window_ui(
|
||||||
windows: Query<Entity, With<Window>>,
|
windows: Query<Entity, With<Window>>,
|
||||||
window: Query<&Window>,
|
window: Query<&Window>,
|
||||||
mut asset_server: ResMut<AssetServer>,
|
mut asset_server: ResMut<AssetServer>,
|
||||||
|
mut event_writer: EventWriter<StructureUpdateMessage>,
|
||||||
) {
|
) {
|
||||||
shared_ui_state.egui.windows.clear();
|
shared_ui_state.egui.windows.clear();
|
||||||
let title = String::from("VVEdit");
|
let title = String::from("VVEdit");
|
||||||
|
@ -622,6 +625,7 @@ pub fn edit_window_ui(
|
||||||
if structure.path == structure_name {
|
if structure.path == structure_name {
|
||||||
let asset = structure_assets.get_mut(structure.id.clone());
|
let asset = structure_assets.get_mut(structure.id.clone());
|
||||||
if asset.is_some() {
|
if asset.is_some() {
|
||||||
|
let mut should_reshape = false;
|
||||||
let selection = asset.unwrap();
|
let selection = asset.unwrap();
|
||||||
ui.collapsing("Node Data", |ui| {
|
ui.collapsing("Node Data", |ui| {
|
||||||
let mut trans = {
|
let mut trans = {
|
||||||
|
@ -632,14 +636,22 @@ pub fn edit_window_ui(
|
||||||
}
|
}
|
||||||
}.clone();
|
}.clone();
|
||||||
ui.label("Position");
|
ui.label("Position");
|
||||||
editable_vec3(ui, &mut trans.translation);
|
editable_vec3(ui, &mut trans.translation, &mut should_reshape);
|
||||||
ui.label("Scale");
|
ui.label("Scale");
|
||||||
editable_vec3(ui, &mut trans.scale);
|
editable_vec3(ui, &mut trans.scale, &mut should_reshape);
|
||||||
ui.label("Rotation");
|
ui.label("Rotation");
|
||||||
editable_quat(ui, &mut trans.rotation);
|
editable_quat(ui, &mut trans.rotation, &mut should_reshape);
|
||||||
|
if should_reshape {
|
||||||
|
|
||||||
|
println!("code reached 2.");
|
||||||
|
event_writer.send(StructureUpdateMessage {
|
||||||
|
update_type: StructureUpdateType::Reshape,
|
||||||
|
entity: structure.edit_entity,
|
||||||
|
});
|
||||||
|
|
||||||
selection.default_pose_positions.insert(selection_name, trans);
|
selection.default_pose_positions.insert(selection_name, trans);
|
||||||
structure.has_changed_since_last_save = true;
|
structure.has_changed_since_last_save = true;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -723,5 +735,6 @@ pub fn edit_window_ui(
|
||||||
&mut contexts,
|
&mut contexts,
|
||||||
&mut asset_server,
|
&mut asset_server,
|
||||||
&mut structure_assets,
|
&mut structure_assets,
|
||||||
|
&mut event_writer,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use bevy::{
|
||||||
system::{Commands, Query, ResMut},
|
system::{Commands, Query, ResMut},
|
||||||
world::Mut,
|
world::Mut,
|
||||||
},
|
},
|
||||||
hierarchy::{BuildChildren, DespawnRecursiveExt},
|
hierarchy::BuildChildren,
|
||||||
pbr::{PbrBundle, StandardMaterial},
|
pbr::{PbrBundle, StandardMaterial},
|
||||||
prelude::{default, SpatialBundle},
|
prelude::{default, SpatialBundle},
|
||||||
reflect::TypePath,
|
reflect::TypePath,
|
||||||
|
@ -25,7 +25,7 @@ use thiserror::Error;
|
||||||
|
|
||||||
use super::s_oct_asset::{MeshingOctTreePairs, OctAssetMarker, OctTreeAsset};
|
use super::s_oct_asset::{MeshingOctTreePairs, OctAssetMarker, OctTreeAsset};
|
||||||
|
|
||||||
#[derive(Asset, TypePath)]
|
#[derive(Asset, TypePath, Debug)]
|
||||||
pub struct StructureAsset {
|
pub struct StructureAsset {
|
||||||
pub layout: StringTree,
|
pub layout: StringTree,
|
||||||
pub default_pose_positions: HashMap<String, Transform>,
|
pub default_pose_positions: HashMap<String, Transform>,
|
||||||
|
@ -52,7 +52,7 @@ pub enum StructureUpdateType {
|
||||||
pub fn build_tree(
|
pub fn build_tree(
|
||||||
root_entity: &Entity,
|
root_entity: &Entity,
|
||||||
asset: &StructureAsset,
|
asset: &StructureAsset,
|
||||||
structure_component: Mut<StructureComponent>,
|
mut structure_component: Mut<StructureComponent>,
|
||||||
materials: &mut ResMut<Assets<StandardMaterial>>,
|
materials: &mut ResMut<Assets<StandardMaterial>>,
|
||||||
meshes: &mut ResMut<Assets<Mesh>>,
|
meshes: &mut ResMut<Assets<Mesh>>,
|
||||||
pairs: &mut ResMut<MeshingOctTreePairs>,
|
pairs: &mut ResMut<MeshingOctTreePairs>,
|
||||||
|
@ -68,45 +68,50 @@ pub fn build_tree(
|
||||||
return Ordering::Equal;
|
return Ordering::Equal;
|
||||||
});
|
});
|
||||||
for each in sorted_construction_order {
|
for each in sorted_construction_order {
|
||||||
if let Some(element_data) = asset.element_data.get(&each) {
|
let element_data = if let Some(element_data) = asset.element_data.get(&each) {
|
||||||
let trans = {
|
element_data.clone()
|
||||||
if let Some(transform) = asset.default_pose_positions.get(&each) {
|
} else {
|
||||||
transform
|
ElementData::None
|
||||||
|
};
|
||||||
|
let trans = {
|
||||||
|
if let Some(transform) = asset.default_pose_positions.get(&each) {
|
||||||
|
transform
|
||||||
|
} else {
|
||||||
|
&Transform::IDENTITY
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let p_entity = {
|
||||||
|
if let Some(parent) = asset.layout.parent_of(&each) {
|
||||||
|
if let Some(result) = structure_component.nodes.get(parent) {
|
||||||
|
result.clone()
|
||||||
} else {
|
} else {
|
||||||
&Transform::IDENTITY
|
root_entity.clone()
|
||||||
}
|
}
|
||||||
};
|
} else {
|
||||||
let p_entity = {
|
root_entity.clone()
|
||||||
if let Some(parent) = asset.layout.parent_of(&each) {
|
}
|
||||||
if let Some(result) = structure_component.nodes.get(parent) {
|
};
|
||||||
result
|
let child = {
|
||||||
} else {
|
match element_data {
|
||||||
&root_entity
|
ElementData::None => {
|
||||||
}
|
let mut spat_bundle = SpatialBundle::from_transform(trans.clone());
|
||||||
} else {
|
spat_bundle.visibility = Visibility::Inherited;
|
||||||
&root_entity
|
commands.spawn(spat_bundle).id()
|
||||||
}
|
}
|
||||||
};
|
ElementData::Unprocessed(_) => {
|
||||||
let child = {
|
println!("somehow not processed in build");
|
||||||
match element_data {
|
let mut spat_bundle = SpatialBundle::from_transform(trans.clone());
|
||||||
ElementData::None => {
|
spat_bundle.visibility = Visibility::Inherited;
|
||||||
let mut spat_bundle = SpatialBundle::from_transform(trans.clone());
|
commands.spawn(spat_bundle).id()
|
||||||
spat_bundle.visibility = Visibility::Inherited;
|
}
|
||||||
commands.spawn(spat_bundle).id()
|
ElementData::MeshAsset(handle, _) => {
|
||||||
}
|
let mut spat_bundle = SpatialBundle::from_transform(trans.clone());
|
||||||
ElementData::Unprocessed(_) => {
|
spat_bundle.visibility = Visibility::Inherited;
|
||||||
println!("somehow not processed in build");
|
commands
|
||||||
let mut spat_bundle = SpatialBundle::from_transform(trans.clone());
|
.spawn(spat_bundle)
|
||||||
spat_bundle.visibility = Visibility::Inherited;
|
.with_children(|parent| {
|
||||||
commands.spawn(spat_bundle).id()
|
let id = parent
|
||||||
}
|
.spawn((
|
||||||
ElementData::MeshAsset(handle, _) => {
|
|
||||||
let mut spat_bundle = SpatialBundle::from_transform(trans.clone());
|
|
||||||
spat_bundle.visibility = Visibility::Inherited;
|
|
||||||
commands
|
|
||||||
.spawn(spat_bundle)
|
|
||||||
.with_children(|parent| {
|
|
||||||
parent.spawn((
|
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: pairs.mesh_handle_for(handle.clone(), meshes),
|
mesh: pairs.mesh_handle_for(handle.clone(), meshes),
|
||||||
material: materials.add(Color::rgb(1., 1., 1.)),
|
material: materials.add(Color::rgb(1., 1., 1.)),
|
||||||
|
@ -115,16 +120,20 @@ pub fn build_tree(
|
||||||
OctAssetMarker {
|
OctAssetMarker {
|
||||||
oct_handle: handle.clone(),
|
oct_handle: handle.clone(),
|
||||||
},
|
},
|
||||||
));
|
))
|
||||||
})
|
.id();
|
||||||
.id()
|
structure_component.nodes.insert(
|
||||||
}
|
id.to_bits().to_string() + "||||" + each.clone().as_str(),
|
||||||
|
id,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.id()
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
structure_component.nodes.insert(each, child.clone());
|
||||||
|
|
||||||
commands.entity(p_entity.clone()).add_child(child.clone());
|
commands.entity(p_entity.clone()).add_child(child.clone());
|
||||||
println!("{}", child.clone().to_bits());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,8 +174,9 @@ pub fn structure_update(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
),
|
),
|
||||||
StructureUpdateType::Rebuild => {
|
StructureUpdateType::Rebuild => {
|
||||||
|
dbg!(&structure_component.nodes);
|
||||||
for (_, each) in &structure_component.nodes {
|
for (_, each) in &structure_component.nodes {
|
||||||
commands.entity(each.clone()).despawn_recursive();
|
commands.entity(each.clone()).despawn();
|
||||||
}
|
}
|
||||||
structure_component.nodes.clear();
|
structure_component.nodes.clear();
|
||||||
build_tree(
|
build_tree(
|
||||||
|
@ -184,7 +194,10 @@ pub fn structure_update(
|
||||||
if let Ok((_, mut trans)) = shaper.get_mut(ent.clone()) {
|
if let Ok((_, mut trans)) = shaper.get_mut(ent.clone()) {
|
||||||
if let Some(value) = asset.default_pose_positions.get(name) {
|
if let Some(value) = asset.default_pose_positions.get(name) {
|
||||||
trans.clone_from(value);
|
trans.clone_from(value);
|
||||||
|
println!("code reached 3.");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
println!("code failed step 3.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,7 +207,7 @@ pub fn structure_update(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum ElementData {
|
pub enum ElementData {
|
||||||
None,
|
None,
|
||||||
Unprocessed(String),
|
Unprocessed(String),
|
||||||
|
|
Loading…
Reference in a new issue