var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var instantiate_exports = {};
__export(instantiate_exports, {
  instantiateEntityObject3D: () => instantiateEntityObject3D
});
module.exports = __toCommonJS(instantiate_exports);
var import_scene = require("./scene.js");
var import_glb = require("./exporters/glb.js");
var import_skinned_mesh = require("./skinned-mesh.js");
var import_animations = require("./animations.js");
function instantiateHierarchy(options) {
  const { THREE, entity } = options;
  const scene = (0, import_scene.createBoxelScene)({ THREE, entity });
  const clips = scene.animations.map((animation) => animation.clip);
  return {
    mode: "hierarchy",
    object: scene.root,
    scene,
    clips,
    findNode: (nodeId) => scene.nodes.get(nodeId)?.object,
    forEachNode: (visitor) => {
      scene.nodes.forEach((meta) => visitor(meta.object, meta.id));
    },
    dispose: () => {
      scene.dispose();
    }
  };
}
function instantiateMerged(options) {
  const { THREE, entity } = options;
  const graph = (0, import_glb.createBoxelSceneGraph)({ THREE, model: entity, mode: "merged" });
  const { root } = graph;
  return {
    mode: "merged",
    object: root,
    dispose: () => {
      graph.dispose();
    }
  };
}
function instantiateSkinned(options) {
  const { THREE, entity } = options;
  const result = (0, import_skinned_mesh.buildEntitySkinnedMesh)({ THREE, entity });
  const boneMap = result.boneMap;
  const animations = (0, import_animations.buildAnimations)(THREE, entity, boneMap);
  const clips = animations.map((animation) => animation.clip);
  return {
    mode: "skinned",
    object: result.mesh,
    skeleton: result.skeleton,
    boneMap,
    clips,
    stats: result.stats,
    warnings: result.warnings,
    findBone: (nodeId) => boneMap.get(nodeId),
    forEachBone: (visitor) => {
      boneMap.forEach((bone, nodeId) => visitor(bone, nodeId));
    },
    dispose: () => {
      result.dispose();
    }
  };
}
function instantiateEntityObject3D(options) {
  const mode = options.mode ?? "hierarchy";
  switch (mode) {
    case "hierarchy":
      return instantiateHierarchy(options);
    case "merged":
      return instantiateMerged(options);
    case "skinned":
      return instantiateSkinned(options);
    default:
      throw new Error(`Unknown entity instantiation mode: ${String(mode)}`);
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  instantiateEntityObject3D
});
