feat: implement settings

This commit is contained in:
2024-04-18 18:39:24 +02:00
parent e7f43020dc
commit 36faeae886
39 changed files with 1398 additions and 196 deletions

View File

@@ -1,6 +1,6 @@
{
"scripts": {
"build": "wasm-pack build --release --out-name index --no-default-features",
"dev": "cargo watch -s 'pnpm build'"
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
}
}

View File

@@ -1,6 +1,6 @@
{
"scripts": {
"build": "wasm-pack build --release --out-name index --no-default-features",
"dev": "cargo watch -s 'pnpm build'"
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
}
}

View File

@@ -1,6 +1,6 @@
{
"scripts": {
"build": "wasm-pack build --release --out-name index --no-default-features",
"dev": "cargo watch -s 'pnpm build'"
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
}
}

View File

@@ -1,6 +1,6 @@
{
"scripts": {
"build": "wasm-pack build --release --out-name index --no-default-features",
"dev": "cargo watch -s 'pnpm build'"
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
}
}

View File

@@ -6,7 +6,7 @@
"op_type": {
"label": "type",
"type": "select",
"labels": [
"options": [
"add",
"subtract",
"multiply",
@@ -22,11 +22,6 @@
"b": {
"type": "float",
"value": 2
},
"clip": {
"type": "boolean",
"value": 0,
"setting": "math.clipping"
}
}
}

View File

@@ -1,6 +1,6 @@
{
"scripts": {
"build": "wasm-pack build --release --out-name index --no-default-features",
"dev": "cargo watch -s 'pnpm build'"
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
}
}

View File

@@ -7,6 +7,13 @@
"model"
],
"external": true
},
"resolution_circle": {
"type": "integer",
"value": 32,
"min": 3,
"max": 64,
"setting": "resolution.circle"
}
}
}

View File

@@ -1,9 +1,9 @@
use glam::{Mat4, Vec3};
use macros::include_definition_file;
use utils::{
concat_args,
concat_args, evaluate_arg,
geometry::{extrude_path, transform_geometry},
get_args,
get_args, log,
};
use wasm_bindgen::prelude::*;
@@ -15,15 +15,20 @@ pub fn execute(input: Vec<i32>) -> Vec<i32> {
let args = get_args(input.as_slice());
let inputs = get_args(args[0]);
let resolution = evaluate_arg(args[1]) as usize;
log!("inputs: {}, resolution: {}", inputs.len(), resolution);
let mut output: Vec<Vec<i32>> = Vec::new();
for arg in args {
for arg in inputs {
if arg.len() < 3 {
continue;
}
if arg[2] == 0 {
let _arg = &arg[3..];
let mut geometry = extrude_path(_arg, 4);
let mut geometry = extrude_path(_arg, resolution);
let matrix = Mat4::from_translation(Vec3::new(0.0, 0.0, 0.0));
geometry = transform_geometry(geometry, matrix);
output.push(geometry);

View File

@@ -1,6 +1,6 @@
{
"scripts": {
"build": "wasm-pack build --release --out-name index --no-default-features",
"dev": "cargo watch -s 'pnpm build'"
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
}
}

View File

@@ -1,6 +1,6 @@
{
"scripts": {
"build": "wasm-pack build --release --out-name index --no-default-features",
"dev": "cargo watch -s 'pnpm build'"
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
}
}

View File

@@ -21,10 +21,12 @@
"element": "slider",
"value": 2
},
"resolution": {
"resolution_curve": {
"type": "integer",
"value": 32,
"setting": "resolution.stem"
"min": 3,
"max": 64,
"setting": "resolution.curve"
}
}
}

View File

@@ -1,5 +1,5 @@
use macros::include_definition_file;
use utils::{evaluate_float, evaluate_vec3, get_args, log, set_panic_hook, wrap_arg};
use utils::{evaluate_arg, evaluate_float, evaluate_vec3, get_args, set_panic_hook, wrap_arg};
use wasm_bindgen::prelude::*;
include_definition_file!("src/input.json");
@@ -10,18 +10,13 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
let args = get_args(input);
log!("Args: {:?}", args);
let origin = evaluate_vec3(args[0]);
log!("Origin: {:?}", origin);
let length = evaluate_float(args[1]);
let thickness = evaluate_float(args[2]);
let resolution = 16;
let res_curve = evaluate_arg(args[3]) as usize;
let mut path: Vec<i32> = vec![0; resolution * 4 + 1];
path.resize(resolution * 4 + 1, 0);
path[0] = 0;
let mut path: Vec<i32> = vec![0; res_curve * 4 + 1];
path.resize(res_curve * 4 + 1, 0);
let slice = &mut path[1..];
@@ -34,8 +29,8 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
std::slice::from_raw_parts_mut(slice.as_ptr() as *mut f32, slice.len())
};
for i in 0..resolution {
let a = i as f32 / resolution as f32;
for i in 0..res_curve {
let a = i as f32 / (res_curve - 1) as f32;
path_p[i * 4] = origin[0] + (a * 8.0).sin() * 0.2;
path_p[i * 4 + 1] = origin[1] + a * length;
path_p[i * 4 + 2] = origin[2] + 0.0;

View File

@@ -1,6 +1,6 @@
{
"scripts": {
"build": "wasm-pack build --release --out-name index --no-default-features",
"dev": "cargo watch -s 'pnpm build'"
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
}
}