feat: add octaves to noise node
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m8s

This commit is contained in:
max_richter 2024-04-30 13:15:56 +02:00
parent 43493522bd
commit eafc9c99c8
11 changed files with 51 additions and 82 deletions

View File

@ -0,0 +1 @@
# Developing Nodes

View File

@ -8,7 +8,7 @@ Nodarium
Nodarium is a WebAssembly based visual programming language. Nodarium is a WebAssembly based visual programming language.
</p> </p>
<img src=".github/graphics/nodes.svg" width="50%"/> <img src=".github/graphics/nodes.svg" width="80%"/>
</div> </div>

View File

@ -117,15 +117,20 @@
</HTML> </HTML>
<style> <style>
.header {
padding: 5px;
}
input { input {
background: var(--layer-0); background: var(--layer-0);
font-family: var(--font-family); font-family: var(--font-family);
border: none; border: none;
border-radius: 5px;
color: var(--text-color); color: var(--text-color);
padding: 0.8em; padding: 0.6em;
width: calc(100% - 2px); width: calc(100% - 2px);
box-sizing: border-box; box-sizing: border-box;
font-size: 1em; font-size: 0.8em;
margin-left: 1px; margin-left: 1px;
margin-top: 1px; margin-top: 1px;
} }

View File

@ -1,19 +1,25 @@
<script lang="ts"> <script lang="ts">
import localStore from "$lib/helpers/localStore"; import localStore from "$lib/helpers/localStore";
import type { RemoteNodeRegistry } from "$lib/node-registry-client"; import type { RemoteNodeRegistry } from "$lib/node-registry-client";
import { writable } from "svelte/store";
import BreadCrumbs from "./BreadCrumbs.svelte"; import BreadCrumbs from "./BreadCrumbs.svelte";
import DraggableNode from "./DraggableNode.svelte"; import DraggableNode from "./DraggableNode.svelte";
export let registry: RemoteNodeRegistry; export let registry: RemoteNodeRegistry;
const activeId = localStore< const activeId = writable("max/plantarium");
`${string}` | `${string}/${string}` | `${string}/${string}/${string}` let showBreadCrumbs = false;
>("nodes.store.activeId", "");
// const activeId = localStore<
// `${string}` | `${string}/${string}` | `${string}/${string}/${string}`
// >("nodes.store.activeId", "");
$: [activeUser, activeCollection, activeNode] = $activeId.split(`/`); $: [activeUser, activeCollection, activeNode] = $activeId.split(`/`);
</script> </script>
<BreadCrumbs {activeId} /> {#if showBreadCrumbs}
<BreadCrumbs {activeId} />
{/if}
<div class="wrapper"> <div class="wrapper">
{#if !activeUser} {#if !activeUser}
@ -68,17 +74,7 @@
<style> <style>
.wrapper { .wrapper {
padding: 0.8em; padding: 0.8em;
max-height: calc(100vh - 170px); max-height: calc(100vh - 100px);
overflow-y: auto; overflow-y: auto;
} }
.header {
display: flex;
align-items: center;
gap: 0.5em;
margin-bottom: 0.5em;
}
h3 {
margin: 0;
}
</style> </style>

View File

@ -33,8 +33,8 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
} }
for path_data in paths.iter() { for path_data in paths.iter() {
// if this is not a path don't modify it // if this is not a path ignore it
if path_data[2] != 0 || path_data[3] < (max_depth - depth) { if path_data[2] != 0 || path_data[3] < (max_depth - depth + 1) {
output.push(path_data.to_vec()); output.push(path_data.to_vec());
continue; continue;
} }

View File

@ -50,38 +50,14 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
let start_point = Vec3::from_slice(&path.points[start_index..start_index + 3]); let start_point = Vec3::from_slice(&path.points[start_index..start_index + 3]);
let end_point = Vec3::from_slice(&path.points[end_index..end_index + 3]); let end_point = Vec3::from_slice(&path.points[end_index..end_index + 3]);
log!("--------------------------------");
log!(
"start_index: {:?} end_index: {:?} length:{}",
start_index,
end_index,
path.points.len()
);
if start_point[0].is_nan() {
log!("start_point is nan {:?}", path.points);
continue;
}
log!("start_point: {:?}", start_point);
log!("end_point: {:?}", end_point);
let length = (end_point - start_point).length(); let length = (end_point - start_point).length();
let normalised = (end_point - start_point).normalize(); let normalised = (end_point - start_point).normalize();
if normalised[0].is_nan() {
log!("normalised is nan {:?}", normalised);
continue;
}
let strength = evaluate_float(args[1]); let strength = evaluate_float(args[1]);
let down_point = Vec3::new(0.0, -length * strength, 0.0); let down_point = Vec3::new(0.0, -length * strength, 0.0);
if down_point[0].is_nan() {
log!("down_point is nan {:?}", down_point);
continue;
}
let curviness = evaluate_float(args[2]); let curviness = evaluate_float(args[2]);
let mut mid_point = lerp_vec3( let mut mid_point = lerp_vec3(
@ -90,13 +66,6 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
curviness * (i as f32 / path.length as f32).sqrt(), curviness * (i as f32 / path.length as f32).sqrt(),
); );
if mid_point[0].is_nan() {
log!("mid_point is nan {:?}", mid_point);
log!("normalised: {:?}", normalised);
log!("curviness: {:?}", curviness);
continue;
}
if mid_point[0] == 0.0 && mid_point[2] == 0.0 { if mid_point[0] == 0.0 && mid_point[2] == 0.0 {
mid_point[0] += 0.0001; mid_point[0] += 0.0001;
mid_point[2] += 0.0001; mid_point[2] += 0.0001;
@ -109,11 +78,6 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
let final_end_point = start_point + mid_point; let final_end_point = start_point + mid_point;
let offset_end_point = end_point + offset_vec; let offset_end_point = end_point + offset_vec;
if offset_end_point[0].is_nan() {
log!("offset_end_point is nan {:?}", offset_end_point);
continue;
}
path.points[end_index] = offset_end_point[0]; path.points[end_index] = offset_end_point[0];
path.points[end_index + 1] = offset_end_point[1]; path.points[end_index + 1] = offset_end_point[1];
path.points[end_index + 2] = offset_end_point[2]; path.points[end_index + 2] = offset_end_point[2];

View File

@ -19,7 +19,7 @@
}, },
"fixBottom": { "fixBottom": {
"type": "float", "type": "float",
"label": "Fixate bottom of plant", "label": "Fix bottom of plant",
"hidden": true, "hidden": true,
"value": 1.0, "value": 1.0,
"min": 0, "min": 0,
@ -43,6 +43,13 @@
"max": 10, "max": 10,
"value": 1, "value": 1,
"hidden": true "hidden": true
},
"octaves": {
"type": "integer",
"min": 1,
"max": 5,
"value": 1,
"hidden": true
} }
} }
} }

View File

@ -1,6 +1,6 @@
use glam::Vec3; use glam::Vec3;
use macros::include_definition_file; use macros::include_definition_file;
use noise::{core::open_simplex::open_simplex_2d, permutationtable::PermutationTable, Vector2}; use noise::{HybridMulti, MultiFractal, NoiseFn, OpenSimplex};
use utils::{ use utils::{
concat_args, evaluate_float, evaluate_int, evaluate_vec3, geometry::wrap_path_mut, concat_args, evaluate_float, evaluate_int, evaluate_vec3, geometry::wrap_path_mut,
reset_call_count, set_panic_hook, split_args, reset_call_count, set_panic_hook, split_args,
@ -32,7 +32,14 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
let depth = evaluate_int(args[6]); let depth = evaluate_int(args[6]);
let hasher = PermutationTable::new(seed as u32); let octaves = evaluate_int(args[7]);
let noise_x: HybridMulti<OpenSimplex> =
HybridMulti::new(seed as u32 + 1).set_octaves(octaves as usize);
let noise_y: HybridMulti<OpenSimplex> =
HybridMulti::new(seed as u32 + 2).set_octaves(octaves as usize);
let noise_z: HybridMulti<OpenSimplex> =
HybridMulti::new(seed as u32 + 3).set_octaves(octaves as usize);
let mut max_depth = 0; let mut max_depth = 0;
for path_data in plants.iter() { for path_data in plants.iter() {
@ -72,31 +79,21 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
for i in 0..path.length { for i in 0..path.length {
let a = i as f64 / (path.length - 1) as f64; let a = i as f64 / (path.length - 1) as f64;
let px = Vector2::new(1000.0 + j as f64 + a * length * scale, a * scale as f64); let px = j as f64 + a * length * scale;
let py = Vector2::new(2000.0 + j as f64 + a * length * scale, a * scale as f64); let py = a * scale as f64;
let pz = Vector2::new(3000.0 + j as f64 + a * length * scale, a * scale as f64);
let nx = open_simplex_2d(px, &hasher) as f32 path.points[i * 4] += noise_x.get([px, py]) as f32
* strength
* 0.1
* directional_strength[0] * directional_strength[0]
* lerp(1.0, a as f32, fix_bottom);
let ny = open_simplex_2d(py, &hasher) as f32
* strength * strength
* 0.1 * lerp(1.0, a as f32, fix_bottom);
path.points[i * 4 + 1] += noise_y.get([px, py]) as f32
* directional_strength[1] * directional_strength[1]
* lerp(1.0, a as f32, fix_bottom);
let nz = open_simplex_2d(pz, &hasher) as f32
* strength * strength
* 0.1
* directional_strength[2]
* lerp(1.0, a as f32, fix_bottom); * lerp(1.0, a as f32, fix_bottom);
path.points[i * 4 + 2] += noise_z.get([px, py]) as f32
path.points[i * 4] += nx; * directional_strength[2]
path.points[i * 4 + 1] += ny; * strength
path.points[i * 4 + 2] += nz; * lerp(1.0, a as f32, fix_bottom);
} }
path_data path_data
}) })

View File

@ -52,7 +52,7 @@ body {
/* Secondary color */ /* Secondary color */
--secondary-color: #6c757d; --secondary-color: #6c757d;
--layer-0: var(--neutral-800); --layer-0: var(--neutral-900);
--layer-1: var(--neutral-500); --layer-1: var(--neutral-500);
--layer-2: var(--neutral-400); --layer-2: var(--neutral-400);
--layer-3: var(--neutral-200); --layer-3: var(--neutral-200);

View File

@ -1,6 +1,5 @@
<script lang="ts"> <script lang="ts">
import { createEventDispatcher } from "svelte"; import { createEventDispatcher } from "svelte";
import { getBoundingValue } from "../helpers/getBoundingValue.js";
export let value = 0.5; export let value = 0.5;
export let step = 0.01; export let step = 0.01;

View File

@ -69,10 +69,10 @@
function handleMouseMove(ev: MouseEvent) { function handleMouseMove(ev: MouseEvent) {
if (!ev.ctrlKey && typeof min === "number" && typeof max === "number") { if (!ev.ctrlKey && typeof min === "number" && typeof max === "number") {
const vx = (ev.clientX - rect.left) / rect.width; const vx = (ev.clientX - rect.left) / rect.width;
value = Math.max(Math.min(Math.floor(min + (max - min) * vx), max), min); value = Math.max(Math.min(Math.round(min + (max - min) * vx), max), min);
} else { } else {
const vx = ev.clientX - downX; const vx = ev.clientX - downX;
value = downV + Math.floor(vx / 10); value = downV + Math.round(vx / 10);
} }
} }
</script> </script>