feat: turned perf up to 11 goodd daaayumn, 1.9m faces in 250ms
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m0s

This commit is contained in:
max_richter 2024-04-25 04:08:54 +02:00
parent f1e5faf040
commit 82f83629c7

View File

@ -1,7 +1,12 @@
<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 { BufferGeometry, Float32BufferAttribute, Vector3 } from "three"; import {
BufferAttribute,
BufferGeometry,
Float32BufferAttribute,
Vector3,
} from "three";
import { decodeFloat } from "@nodes/utils"; import { decodeFloat } from "@nodes/utils";
import type { PerformanceStore } from "$lib/performance"; import type { PerformanceStore } from "$lib/performance";
import { AppSettings } from "$lib/settings/app-settings"; import { AppSettings } from "$lib/settings/app-settings";
@ -50,11 +55,42 @@
); );
index = index + vertexCount * 3; index = index + vertexCount * 3;
if (
geometry.userData?.faceCount !== faceCount ||
geometry.userData?.vertexCount !== vertexCount
) {
// Add data to geometry // Add data to geometry
geometry.setIndex([...indices]); geometry.setIndex([...indices]);
geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3)); }
let posAttribute = geometry.getAttribute(
"position",
) as BufferAttribute | null;
if (posAttribute && posAttribute.count === vertexCount) {
posAttribute.set(vertices, 0);
posAttribute.needsUpdate = true;
} else {
geometry.setAttribute(
"position",
new Float32BufferAttribute(vertices, 3),
);
}
const normalsAttribute = geometry.getAttribute(
"normal",
) as BufferAttribute | null;
if (normalsAttribute && normalsAttribute.count === vertexCount) {
normalsAttribute.set(normals, 0);
normalsAttribute.needsUpdate = true;
} else {
geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3)); geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
geometry.computeVertexNormals(); }
geometry.userData = {
vertexCount,
faceCount,
};
return geometry; return geometry;
} }
@ -152,6 +188,10 @@
b = performance.now(); b = performance.now();
perf?.addPoint("create-geometries", b - a); perf?.addPoint("create-geometries", b - a);
for (const geometry of geometries) {
geometry.needsUpdate = true;
}
perf?.addPoint("total-vertices", totalVertices); perf?.addPoint("total-vertices", totalVertices);
perf?.addPoint("total-faces", totalFaces); perf?.addPoint("total-faces", totalFaces);