Skip to content

Commit

Permalink
More 2D transform modes
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Oct 12, 2024
1 parent edc3181 commit dcccb87
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 37 deletions.
2 changes: 1 addition & 1 deletion StarterProject.eldiron

Large diffs are not rendered by default.

66 changes: 47 additions & 19 deletions shared/src/geofxnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ impl GeoFXNode {
coll.set("Thickness", TheValue::FloatRange(0.1, 0.001..=1.0));
coll.set(
"2D Mode",
TheValue::TextList(0, vec![str!("Normal"), str!("-1 Pos, +1 Length")]),
TheValue::TextList(
0,
vec![
str!("Normal"),
str!("-1 Pos, +1 Length"),
str!("-1 Pos, +2 Length"),
],
),
);
}
Material => {
Expand Down Expand Up @@ -536,7 +543,7 @@ impl GeoFXNode {
}

/// Returns all tiles which are touched by this geometry.
pub fn area(&self) -> Vec<Vec2i> {
pub fn area(&self, no_2d_transforms: bool) -> Vec<Vec2i> {
let mut area = Vec::new();
if let Some(coll) = self
.timeline
Expand Down Expand Up @@ -587,11 +594,19 @@ impl GeoFXNode {
let mut pos = Vec2i::from(self.position(&coll));
let mut length = self.length().ceil() as i32;

if let Some(value) = coll.get("2D Mode") {
if let Some(mode) = value.to_i32() {
if mode == 1 && self.is_vertical() {
pos.y -= 1;
length += 1;
if !no_2d_transforms {
if let Some(value) = coll.get("2D Mode") {
if let Some(mode) = value.to_i32() {
let is_vertical = self.is_vertical();
if is_vertical {
if mode == 1 {
pos.y -= 1;
length += 1;
} else if mode == 2 {
pos.y -= 1;
length += 2;
}
}
}
}
}
Expand All @@ -606,9 +621,15 @@ impl GeoFXNode {

if let Some(value) = coll.get("2D Mode") {
if let Some(mode) = value.to_i32() {
if mode == 1 && !self.is_vertical() {
pos.x -= 1;
length += 1;
let is_vertical = self.is_vertical();
if !is_vertical {
if mode == 1 {
pos.x -= 1;
length += 1;
} else if mode == 2 {
pos.x -= 1;
length += 2;
}
}
}
}
Expand Down Expand Up @@ -944,14 +965,21 @@ impl GeoFXNode {
}

pub fn update_parameters(&mut self) {
// match self.role {
// LeftWall | FrontWall | RightWall | BackWall | MiddleWallH | MiddleWallV => {
// self.set(
// "2D Mode",
// TheValue::TextList(0, vec![str!("Normal"), str!("-1 Pos, +1 Length")]),
// );
// }
// _ => {}
// }
match self.role {
LeftWall | FrontWall | RightWall | BackWall | MiddleWallH | MiddleWallV => {
self.set(
"2D Mode",
TheValue::TextList(
0,
vec![
str!("Normal"),
str!("-1 Pos, +1 Length"),
str!("-1 Pos, +2 Length"),
],
),
);
}
_ => {}
}
}
}
26 changes: 10 additions & 16 deletions shared/src/geofxobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,9 @@ impl GeoFXObject {

pub fn update_area(&mut self) {
self.area.clear();
// let mut area = AABB2D::zero();
// for geo in &self.nodes {
// if let Some(aabb) = geo.aabb(&TheTime::default()) {
// area.grow(aabb);
// }
// }
// self.area = area.to_tiles();

// for geo in &self.nodes {
// let p = geo.position();
// let pp = vec2i(p.x as i32, p.y as i32);
// if !self.area.contains(&pp) {
// self.area.push(pp);
// }
// }

for geo in &self.nodes {
let area = geo.area();
let area = geo.area(false);
self.height = geo.height().ceil() as i32;
for p in area {
if !self.area.contains(&p) {
Expand Down Expand Up @@ -243,6 +228,15 @@ impl GeoFXObject {
}
}

/// Returns the area of the object without any 2D transforms, so that the 3D rendere can mask against it.
pub fn area_without_2d_transforms(&self) -> Vec<Vec2i> {
if let Some(geo) = self.nodes.first() {
geo.area(true)
} else {
vec![]
}
}

/// Get the length of the node.
pub fn get_length(&self) -> f32 {
if let Some(geo) = self.nodes.first() {
Expand Down
8 changes: 7 additions & 1 deletion shared/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,13 @@ impl Renderer {
if let Some(ids) = region.geometry_areas.get(&vec3i(key.x, 0, key.z)) {
for id in ids {
if let Some(geo_obj) = region.geometry.get(id) {
if key.y <= geo_obj.height && !geo_ids.contains(id) {
let area_without_2d_transforms =
geo_obj.area_without_2d_transforms();

if key.y <= geo_obj.height
&& !geo_ids.contains(id)
&& area_without_2d_transforms.contains(&vec2i(key.x, key.z))
{
geo_ids.push(*id);
}
}
Expand Down

0 comments on commit dcccb87

Please sign in to comment.