"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var import_node_test = __toESM(require("node:test"));
var import_strict = __toESM(require("node:assert/strict"));
var THREE = __toESM(require("three"));
var import_node_path = __toESM(require("node:path"));
var import_node_url = require("node:url");
var import_promises = require("node:fs/promises");
var import_boxel_core = require("@playdrop/boxel-core");
var import_GLTFExporter = require("three/examples/jsm/exporters/GLTFExporter.js");
var import_glb = require("../src/exporters/glb.js");
const import_meta = {};
const HERE = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
const fixture = (...segments) => import_node_path.default.resolve(HERE, "./fixtures", ...segments);
if (typeof globalThis.FileReader === "undefined") {
  class NodeFileReader {
    constructor() {
      this.onload = null;
      this.onloadend = null;
      this.onerror = null;
      this.onabort = null;
      this.result = null;
    }
    readAsDataURL(blob) {
      blob.arrayBuffer().then((buffer) => {
        const mime = blob.type || "application/octet-stream";
        const base64 = Buffer.from(buffer).toString("base64");
        this.result = `data:${mime};base64,${base64}`;
        const event = { target: { result: this.result } };
        this.onload?.(event);
        this.onloadend?.(event);
      }).catch((error) => {
        this.onerror?.(error);
        this.onloadend?.({ target: { result: null } });
      });
    }
    readAsArrayBuffer(blob) {
      blob.arrayBuffer().then((buffer) => {
        this.result = buffer;
        const event = { target: { result: this.result } };
        this.onload?.(event);
        this.onloadend?.(event);
      }).catch((error) => {
        this.onerror?.(error);
        this.onloadend?.({ target: { result: null } });
      });
    }
    abort() {
      this.onabort?.(new Error("filereader_abort_not_supported"));
    }
  }
  globalThis.FileReader = NodeFileReader;
}
async function loadEntity(relativePath) {
  const raw = await (0, import_promises.readFile)(fixture(relativePath), "utf-8");
  return (0, import_boxel_core.parseBoxel)(JSON.parse(raw));
}
(0, import_node_test.default)("createBoxelSceneGraph skinned mode exposes skinned mesh and bones", async () => {
  const entity = await loadEntity("entity-connect.json");
  const graph = (0, import_glb.createBoxelSceneGraph)({ THREE, model: entity, mode: "skinned" });
  try {
    import_strict.default.ok(graph.root instanceof THREE.Object3D, "root should be Object3D");
    const skinnedMesh = graph.root.children.find((child) => child instanceof THREE.SkinnedMesh);
    import_strict.default.ok(skinnedMesh, "skinned mesh missing from scene graph");
    const boneIds = Array.from(graph.nodeLookup.keys());
    import_strict.default.ok(boneIds.length > 0, "expected bones in lookup");
    import_strict.default.ok(boneIds.some((id) => id.toLowerCase().includes("chest")), "expected Chest bone in lookup");
    import_strict.default.ok(graph.animations.every((entry) => entry.clip instanceof THREE.AnimationClip), "clips missing");
  } finally {
    graph.dispose();
  }
});
(0, import_node_test.default)("exportModelToGLB supports skinned mode", async () => {
  const entity = await loadEntity("entity-connect.json");
  const blob = await (0, import_glb.exportModelToGLB)({
    THREE,
    GLTFExporterCtor: import_GLTFExporter.GLTFExporter,
    model: entity,
    mode: "skinned"
  });
  const buffer = Buffer.from(await blob.arrayBuffer());
  import_strict.default.ok(buffer.length > 0, "skinned export should produce non-empty binary");
});
