feat: add box node

This commit is contained in:
2024-04-17 15:34:28 +02:00
parent ddd0e6a0cf
commit 7579c6c00b
24 changed files with 364 additions and 99 deletions

6
nodes/max/plantarium/box/.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 = "box"
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,11 @@
{
"outputs": [
"model"
],
"inputs": {
"size": {
"type": "float",
"value": 2
}
}
}

View File

@@ -0,0 +1,83 @@
use macros::include_definition_file;
use utils::{decode_float, encode_float, evaluate_args, get_args, set_panic_hook, 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> {
set_panic_hook();
let args = get_args(input);
console::log_1(&format!("WASM(cube): input: {:?} -> {:?}", input, args ).into());
let arg1 = evaluate_args(args[0]);
let decoded = decode_float(arg1[0]);
let p = encode_float(decoded);
let n = encode_float(-decoded);
// [[1,3, x, y, z, x, y,z,x,y,z]];
wrap_arg(&[
1, // 1: geometry
8, // 8 vertices
12, // 12 faces
/*
Indeces:
5----6
| 4--+-7
0-|--1 |
3----2
*/
// this are the indeces for the face
0, 1, 2,
0, 2, 3,
0, 3, 4,
4, 5, 0,
6, 1, 0,
5, 6, 0,
7, 2, 1,
6, 7, 1,
2, 7, 3,
3, 7, 4,
7, 6, 4,
4, 6, 5,
// this is the normal for every single face 1065353216 == 1.0f encoded is i32
0, 1065353216, 0,
0, 1065353216, 0,
0, 1065353216, 0,
0, 1065353216, 0,
0, 1065353216, 0,
0, 1065353216, 0,
0, 1065353216, 0,
0, 1065353216, 0,
0, 1065353216, 0,
0, 1065353216, 0,
0, 1065353216, 0,
0, 1065353216, 0,
// Bottom plate
p, n, n,
p, n, p,
n, n, p,
n, n, n,
// Top Plate
n, p, n,
p, p, n,
p, p, p,
n, p, p,
])
}

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);
}