added collision conversion
This commit is contained in:
103
app/page.tsx
103
app/page.tsx
@@ -1,4 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useRef, useEffect } from "react";
|
||||
|
||||
export default function XgridsWizard() {
|
||||
@@ -19,21 +20,15 @@ export default function XgridsWizard() {
|
||||
|
||||
if (type === "DONE") {
|
||||
setIsProcessing(false);
|
||||
setStatus(
|
||||
`Conversion Complete! Downloading ${data.files.length} files...`,
|
||||
);
|
||||
|
||||
// Loop through all generated files and trigger downloads
|
||||
setStatus("Pipeline Complete!");
|
||||
data.files.forEach((file: { name: string; blob: Blob }) => {
|
||||
downloadFile(file.blob, file.name);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return () => worker.terminate();
|
||||
}, []);
|
||||
|
||||
// Helper to trigger browser downloads
|
||||
const downloadFile = (blob: Blob, name: string) => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
@@ -51,23 +46,46 @@ export default function XgridsWizard() {
|
||||
}
|
||||
};
|
||||
|
||||
const startConversion = async () => {
|
||||
const startPipeline = async () => {
|
||||
if (!files.length || !workerRef.current) return;
|
||||
|
||||
setIsProcessing(true);
|
||||
setStatus("Reading files into memory (this might take a moment)...");
|
||||
|
||||
// Find the main .lcc file to act as our entry point
|
||||
const lccFile = files.find((f) => f.name.endsWith(".lcc"));
|
||||
// FIND SPECIFIC ENTRIES
|
||||
const lciFile = files.find((f) => f.name.toLowerCase() === "collision.lci");
|
||||
const lccFile = files.find((f) => f.name.toLowerCase().endsWith(".lcc"));
|
||||
|
||||
if (!lciFile) {
|
||||
setStatus("Error: 'collision.lci' not found in folder.");
|
||||
return;
|
||||
}
|
||||
if (!lccFile) {
|
||||
setStatus("Error: Missing .lcc file in folder.");
|
||||
setIsProcessing(false);
|
||||
setStatus("Error: Main '.lcc' scene file not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
setIsProcessing(true);
|
||||
|
||||
try {
|
||||
// 1. Convert all File objects into an array of { name, buffer }
|
||||
// --- PHASE 1: Python (Only collision.lci) ---
|
||||
setStatus("Step 1/2: Converting collision.lci to PLY...");
|
||||
const formData = new FormData();
|
||||
formData.append("file", lciFile);
|
||||
|
||||
const pyResponse = await fetch("/api/convert", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!pyResponse.ok) {
|
||||
const err = await pyResponse.json();
|
||||
throw new Error(err.error || "Python script failed");
|
||||
}
|
||||
|
||||
const plyBlob = await pyResponse.blob();
|
||||
downloadFile(plyBlob, "collision_mesh.ply");
|
||||
|
||||
// --- PHASE 2: Worker (The whole folder context) ---
|
||||
setStatus("Step 2/2: Generating Splats and LODs from .lcc...");
|
||||
|
||||
const filesData = await Promise.all(
|
||||
files.map(async (f) => ({
|
||||
name: f.name,
|
||||
@@ -75,8 +93,6 @@ export default function XgridsWizard() {
|
||||
})),
|
||||
);
|
||||
|
||||
// 2. Extract just the ArrayBuffers so we can "transfer" them to the worker efficiently
|
||||
// This prevents duplicating the 272MB data in RAM
|
||||
const buffersToTransfer = filesData.map((f) => f.buffer);
|
||||
|
||||
workerRef.current.postMessage(
|
||||
@@ -84,13 +100,13 @@ export default function XgridsWizard() {
|
||||
type: "START_CONVERSION",
|
||||
filesData,
|
||||
mainLccName: lccFile.name,
|
||||
fileName: lccFile.name.replace(".lcc", ""), // e.g., "Wilhelm Studios"
|
||||
fileName: lccFile.name.replace(".lcc", ""),
|
||||
},
|
||||
buffersToTransfer, // Passes ownership to the worker to save memory
|
||||
buffersToTransfer,
|
||||
);
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
setStatus("Error reading files. Check console.");
|
||||
setStatus(`Error: ${error.message}`);
|
||||
setIsProcessing(false);
|
||||
}
|
||||
};
|
||||
@@ -98,11 +114,9 @@ export default function XgridsWizard() {
|
||||
return (
|
||||
<main className="min-h-screen bg-slate-900 text-white p-8 flex flex-col items-center">
|
||||
<div className="max-w-2xl w-full bg-slate-800 rounded-xl p-8 shadow-2xl border border-slate-700">
|
||||
<header className="mb-8">
|
||||
<header className="mb-8 text-center">
|
||||
<h1 className="text-3xl font-bold mb-2">Xgrids Scene Wizard</h1>
|
||||
<p className="text-slate-400">
|
||||
Convert .lcc/.lci to SOG, LODs, and PLY meshes locally.
|
||||
</p>
|
||||
<p className="text-slate-400">Targeting collision.lci + scene.lcc</p>
|
||||
</header>
|
||||
|
||||
<div className="space-y-6">
|
||||
@@ -117,13 +131,13 @@ export default function XgridsWizard() {
|
||||
onChange={handleFolderUpload}
|
||||
/>
|
||||
<label htmlFor="folder-upload" className="cursor-pointer">
|
||||
<span className="bg-blue-600 px-6 py-3 rounded-md font-medium hover:bg-blue-500 transition-colors inline-block">
|
||||
<span className="bg-blue-600 px-6 py-3 rounded-md font-medium hover:bg-blue-500 transition-all inline-block shadow-lg">
|
||||
Select Xgrids Folder
|
||||
</span>
|
||||
<p className="mt-4 text-sm text-slate-500 italic">
|
||||
{files.length > 0
|
||||
? `${files.length} files selected`
|
||||
: "Drag and drop or click to browse"}
|
||||
: "Upload folder"}
|
||||
</p>
|
||||
</label>
|
||||
</div>
|
||||
@@ -137,39 +151,14 @@ export default function XgridsWizard() {
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={startConversion}
|
||||
onClick={startPipeline}
|
||||
disabled={files.length === 0 || isProcessing}
|
||||
className="w-full py-4 bg-emerald-600 hover:bg-emerald-500 disabled:bg-slate-700 disabled:text-slate-500 disabled:cursor-not-allowed rounded-lg font-bold transition-all shadow-lg"
|
||||
className="w-full py-4 bg-emerald-600 hover:bg-emerald-500 disabled:bg-slate-700 disabled:text-slate-500 rounded-lg font-bold transition-all shadow-lg"
|
||||
>
|
||||
{isProcessing ? (
|
||||
<span className="flex items-center justify-center gap-2">
|
||||
<svg
|
||||
className="animate-spin h-5 w-5 text-white"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle
|
||||
className="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
strokeWidth="4"
|
||||
fill="none"
|
||||
/>
|
||||
<path
|
||||
className="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
/>
|
||||
</svg>
|
||||
Processing...
|
||||
</span>
|
||||
) : (
|
||||
"Generate Scene Files"
|
||||
)}
|
||||
{isProcessing ? "Processing..." : "Generate Scene Files"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user