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_src = require("../src/index.js");
const OVERLAY_THICKNESS = 0.25;
const overlayEntity = {
  id: "overlay-sample",
  geometry: {
    id: "geom",
    root: {
      id: "Root",
      position: [0, 0, 0],
      children: [
        {
          id: "BoxNode",
          position: [0, 0, 0],
          mesh: "overlay_box",
          children: []
        }
      ]
    }
  },
  primitives: [
    {
      id: "overlay_box",
      kind: "textured_box",
      size: [2, 2, 2],
      all: "base_texture",
      northOverlay: "overlay_texture"
    }
  ],
  textures: [
    {
      id: "base_texture",
      pattern: "base_pattern",
      materials: ["base_material"]
    },
    {
      id: "overlay_texture",
      pattern: "overlay_pattern",
      materials: ["overlay_material"]
    }
  ],
  patterns: [
    {
      id: "base_pattern",
      size: [2, 2],
      data: [0, 0, 0, 0]
    },
    {
      id: "overlay_pattern",
      size: [2, 2],
      data: [0, 0, 0, 0]
    }
  ],
  materials: [
    { id: "base_material", baseColor: [255, 0, 0] },
    { id: "overlay_material", baseColor: [0, 255, 0] }
  ],
  animations: []
};
(0, import_node_test.default)("textured box overlay attaches inflated mesh with transparent materials", () => {
  const scene = (0, import_src.createBoxelScene)({ THREE, entity: overlayEntity });
  let baseMesh = null;
  let overlayMesh = null;
  scene.root.traverse((object) => {
    if (object instanceof THREE.Mesh && object.userData?.primitiveId === "overlay_box" && !object.userData.overlay) {
      baseMesh = object;
      const overlayChild = object.children.find((child) => child instanceof THREE.Mesh && child.userData?.overlay);
      if (overlayChild instanceof THREE.Mesh) {
        overlayMesh = overlayChild;
      }
    }
  });
  import_strict.default.ok(baseMesh, "base textured mesh missing");
  import_strict.default.ok(overlayMesh, "overlay mesh missing");
  const baseMeshRef = baseMesh;
  const overlayMeshRef = overlayMesh;
  const baseGeometry = baseMeshRef.geometry;
  const overlayGeometry = overlayMeshRef.geometry;
  import_strict.default.ok(baseGeometry && overlayGeometry, "expected box geometries on both meshes");
  const overlayWidth = overlayGeometry.parameters?.width ?? 0;
  const baseWidth = baseGeometry.parameters?.width ?? 0;
  import_strict.default.equal(overlayWidth, baseWidth + OVERLAY_THICKNESS * 2, "overlay geometry should be inflated along X axis");
  const overlayMaterials = Array.isArray(overlayMeshRef.material) ? overlayMeshRef.material : [overlayMeshRef.material];
  const visibleMaterials = overlayMaterials.filter((material) => material.visible !== false && material.opacity !== 0);
  const hiddenMaterials = overlayMaterials.filter((material) => material.visible === false || material.opacity === 0);
  import_strict.default.ok(visibleMaterials.length >= 1, "expected at least one visible overlay material");
  import_strict.default.ok(hiddenMaterials.length >= 1, "expected non-overlay faces to be hidden");
  visibleMaterials.forEach((material) => {
    import_strict.default.equal(material.transparent, true, "overlay materials must be rendered with transparency");
    import_strict.default.equal(material.depthWrite, false, "overlay materials should disable depth writing");
  });
  scene.dispose();
});
(0, import_node_test.default)("merged scene graph export includes overlay atlas data", () => {
  const graph = (0, import_src.createBoxelSceneGraph)({ THREE, model: overlayEntity, mode: "merged" });
  let meshCount = 0;
  let transparentMaterialDetected = false;
  graph.root.traverse((object) => {
    if (object instanceof THREE.Mesh) {
      meshCount += 1;
      const materials = Array.isArray(object.material) ? object.material : [object.material];
      materials.forEach((material) => {
        if (material.transparent) {
          transparentMaterialDetected = true;
        }
      });
    }
  });
  import_strict.default.ok(meshCount >= 1, "merged graph should contain at least one mesh");
  import_strict.default.equal(transparentMaterialDetected, true, "merged atlas material should be marked transparent when overlays are present");
  graph.dispose();
});
