feat: add vec3 to stem

This commit is contained in:
2024-04-18 13:16:33 +02:00
parent 815152d23c
commit 32426ac045
31 changed files with 563 additions and 327 deletions

View File

@@ -0,0 +1,6 @@
/target
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log

View File

@@ -0,0 +1,28 @@
[package]
name = "triangle"
version = "0.1.0"
authors = ["Max Richter <jim-x@web.de>"]
edition = "2018"
[lib]
crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook"]
[dependencies]
wasm-bindgen = "0.2.84"
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
utils = { version = "0.1.0", path = "../../../../packages/utils" }
macros = { version = "0.1.0", path = "../../../../packages/macros" }
serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = "0.4"
console_error_panic_hook = { version = "0.1.7", optional = true }
web-sys = { version = "0.3.69", features = ["console"] }
[dev-dependencies]
wasm-bindgen-test = "0.3.34"

View File

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

View File

@@ -0,0 +1,4 @@
{
"outputs": [],
"inputs": {}
}

View File

@@ -0,0 +1,12 @@
use macros::include_definition_file;
use utils::{decode_float, encode_float, wrap_arg};
use wasm_bindgen::prelude::*;
use web_sys::console;
include_definition_file!("src/input.json");
#[rustfmt::skip]
#[wasm_bindgen]
pub fn execute(input: &[i32]) -> Vec<i32> {
vec![]
}

View File

@@ -0,0 +1,13 @@
//! Test suite for the Web and headless browsers.
#![cfg(target_arch = "wasm32")]
extern crate wasm_bindgen_test;
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test]
fn pass() {
assert_eq!(1 + 1, 2);
}

View File

@@ -1,5 +1,5 @@
use macros::include_definition_file;
use utils::{evaluate_args, get_args};
use utils::{evaluate_arg, get_args};
use wasm_bindgen::prelude::*;
use web_sys::console;
@@ -11,9 +11,8 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
let args = get_args(input);
let value_encoded = evaluate_args(args[0]);
// let value = decode_float(value_encoded[0], value_encoded[1]);
let length = (args[1][0]) as usize;
let value_encoded = evaluate_arg(args[0]);
let length = evaluate_arg(args[1]) as usize;
console::log_1(&format!("WASM(array): input: {:?} -> {:?}", args, value_encoded).into());
@@ -22,7 +21,7 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
res.push(0);
res.push(length as i32 + 4);
for _ in 0..length {
res.push(value_encoded[0]);
res.push(value_encoded);
}
res.push(1);
res.push(1);

View File

@@ -1,7 +1,6 @@
use crate::geometry::calculate_normals;
use macros::include_definition_file;
use utils::{
decode_float, encode_float, evaluate_args, geometry, get_args, set_panic_hook, wrap_arg,
encode_float, evaluate_float, geometry::calculate_normals, get_args, set_panic_hook, wrap_arg,
};
use wasm_bindgen::prelude::*;
use web_sys::console;
@@ -18,12 +17,10 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
console::log_1(&format!("WASM(cube): input: {:?} -> {:?}", input, args ).into());
let arg1 = evaluate_args(args[0]);
let size = evaluate_float(args[0]);
let decoded = decode_float(arg1[0]);
let p = encode_float(decoded);
let n = encode_float(-decoded);
let p = encode_float(size);
let n = encode_float(-size);
// [[1,3, x, y, z, x, y,z,x,y,z]];

View File

@@ -25,6 +25,7 @@ macros = { version = "0.1.0", path = "../../../../packages/macros" }
serde-wasm-bindgen = "0.4"
console_error_panic_hook = { version = "0.1.7", optional = true }
web-sys = { version = "0.3.69", features = ["console"] }
glam = "0.27.0"
[dev-dependencies]
wasm-bindgen-test = "0.3.34"

View File

@@ -1,31 +1,36 @@
use glam::{Mat4, Vec3};
use macros::include_definition_file;
use utils::{concat_args, geometry::extrude_path, get_args};
use utils::{
concat_args,
geometry::{extrude_path, transform_geometry},
get_args,
};
use wasm_bindgen::prelude::*;
include_definition_file!("src/inputs.json");
#[rustfmt::skip]
#[wasm_bindgen]
pub fn execute(input: Vec<i32>) -> Vec<i32> {
utils::set_panic_hook();
let args = get_args(input.as_slice());
let mut output:Vec<Vec<i32>> = Vec::new();
let mut output: Vec<Vec<i32>> = Vec::new();
for arg in args {
if arg.len() < 3 { continue; }
if arg.len() < 3 {
continue;
}
if arg[2] == 0 {
let _arg = &arg[3..];
let geometry = extrude_path(_arg, 16);
let mut geometry = extrude_path(_arg, 4);
let matrix = Mat4::from_translation(Vec3::new(0.0, 0.0, 0.0));
geometry = transform_geometry(geometry, matrix);
output.push(geometry);
}else if arg[2] == 1 {
} else if arg[2] == 1 {
output.push(arg.to_vec());
}
}
concat_args(output)
}

View File

@@ -3,6 +3,15 @@
"plant"
],
"inputs": {
"origin": {
"type": "vec3",
"value": [
0,
0,
0
],
"external": true
},
"length": {
"type": "float",
"value": 2

View File

@@ -1,5 +1,5 @@
use macros::include_definition_file;
use utils::{decode_float, evaluate_args, get_args, set_panic_hook, wrap_arg};
use utils::{evaluate_float, evaluate_vec3, get_args, log, set_panic_hook, wrap_arg};
use wasm_bindgen::prelude::*;
include_definition_file!("src/input.json");
@@ -10,9 +10,13 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
let args = get_args(input);
let length = decode_float(evaluate_args(args[0])[0]);
let thickness = decode_float(evaluate_args(args[1])[0]);
let resolution = 512; //evaluate_args(args[2]);
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 mut path: Vec<i32> = vec![0; resolution * 4 + 1];
path.resize(resolution * 4 + 1, 0);
@@ -32,9 +36,9 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
for i in 0..resolution {
let a = i as f32 / resolution as f32;
path_p[i * 4] = (a * 8.0).sin() * 0.2;
path_p[i * 4 + 1] = a * length;
path_p[i * 4 + 2] = 0.0;
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;
path_p[i * 4 + 3] = thickness * (1.0 - a);
}

View File

@@ -1,5 +1,5 @@
[package]
name = "sum"
name = "max-plantarium-sum"
version = "0.1.0"
authors = ["Max Richter <jim-x@web.de>"]
edition = "2018"

View File

@@ -1,5 +1,5 @@
[package]
name = "triangle"
name = "max-plantarium-triangle"
version = "0.1.0"
authors = ["Max Richter <jim-x@web.de>"]
edition = "2018"

6
nodes/max/plantarium/vec3/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
/target
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log

View File

@@ -0,0 +1,28 @@
[package]
name = "max-plantarium-vec3"
version = "0.1.0"
authors = ["Max Richter <jim-x@web.de>"]
edition = "2018"
[lib]
crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook"]
[dependencies]
wasm-bindgen = "0.2.84"
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
utils = { version = "0.1.0", path = "../../../../packages/utils" }
macros = { version = "0.1.0", path = "../../../../packages/macros" }
serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = "0.4"
console_error_panic_hook = { version = "0.1.7", optional = true }
web-sys = { version = "0.3.69", features = ["console"] }
[dev-dependencies]
wasm-bindgen-test = "0.3.34"

View File

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

View File

@@ -0,0 +1,16 @@
{
"outputs": [
"vec3"
],
"inputs": {
"0": {
"type": "float"
},
"1": {
"type": "float"
},
"2": {
"type": "float"
}
}
}

View File

@@ -0,0 +1,20 @@
use macros::include_definition_file;
use utils::log;
use wasm_bindgen::prelude::*;
include_definition_file!("src/input.json");
#[wasm_bindgen]
pub fn execute(args: &[i32]) -> Vec<i32> {
let mut result = Vec::with_capacity(args.len() + 2);
result.push(0); // encoding the [ bracket
result.push(args[1]);
result.extend_from_slice(&args[2..]);
result.push(1);
result.push(1); // closing bracket
log!("WASM(vec3): res {:?}", result);
result
}

View File

@@ -0,0 +1,13 @@
//! Test suite for the Web and headless browsers.
#![cfg(target_arch = "wasm32")]
extern crate wasm_bindgen_test;
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test]
fn pass() {
assert_eq!(1 + 1, 2);
}