Пісочниця WebGL — Живий Редактор Коду · 3D Симуляції

JavaScript · Three.js r160
Перегляд
Консоль
`; const blob = new Blob([html], { type: "text/html" }); const old = frame.src; if (old && old.startsWith("blob:")) URL.revokeObjectURL(old); frame.src = URL.createObjectURL(blob); addConsole("▶ Виконується…", "info"); } // Receive console messages from iframe window.addEventListener("message", (e) => { if (e.data && e.data.type === "console") { addConsole(e.data.msg, e.data.level); } }); // ═══════════════════════════════════════════════════════════════ // Toolbar buttons // ═══════════════════════════════════════════════════════════════ document.getElementById("run-btn").addEventListener("click", runCode); document.getElementById("reset-btn").addEventListener("click", () => { editor.setValue(SNIPPETS[currentSnippetKey] || SNIPPETS.cube); addConsole("↺ Код скинуто до початкового сніпета.", "info"); }); document.getElementById("clear-btn").addEventListener("click", () => { consoleOutput.innerHTML = ""; }); document.getElementById("share-btn").addEventListener("click", () => { const code = encodeURIComponent(editor.getValue()); const maxLen = 4096; // тримати URL у розумних межах if (code.length > maxLen) { addConsole( "⚠ Код задовгий, щоб поділитися через URL. Скористайтеся «Завантажити».", "warn", ); return; } const url = location.origin + location.pathname + "?code=" + code; navigator.clipboard .writeText(url) .then(() => showToast("✓ URL для обміну скопійовано в буфер!")) .catch(() => { // Запасний варіант: відкрити в новій вкладці window.open(url, "_blank", "noopener"); }); }); document.getElementById("export-btn").addEventListener("click", () => { const code = editor.getValue(); const html = ` Експорт із 3DS Пісочниці