feat: fucking hell yeah (it works) dont look at commit time pls
This commit is contained in:
parent
98cf2e8369
commit
00776b92d3
53
Cargo.lock
generated
53
Cargo.lock
generated
@ -16,6 +16,12 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "box"
|
name = "box"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -160,11 +166,12 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "noise"
|
name = "nodes-noise"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
"macros",
|
"macros",
|
||||||
|
"noise",
|
||||||
"serde",
|
"serde",
|
||||||
"serde-wasm-bindgen",
|
"serde-wasm-bindgen",
|
||||||
"utils",
|
"utils",
|
||||||
@ -173,6 +180,26 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "noise"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6da45c8333f2e152fc665d78a380be060eb84fad8ca4c9f7ac8ca29216cff0cc"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
"rand",
|
||||||
|
"rand_xorshift",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.19.0"
|
version = "1.19.0"
|
||||||
@ -212,6 +239,30 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_xorshift"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
|
||||||
|
dependencies = [
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "random"
|
name = "random"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -23,16 +23,6 @@
|
|||||||
<T.GridHelper args={[20, 20]} />
|
<T.GridHelper args={[20, 20]} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if lines}
|
|
||||||
{#each lines as line}
|
|
||||||
<T.Mesh>
|
|
||||||
<MeshLineGeometry points={line} />
|
|
||||||
|
|
||||||
<MeshLineMaterial width={0.1} depthTest={false} />
|
|
||||||
</T.Mesh>
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<T.PerspectiveCamera position={[-10, 10, 10]} makeDefault fov={50}>
|
<T.PerspectiveCamera position={[-10, 10, 10]} makeDefault fov={50}>
|
||||||
<OrbitControls />
|
<OrbitControls />
|
||||||
</T.PerspectiveCamera>
|
</T.PerspectiveCamera>
|
||||||
@ -54,6 +44,19 @@
|
|||||||
</T.Points>
|
</T.Points>
|
||||||
{/if}
|
{/if}
|
||||||
<T.Mesh geometry={geo}>
|
<T.Mesh geometry={geo}>
|
||||||
<T.MeshStandardMaterial color="green" wireframe={$AppSettings.wireframe} />
|
<T.MeshStandardMaterial
|
||||||
|
color="green"
|
||||||
|
depthTest={true}
|
||||||
|
wireframe={$AppSettings.wireframe}
|
||||||
|
/>
|
||||||
</T.Mesh>
|
</T.Mesh>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
|
{#if $AppSettings.showStemLines && lines}
|
||||||
|
{#each lines as line}
|
||||||
|
<T.Mesh scale={2}>
|
||||||
|
<MeshLineGeometry points={line} />
|
||||||
|
<MeshLineMaterial width={0.1} color="red" depthTest={false} />
|
||||||
|
</T.Mesh>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
@ -58,6 +58,11 @@ export const AppSettingTypes = {
|
|||||||
label: "Show Indices",
|
label: "Show Indices",
|
||||||
value: false,
|
value: false,
|
||||||
},
|
},
|
||||||
|
showStemLines: {
|
||||||
|
type: "boolean",
|
||||||
|
label: "Show Stem Lines",
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
stressTest: {
|
stressTest: {
|
||||||
__title: "Stress Test",
|
__title: "Stress Test",
|
||||||
amount: {
|
amount: {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "noise"
|
name = "nodes-noise"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Max Richter <jim-x@web.de>"]
|
authors = ["Max Richter <jim-x@web.de>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
@ -23,6 +23,7 @@ serde = { version = "1.0", features = ["derive"] }
|
|||||||
serde-wasm-bindgen = "0.4"
|
serde-wasm-bindgen = "0.4"
|
||||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||||
web-sys = { version = "0.3.69", features = ["console"] }
|
web-sys = { version = "0.3.69", features = ["console"] }
|
||||||
|
noise = "0.9.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
wasm-bindgen-test = "0.3.34"
|
wasm-bindgen-test = "0.3.34"
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
"type": "float",
|
"type": "float",
|
||||||
"min": 0.1,
|
"min": 0.1,
|
||||||
"max": 100
|
"max": 100
|
||||||
|
},
|
||||||
|
"seed": {
|
||||||
|
"type": "seed"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,46 @@
|
|||||||
use macros::include_definition_file;
|
use macros::include_definition_file;
|
||||||
use utils::{concat_args, get_args, log};
|
use noise::{core::open_simplex::open_simplex_2d, permutationtable::PermutationTable, Vector2};
|
||||||
|
use utils::{
|
||||||
|
concat_args, decode_float, encode_float, evaluate_float, get_args, log, set_panic_hook,
|
||||||
|
};
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
include_definition_file!("src/input.json");
|
include_definition_file!("src/input.json");
|
||||||
|
|
||||||
#[rustfmt::skip]
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn execute(input: &[i32]) -> Vec<i32> {
|
pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||||
|
set_panic_hook();
|
||||||
|
|
||||||
let args = get_args(input);
|
let args = get_args(input);
|
||||||
let plants = get_args(args[0]);
|
let plants = get_args(args[0]);
|
||||||
log!("noise plants: {:?}", plants);
|
let scale = evaluate_float(args[1]);
|
||||||
concat_args(vec![plants[0].to_vec()])
|
let strength = evaluate_float(args[2]);
|
||||||
|
let seed = args[3][0];
|
||||||
|
|
||||||
|
let hasher = PermutationTable::new(seed as u32);
|
||||||
|
log!("scale: {}, strength: {}, seed: {}", scale, strength, seed);
|
||||||
|
|
||||||
|
let output: Vec<Vec<i32>> = plants
|
||||||
|
.iter()
|
||||||
|
.map(|p| {
|
||||||
|
let mut plant = p.to_vec();
|
||||||
|
|
||||||
|
log!("plant: {:?}", plant);
|
||||||
|
|
||||||
|
let points = (plant.len() - 5) / 4;
|
||||||
|
for i in 0..points {
|
||||||
|
let a = i as f64 / (points - 1) as f64;
|
||||||
|
let px = Vector2::new(0.0, a * scale as f64);
|
||||||
|
let pz = Vector2::new(a * scale as f64, 0.0);
|
||||||
|
let nx = open_simplex_2d(px, &hasher) as f32 * strength * 0.1;
|
||||||
|
let nz = open_simplex_2d(pz, &hasher) as f32 * strength * 0.1;
|
||||||
|
plant[3 + i * 4] = encode_float(decode_float(plant[3 + i * 4]) + nx);
|
||||||
|
plant[5 + i * 4] = encode_float(decode_float(plant[5 + i * 4]) + nz);
|
||||||
|
}
|
||||||
|
|
||||||
|
plant
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
concat_args(output.iter().map(|v| v.as_slice()).collect())
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,10 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
|||||||
|
|
||||||
if arg_type == 0 {
|
if arg_type == 0 {
|
||||||
// this is stem
|
// this is stem
|
||||||
let stem = &arg[2..arg.len() - 2];
|
let stem = &arg[3..arg.len() - 2];
|
||||||
output.push(arg.to_vec());
|
output.push(arg.to_vec());
|
||||||
|
log!("stem: {:?}", stem);
|
||||||
let geometry = extrude_path(stem, resolution);
|
let geometry = extrude_path(stem, resolution);
|
||||||
log!("geometry: {:?}", geometry);
|
|
||||||
output.push(geometry);
|
output.push(geometry);
|
||||||
} else if arg_type == 1 {
|
} else if arg_type == 1 {
|
||||||
// this is geometry
|
// this is geometry
|
||||||
|
Loading…
Reference in New Issue
Block a user