finished with lods supports

This commit is contained in:
Dmitry Stepanov
2021-12-10 18:42:43 +03:00
parent 41b1c79b5d
commit dcec844938
3 changed files with 68 additions and 6 deletions
+2
View File
@@ -9,6 +9,7 @@ use crate::{
},
Message,
};
use rg3d::scene::base::LodControlledObject;
use rg3d::{
core::{inspect::Inspect, parking_lot::Mutex, pool::ErasedHandle, pool::Handle},
gui::inspector::editors::{
@@ -248,6 +249,7 @@ pub fn make_property_editors_container(
container.insert(VecCollectionPropertyEditorDefinition::<ErasedHandle>::new());
container.insert(VecCollectionPropertyEditorDefinition::<Handle<Node>>::new());
container.insert(VecCollectionPropertyEditorDefinition::<Property>::new());
container.insert(VecCollectionPropertyEditorDefinition::<LodControlledObject>::new());
container.insert(make_physics_binding_enum_editor_definition());
container.insert(make_mobility_enum_editor_definition());
container.insert(make_exposure_enum_editor_definition());
+22 -2
View File
@@ -4,7 +4,7 @@ use crate::{
scene::commands::{graph::*, lod::*},
ErasedHandle, SceneCommand,
};
use rg3d::scene::base::LodGroup;
use rg3d::scene::base::{LodControlledObject, LodGroup};
use rg3d::{
core::pool::Handle,
gui::inspector::{CollectionChanged, FieldKind, PropertyChanged},
@@ -185,7 +185,27 @@ pub fn handle_base_property_changed(
object_index,
)))
}
CollectionChanged::ItemChanged { .. } => None,
CollectionChanged::ItemChanged {
index,
ref property,
} => match property.name.as_ref() {
LodControlledObject::F_0 => {
if let FieldKind::Object(ref value) = property.value
{
Some(SceneCommand::new(
SetLodGroupLodObjectValue {
handle,
lod_index,
object_index: index,
value: value.cast_value_cloned()?,
},
))
} else {
None
}
}
_ => None,
},
},
_ => None,
}
+44 -4
View File
@@ -1,7 +1,11 @@
use crate::{command::Command, define_node_command, get_set_swap, scene::commands::SceneContext};
use rg3d::{
core::pool::Handle,
scene::{base::LevelOfDetail, base::LodGroup, graph::Graph, node::Node},
scene::{
base::{LevelOfDetail, LodControlledObject, LodGroup},
graph::Graph,
node::Node,
},
};
#[derive(Debug)]
@@ -167,12 +171,12 @@ impl Command for ChangeLodRangeEndCommand {
pub struct AddLodObjectCommand {
handle: Handle<Node>,
lod_index: usize,
object: Handle<Node>,
object: LodControlledObject,
object_index: usize,
}
impl AddLodObjectCommand {
pub fn new(handle: Handle<Node>, lod_index: usize, object: Handle<Node>) -> Self {
pub fn new(handle: Handle<Node>, lod_index: usize, object: LodControlledObject) -> Self {
Self {
handle,
lod_index,
@@ -211,7 +215,7 @@ impl Command for AddLodObjectCommand {
pub struct RemoveLodObjectCommand {
handle: Handle<Node>,
lod_index: usize,
object: Handle<Node>,
object: LodControlledObject,
object_index: usize,
}
@@ -254,6 +258,42 @@ impl Command for RemoveLodObjectCommand {
}
}
#[derive(Debug)]
pub struct SetLodGroupLodObjectValue {
pub handle: Handle<Node>,
pub lod_index: usize,
pub object_index: usize,
pub value: Handle<Node>,
}
impl SetLodGroupLodObjectValue {
fn swap(&mut self, context: &mut SceneContext) {
std::mem::swap(
&mut context.scene.graph[self.handle]
.lod_group_mut()
.unwrap()
.levels[self.lod_index]
.objects[self.object_index]
.0,
&mut self.value,
);
}
}
impl Command for SetLodGroupLodObjectValue {
fn name(&mut self, _context: &SceneContext) -> String {
"Set Lod Object".to_owned()
}
fn execute(&mut self, context: &mut SceneContext) {
self.swap(context)
}
fn revert(&mut self, context: &mut SceneContext) {
self.swap(context)
}
}
define_node_command!(SetLodGroupCommand("Set Lod Group", Option<LodGroup>) where fn swap(self, node) {
get_set_swap!(self, node, take_lod_group, set_lod_group);
});