fix: make camera position and loader more robust for GSPLAT
This commit is contained in:
parent
8191e9c869
commit
d3a594e8ad
1 changed files with 15 additions and 10 deletions
|
|
@ -128,18 +128,22 @@
|
||||||
const loading = document.getElementById('loading');
|
const loading = document.getElementById('loading');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Initialize Renderer
|
|
||||||
const renderer = new GSPLAT.WebGLRenderer();
|
|
||||||
container.appendChild(renderer.canvas);
|
|
||||||
|
|
||||||
// Initialize Scene
|
// Initialize Scene
|
||||||
const scene = new GSPLAT.Scene();
|
const scene = new GSPLAT.Scene();
|
||||||
const camera = new GSPLAT.Camera();
|
const camera = new GSPLAT.Camera();
|
||||||
|
const renderer = new GSPLAT.WebGLRenderer();
|
||||||
|
container.appendChild(renderer.canvas);
|
||||||
|
|
||||||
const controls = new GSPLAT.OrbitControls(camera, renderer.canvas);
|
const controls = new GSPLAT.OrbitControls(camera, renderer.canvas);
|
||||||
|
|
||||||
// Adjust camera initial position (GSPLAT uses camera.data.position)
|
// Set camera position safely
|
||||||
|
if (camera.position) {
|
||||||
|
camera.position.set(0, 0, 5);
|
||||||
|
} else if (camera.data && camera.data.position) {
|
||||||
camera.data.position.set(0, 0, 5);
|
camera.data.position.set(0, 0, 5);
|
||||||
controls.update();
|
}
|
||||||
|
|
||||||
|
if (controls.update) controls.update();
|
||||||
|
|
||||||
// Resize handler
|
// Resize handler
|
||||||
const resize = () => {
|
const resize = () => {
|
||||||
|
|
@ -152,7 +156,9 @@
|
||||||
status.innerText = "Downloading compressed Splat...";
|
status.innerText = "Downloading compressed Splat...";
|
||||||
|
|
||||||
// Using the .splat file provided by user
|
// Using the .splat file provided by user
|
||||||
await GSPLAT.loadAsync(
|
// Try GSPLAT.Loader first, fallback to LoadAsync if needed
|
||||||
|
const loader = GSPLAT.Loader ? GSPLAT.Loader : GSPLAT;
|
||||||
|
await loader.loadAsync(
|
||||||
"/models/gs/nebula_rnd1.splat",
|
"/models/gs/nebula_rnd1.splat",
|
||||||
scene,
|
scene,
|
||||||
(progress) => {
|
(progress) => {
|
||||||
|
|
@ -160,7 +166,6 @@
|
||||||
status.innerText = `Loading: ${percent}%`;
|
status.innerText = `Loading: ${percent}%`;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
loading.style.display = 'none';
|
loading.style.display = 'none';
|
||||||
|
|
||||||
// Animation loop
|
// Animation loop
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue