Skip to content

Commit

Permalink
MeshLayer.getObjectPosition now samples up to ~100,000 vertices
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisj committed Mar 6, 2024
1 parent 06ed3e5 commit 743862c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/mesh/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ export class MeshLayer extends PerspectiveViewRenderLayer<ThreeDimensionalRender
rank,
);
const { fragmentIds } = chunk;
const closestVertex = new Float32Array(rank);
let closestDistanceSq = Number.POSITIVE_INFINITY;
let vertexCount = 0;
const fragmentChunks: FragmentChunk[] = [];
for (const fragmentId of fragmentIds) {
const { key: fragmentKey } = this.source.getFragmentKey(key, fragmentId);
const fragmentChunk = this.source.fragmentSource.chunks.get(fragmentKey);
Expand All @@ -625,9 +625,21 @@ export class MeshLayer extends PerspectiveViewRenderLayer<ThreeDimensionalRender
) {
continue;
}
vertexCount += meshData.vertexPositions.length / rank;
fragmentChunks.push(fragmentChunk);
}
// Only check up to ~100,000 vertices.
// Not exact because it restarts the interval for each fragment chunk.
const TARGET_VERTEX_COUNT = 100 * 1000;
const sampleRate = TARGET_VERTEX_COUNT / vertexCount;
const sampleInterval = Math.max(1, Math.floor(1 / sampleRate));
const closestVertex = new Float32Array(rank);
let closestDistanceSq = Number.POSITIVE_INFINITY;
for (const fragmentChunk of fragmentChunks) {
const { meshData } = fragmentChunk;
const { vertexPositions } = meshData;
if (vertexPositions.length < rank) continue;
for (let i = 0; i < vertexPositions.length; i += rank) {
for (let i = 0; i < vertexPositions.length; i += rank * sampleInterval) {
let distanceSq = 0;
for (let j = 0; j < rank; j++) {
distanceSq +=
Expand Down

0 comments on commit 743862c

Please sign in to comment.