fix: some small issues
Some checks failed
Deploy to GitHub Pages / build_site (push) Has been cancelled

This commit is contained in:
max_richter 2024-05-06 01:38:59 +02:00
parent 10a12ad41c
commit 2351c65179
5 changed files with 69 additions and 57 deletions

View File

@ -1,14 +1,43 @@
<script lang="ts"> <script lang="ts">
import { Canvas } from "@threlte/core"; import { Canvas } from "@threlte/core";
import Scene from "./Scene.svelte"; import Scene from "./Scene.svelte";
import { Group, Vector3 } from "three"; import { Vector3 } from "three";
import { updateGeometries } from "./updateGeometries";
import { decodeFloat, splitNestedArray } from "@nodes/utils"; import { decodeFloat, splitNestedArray } from "@nodes/utils";
import type { PerformanceStore } from "@nodes/utils"; import type { PerformanceStore } from "@nodes/utils";
import { AppSettings } from "$lib/settings/app-settings"; import { AppSettings } from "$lib/settings/app-settings";
import SmallPerformanceViewer from "$lib/performance/SmallPerformanceViewer.svelte"; import SmallPerformanceViewer from "$lib/performance/SmallPerformanceViewer.svelte";
import { MeshMatcapMaterial, TextureLoader, type Group } from "three";
import {
createGeometryPool,
createInstancedGeometryPool,
} from "./geometryPool";
const loader = new TextureLoader();
const matcap = loader.load("/matcap_green.jpg");
matcap.colorSpace = "srgb";
const material = new MeshMatcapMaterial({
color: 0xffffff,
matcap,
});
let geometryPool: ReturnType<typeof createGeometryPool>;
let instancePool: ReturnType<typeof createInstancedGeometryPool>;
export function updateGeometries(inputs: Int32Array[], group: Group) {
geometryPool = geometryPool || createGeometryPool(group, material);
instancePool = instancePool || createInstancedGeometryPool(group, material);
let meshes = geometryPool.update(inputs.filter((i) => i[0] === 1));
let faces = instancePool.update(inputs.filter((i) => i[0] === 2));
return {
totalFaces: meshes.totalFaces + faces.totalFaces,
totalVertices: meshes.totalVertices + faces.totalVertices,
};
}
export let centerCamera: boolean = true; export let centerCamera: boolean = true;
export let perf: PerformanceStore; export let perf: PerformanceStore;
export let scene: Group; export let scene: Group;

View File

@ -24,6 +24,9 @@ export function createGeometryPool(parentScene: Group, material: Material) {
let meshes: Mesh[] = []; let meshes: Mesh[] = [];
let totalVertices = 0;
let totalFaces = 0;
function updateSingleGeometry(data: Int32Array, existingMesh: Mesh | null = null) { function updateSingleGeometry(data: Int32Array, existingMesh: Mesh | null = null) {
let hash = fastArrayHash(data); let hash = fastArrayHash(data);
@ -34,7 +37,9 @@ export function createGeometryPool(parentScene: Group, material: Material) {
// const geometryType = encodedData[index++]; // const geometryType = encodedData[index++];
let index = 1; let index = 1;
const vertexCount = data[index++]; const vertexCount = data[index++];
totalVertices += vertexCount;
const faceCount = data[index++]; const faceCount = data[index++];
totalFaces += faceCount;
if (geometry.userData?.hash === hash) { if (geometry.userData?.hash === hash) {
return; return;
@ -111,6 +116,8 @@ export function createGeometryPool(parentScene: Group, material: Material) {
update( update(
newData: Int32Array[], newData: Int32Array[],
) { ) {
totalVertices = 0;
totalFaces = 0;
for (let i = 0; i < Math.max(newData.length, meshes.length); i++) { for (let i = 0; i < Math.max(newData.length, meshes.length); i++) {
const existingMesh = meshes[i]; const existingMesh = meshes[i];
let input = newData[i]; let input = newData[i];
@ -121,6 +128,7 @@ export function createGeometryPool(parentScene: Group, material: Material) {
scene.remove(existingMesh); scene.remove(existingMesh);
} }
} }
return { totalVertices, totalFaces };
} }
} }
} }
@ -130,6 +138,8 @@ export function createInstancedGeometryPool(parentScene: Group, material: Materi
parentScene.add(scene); parentScene.add(scene);
const instances: InstancedMesh[] = []; const instances: InstancedMesh[] = [];
let totalVertices = 0;
let totalFaces = 0;
function updateSingleInstance(data: Int32Array, existingInstance: InstancedMesh | null = null) { function updateSingleInstance(data: Int32Array, existingInstance: InstancedMesh | null = null) {
@ -144,6 +154,8 @@ export function createInstancedGeometryPool(parentScene: Group, material: Materi
const faceCount = data[index++]; const faceCount = data[index++];
const instanceCount = data[index++]; const instanceCount = data[index++];
const stemDepth = data[index++]; const stemDepth = data[index++];
totalVertices += vertexCount * instanceCount;
totalFaces += faceCount * instanceCount;
// Indices // Indices
const indicesEnd = index + faceCount * 3; const indicesEnd = index + faceCount * 3;
@ -237,6 +249,8 @@ export function createInstancedGeometryPool(parentScene: Group, material: Materi
update( update(
newData: Int32Array[], newData: Int32Array[],
) { ) {
totalVertices = 0;
totalFaces = 0;
for (let i = 0; i < Math.max(newData.length, instances.length); i++) { for (let i = 0; i < Math.max(newData.length, instances.length); i++) {
const existingMesh = instances[i]; const existingMesh = instances[i];
let input = newData[i]; let input = newData[i];
@ -247,6 +261,7 @@ export function createInstancedGeometryPool(parentScene: Group, material: Materi
scene.remove(existingMesh); scene.remove(existingMesh);
} }
} }
return { totalVertices, totalFaces };
} }
} }
} }

View File

@ -27,6 +27,13 @@
"max":1, "max":1,
"value":1, "value":1,
"hidden": true "hidden": true
},
"depth": {
"type":"integer",
"min": 1,
"max":10,
"value": 1,
"hidden": true
} }
} }
} }

View File

@ -11,59 +11,6 @@ use wasm_bindgen::prelude::*;
include_definition_file!("src/input.json"); include_definition_file!("src/input.json");
#[rustfmt::skip]
fn create_geo() -> Vec<i32> {
let size = 5.0;
let p = encode_float(size);
let n = encode_float(-size);
// [[1,3, x, y, z, x, y,z,x,y,z]];
wrap_arg(calculate_normals(&mut [
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, // 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, // this is the normal for every single vert 1065353216 == 1.0f encoded is i32
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
]))
}
#[wasm_bindgen] #[wasm_bindgen]
pub fn execute(input: &[i32]) -> Vec<i32> { pub fn execute(input: &[i32]) -> Vec<i32> {
set_panic_hook(); set_panic_hook();
@ -77,7 +24,21 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
let mut transforms: Vec<Mat4> = Vec::new(); let mut transforms: Vec<Mat4> = Vec::new();
let mut max_depth = 0;
for path_data in inputs.iter() { for path_data in inputs.iter() {
if path_data[2] != 0 {
continue;
}
max_depth = max_depth.max(path_data[3]);
}
let depth = evaluate_int(args[5]);
for path_data in inputs.iter() {
if path_data[3] < (max_depth - depth + 1) {
continue;
}
let amount = evaluate_int(args[2]); let amount = evaluate_int(args[2]);
let lowest_instance = evaluate_float(args[3]); let lowest_instance = evaluate_float(args[3]);
@ -93,7 +54,7 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
let direction = path.get_direction_at(alpha); let direction = path.get_direction_at(alpha);
let transform = Mat4::from_scale_rotation_translation( let transform = Mat4::from_scale_rotation_translation(
Vec3::new(0.1, 0.1, 0.1), Vec3::new(point[3], point[3], point[3]),
Quat::from_xyzw(direction[0], direction[1], direction[2], 1.0).normalize(), Quat::from_xyzw(direction[0], direction[1], direction[2], 1.0).normalize(),
Vec3::from_slice(&point), Vec3::from_slice(&point),
); );

View File

@ -10,7 +10,7 @@ const nodeRegistry = new RemoteNodeRegistry("");
nodeRegistry.cache = indexDbCache; nodeRegistry.cache = indexDbCache;
const executor = new MemoryRuntimeExecutor(nodeRegistry, cache); const executor = new MemoryRuntimeExecutor(nodeRegistry, cache);
const performanceStore = createPerformanceStore("worker"); const performanceStore = createPerformanceStore();
executor.perf = performanceStore; executor.perf = performanceStore;
export async function executeGraph(graph: Graph, settings: Record<string, unknown>): Promise<Int32Array> { export async function executeGraph(graph: Graph, settings: Record<string, unknown>): Promise<Int32Array> {