feat: add benchmark settings panel
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 1m59s
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 1m59s
This commit is contained in:
@ -43,7 +43,6 @@
|
||||
? filterInputs(node.tmp.type.inputs)
|
||||
: undefined;
|
||||
$: store = node ? createStore(node.props, nodeDefinition) : undefined;
|
||||
$: console.log(nodeDefinition, store);
|
||||
|
||||
let lastPropsHash = "";
|
||||
function updateNode() {
|
||||
|
88
app/src/lib/settings/panels/BenchmarkPanel.svelte
Normal file
88
app/src/lib/settings/panels/BenchmarkPanel.svelte
Normal file
@ -0,0 +1,88 @@
|
||||
<script lang="ts">
|
||||
import localStore from "$lib/helpers/localStore";
|
||||
import { Integer } from "@nodes/ui";
|
||||
import { writable } from "svelte/store";
|
||||
|
||||
export let run: () => Promise<any>;
|
||||
|
||||
let isRunning = false;
|
||||
let amount = localStore<number>("nodes.benchmark.samples", 500);
|
||||
let samples = 0;
|
||||
let warmUp = writable(0);
|
||||
let warmUpAmount = 10;
|
||||
let state = "";
|
||||
let result = "";
|
||||
|
||||
const copyContent = async (text: string) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
} catch (err) {
|
||||
console.error("Failed to copy: ", err);
|
||||
}
|
||||
};
|
||||
|
||||
async function benchmark() {
|
||||
if (isRunning) return;
|
||||
isRunning = true;
|
||||
|
||||
samples = 0;
|
||||
$warmUp = 0;
|
||||
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
|
||||
// warm up
|
||||
for (let i = 0; i < warmUpAmount; i++) {
|
||||
await run();
|
||||
$warmUp = i + 1;
|
||||
}
|
||||
|
||||
let results = [];
|
||||
|
||||
// perform run
|
||||
for (let i = 0; i < $amount; i++) {
|
||||
const a = performance.now();
|
||||
await run();
|
||||
samples = i;
|
||||
const b = performance.now();
|
||||
results.push(b - a);
|
||||
console.log(b - a);
|
||||
}
|
||||
result = results.join(" ");
|
||||
}
|
||||
</script>
|
||||
|
||||
{state}
|
||||
|
||||
<div class="wrapper" class:running={isRunning}>
|
||||
{#if isRunning}
|
||||
<p>WarmUp ({$warmUp}/{warmUpAmount})</p>
|
||||
<progress value={$warmUp} max={warmUpAmount}
|
||||
>{Math.floor(($warmUp / warmUpAmount) * 100)}%</progress
|
||||
>
|
||||
<p>Progress ({samples}/{$amount})</p>
|
||||
<progress value={samples} max={$amount}
|
||||
>{Math.floor((samples / $amount) * 100)}%</progress
|
||||
>
|
||||
|
||||
{#if result}
|
||||
<textarea readonly>{result}</textarea>
|
||||
<div>
|
||||
<button on:click={() => copyContent(result)}>Copy</button>
|
||||
<button on:click={() => (isRunning = false)}>reset</button>
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<label for="bench-samples">Samples</label>
|
||||
<Integer id="bench-sample" bind:value={$amount} max={1000} />
|
||||
<button on:click={benchmark} disabled={isRunning}> start </button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.wrapper {
|
||||
padding: 1em;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1em;
|
||||
}
|
||||
</style>
|
53
app/src/lib/settings/panels/ExportSettings.svelte
Normal file
53
app/src/lib/settings/panels/ExportSettings.svelte
Normal file
@ -0,0 +1,53 @@
|
||||
<script lang="ts">
|
||||
import type { Scene } from "three";
|
||||
import { OBJExporter } from "three/addons/exporters/OBJExporter.js";
|
||||
import { GLTFExporter } from "three/addons/exporters/GLTFExporter.js";
|
||||
import FileSaver from "file-saver";
|
||||
|
||||
// Download
|
||||
const download = (
|
||||
data: string,
|
||||
name: string,
|
||||
mimetype: string,
|
||||
extension: string,
|
||||
) => {
|
||||
if (typeof data !== "string") data = JSON.stringify(data);
|
||||
const blob = new Blob([data], { type: mimetype + ";charset=utf-8" });
|
||||
FileSaver.saveAs(blob, name + "." + extension);
|
||||
};
|
||||
|
||||
// export const json = (data, name = 'default') => {
|
||||
// download(JSON.stringify(data), name, 'application/json', 'json');
|
||||
// };
|
||||
//
|
||||
// export const obj = (data, name = 'default') => {
|
||||
// };
|
||||
|
||||
export let scene: Scene;
|
||||
|
||||
function exportGltf() {
|
||||
const exporter = new GLTFExporter();
|
||||
exporter.parse(
|
||||
scene,
|
||||
(gltf) => {
|
||||
// download .gltf file
|
||||
download(gltf, "plant", "text/plain", "gltf");
|
||||
},
|
||||
(err) => {
|
||||
console.log(err);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function exportObj() {
|
||||
const exporter = new OBJExporter();
|
||||
const result = exporter.parse(scene);
|
||||
// download .obj file
|
||||
download(result, "plant", "text/plain", "obj");
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="p-2">
|
||||
<button on:click={exportObj}> export obj </button>
|
||||
<button on:click={exportGltf}> export gltf </button>
|
||||
</div>
|
@ -4,10 +4,11 @@
|
||||
|
||||
export let keymap: ReturnType<typeof createKeyMap>;
|
||||
const keys = keymap?.keys;
|
||||
export let title = "Keymap";
|
||||
</script>
|
||||
|
||||
<div class="wrapper">
|
||||
<h3>Editor</h3>
|
||||
<h3>{title}</h3>
|
||||
|
||||
<section>
|
||||
{#each $keys as key}
|
||||
|
Reference in New Issue
Block a user