fix: gravity node
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m35s

This commit is contained in:
2024-05-02 18:49:08 +02:00
parent dca4469f55
commit 26d3f6a2f1
31 changed files with 1557 additions and 536 deletions

View File

@@ -17,7 +17,7 @@
camera: Vector3Tuple;
target: Vector3Tuple;
}>("nodes.camera.transform", {
camera: [0, 0, 10],
camera: [10, 10, 10],
target: [0, 0, 0],
});

View File

@@ -11,20 +11,43 @@
import { AppSettings } from "../settings/app-settings";
import Camera from "./Camera.svelte";
const d = useThrelte();
const threlte = useThrelte();
export const invalidate = d.invalidate;
export const invalidate = function () {
if (scene) {
geometries = scene.children
.filter(
(child) => "geometry" in child && child.isObject3D && child.geometry,
)
.map((child) => {
return child.geometry;
});
}
export let geometries: BufferGeometry[];
if (geometries && scene && centerCamera) {
const aabb = new Box3().setFromObject(scene);
center = aabb
.getCenter(new Vector3())
.max(new Vector3(-4, -4, -4))
.min(new Vector3(4, 4, 4));
}
threlte.invalidate();
};
let geometries: BufferGeometry[] = [];
export let lines: Vector3[][];
export let scene;
let geos: Group;
$: scene = geos;
export let geoGroup: Group;
export let scene: Group;
export let centerCamera: boolean = true;
let center = new Vector3(0, 4, 0);
$: if ($AppSettings && scene) {
scene.children.forEach((child) => {
child.material.wireframe = $AppSettings.wireframe;
threlte.invalidate();
});
}
function getPosition(geo: BufferGeometry, i: number) {
return [
geo.attributes.position.array[i],
@@ -32,14 +55,6 @@
geo.attributes.position.array[i + 2],
] as Vector3Tuple;
}
$: if (geometries && geos && centerCamera) {
const aabb = new Box3().setFromObject(geos);
center = aabb
.getCenter(new Vector3())
.max(new Vector3(-4, -4, -4))
.min(new Vector3(4, 4, 4));
}
</script>
<Camera {center} {centerCamera} />
@@ -48,7 +63,7 @@
<T.GridHelper args={[20, 20]} />
{/if}
<T.Group bind:ref={geos}>
<T.Group>
{#each geometries as geo}
{#if $AppSettings.showIndices}
{#each geo.attributes.position.array as _, i}
@@ -66,7 +81,7 @@
{/if}
{/each}
<T.Group bind:ref={geoGroup}></T.Group>
<T.Group bind:ref={scene}></T.Group>
</T.Group>
{#if $AppSettings.showStemLines && lines}

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import { Canvas } from "@threlte/core";
import Scene from "./Scene.svelte";
import { BufferGeometry, Group, Vector3 } from "three";
import { Group, Vector3 } from "three";
import { updateGeometries } from "./updateGeometries";
import { decodeFloat, splitNestedArray } from "@nodes/utils";
@@ -12,9 +12,6 @@
export let perf: PerformanceStore;
export let scene: Group;
let geoGroup: Group;
let geometries: BufferGeometry[] = [];
let lines: Vector3[][] = [];
let invalidate: () => void;
@@ -53,7 +50,7 @@
perf?.addPoint("update-geometries");
const { totalVertices, totalFaces } = updateGeometries(inputs, geoGroup);
const { totalVertices, totalFaces } = updateGeometries(inputs, scene);
perf?.endPoint();
perf?.addPoint("total-vertices", totalVertices);
@@ -63,12 +60,5 @@
</script>
<Canvas>
<Scene
bind:scene
bind:geoGroup
bind:invalidate
{geometries}
{lines}
{centerCamera}
/>
<Scene bind:scene bind:invalidate {lines} {centerCamera} />
</Canvas>