Spaces:
Paused
Paused
Fix camera target by transforming original center with SplatMesh matrix
Browse files- static/viewer/viewer.html +18 -16
static/viewer/viewer.html
CHANGED
|
@@ -157,6 +157,24 @@
|
|
| 157 |
const cz = parseFloat(urlParams.get("cz") || "0");
|
| 158 |
const r = parseFloat(urlParams.get("r") || "2");
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
// Setup Camera and OrbitControls
|
| 161 |
const camera = new THREE.PerspectiveCamera(
|
| 162 |
45,
|
|
@@ -165,9 +183,6 @@
|
|
| 165 |
Math.max(1000, r * 10),
|
| 166 |
);
|
| 167 |
|
| 168 |
-
// ZipSplat generates Gaussians in OpenCV Y-down frame, and we rotate them by Math.PI around X.
|
| 169 |
-
// The effective target center in Three.js space is thus (cx, -cy, -cz)
|
| 170 |
-
const center = new THREE.Vector3(cx, -cy, -cz);
|
| 171 |
const dist = Math.max(r * 2.0, 0.5);
|
| 172 |
camera.position.copy(center).add(new THREE.Vector3(0, r * 0.2, dist));
|
| 173 |
|
|
@@ -179,19 +194,6 @@
|
|
| 179 |
controls.target.copy(center);
|
| 180 |
controls.update();
|
| 181 |
|
| 182 |
-
const splat = new SplatMesh({
|
| 183 |
-
url: url,
|
| 184 |
-
onLoad: () => {
|
| 185 |
-
loadingEl.style.display = "none";
|
| 186 |
-
},
|
| 187 |
-
});
|
| 188 |
-
|
| 189 |
-
// Re-orient for Three.js (+Y up)
|
| 190 |
-
splat.rotation.y = Math.PI / 2;
|
| 191 |
-
splat.rotation.x = Math.PI;
|
| 192 |
-
scene.add(splat);
|
| 193 |
-
splat.updateMatrixWorld(true);
|
| 194 |
-
|
| 195 |
window.addEventListener("resize", () => {
|
| 196 |
camera.aspect = window.innerWidth / window.innerHeight;
|
| 197 |
camera.updateProjectionMatrix();
|
|
|
|
| 157 |
const cz = parseFloat(urlParams.get("cz") || "0");
|
| 158 |
const r = parseFloat(urlParams.get("r") || "2");
|
| 159 |
|
| 160 |
+
const splat = new SplatMesh({
|
| 161 |
+
url: url,
|
| 162 |
+
onLoad: () => {
|
| 163 |
+
loadingEl.style.display = "none";
|
| 164 |
+
},
|
| 165 |
+
});
|
| 166 |
+
|
| 167 |
+
// Re-orient for Three.js (+Y up)
|
| 168 |
+
splat.rotation.y = Math.PI / 2;
|
| 169 |
+
splat.rotation.x = Math.PI;
|
| 170 |
+
scene.add(splat);
|
| 171 |
+
splat.updateMatrixWorld(true);
|
| 172 |
+
|
| 173 |
+
// The center is in the original unrotated coordinates
|
| 174 |
+
const center = new THREE.Vector3(cx, cy, cz);
|
| 175 |
+
// Apply the splat's transform so the camera looks at the correct world position
|
| 176 |
+
center.applyMatrix4(splat.matrixWorld);
|
| 177 |
+
|
| 178 |
// Setup Camera and OrbitControls
|
| 179 |
const camera = new THREE.PerspectiveCamera(
|
| 180 |
45,
|
|
|
|
| 183 |
Math.max(1000, r * 10),
|
| 184 |
);
|
| 185 |
|
|
|
|
|
|
|
|
|
|
| 186 |
const dist = Math.max(r * 2.0, 0.5);
|
| 187 |
camera.position.copy(center).add(new THREE.Vector3(0, r * 0.2, dist));
|
| 188 |
|
|
|
|
| 194 |
controls.target.copy(center);
|
| 195 |
controls.update();
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
window.addEventListener("resize", () => {
|
| 198 |
camera.aspect = window.innerWidth / window.innerHeight;
|
| 199 |
camera.updateProjectionMatrix();
|