feat: some stuff

This commit is contained in:
2024-04-17 16:39:56 +02:00
parent 7579c6c00b
commit 1da13523ea
9 changed files with 99 additions and 36 deletions

View File

@ -34,7 +34,7 @@
<T.PointsMaterial size={0.25} />
</T.Points>
<T.Mesh geometry={geo}>
<T.MeshBasicMaterial color="red" />
<T.MeshStandardMaterial color="hotpink" />
</T.Mesh>
{:else}
<T.Mesh>

View File

@ -1,12 +1,7 @@
<script lang="ts">
import { Canvas } from "@threlte/core";
import Scene from "./Scene.svelte";
import {
BufferAttribute,
BufferGeometry,
Float32BufferAttribute,
} from "three";
import { decodeFloat } from "$lib/helpers/encode";
import { BufferGeometry, Float32BufferAttribute } from "three";
export let result: Int32Array;
@ -24,15 +19,9 @@
const faceCount = encodedData[index++];
// Indices
const indices = encodedData.subarray(index, index + faceCount * 3);
index = index + faceCount * 3;
const normals = new Float32Array(
encodedData.buffer,
index * 4,
faceCount * 3,
);
index = index + faceCount * 3;
const indicesEnd = index + faceCount * 3;
const indices = encodedData.subarray(index, indicesEnd);
index = indicesEnd;
// Vertices
const vertices = new Float32Array(
@ -40,12 +29,21 @@
index * 4,
vertexCount * 3,
);
index = index + vertexCount * 3;
const normals = new Float32Array(
encodedData.buffer,
index * 4,
vertexCount * 3,
);
index = index + vertexCount * 3;
// Add data to geometry
geometry.setIndex([...indices]);
geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
// geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
geometry.computeVertexNormals();
geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
// geometry.computeVertexNormals();
//geometry.computeVertexNormals();
return geometry;
}