Skip to content

Commit 9d3f79b

Browse files
Merge pull request #189 from pnext/gaussians-lod
feat: Gaussians LOD
2 parents 8c805d1 + aa0f516 commit 9d3f79b

33 files changed

+14152
-206
lines changed

example/main.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,22 @@ body,
2020
left: 20px;
2121
}
2222

23+
.btn-container-splats {
24+
position: absolute;
25+
bottom: 80px;
26+
left: 20px;
27+
}
28+
2329
.btn-container-v1 button {
2430
margin-right: 10px;
2531
}
2632

2733
.btn-container-v2 button {
2834
margin-right: 10px;
2935
}
36+
37+
.btn-container-splats button {
38+
margin-right: 10px;
39+
}
40+
41+

example/main.ts

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Vector3 } from 'three';
21
import { ClipMode, PointCloudOctree } from '../src';
32
import { Viewer } from './viewer';
43

@@ -14,18 +13,19 @@ viewer.initialize(targetEl);
1413
interface PointCloudsConfig {
1514
file: string;
1615
url: string;
17-
version: 'v1' | 'v2';
16+
version: 'v1' | 'v2' | 'splats';
1817
}
1918

2019
const examplePointClouds: PointCloudsConfig[] = [
2120
{
2221
file: 'cloud.js',
2322
url: 'https://raw.githubusercontent.com/potree/potree/develop/pointclouds/lion_takanawa/',
24-
version: 'v1'
25-
}, {
23+
version: 'v1',
24+
},
25+
{
2626
file: 'metadata.json',
2727
url: 'https://test-pix4d-cloud-eu-central-1.s3.eu-central-1.amazonaws.com/lion_takanawa_converted/',
28-
version: 'v2'
28+
version: 'v2',
2929
}
3030
];
3131

@@ -39,15 +39,17 @@ interface LoadedState {
3939

4040
const pointClouds: PointClouds = {
4141
v1: undefined,
42-
v2: undefined
42+
v2: undefined,
43+
splats: undefined
4344
};
4445

4546
const loaded: LoadedState = {
4647
v1: false,
47-
v2: false
48+
v2: false,
49+
splats: false
4850
};
4951

50-
function createButton(text: string, onClick: () => void): HTMLButtonElement {
52+
function createButton(text: string, onClick: (e: MouseEvent) => void): HTMLButtonElement {
5153
const button: HTMLButtonElement = document.createElement('button');
5254
button.textContent = text;
5355
button.addEventListener('click', onClick);
@@ -58,45 +60,67 @@ function createSlider(version: string): HTMLInputElement {
5860
const slider: HTMLInputElement = document.createElement('input');
5961
slider.type = 'range';
6062
slider.min = '10000';
61-
slider.max = '500000';
63+
slider.max = '1000000';
64+
slider.value = '1000000';
6265
slider.className = 'budget-slider';
6366
slider.addEventListener('change', () => {
6467
const cloud = pointClouds[version];
6568
if (!cloud) {
6669
return;
6770
}
6871
cloud.potree.pointBudget = parseInt(slider.value, 10);
72+
viewer.update(0);
6973
console.log(cloud.potree.pointBudget);
7074
});
7175
return slider;
7276
}
7377

74-
function setupPointCloud(version: 'v1' | 'v2', file: string, url: string): void {
78+
function setupPointCloud(version: 'v1' | 'v2' | 'splats', file: string, url: string): void {
7579
if (loaded[version]) {
7680
return;
7781
}
7882
loaded[version] = true;
7983

80-
viewer.load(file, url, version)
84+
//TODO: check for mobile, not noly IOS
85+
function isIOS() {
86+
const ua = navigator.userAgent;
87+
return ua.indexOf('iPhone') > 0 || ua.indexOf('iPad') > 0;
88+
}
89+
90+
viewer.load(file, url, version == 'splats' ? 'v2' : version, !isIOS())
8191
.then(pco => {
8292
pointClouds[version] = pco;
83-
pco.rotateX(-Math.PI / 2);
8493
pco.material.size = 1.0;
94+
95+
pco.material.pointColorType = 0;
96+
8597
pco.material.clipMode = ClipMode.CLIP_HORIZONTALLY;
8698
pco.material.clipExtent = [0.0, 0.0, 1.0, 1.0];
99+
pco.position.set(0, 0, 0);
87100

88101
const camera = viewer.camera;
102+
camera.up.set(0, 0, 1);
89103
camera.far = 1000;
90104
camera.updateProjectionMatrix();
91-
camera.position.set(0, 0, 10);
92-
camera.lookAt(new Vector3());
105+
camera.position.set(-4, 4, 16);
93106

94107
viewer.add(pco);
95108
})
96109
.catch(err => console.error(err));
97110
}
98111

99112
function setupUI(cfg: PointCloudsConfig): void {
113+
114+
const updateBtn = createButton("Update", (e: MouseEvent) => {
115+
e.stopPropagation();
116+
viewer.enableUpdate = !viewer.enableUpdate;
117+
updateBtn.style.backgroundColor = viewer.enableUpdate ? "#00ff00" : "#ff0000";
118+
})
119+
120+
updateBtn.style.backgroundColor ="#00ff00";
121+
122+
const slider = createSlider(cfg.version);
123+
100124
const unloadBtn = createButton('Unload', () => {
101125
if (!loaded[cfg.version]) {
102126
return;
@@ -109,18 +133,25 @@ function setupUI(cfg: PointCloudsConfig): void {
109133
viewer.disposePointCloud(pointCloud);
110134
loaded[cfg.version] = false;
111135
pointClouds[cfg.version] = undefined;
112-
});
113136

114-
const loadBtn = createButton('Load', () => setupPointCloud(cfg.version, cfg.file, cfg.url));
137+
viewer.enableUpdate = true;
138+
updateBtn.style.backgroundColor ="#00ff00";
139+
});
115140

116-
const slider = createSlider(cfg.version);
141+
const loadBtn = createButton('Load', (e: MouseEvent) => {
142+
e.stopPropagation();
143+
setupPointCloud(cfg.version, cfg.file, cfg.url)
144+
}
145+
);
117146

118147
const btnContainer: HTMLDivElement = document.createElement('div');
119148
btnContainer.className = 'btn-container-' + cfg.version;
120149
document.body.appendChild(btnContainer);
121150
btnContainer.appendChild(unloadBtn);
122151
btnContainer.appendChild(loadBtn);
152+
btnContainer.append(updateBtn);
123153
btnContainer.appendChild(slider);
154+
124155
}
125156

126157
examplePointClouds.forEach(setupUI);

example/sorter_test.wasm

494 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)