Skip to content

Commit f1fbccb

Browse files
committed
Migrate noise pattern node to input properties
1 parent 228dedd commit f1fbccb

File tree

3 files changed

+282
-189
lines changed

3 files changed

+282
-189
lines changed

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 199 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -792,18 +792,18 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
792792
"Clip".into(),
793793
"Seed".into(),
794794
PropertiesRow::with_override("Scale", WidgetOverride::Custom("noise_properties_scale".to_string())),
795-
"Noise Type".into(),
796-
"Domain Warp Type".into(),
797-
"Domain Warp Amplitude".into(),
798-
"Fractal Type".into(),
799-
"Fractal Octaves".into(),
800-
"Fractal Lacunarity".into(),
801-
"Fractal Gain".into(),
802-
"Fractal Weighted Strength".into(),
803-
"Fractal Ping Pong Strength".into(),
804-
"Cellular Distance Function".into(),
805-
"Cellular Return Type".into(),
806-
"Cellular Jitter".into(),
795+
PropertiesRow::with_override("Noise Type", WidgetOverride::Custom("noise_properties_noise_type".to_string())),
796+
PropertiesRow::with_override("Domain Warp Type", WidgetOverride::Custom("noise_properties_domain_warp_type".to_string())),
797+
PropertiesRow::with_override("Domain Warp Amplitude", WidgetOverride::Custom("noise_properties_domain_warp_amplitude".to_string())),
798+
PropertiesRow::with_override("Fractal Type", WidgetOverride::Custom("noise_properties_fractal_type".to_string())),
799+
PropertiesRow::with_override("Fractal Octaves", WidgetOverride::Custom("noise_properties_fractal_octaves".to_string())),
800+
PropertiesRow::with_override("Fractal Lacunarity", WidgetOverride::Custom("noise_properties_fractal_lacunarity".to_string())),
801+
PropertiesRow::with_override("Fractal Gain", WidgetOverride::Custom("noise_properties_fractal_gain".to_string())),
802+
PropertiesRow::with_override("Fractal Weighted Strength", WidgetOverride::Custom("noise_properties_fractal_weighted_strength".to_string())),
803+
PropertiesRow::with_override("Fractal Ping Pong Strength", WidgetOverride::Custom("noise_properties_ping_pong_strength".to_string())),
804+
PropertiesRow::with_override("Cellular Distance Function", WidgetOverride::Custom("noise_properties_cellular_distance_function".to_string())),
805+
PropertiesRow::with_override("Cellular Return Type", WidgetOverride::Custom("noise_properties_cellular_return_type".to_string())),
806+
PropertiesRow::with_override("Cellular Jitter", WidgetOverride::Custom("noise_properties_cellular_jitter".to_string())),
807807
],
808808
output_names: vec!["Image".to_string()],
809809
network_metadata: Some(NodeNetworkMetadata {
@@ -2736,22 +2736,196 @@ fn static_input_properties() -> HashMap<String, Box<dyn Fn(NodeId, usize, &mut N
27362736
map.insert(
27372737
"noise_properties_scale".to_string(),
27382738
Box::new(|node_id, index, context| {
2739-
let network = context.network_interface.network(context.selection_network_path).ok_or("network not found in noise_properties_scale")?;
2740-
let document_node = network.nodes.get(&node_id).ok_or("node not found in noise_properties_scale")?;
2741-
let current_noise_type = document_node.inputs.iter().find_map(|input| match input.as_value() {
2742-
Some(&TaggedValue::NoiseType(noise_type)) => Some(noise_type),
2743-
_ => None,
2744-
});
2745-
let coherent_noise_active = current_noise_type != Some(NoiseType::WhiteNoise);
2746-
let input_name = context
2747-
.network_interface
2748-
.input_name(&node_id, index, context.selection_network_path)
2749-
.ok_or("input name not found in noise_properties_scale")?;
2750-
2751-
let scale = node_properties::number_widget(document_node, node_id, 2, input_name, NumberInput::default().min(0.).disabled(!coherent_noise_active), true);
2739+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2740+
let (_, coherent_noise_active, _, _, _, _) = node_properties::query_noise_pattern_state(node_id, context)?;
2741+
let scale = node_properties::number_widget(document_node, node_id, index, input_name, NumberInput::default().min(0.).disabled(!coherent_noise_active), true);
27522742
Ok(vec![scale.into()])
27532743
}),
27542744
);
2745+
map.insert(
2746+
"noise_properties_noise_type".to_string(),
2747+
Box::new(|node_id, index, context| {
2748+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2749+
let (_, coherent_noise_active, _, _, _, _) = node_properties::query_noise_pattern_state(node_id, context)?;
2750+
let noise_type_row = node_properties::noise_type(document_node, node_id, index, input_name, true);
2751+
Ok(vec![noise_type_row, LayoutGroup::Row { widgets: Vec::new() }])
2752+
}),
2753+
);
2754+
map.insert(
2755+
"noise_properties_domain_warp_type".to_string(),
2756+
Box::new(|node_id, index, context| {
2757+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2758+
let (_, coherent_noise_active, _, _, _, _) = node_properties::query_noise_pattern_state(node_id, context)?;
2759+
let domain_warp_type = node_properties::domain_warp_type(document_node, node_id, index, input_name, true, !coherent_noise_active);
2760+
Ok(vec![domain_warp_type.into()])
2761+
}),
2762+
);
2763+
map.insert(
2764+
"noise_properties_domain_warp_amplitude".to_string(),
2765+
Box::new(|node_id, index, context| {
2766+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2767+
let (_, coherent_noise_active, _, _, domain_warp_active, _) = node_properties::query_noise_pattern_state(node_id, context)?;
2768+
let domain_warp_amplitude = node_properties::number_widget(
2769+
document_node,
2770+
node_id,
2771+
index,
2772+
input_name,
2773+
NumberInput::default().min(0.).disabled(!coherent_noise_active || !domain_warp_active),
2774+
true,
2775+
);
2776+
Ok(vec![domain_warp_amplitude.into(), LayoutGroup::Row { widgets: Vec::new() }])
2777+
}),
2778+
);
2779+
map.insert(
2780+
"noise_properties_fractal_type".to_string(),
2781+
Box::new(|node_id, index, context| {
2782+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2783+
let (_, coherent_noise_active, _, _, _, _) = node_properties::query_noise_pattern_state(node_id, context)?;
2784+
let fractal_type_row = node_properties::fractal_type(document_node, node_id, index, input_name, true, !coherent_noise_active);
2785+
Ok(vec![fractal_type_row.into()])
2786+
}),
2787+
);
2788+
map.insert(
2789+
"noise_properties_fractal_octaves".to_string(),
2790+
Box::new(|node_id, index, context| {
2791+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2792+
let (fractal_active, coherent_noise_active, _, _, _, domain_warp_only_fractal_type_wrongly_active) = node_properties::query_noise_pattern_state(node_id, context)?;
2793+
let fractal_octaves = node_properties::number_widget(
2794+
document_node,
2795+
node_id,
2796+
index,
2797+
input_name,
2798+
NumberInput::default()
2799+
.mode_range()
2800+
.min(1.)
2801+
.max(10.)
2802+
.range_max(Some(4.))
2803+
.is_integer(true)
2804+
.disabled(!coherent_noise_active || !fractal_active || domain_warp_only_fractal_type_wrongly_active),
2805+
true,
2806+
);
2807+
Ok(vec![fractal_octaves.into()])
2808+
}),
2809+
);
2810+
map.insert(
2811+
"noise_properties_fractal_lacunarity".to_string(),
2812+
Box::new(|node_id, index, context| {
2813+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2814+
let (fractal_active, coherent_noise_active, _, _, _, domain_warp_only_fractal_type_wrongly_active) = node_properties::query_noise_pattern_state(node_id, context)?;
2815+
let fractal_lacunarity = node_properties::number_widget(
2816+
document_node,
2817+
node_id,
2818+
index,
2819+
input_name,
2820+
NumberInput::default()
2821+
.mode_range()
2822+
.min(0.)
2823+
.range_max(Some(10.))
2824+
.disabled(!coherent_noise_active || !fractal_active || domain_warp_only_fractal_type_wrongly_active),
2825+
true,
2826+
);
2827+
Ok(vec![fractal_lacunarity.into()])
2828+
}),
2829+
);
2830+
map.insert(
2831+
"noise_properties_fractal_gain".to_string(),
2832+
Box::new(|node_id, index, context| {
2833+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2834+
let (fractal_active, coherent_noise_active, _, _, _, domain_warp_only_fractal_type_wrongly_active) = node_properties::query_noise_pattern_state(node_id, context)?;
2835+
let fractal_gain = node_properties::number_widget(
2836+
document_node,
2837+
node_id,
2838+
index,
2839+
input_name,
2840+
NumberInput::default()
2841+
.mode_range()
2842+
.min(0.)
2843+
.range_max(Some(10.))
2844+
.disabled(!coherent_noise_active || !fractal_active || domain_warp_only_fractal_type_wrongly_active),
2845+
true,
2846+
);
2847+
Ok(vec![fractal_gain.into()])
2848+
}),
2849+
);
2850+
map.insert(
2851+
"noise_properties_fractal_weighted_strength".to_string(),
2852+
Box::new(|node_id, index, context| {
2853+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2854+
let (fractal_active, coherent_noise_active, _, _, _, domain_warp_only_fractal_type_wrongly_active) = node_properties::query_noise_pattern_state(node_id, context)?;
2855+
let fractal_weighted_strength = node_properties::number_widget(
2856+
document_node,
2857+
node_id,
2858+
index,
2859+
input_name,
2860+
NumberInput::default()
2861+
.mode_range()
2862+
.min(0.)
2863+
.max(1.) // Defined for the 0-1 range
2864+
.disabled(!coherent_noise_active || !fractal_active || domain_warp_only_fractal_type_wrongly_active),
2865+
true,
2866+
);
2867+
Ok(vec![fractal_weighted_strength.into()])
2868+
}),
2869+
);
2870+
map.insert(
2871+
"noise_properties_ping_pong_strength".to_string(),
2872+
Box::new(|node_id, index, context| {
2873+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2874+
let (fractal_active, coherent_noise_active, _, ping_pong_active, _, domain_warp_only_fractal_type_wrongly_active) = node_properties::query_noise_pattern_state(node_id, context)?;
2875+
let fractal_ping_pong_strength = node_properties::number_widget(
2876+
document_node,
2877+
node_id,
2878+
index,
2879+
input_name,
2880+
NumberInput::default()
2881+
.mode_range()
2882+
.min(0.)
2883+
.range_max(Some(10.))
2884+
.disabled(!ping_pong_active || !coherent_noise_active || !fractal_active || domain_warp_only_fractal_type_wrongly_active),
2885+
true,
2886+
);
2887+
Ok(vec![fractal_ping_pong_strength.into(), LayoutGroup::Row { widgets: Vec::new() }])
2888+
}),
2889+
);
2890+
map.insert(
2891+
"noise_properties_cellular_distance_function".to_string(),
2892+
Box::new(|node_id, index, context| {
2893+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2894+
let (_, coherent_noise_active, cellular_noise_active, _, _, _) = node_properties::query_noise_pattern_state(node_id, context)?;
2895+
let cellular_distance_function_row = node_properties::cellular_distance_function(document_node, node_id, index, input_name, true, !coherent_noise_active || !cellular_noise_active);
2896+
Ok(vec![cellular_distance_function_row.into()])
2897+
}),
2898+
);
2899+
map.insert(
2900+
"noise_properties_cellular_return_type".to_string(),
2901+
Box::new(|node_id, index, context| {
2902+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2903+
let (_, coherent_noise_active, cellular_noise_active, _, _, _) = node_properties::query_noise_pattern_state(node_id, context)?;
2904+
let cellular_return_type = node_properties::cellular_return_type(document_node, node_id, index, input_name, true, !coherent_noise_active || !cellular_noise_active);
2905+
Ok(vec![cellular_return_type.into()])
2906+
}),
2907+
);
2908+
map.insert(
2909+
"noise_properties_cellular_jitter".to_string(),
2910+
Box::new(|node_id, index, context| {
2911+
let (document_node, input_name) = node_properties::query_node_and_input_name(node_id, index, context)?;
2912+
let (_, coherent_noise_active, cellular_noise_active, _, _, _) = node_properties::query_noise_pattern_state(node_id, context)?;
2913+
let cellular_jitter = node_properties::number_widget(
2914+
document_node,
2915+
node_id,
2916+
index,
2917+
input_name,
2918+
NumberInput::default()
2919+
.mode_range()
2920+
.range_min(Some(0.))
2921+
.range_max(Some(1.))
2922+
.disabled(!coherent_noise_active || !cellular_noise_active),
2923+
true,
2924+
);
2925+
Ok(vec![cellular_jitter.into()])
2926+
}),
2927+
);
2928+
27552929
map
27562930
}
27572931

0 commit comments

Comments
 (0)