fix rendering issues on the sandbox

This commit is contained in:
2026-01-25 10:57:29 +01:00
parent 559a4c3e9f
commit 4cec4b1bb4

View File

@@ -222,7 +222,7 @@ const initThreeJS = () => {
}); });
const width = canvasRef.value.clientWidth || 800; const width = canvasRef.value.clientWidth || 800;
const height = canvasRef.value.clientHeight || 600; const height = canvasRef.value.clientHeight || 800;
renderer.setSize(width, height); renderer.setSize(width, height);
renderer.setPixelRatio(window.devicePixelRatio); renderer.setPixelRatio(window.devicePixelRatio);
@@ -240,6 +240,7 @@ const initThreeJS = () => {
// Animation loop control // Animation loop control
const startAnimation = () => { const startAnimation = () => {
console.log('starting animation')
if (animationId) return; // Already running if (animationId) return; // Already running
const animate = () => { const animate = () => {
@@ -257,6 +258,7 @@ const startAnimation = () => {
}; };
const pauseAnimation = () => { const pauseAnimation = () => {
console.log('pausing animation')
animationPaused = true; animationPaused = true;
if (animationId) { if (animationId) {
cancelAnimationFrame(animationId); cancelAnimationFrame(animationId);
@@ -265,12 +267,14 @@ const pauseAnimation = () => {
}; };
const resumeAnimation = () => { const resumeAnimation = () => {
console.log('resuming animation')
animationPaused = false; animationPaused = false;
startAnimation(); startAnimation();
}; };
// Render a single frame (for when animation is paused but we need to update the view) // Render a single frame (for when animation is paused but we need to update the view)
const renderSingleFrame = () => { const renderSingleFrame = () => {
console.log('Rendering single frame')
if (renderer && scene && camera) { if (renderer && scene && camera) {
renderer.render(scene, camera); renderer.render(scene, camera);
} }
@@ -281,7 +285,7 @@ const handleResize = () => {
if (!canvasRef.value || !renderer || !camera) return; if (!canvasRef.value || !renderer || !camera) return;
const width = canvasRef.value.clientWidth || 800; const width = canvasRef.value.clientWidth || 800;
const height = canvasRef.value.clientHeight || 600; const height = canvasRef.value.clientHeight || 800;
renderer.setSize(width, height); renderer.setSize(width, height);
renderer.setPixelRatio(window.devicePixelRatio); renderer.setPixelRatio(window.devicePixelRatio);
@@ -341,15 +345,6 @@ const loadTileData = (tileData, newTileId) => {
// Z scaling: make Z variation visible but proportional // Z scaling: make Z variation visible but proportional
const zScale = normalizeScale * (maxSpan * 0.1) / spanZ; const zScale = normalizeScale * (maxSpan * 0.1) / spanZ;
console.log('Tile scaling:', {
spanX: spanX.toFixed(2),
spanY: spanY.toFixed(2),
spanZ: spanZ.toFixed(2),
tileAspect: tileAspect.toFixed(3),
normalizeScale: normalizeScale.toFixed(4),
zScale: zScale.toFixed(4)
});
// Transform positions // Transform positions
const transformedPositions = new Float32Array(tileData.positions.length); const transformedPositions = new Float32Array(tileData.positions.length);
for (let i = 0; i < tileData.positions.length; i += 3) { for (let i = 0; i < tileData.positions.length; i += 3) {
@@ -672,18 +667,45 @@ const downloadLastRender = () => {
// Cleanup // Cleanup
const cleanup = () => { const cleanup = () => {
// Stop animation
pauseAnimation(); pauseAnimation();
// Dispose resize observer
if (resizeObserver) { if (resizeObserver) {
resizeObserver.disconnect(); resizeObserver.disconnect();
resizeObserver = null; resizeObserver = null;
} }
if (renderer) {
renderer.dispose(); // Dispose mesh
}
if (mesh) { if (mesh) {
scene?.remove(mesh);
if (mesh.geometry) mesh.geometry.dispose(); if (mesh.geometry) mesh.geometry.dispose();
if (mesh.material) mesh.material.dispose(); if (mesh.material) mesh.material.dispose();
mesh = null;
} }
// Dispose renderer
if (renderer) {
renderer.dispose();
renderer = null;
}
// Clear scene
if (scene) {
scene.clear();
scene = null;
}
// Clear other Three.js objects
camera = null;
directionalLight = null;
ambientLight = null;
// Clear geometry cache
geometryCache = null;
// Reset tile state
tileLoaded.value = false;
}; };
// Lifecycle // Lifecycle
@@ -711,6 +733,7 @@ onMounted(() => {
// Watch for visibility changes // Watch for visibility changes
watch(() => props.visible, (newVal) => { watch(() => props.visible, (newVal) => {
if (newVal && !renderer) { if (newVal && !renderer) {
// Coming visible and no renderer exists → initialize
nextTick(() => { nextTick(() => {
initThreeJS(); initThreeJS();
@@ -728,11 +751,11 @@ watch(() => props.visible, (newVal) => {
} }
}); });
} else if (newVal && !props.offscreen) { } else if (newVal && !props.offscreen) {
// Component already initialized, just resume animation // Component already initialized, becoming on-screen → just resume animation
resumeAnimation(); resumeAnimation();
} else if (!newVal) { } else if (!newVal) {
// Hidden - pause animation // Becoming invisible → full cleanup
pauseAnimation(); cleanup();
} }
}); });