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 context_exports = {};
__export(context_exports, {
  clearTextureCache: () => clearTextureCache,
  createBuilderContext: () => createBuilderContext,
  updateBuilderContext: () => updateBuilderContext
});
module.exports = __toCommonJS(context_exports);
function createBuilderContext(options) {
  return {
    THREE: options.THREE,
    settings: { ...options.settings },
    entity: null,
    materialsById: /* @__PURE__ */ new Map(),
    primitivesById: /* @__PURE__ */ new Map(),
    textureCache: /* @__PURE__ */ new Map()
  };
}
function updateBuilderContext(context, update) {
  if (update.settings) {
    context.settings = { ...context.settings, ...update.settings };
  }
  if (update.entity !== void 0) {
    context.entity = update.entity;
    context.materialsById = update.entity ? new Map(update.entity.materials.map((material) => [material.id, material])) : /* @__PURE__ */ new Map();
    context.primitivesById = update.entity ? new Map(update.entity.primitives.map((primitive) => [primitive.id, primitive])) : /* @__PURE__ */ new Map();
    clearTextureCache(context);
  }
}
function clearTextureCache(context) {
  context.textureCache.forEach((bundle) => {
    bundle.color.dispose();
    bundle.emissive?.dispose();
  });
  context.textureCache.clear();
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  clearTextureCache,
  createBuilderContext,
  updateBuilderContext
});
