Skip to content

Commit

Permalink
Preparing geo nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed May 26, 2024
1 parent 811d3bf commit 3581f6a
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 49 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion StarterProject.eldiron

Large diffs are not rendered by default.

53 changes: 34 additions & 19 deletions creator/src/modelfxeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub enum ModelFXMode {

pub struct ModelFXEditor {
pub mode: ModelFXMode,
pub geo_names: FxHashMap<(i32, i32), String>,
pub geos: FxHashMap<(i32, i32), GeoFXNode>,

pub modelfx: ModelFX,

Expand All @@ -22,7 +22,7 @@ impl ModelFXEditor {
pub fn new() -> Self {
Self {
mode: ModelFXMode::Floor,
geo_names: FxHashMap::default(),
geos: FxHashMap::default(),

modelfx: ModelFX::default(),

Expand Down Expand Up @@ -132,12 +132,13 @@ impl ModelFXEditor {
..Default::default()
}));

let mut zoom = TheSlider::new(TheId::named("ModelFX Zoom"));
zoom.set_value(TheValue::Float(1.0));
zoom.set_default_value(TheValue::Float(1.0));
zoom.set_range(TheValue::RangeF32(1.0..=5.0));
zoom.set_continuous(true);
zoom.limiter_mut().set_max_width(120);
let mut blend = TheSlider::new(TheId::named("ModelFX Blend"));
blend.set_value(TheValue::Float(0.5));
blend.set_default_value(TheValue::Float(0.5));
blend.set_range(TheValue::RangeF32(0.0..=1.0));
blend.set_continuous(true);
blend.limiter_mut().set_max_width(120);
blend.set_status_text("Sets the blend factor for the preview in the 2D Map. 0 only shows the conceptual preview, 1 the fully rendered preview.");

// toolbar_hlayout.add_widget(Box::new(clear_button));
// toolbar_hlayout.add_widget(Box::new(move_button));
Expand All @@ -147,10 +148,10 @@ impl ModelFXEditor {
spacer.limiter_mut().set_max_size(vec2i(40, 5));
toolbar_hlayout.add_widget(Box::new(spacer));

toolbar_hlayout.add_widget(Box::new(floors_button));
toolbar_hlayout.add_widget(Box::new(walls_button));
toolbar_hlayout.add_widget(Box::new(material_button));
toolbar_hlayout.add_widget(Box::new(zoom));
// toolbar_hlayout.add_widget(Box::new(floors_button));
// toolbar_hlayout.add_widget(Box::new(walls_button));
// toolbar_hlayout.add_widget(Box::new(material_button));
toolbar_hlayout.add_widget(Box::new(blend));
toolbar_hlayout.set_reverse_index(Some(1));

/*
Expand Down Expand Up @@ -223,7 +224,7 @@ impl ModelFXEditor {
ctx: &mut TheContext,
project: &mut Project,
_server: &mut Server,
_server_ctx: &mut ServerContext,
server_ctx: &mut ServerContext,
) -> bool {
let mut redraw = false;

Expand Down Expand Up @@ -394,12 +395,9 @@ impl ModelFXEditor {
}
}*/
TheEvent::ValueChanged(id, value) => {
if id.name == "ModelFX Zoom" {
if id.name == "ModelFX Blend" {
if let TheValue::Float(value) = value {
self.modelfx.zoom = *value;
self.modelfx.draw(ui, ctx, &project.palette);
self.update_node_canvas(&project.palette, ui);
redraw = true;
server_ctx.conceptual_display = Some(*value);
}
} else if id.name == "Palette Color Picker" {
let index = project.palette.current_index;
Expand Down Expand Up @@ -686,7 +684,7 @@ impl ModelFXEditor {

/// Set the tiles for the picker.
pub fn set_geo_tiles(&mut self, ui: &mut TheUI, _ctx: &mut TheContext) {
self.geo_names.clear();
self.geos.clear();
let tile_size = 48;

let geo_tiles = GeoFXNode::nodes();
Expand Down Expand Up @@ -734,10 +732,27 @@ impl ModelFXEditor {

tile.preview(&mut tile_buffer);
buffer.copy_into(x * grid, y * grid, &tile_buffer);
self.geos.insert((x, y), tile.clone());
}

rgba_view.set_buffer(buffer);
}
}
}

/// Get the currently selected geometry node.
pub fn get_geo_node(&self, ui: &mut TheUI) -> Option<GeoFXNode> {
if let Some(editor) = ui.get_rgba_layout("ModelFX RGBA Layout") {
if let Some(rgba_view) = editor.rgba_view_mut().as_rgba_view() {
let selection = rgba_view.selection();
for i in selection {
if let Some(tile) = self.geos.get(&i) {
return Some(tile.clone());
}
}
}
}

None
}
}
13 changes: 11 additions & 2 deletions creator/src/tileeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ impl TileEditor {
}
}
} else if id.name == "Editor Group" {
server_ctx.conceptual_display = None;
if *index == EditorMode::Draw as usize {
self.editor_mode = EditorMode::Draw;
server_ctx.tile_selection = None;
Expand Down Expand Up @@ -492,6 +493,9 @@ impl TileEditor {
TheId::named("Set Region Modeler"),
TheValue::Empty,
));
if let Some(TheValue::Float(f)) = ui.get_widget_value("ModelFX Blend") {
server_ctx.conceptual_display = Some(f);
}
} else if *index == EditorMode::Tilemap as usize {
self.editor_mode = EditorMode::Tilemap;
server_ctx.tile_selection = None;
Expand Down Expand Up @@ -1044,10 +1048,14 @@ impl TileEditor {
}

if self.editor_mode == EditorMode::Model {
let palette = project.palette.clone();
//let palette = project.palette.clone();
if let Some(region) = project.get_region_mut(&server_ctx.curr_region) {
let mut model = MODELFXEDITOR.lock().unwrap().get_model();
//let model = MODELFXEDITOR.lock().unwrap().get_model();
if let Some(geo) = MODELFXEDITOR.lock().unwrap().get_geo_node(ui) {
region.add_geo(vec3i(coord.x, 0, coord.y), geo)
}

/*
model.create_voxels(
region.grid_size as u8,
&vec3f(coord.x as f32, 0.0, coord.y as f32),
Expand Down Expand Up @@ -1091,6 +1099,7 @@ impl TileEditor {
.add_region_undo(&region.id, undo, ctx);
server.update_region(region);
RENDERER.lock().unwrap().set_region(region);
*/
}
} else if self.editor_mode == EditorMode::Select {
let p = (coord.x, coord.y);
Expand Down
32 changes: 6 additions & 26 deletions shared/src/geofxnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,18 @@ use theframework::prelude::*;

#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
pub enum GeoFXNode {
Disc(TheCollection),
Disc(TheTimeline),
}

impl GeoFXNode {
pub fn new_node(name: &str, collection: Option<TheCollection>) -> Option<Self> {
let mut coll = TheCollection::named(name.into());
match name {
"Disc" => {
if let Some(collection) = collection {
coll = collection;
} else {
coll.set("Radius", TheValue::FloatRange(0.01, 0.0..=5.0));
}
Some(Self::Disc(coll))
}
// Box
_ => {
if let Some(collection) = collection {
coll = collection;
} else {
coll.set("Size", TheValue::FloatRange(0.01, 0.0..=5.0));
}
Some(Self::Disc(coll))
}
}
pub fn new_disc() -> Self {
let mut coll = TheCollection::named(str!("Geo"));
coll.set("Radius", TheValue::FloatRange(0.01, 0.000..=5.0));
Self::Disc(TheTimeline::collection(coll))
}

pub fn nodes() -> Vec<Self> {
vec![
Self::new_node("Disc", None).unwrap(),
Self::new_node("Box", None).unwrap(),
]
vec![Self::new_disc()]
}

pub fn distance(&self, p: Vec2f, coll: &TheCollection) -> f32 {
Expand Down
26 changes: 26 additions & 0 deletions shared/src/geofxobject.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::prelude::*;
use theframework::prelude::*;

/// A character instance.
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
pub struct GeoFXObject {
pub id: Uuid,

pub geos: Vec<GeoFXNode>,
}

impl Default for GeoFXObject {
fn default() -> Self {
Self::new()
}
}

impl GeoFXObject {
pub fn new() -> Self {
Self {
id: Uuid::new_v4(),

geos: Vec::new(),
}
}
}
2 changes: 2 additions & 0 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod character;
pub mod client;
pub mod fx;
pub mod geofxnode;
pub mod geofxobject;
pub mod interaction;
pub mod item;
pub mod level;
Expand Down Expand Up @@ -39,6 +40,7 @@ pub mod prelude {
pub use crate::client::*;
pub use crate::fx::*;
pub use crate::geofxnode::*;
pub use crate::geofxobject::*;
pub use crate::interaction::*;
pub use crate::item::Item;
pub use crate::level::*;
Expand Down
16 changes: 16 additions & 0 deletions shared/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ pub struct Region {
#[serde(with = "vectorize")]
pub models: FxHashMap<(i32, i32, i32), ModelFXStore>,

#[serde(default)]
#[serde(with = "vectorize")]
pub geometry: FxHashMap<Vec3i, GeoFXObject>,

#[serde(default)]
pub areas: FxHashMap<Uuid, Area>,

Expand Down Expand Up @@ -101,6 +105,7 @@ impl Region {

tiles: FxHashMap::default(),
models: FxHashMap::default(),
geometry: FxHashMap::default(),

areas: FxHashMap::default(),
characters: FxHashMap::default(),
Expand Down Expand Up @@ -169,6 +174,17 @@ impl Region {
}
}

/// Add a geometry node to the given position.
pub fn add_geo(&mut self, at: Vec3i, geo: GeoFXNode) {
if let Some(geo_obj) = self.geometry.get_mut(&at) {
geo_obj.geos.push(geo);
} else {
let mut geo_obj = GeoFXObject::default();
geo_obj.geos.push(geo);
self.geometry.insert(at, geo_obj);
}
}

/// Set the timeline.
pub fn set_tilefx(&mut self, pos: (i32, i32), timeline: TheTimeline) {
if let Some(tile) = self.tiles.get_mut(&pos) {
Expand Down
6 changes: 6 additions & 0 deletions shared/src/server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ pub struct ServerContext {

/// The logged interactions of the characters.
pub interactions: FxHashMap<Uuid, Vec<Interaction>>,

/// The conceptual display range [0..1] of the 2D preview.
/// Only relevent in Model view. 0 is full conceptual display. 1 is full detail.
pub conceptual_display: Option<f32>,
}

impl Default for ServerContext {
Expand Down Expand Up @@ -69,6 +73,8 @@ impl ServerContext {
show_fx_marker: false,

interactions: FxHashMap::default(),

conceptual_display: None,
}
}

Expand Down
9 changes: 9 additions & 0 deletions shared/src/tiledrawer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub struct RegionDrawSettings {

pub time: TheTime,
pub center_on_character: Option<Uuid>,

pub conceptual_display: Option<f32>,
}

#[allow(clippy::new_without_default)]
Expand All @@ -44,6 +46,8 @@ impl RegionDrawSettings {

time: TheTime::default(),
center_on_character: None,

conceptual_display: None,
}
}
}
Expand Down Expand Up @@ -170,6 +174,11 @@ impl TileDrawer {

let mut mirror: Option<(i32, i32)> = None;

for (pos, geo) in &region.geometry {
let p = Vec2f::new(pos.x as f32, pos.z as f32)
- vec2f(tile_x as f32, tile_y as f32);
}

if let Some(tile) = region.tiles.get(&(tile_x, tile_y)) {
for tile_index in 0..tile.layers.len() {
if let Some(tile_uuid) = tile.layers[tile_index] {
Expand Down

0 comments on commit 3581f6a

Please sign in to comment.