Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ pub(crate) fn property_from_type(
Type::Concrete(concrete_type) => {
match concrete_type.alias.as_ref().map(|x| x.as_ref()) {
// Aliased types (ambiguous values)
Some("Percentage") => number_widget(default_info, number_input.percentage().min(min(0.)).max(max(100.))).into(),
Some("SignedPercentage") => number_widget(default_info, number_input.percentage().min(min(-100.)).max(max(100.))).into(),
Some("Angle") => number_widget(default_info, number_input.mode_range().min(min(-180.)).max(max(180.)).unit(unit.unwrap_or("°"))).into(),
Some("Percentage") | Some("PercentageF32") => number_widget(default_info, number_input.percentage().min(min(0.)).max(max(100.))).into(),
Some("SignedPercentage") | Some("SignedPercentageF32") => number_widget(default_info, number_input.percentage().min(min(-100.)).max(max(100.))).into(),
Some("Angle") | Some("AngleF32") => number_widget(default_info, number_input.mode_range().min(min(-180.)).max(max(180.)).unit(unit.unwrap_or("°"))).into(),
Some("Multiplier") => number_widget(default_info, number_input.unit(unit.unwrap_or("x"))).into(),
Some("PixelLength") => number_widget(default_info, number_input.min(min(0.)).unit(unit.unwrap_or(" px"))).into(),
Some("Length") => number_widget(default_info, number_input.min(min(0.))).into(),
Expand All @@ -166,7 +166,7 @@ pub(crate) fn property_from_type(
// ===============
// PRIMITIVE TYPES
// ===============
Some(x) if x == TypeId::of::<f64>() => number_widget(default_info, number_input.min(min(f64::NEG_INFINITY)).max(max(f64::INFINITY))).into(),
Some(x) if x == TypeId::of::<f64>() || x == TypeId::of::<f32>() => number_widget(default_info, number_input.min(min(f64::NEG_INFINITY)).max(max(f64::INFINITY))).into(),
Some(x) if x == TypeId::of::<u32>() => number_widget(default_info, number_input.int().min(min(0.)).max(max(f64::from(u32::MAX)))).into(),
Some(x) if x == TypeId::of::<u64>() => number_widget(default_info, number_input.int().min(min(0.))).into(),
Some(x) if x == TypeId::of::<bool>() => bool_widget(default_info, CheckboxInput::default()).into(),
Expand Down Expand Up @@ -805,6 +805,14 @@ pub fn number_widget(parameter_widgets_info: ParameterWidgetsInfo, number_props:
.on_commit(commit_value)
.widget_holder(),
]),
Some(&TaggedValue::F32(x)) => widgets.extend_from_slice(&[
Separator::new(SeparatorType::Unrelated).widget_holder(),
number_props
.value(Some(x as f64))
.on_update(update_value(move |x: &NumberInput| TaggedValue::F32(x.value.unwrap() as f32), node_id, index))
.on_commit(commit_value)
.widget_holder(),
]),
Some(&TaggedValue::U32(x)) => widgets.extend_from_slice(&[
Separator::new(SeparatorType::Unrelated).widget_holder(),
number_props
Expand Down Expand Up @@ -851,6 +859,15 @@ pub fn number_widget(parameter_widgets_info: ParameterWidgetsInfo, number_props:
.on_commit(commit_value)
.widget_holder(),
]),
Some(&TaggedValue::Vec2(vec2)) => widgets.extend_from_slice(&[
Separator::new(SeparatorType::Unrelated).widget_holder(),
number_props
// We use an arbitrary `y` instead of an arbitrary `x` here because the "Grid" node's "Spacing" value's height should be used from rectangular mode when transferred to "Y Spacing" in isometric mode
.value(Some(vec2.y as f64))
.on_update(update_value(move |x: &NumberInput| TaggedValue::F32(x.value.unwrap() as f32), node_id, index))
.on_commit(commit_value)
.widget_holder(),
]),
_ => {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl FrontendGraphDataType {
match TaggedValue::from_type_or_none(input) {
TaggedValue::U32(_)
| TaggedValue::U64(_)
| TaggedValue::F32(_)
| TaggedValue::F64(_)
| TaggedValue::DVec2(_)
| TaggedValue::F64Array4(_)
Expand Down
2 changes: 1 addition & 1 deletion node-graph/gbrush/src/brush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub async fn create_brush_texture(brush_style: &BrushStyle) -> Raster<CPU> {
}

pub fn blend_with_mode(background: TableRow<Raster<CPU>>, foreground: TableRow<Raster<CPU>>, blend_mode: BlendMode, opacity: f64) -> TableRow<Raster<CPU>> {
let opacity = opacity / 100.;
let opacity = opacity as f32 / 100.;
match std::hint::black_box(blend_mode) {
// Normal group
BlendMode::Normal => blend_image_closure(foreground, background, |a, b| blend_colors(a, b, BlendMode::Normal, opacity)),
Expand Down
6 changes: 6 additions & 0 deletions node-graph/gcore-shaders/src/registry.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
pub mod types {
/// 0% - 100%
pub type Percentage = f64;
/// 0% - 100%
pub type PercentageF32 = f32;
/// -100% - 100%
pub type SignedPercentage = f64;
/// -100% - 100%
pub type SignedPercentageF32 = f32;
/// -180° - 180°
pub type Angle = f64;
/// -180° - 180°
pub type AngleF32 = f32;
/// Ends in the unit of x
pub type Multiplier = f64;
/// Non-negative integer with px unit
Expand Down
23 changes: 22 additions & 1 deletion node-graph/graph-craft/src/document/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::proto::{Any as DAny, FutureAny};
use crate::wasm_application_io::WasmEditorApi;
use dyn_any::DynAny;
pub use dyn_any::StaticType;
use glam::{Affine2, Vec2};
pub use glam::{DAffine2, DVec2, IVec2, UVec2};
use graphene_application_io::{ImageTexture, SurfaceFrame};
use graphene_brush::brush_cache::BrushCache;
Expand Down Expand Up @@ -163,7 +164,7 @@ tagged_value! {
// ===============
// PRIMITIVE TYPES
// ===============
#[serde(alias = "F32")] // TODO: Eventually remove this alias document upgrade code
F32(f32),
F64(f64),
U32(u32),
U64(u64),
Expand Down Expand Up @@ -201,6 +202,8 @@ tagged_value! {
// ============
// STRUCT TYPES
// ============
Vec2(Vec2),
Copy link
Copy Markdown
Member

@Keavon Keavon Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please call this FVec2 because the user-facing name for DVec2 is already "Vec2" and we need to avoid the confusion of the internal version being given the opposite name of the user-facing version. And probably the same for Affine2 -> FAffine2 for consistency. This also lets us discriminate between them in the future for rename purposes if we figure out how to clean this up once there is more Graphene infrastructure in place to handle numeric precision and units.

Affine2(Affine2),
#[serde(alias = "IVec2", alias = "UVec2")]
DVec2(DVec2),
DAffine2(DAffine2),
Expand Down Expand Up @@ -257,6 +260,7 @@ impl TaggedValue {
TaggedValue::String(x) => format!("\"{x}\""),
TaggedValue::U32(x) => x.to_string() + "_u32",
TaggedValue::U64(x) => x.to_string() + "_u64",
TaggedValue::F32(x) => x.to_string() + "_f32",
TaggedValue::F64(x) => x.to_string() + "_f64",
TaggedValue::Bool(x) => x.to_string(),
TaggedValue::BlendMode(x) => "BlendMode::".to_string() + &x.to_string(),
Expand Down Expand Up @@ -348,6 +352,7 @@ impl TaggedValue {
x if x == TypeId::of::<()>() => TaggedValue::None,
x if x == TypeId::of::<String>() => TaggedValue::String(string.into()),
x if x == TypeId::of::<f64>() => FromStr::from_str(string).map(TaggedValue::F64).ok()?,
x if x == TypeId::of::<f32>() => FromStr::from_str(string).map(TaggedValue::F32).ok()?,
x if x == TypeId::of::<u64>() => FromStr::from_str(string).map(TaggedValue::U64).ok()?,
x if x == TypeId::of::<u32>() => FromStr::from_str(string).map(TaggedValue::U32).ok()?,
x if x == TypeId::of::<DVec2>() => to_dvec2(string).map(TaggedValue::DVec2)?,
Expand Down Expand Up @@ -378,6 +383,7 @@ impl Display for TaggedValue {
TaggedValue::String(x) => f.write_str(x),
TaggedValue::U32(x) => f.write_fmt(format_args!("{x}")),
TaggedValue::U64(x) => f.write_fmt(format_args!("{x}")),
TaggedValue::F32(x) => f.write_fmt(format_args!("{x}")),
TaggedValue::F64(x) => f.write_fmt(format_args!("{x}")),
TaggedValue::Bool(x) => f.write_fmt(format_args!("{x}")),
_ => panic!("Cannot convert to string"),
Expand Down Expand Up @@ -463,6 +469,21 @@ mod fake_hash {
self.to_cols_array().iter().for_each(|x| x.to_bits().hash(state))
}
}
impl FakeHash for f32 {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.to_bits().hash(state)
}
}
impl FakeHash for Vec2 {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.to_array().iter().for_each(|x| x.to_bits().hash(state))
}
}
impl FakeHash for Affine2 {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.to_cols_array().iter().for_each(|x| x.to_bits().hash(state))
}
}
impl<X: FakeHash> FakeHash for Option<X> {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
if let Some(x) = self {
Expand Down
4 changes: 3 additions & 1 deletion node-graph/graph-craft/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,11 @@ mod test {
construction_network.generate_stable_node_ids();
assert_eq!(construction_network.nodes[0].1.identifier.name.as_ref(), "value");
let ids: Vec<_> = construction_network.nodes.iter().map(|(id, _)| *id).collect();

// If this assert fails: These NodeIds seem to be changing when you modify TaggedValue, just update them.
assert_eq!(
ids,
vec![NodeId(13743208144182721472), NodeId(4607569396187877965), NodeId(16950305885390329527), NodeId(15151181027373658932)]
vec![NodeId(2791689253855410677), NodeId(11246167042277902310), NodeId(1014827049498980779), NodeId(4864562752646903491)]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment I left correct? Based on git history, I see them being updated frequently

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think the test network contains a U32(u32), so moving the position of that will change the hash.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0HyperCube what about the comment right above, which github is hiding?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems fair. I don't really see why it matters if the node ids aren't stable across different commits. However most modifications to the TaggedValue take place under the U32 so it probably shouldn't break too much.

);
}

Expand Down
Loading