Fix editor regressions and add Blender scene and animated material import

This commit is contained in:
emil28092005
2026-09-12 00:53:20 +03:00
parent 1a0bf725fa
commit 6f497d1977
34 changed files with 1241 additions and 213 deletions
+8 -26
View File
@@ -11,7 +11,7 @@ import { defaultProject } from "../engine/templates.ts";
import { entity, uid, validateProject } from "../engine/schema.ts";
import { projectArchive, gameArchive, decodeData } from "../engine/archive.ts";
import { createMcp, type EngineService } from "./mcp.ts";
import { inspectModel } from "../engine/model.ts";
import { portableModel, modelComponents, modelDataUri, modelProject } from "../engine/model-import.ts";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const mime: Record<string, string> = {
".html": "text/html; charset=utf-8",
@@ -207,32 +207,14 @@ export async function createService(
const bytes = a.base64
? Buffer.from(a.base64, "base64")
: Buffer.from(await safeRead(projectDir, a.path));
const metadata = inspectModel(bytes, a.name),
gltf = a.name.toLowerCase().endsWith(".gltf");
const id = uid("asset"),
asset = {
id,
name: a.name,
kind: "model",
metadata,
uri:
"data:" +
(gltf ? "model/gltf+json" : "model/gltf-binary") +
";base64," +
bytes.toString("base64"),
},
commands: any[] = [{ op: "asset.upsert", args: { asset } }];
if (a.instantiate)
commands.push({
op: "node.create",
args: {
entity: entity(a.name.replace(/\.(glb|gltf)$/i, ""), {
mesh: { type: "model", assetId: id },
}),
},
});
const sourceName = a.path || a.name;
const model = await portableModel(bytes, sourceName, a.path ? file => safeRead(projectDir, file) : undefined);
const id = uid("asset");
const asset = { id, name: model.name, kind: "model", metadata: model.metadata, uri: modelDataUri(model) };
const commands: any[] = [{ op: "asset.upsert", args: { asset } }];
if (a.instantiate) commands.push({ op: "node.create", args: { entity: entity(model.name.replace(/\.(glb|gltf)$/i, ""), modelComponents(id, model.metadata)) } });
return store.transaction({
commands,
commands: a.asScene ? [{ op: "project.replace", args: { project: modelProject(model) } }] : commands,
expectedRevision: a.expectedRevision,
requestId: a.requestId,
label: "Импорт " + a.name,