Skip to content

Added the ability to build an octree, and an example of using the built octree to speed up ray detection #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions dist/types/SplatMesh.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RgbaArray } from './RgbaArray';
import { SplatEdit } from './SplatEdit';
import { GsplatModifier, SplatGenerator, SplatTransformer } from './SplatGenerator';
import { SplatFileType } from './SplatLoader';
import { SplatTree } from './SplatTree';
import { SplatSkinning } from './SplatSkinning';
import { DynoFloat, DynoUsampler2DArray, DynoVal, DynoVec4, Gsplat } from './dyno';
import * as THREE from "three";
Expand Down Expand Up @@ -56,6 +57,9 @@ export declare class SplatMesh extends SplatGenerator {
private rgbaDisplaceEdits;
splatRgba: RgbaArray | null;
maxSh: number;
splatTree: SplatTree | null;
baseSplatTree: SplatTree | null;
disposed: boolean;
constructor(options?: SplatMeshOptions);
asyncInitialize(options: SplatMeshOptions): Promise<void>;
static staticInitialized: Promise<void>;
Expand All @@ -64,6 +68,41 @@ export declare class SplatMesh extends SplatGenerator {
static staticInitialize(): Promise<void>;
pushSplat(center: THREE.Vector3, scales: THREE.Vector3, quaternion: THREE.Quaternion, opacity: number, color: THREE.Color): void;
forEachSplat(callback: (index: number, center: THREE.Vector3, scales: THREE.Vector3, quaternion: THREE.Quaternion, opacity: number, color: THREE.Color) => void): void;
/**
* Retrieves the color and opacity of a specific splat
* @param index - The index of the splat to retrieve color from
* @param out - Output vector to store the color (RGBA format)
* @returns The output vector containing the splat's color and opacity
*/
getSplatColor(index: number, out: THREE.Vector4): THREE.Vector4;
/**
* Retrieves the scale and rotation (quaternion) of a specific splat
* @param index - The index of the splat to retrieve scale and rotation from
* @param out - Output vector to store the scale (x, y, z components)
* @param out2 - Output quaternion to store the rotation
* @returns The output vector containing the splat's scale
*/
getSplatScaleAndRotation(index: number, out: THREE.Vector3, out2: THREE.Quaternion): THREE.Vector3;
/**
* Gets the total number of splats in the mesh
* @returns The total count of splats
*/
getSplatCount(): number;
/**
* Gets the scene index for a specific splat
* Currently returns 0 as a default implementation
* @param index - The index of the splat
* @returns The scene index (always 0 in this implementation)
*/
getSceneIndexForSplat(index: number): number;
/**
* Gets the current scene object
* @returns The current SplatMesh instance as the scene
*/
getScene(): this;
getSplatCenter(index: number, out: THREE.Vector3): THREE.Vector3;
buildSplatTree(minAlphas?: number[], onSplatTreeIndexesUpload?: Function, onSplatTreeConstruction?: Function): Promise<void>;
disposeSplatTree(): void;
dispose(): void;
constructGenerator(context: SplatMeshContext): void;
updateGenerator(): void;
Expand Down
53 changes: 53 additions & 0 deletions dist/types/SplatTree.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { SplatMesh } from './SplatMesh';
import * as THREE from 'three';
declare class SplatTreeNode {
static idGen: number;
min: THREE.Vector3;
max: THREE.Vector3;
boundingBox: THREE.Box3;
center: THREE.Vector3;
depth: number;
children: SplatTreeNode[];
data: {
indexes: number[];
};
id: number;
constructor(min: THREE.Vector3, max: THREE.Vector3, depth: number, id: number);
}
declare class SplatSubTree {
maxDepth: number;
maxCentersPerNode: number;
sceneDimensions: THREE.Vector3;
sceneMin: THREE.Vector3;
sceneMax: THREE.Vector3;
rootNode: SplatTreeNode | null;
nodesWithIndexes: SplatTreeNode[];
splatMesh: SplatMesh | null;
constructor(maxDepth: number, maxCentersPerNode: number);
static convertWorkerSubTreeNode(workerSubTreeNode: any): SplatTreeNode;
static convertWorkerSubTree(workerSubTree: any, splatMesh: SplatMesh): SplatSubTree;
}
export declare class SplatTree {
maxDepth: number;
maxCentersPerNode: number;
subTrees: SplatSubTree[];
splatMesh: SplatMesh | null;
disposed: boolean;
splatTreeWorker: Worker | null;
constructor(maxDepth: number, maxCentersPerNode: number);
dispose(): void;
diposeSplatTreeWorker(): void;
/**
* Build SplatTree (octree) from a SplatMesh instance.
*
* @param {SplatMesh} splatMesh SplatMesh instance to build octree from
* @param {function} filterFunc Optional, filter out unwanted splats (points), return true to keep
* @param {function} onIndexesUpload Callback when uploading splat centers to worker (start/end)
* @param {function} onSplatTreeConstruction Callback when worker is building local splat tree (start/end)
* @return {Promise<void>} Promise that resolves when octree building is complete
*/
processSplatMesh(splatMesh: SplatMesh, filterFunc?: (index: number) => boolean, onIndexesUpload?: (isUploading: boolean) => void, onSplatTreeConstruction?: (isBuilding: boolean) => void): Promise<void>;
countLeaves(): number;
visitLeaves(visitFunc: (node: SplatTreeNode) => void): void;
}
export {};
1 change: 1 addition & 0 deletions examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@
<a href="#multiple-viewpoints" data-example="multiple-viewpoints" class="example-link">Multiple Viewpoints</a>
<a href="#procedural-splats" data-example="procedural-splats" class="example-link">Procedural Splats</a>
<a href="#raycasting" data-example="raycasting" class="example-link">Raycasting</a>
<a href="#octree-raycasting" data-example="octree-raycasting" class="example-link">Octree Raycasting</a>
<a href="#dynamic-lighting" data-example="dynamic-lighting" class="example-link">Dynamic Lighting</a>
<a href="#particle-animation" data-example="particle-animation" class="example-link">Particle Animation</a>
<a href="#particle-simulation" data-example="particle-simulation" class="example-link">Particle Simulation</a>
Expand Down
Loading