feat: improve get_args functions
This commit is contained in:
@ -1,11 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { T } from "@threlte/core";
|
||||
import { Text } from "@threlte/extras";
|
||||
import type { BufferGeometry } from "three";
|
||||
import { MeshLineGeometry, MeshLineMaterial, Text } from "@threlte/extras";
|
||||
import type { BufferGeometry, Vector3 } from "three";
|
||||
import { OrbitControls } from "@threlte/extras";
|
||||
import { AppSettings } from "../settings/app-settings";
|
||||
|
||||
export let geometry: BufferGeometry[];
|
||||
export let geometries: BufferGeometry[];
|
||||
export let lines: Vector3[][];
|
||||
$: console.log({ geometries, lines });
|
||||
|
||||
function getPosition(geo: BufferGeometry, i: number) {
|
||||
const pos = [
|
||||
@ -21,6 +23,16 @@
|
||||
<T.GridHelper args={[20, 20]} />
|
||||
{/if}
|
||||
|
||||
{#if lines}
|
||||
{#each lines as line}
|
||||
<T.Mesh>
|
||||
<MeshLineGeometry points={line} />
|
||||
|
||||
<MeshLineMaterial width={0.1} depthTest={false} />
|
||||
</T.Mesh>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
<T.PerspectiveCamera position={[-10, 10, 10]} makeDefault fov={50}>
|
||||
<OrbitControls />
|
||||
</T.PerspectiveCamera>
|
||||
@ -28,7 +40,7 @@
|
||||
<T.DirectionalLight position={[0, 10, 10]} />
|
||||
<T.AmbientLight intensity={0.5} />
|
||||
|
||||
{#each geometry as geo}
|
||||
{#each geometries as geo}
|
||||
{#if $AppSettings.showIndices}
|
||||
{#each geo.attributes.position.array as _, i}
|
||||
{#if i % 3 === 0}
|
||||
|
@ -1,11 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { Canvas } from "@threlte/core";
|
||||
import Scene from "./Scene.svelte";
|
||||
import { BufferGeometry, Float32BufferAttribute } from "three";
|
||||
import { BufferGeometry, Float32BufferAttribute, Vector3 } from "three";
|
||||
import { decodeFloat } from "@nodes/utils";
|
||||
|
||||
export let result: Int32Array;
|
||||
|
||||
let geometries: BufferGeometry[] = [];
|
||||
let lines: Vector3[][] = [];
|
||||
|
||||
function createGeometryFromEncodedData(
|
||||
encodedData: Int32Array,
|
||||
@ -90,9 +92,34 @@
|
||||
return res;
|
||||
}
|
||||
|
||||
globalThis.parse_args = parse_args;
|
||||
|
||||
function createLineGeometryFromEncodedData(encodedData: Int32Array) {
|
||||
const positions: Vector3[] = [];
|
||||
|
||||
const amount = (encodedData.length - 1) / 4;
|
||||
|
||||
for (let i = 0; i < amount; i++) {
|
||||
const x = decodeFloat(encodedData[1 + i * 4 + 0]);
|
||||
const y = decodeFloat(encodedData[1 + i * 4 + 1]);
|
||||
const z = decodeFloat(encodedData[1 + i * 4 + 2]);
|
||||
positions.push(new Vector3(x, y, z));
|
||||
}
|
||||
|
||||
return positions;
|
||||
}
|
||||
|
||||
$: if (result) {
|
||||
const inputs = parse_args(result);
|
||||
|
||||
lines = inputs
|
||||
.map((input) => {
|
||||
if (input[0] === 0) {
|
||||
return createLineGeometryFromEncodedData(input);
|
||||
}
|
||||
})
|
||||
.filter(Boolean) as Vector3[][];
|
||||
|
||||
geometries = inputs
|
||||
.map((input) => {
|
||||
if (input[0] === 1) {
|
||||
@ -101,9 +128,11 @@
|
||||
}
|
||||
})
|
||||
.filter(Boolean) as BufferGeometry[];
|
||||
|
||||
console.log(lines);
|
||||
}
|
||||
</script>
|
||||
|
||||
<Canvas>
|
||||
<Scene geometry={geometries} />
|
||||
<Scene {geometries} {lines} />
|
||||
</Canvas>
|
||||
|
Reference in New Issue
Block a user