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.
</p>
<img src=".github/graphics/nodes.svg" width="50%"/>
<img src=".github/graphics/nodes.svg" width="80%"/>
</div>

View File

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

View File

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

View File

@ -33,8 +33,8 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
}
for path_data in paths.iter() {
// if this is not a path don't modify it
if path_data[2] != 0 || path_data[3] < (max_depth - depth) {
// if this is not a path ignore it
if path_data[2] != 0 || path_data[3] < (max_depth - depth + 1) {
output.push(path_data.to_vec());
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 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 normalised = (end_point - start_point).normalize();
if normalised[0].is_nan() {
log!("normalised is nan {:?}", normalised);
continue;
}
let strength = evaluate_float(args[1]);
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 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(),
);
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 {
mid_point[0] += 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 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 + 1] = offset_end_point[1];
path.points[end_index + 2] = offset_end_point[2];

View File

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

View File

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

View File

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

View File

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

View File

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