var G = Object.defineProperty;
var U = (c, d, g) => d in c ? G(c, d, { enumerable: !0, configurable: !0, writable: !0, value: g }) : c[d] = g;
var v = (c, d, g) => U(c, typeof d != "symbol" ? d + "" : d, g);
import { defineComponent as I, watch as m, createElementBlock as T, openBlock as M, createElementVNode as V, createCommentVNode as q, normalizeClass as N, unref as R, toDisplayString as K, ref as P, onMounted as J, onBeforeUnmount as Z } from "vue";
import "@babylonjs/loaders/glTF";
import { cloneDeep as l, isEqual as p } from "lodash";
import { Vector3 as u, Engine as j, Scene as Q, Color4 as S, Color3 as y, DefaultRenderingPipeline as X, DepthOfFieldEffectBlurLevel as x, ArcRotateCamera as Y, Tools as w, HemisphericLight as $, DirectionalLight as O, PointLight as ee, SceneLoader as ie } from "@babylonjs/core";
import { useResizeObserver as te } from "@vueuse/core";
import "../text-text-basic/index.mjs";
import "../text-table-basic/index.mjs";
import "../chart-other-gauge/index.mjs";
import "../chart-other-gauge-stage/index.mjs";
import "../chart-other-gauge-grade/index.mjs";
import "../chart-other-word-cloud/index.mjs";
import "../chart-other-liquidfill/index.mjs";
import "../chart-other-funnel/index.mjs";
import "../chart-other-force/index.mjs";
import "../chart-other-radar/index.mjs";
import "../chart-other-funnel-split/index.mjs";
import "../chart-other-funnel-contrast/index.mjs";
import "../chart-other-candlestick-basic/index.mjs";
import "../chart-other-candlestick-shanghai/index.mjs";
import "../chart-other-candlestick-demo/index.mjs";
import "../chart-other-heatmap/index.mjs";
import "../chart-other-force2/index.mjs";
import "../chart-other-graph-basic/index.mjs";
import "../chart-other-graph-basic2/index.mjs";
import "../chart-other-graph-calendar/index.mjs";
import "../chart-other-tree-line/index.mjs";
import "../chart-other-treemap-basic/index.mjs";
import "../chart-other-sunburst-basic/index.mjs";
import "../chart-other-sunburst-basic2/index.mjs";
import "../chart-other-sunburst-basic3/index.mjs";
import "../chart-other-sunburst-basic4/index.mjs";
import "../chart-other-sunburst-book/index.mjs";
import "../chart-other-sunburst-radius/index.mjs";
import "../chart-other-sunburst-flavors/index.mjs";
import "../chart-other-parallel-basic/index.mjs";
import "../chart-other-parallel-mul/index.mjs";
import "../chart-other-circular-graph/index.mjs";
import "../map-earth-basic/index.mjs";
import "../map-earth-cool-tech/index.mjs";
import "../map-earth-particle/index.mjs";
import "../map-earth-hacker/index.mjs";
import "../map-earth-fly-line/index.mjs";
import "../chart-other-grid-percentage/index.mjs";
import "../chart-other-radar-stack/index.mjs";
import "../chart-other-funnel2/index.mjs";
import "../chart-other-label-gauge/index.mjs";
import "../chart-other-theme-river/index.mjs";
import "../chart-other-tree/index.mjs";
import "../chart-other-treemap/index.mjs";
import "../commons-product-model/index.mjs";
import "../commons-vr-photo/index.mjs";
import "../commons-vr-video/index.mjs";
import "./index.mjs";
import "../commons-three-loader3/index.mjs";
import "../commons-loop-iterator/index.mjs";
import "../commons-gaussian-splatting-view/index.mjs";
import "../commons-babylon/index.mjs";
import "../commons-svg/index.mjs";
import "../commons-weather/index.mjs";
import "../commons-weather-dynamic/index.mjs";
import "../media-wavesurfer/index.mjs";
import "../interaction-tabs/index.mjs";
import "../interaction-tabs2/index.mjs";
import "../interaction-button/index.mjs";
import "../interaction-button-image/index.mjs";
import "../interaction-select/index.mjs";
import "../interaction-input/index.mjs";
import "../interaction-radio/index.mjs";
import "../interaction-slider/index.mjs";
import "../interaction-switch/index.mjs";
import "../interaction-data-picker/index.mjs";
import "../interaction-button-refresh/index.mjs";
import "../media-image/index.mjs";
import "../text-title/index.mjs";
import "../commons-qrcode/index.mjs";
import "../media-video/index.mjs";
import "../media-audio/index.mjs";
import "../text-real-time/index.mjs";
import "../media-carousel/index.mjs";
import "../media-carousel-slides/index.mjs";
import "../media-iframe-carousel/index.mjs";
import "../media-iframe/index.mjs";
import "../media-m3u8/index.mjs";
import "../media-m3u8-dynamic/index.mjs";
import "../media-audio-dynamic/index.mjs";
import "../media-video-dynamic/index.mjs";
import "../media-image-dynamic/index.mjs";
import "../media-iframe-dynamic/index.mjs";
import "../media-flv/index.mjs";
import "../commons-echarts/index.mjs";
import "../text-over-number/index.mjs";
import "../text-table-scroll/index.mjs";
import "../text-carousel/index.mjs";
import "../text-row-scroll/index.mjs";
import "../text-text-dynamic/index.mjs";
import "../text-count-down/index.mjs";
import "../graphical-circle/index.mjs";
import "../graphical-diamond/index.mjs";
import "../graphical-hexagon/index.mjs";
import "../graphical-isosceles-triangle/index.mjs";
import "../graphical-pentagon/index.mjs";
import "../graphical-rect/index.mjs";
import "../graphical-right-triangle/index.mjs";
import "../scene-map3d/index.mjs";
import "../scene-amap2d/index.mjs";
import "../scene-amap3d/index.mjs";
import "../scene-vr/index.mjs";
import "../scene-unity-iframe/index.mjs";
import "../scene-unity-webgl/index.mjs";
import "../scene-ue-iframe/index.mjs";
import "../scene-ue-shj/index.mjs";
import "../scene-default/index.mjs";
import "../interaction/tabs/index.mjs";
import "../interaction/tabs-icon/index.mjs";
import "../interaction/button/index.mjs";
import "../interaction/date-picker/src/date-picker/index.mjs";
import "../interaction/date-picker/src/date-picker-range/index.mjs";
import "../text/list/index.mjs";
import "../chart/src/bar/basic/index.mjs";
import "../chart/src/bar/animation/index.mjs";
import "../chart/src/bar/contrast/index.mjs";
import "../chart/src/bar/contrast2/index.mjs";
import "../chart/src/bar/contrast3/index.mjs";
import "../chart/src/bar/gradient-column-chart/index.mjs";
import "../chart/src/bar/horizontal/index.mjs";
import "../chart/src/bar/horizontal-stack/index.mjs";
import "../chart/src/bar/line-bar/index.mjs";
import "../chart/src/bar/line-bar2/index.mjs";
import "../chart/src/bar/loop/index.mjs";
import "../chart/src/bar/mini/index.mjs";
import "../chart/src/bar/polar/index.mjs";
import "../chart/src/bar/polar-stack/index.mjs";
import "../chart/src/bar/polar2/index.mjs";
import "../chart/src/bar/radius-circle/index.mjs";
import "../chart/src/bar/rank/index.mjs";
import "../chart/src/bar/segmented-progress/index.mjs";
import "../chart/src/bar/spire/index.mjs";
import "../chart/src/bar/stack/index.mjs";
import "../chart/src/bar/stack-line/index.mjs";
import "../chart/src/bar/stack2/index.mjs";
import "../chart/src/bar/stack3/index.mjs";
import "../chart/src/bar/staggered/index.mjs";
import "../chart/src/bar/three/index.mjs";
import "../chart/src/bar/waterfall/index.mjs";
import "../chart/src/bar/zebra/index.mjs";
import "../chart/src/line/area-gradient/index.mjs";
import "../chart/src/line/area-highlight/index.mjs";
import "../chart/src/line/area-highlight2/index.mjs";
import "../chart/src/line/basic/index.mjs";
import "../chart/src/line/bump/index.mjs";
import "../chart/src/line/dashed/index.mjs";
import "../chart/src/line/ladder/index.mjs";
import "../chart/src/line/logarithm/index.mjs";
import "../chart/src/line/multix/index.mjs";
import "../chart/src/line/polar-double/index.mjs";
import "../chart/src/line/rain-flow/index.mjs";
import "../chart/src/line/scale/index.mjs";
import "../chart/src/line/smooth/index.mjs";
import "../chart/src/line/smooth-area/index.mjs";
import "../chart/src/line/stack/index.mjs";
import "../chart/src/line/stack-area/index.mjs";
import "../chart/src/line/temp/index.mjs";
import "../chart/src/line/vertical/index.mjs";
import "../chart/src/map/basic/index.mjs";
import "../chart/src/map/bmap-basic/index.mjs";
import "../chart/src/map/bmap-heatmap/index.mjs";
import "../chart/src/map/bmap-rich/index.mjs";
import "../chart/src/map/customize/index.mjs";
import "../chart/src/map/lines/index.mjs";
import "../chart/src/map/scatter/index.mjs";
import "../chart/src/pie/3d/index.mjs";
import "../chart/src/pie/basic/index.mjs";
import "../chart/src/pie/basic2/index.mjs";
import "../chart/src/pie/customized/index.mjs";
import "../chart/src/pie/index/index.mjs";
import "../chart/src/pie/interval/index.mjs";
import "../chart/src/pie/legend-scroll/index.mjs";
import "../chart/src/pie/radius/index.mjs";
import "../chart/src/pie/rose/index.mjs";
import "../chart/src/pie/round/index.mjs";
import "../chart/src/pie/sunburst/index.mjs";
import "../chart/src/scatter/basic/index.mjs";
import "../chart/src/scatter/basic2/index.mjs";
import "../chart/src/scatter/bubble/index.mjs";
import "../chart/src/scatter/ripples/index.mjs";
/* empty css                        */
/* empty css                               */
import "../../plugins/datasource/utils/request.mjs";
import "../../plugins/datasource/utils/wsManager.mjs";
import { SHJParseEvent as oe } from "../../plugins/event/index.mjs";
const se = { class: "zerov-widget" }, re = I({ name: "zv-commons-three-loader" }), _o = /* @__PURE__ */ I({
  ...re,
  props: {
    basicOption: {},
    basicEvents: {},
    useEvents: {}
  },
  emits: [
    "on-load-success",
    "on-play-animation"
  ],
  setup(c, { expose: d, emit: g }) {
    const C = g, n = c, H = (t, r) => {
      const h = P(), L = P(), E = P(!0);
      class W {
        // eslint-disable-next-line no-useless-constructor
        constructor(e) {
          // optional, but needed due to interface definitions
          v(this, "loadingUIBackgroundColor");
          this.loadingUIText = e;
        }
        displayLoadingUI() {
          h.value && (E.value = !0);
        }
        hideLoadingUI() {
          h.value && (E.value = !1);
        }
      }
      class D {
        constructor(e, o, i) {
          v(this, "scene");
          v(this, "engine");
          v(this, "meshe");
          v(this, "defaultPipeline");
          this.canvas = e, this.option = o, this.events = i;
          try {
            this.engine = new j(this.canvas, !0, {}, !1), this.engine.loadingScreen = new W(""), window.addEventListener("resize", () => {
              this.engine.resize();
            }), this.scene = this.createScene();
          } catch {
          }
        }
        createScene() {
          return this.scene = new Q(this.engine), this.option.scene.colorShow ? this.scene.clearColor = S.FromHexString(this.option.scene.color || "#000000") : this.scene.clearColor = new S(0, 0, 0, 0), this.scene.fogEnabled = this.option.scene.fogEnabled, this.scene.fogMode = this.option.scene.fogMode || 1, this.scene.fogColor = y.FromHexString(this.option.scene.fogColor || "#ffffff"), this.scene.fogEnd = this.option.scene.fogEnd || 60, this.scene.fogStart = this.option.scene.fogStart || 1, this.scene.fogDensity = this.option.scene.fogDensity || 0.1, this.createCamera(this.option.camera, this.scene), this.createLights(this.option.lights, this.scene), this.createMeshs(this.scene), this.scene;
        }
        updateScenePipeline(e) {
          this.scene.activeCamera && e && (e.enabled ? (this.defaultPipeline || (this.defaultPipeline = new X(
            "defaultPipeline",
            !0,
            this.scene,
            [this.scene.activeCamera]
          )), this.defaultPipeline.samples = e.samples ? 4 : 1, this.defaultPipeline.fxaaEnabled = e.fxaaEnabled, this.defaultPipeline.grainEnabled = e.grainEnabled, this.defaultPipeline.grain.intensity = e.grainIntensity, this.defaultPipeline.grain.animated = e.grainAnimated, this.defaultPipeline.bloomEnabled = e.bloomEnabled, this.defaultPipeline.bloomThreshold = e.bloomThreshold, this.defaultPipeline.bloomWeight = e.bloomWeight, this.defaultPipeline.bloomKernel = e.bloomKernel, this.defaultPipeline.bloomScale = e.bloomScale, this.defaultPipeline.depthOfFieldEnabled = e.depthOfFieldEnabled, e.depthOfFieldBlurLevel < 1 ? this.defaultPipeline.depthOfFieldBlurLevel = x.Low : e.depthOfFieldBlurLevel < 2 ? this.defaultPipeline.depthOfFieldBlurLevel = x.Medium : e.depthOfFieldBlurLevel < 3 && (this.defaultPipeline.depthOfFieldBlurLevel = x.High), this.defaultPipeline.depthOfField.focusDistance = e.depthOfFieldFocusDistance, this.defaultPipeline.depthOfField.fStop = e.depthOfFieldFStop, this.defaultPipeline.depthOfField.focalLength = e.depthOfFieldFocalLength, this.defaultPipeline.chromaticAberrationEnabled = e.chromaticAberrationEnabled, this.defaultPipeline.chromaticAberration.aberrationAmount = e.chromaticAberrationAberrationAmount, this.defaultPipeline.chromaticAberration.radialIntensity = e.chromaticAberrationRadialIntensity, e.chromaticAberrationDirection === 0 ? (this.defaultPipeline.chromaticAberration.direction.x = 0, this.defaultPipeline.chromaticAberration.direction.y = 0) : (this.defaultPipeline.chromaticAberration.direction.x = Math.sin(e.chromaticAberrationDirection), this.defaultPipeline.chromaticAberration.direction.y = Math.cos(e.chromaticAberrationDirection)), this.defaultPipeline.sharpenEnabled = e.sharpenEnabled, this.defaultPipeline.sharpen.edgeAmount = e.sharpenEdgeAmount, this.defaultPipeline.sharpen.colorAmount = e.sharpenColorAmount) : this.defaultPipeline && (this.defaultPipeline.dispose(), this.defaultPipeline = null));
        }
        updateScene(e) {
          e.colorShow ? this.scene.clearColor = S.FromHexString(e.color || "#000000") : this.scene.clearColor = new S(0, 0, 0, 0), this.scene.fogEnabled = e.fogEnabled, this.scene.fogMode = e.fogMode || 1, this.scene.fogColor = y.FromHexString(e.fogColor || "#ffffff"), this.scene.fogEnd = e.fogEnd || 60, this.scene.fogStart = e.fogStart || 1, this.scene.fogDensity = e.fogDensity || 0.1;
        }
        createCamera(e, o) {
          const i = new Y("", w.ToRadians(e.alpha || 90), w.ToRadians(e.beta || 75), e.radius || 1, new u(...e.target), o);
          i.attachControl(h.value, !0), i.useAutoRotationBehavior = e.autoRotation, i.wheelDeltaPercentage = e.wheelDeltaPercentage || 0.01, i.zoomToMouseLocation = e.zoomToMouseLocation, i.lowerRadiusLimit = e.lowerRadiusLimit, i.upperRadiusLimit = e.upperRadiusLimit, i.minZ = 0.01;
        }
        updateCamera(e) {
          const o = this.scene.activeCamera;
          o && (e.radius && (o.radius = e.radius), o.beta = w.ToRadians(e.beta), o.alpha = w.ToRadians(e.alpha), o.useAutoRotationBehavior = e.autoRotation, o.zoomToMouseLocation = e.zoomToMouseLocation, o.wheelDeltaPercentage = e.wheelDeltaPercentage || 0.01, o.lowerRadiusLimit = e.lowerRadiusLimit, o.upperRadiusLimit = e.upperRadiusLimit, o.target = new u(...e.target));
        }
        createLights(e, o) {
          this.scene && this.scene.lights && this.scene.lights.forEach((i, a) => {
            setTimeout(() => {
              i.dispose();
            });
          }), setTimeout(() => {
            e.forEach((i) => {
              if (i.type === "HemisphericLight") {
                const a = new $("", new u(...i.direction), o);
                a.intensity = i.intensity !== void 0 ? i.intensity : 0.5, a.groundColor = y.FromHexString(i.groundColor || "#ffffff"), a.diffuse = y.FromHexString(i.diffuse || "#ffffff");
              }
              if (i.type === "DirectionalLight") {
                const a = new O("", new u(...i.direction), o);
                a.intensity = i.intensity !== void 0 ? i.intensity : 0.5, a.diffuse = y.FromHexString(i.diffuse || "#ffffff");
              }
              if (i.type === "PointLight") {
                const a = new ee("", new u(...i.position), o);
                a.intensity = i.intensity !== void 0 ? i.intensity : 0.5, a.diffuse = y.FromHexString(i.diffuse || "#ffffff");
              }
            });
          });
        }
        createMeshs(e) {
          e.meshes.forEach((o) => setTimeout(() => o.dispose())), ie.ImportMeshAsync("", this.option.meshs.url, "", e, (o) => {
            L.value = (o.loaded / o.total * 100).toFixed(2);
          }).then((o) => {
            this.meshe = o.meshes, this.updateScenePipeline(this.option.pipelineOption), this.option.animationGroups = e.animationGroups.map((i) => ({
              uniqueId: i.uniqueId,
              name: i.name
            })), this.events && (this.events.function[0].args[0].select = e.animationGroups.map((i) => ({
              name: i.name,
              value: i.name
            }))), this.option.defaultAnimation && this.option.defaultAnimation.name ? this.playAnimation(this.option.defaultAnimation.name, {
              loop: this.option.defaultAnimation.loop,
              speedRatio: this.option.defaultAnimation.speedRatio
            }) : e.animationGroups && e.animationGroups[0] && e.animationGroups[0].stop(), this.setMeshSize(this.option.meshs), setTimeout(() => {
              this.engine.hideLoadingUI(), C("on-load-success"), this.engine.hideLoadingUI();
            }, 100);
          });
        }
        setMeshSize(e) {
          if (e.autoSize) {
            const i = this.meshe[0].getBoundingInfo().boundingBox, b = 0.7 / (Math.max(
              i.maximumWorld.x - i.minimumWorld.x,
              i.maximumWorld.y - i.minimumWorld.y,
              i.maximumWorld.z - i.minimumWorld.z
            ) || 1);
            this.meshe[0].scaling = new u(b, b, b);
            const k = i.centerWorld;
            this.meshe[0].position = this.meshe[0].position.subtract(k.multiplyByFloats(b, b, b)), this.meshe[0].rotation = new u(0, 0, 0);
          } else {
            const { position: o, scaling: i, rotation: a } = e;
            this.meshe[0].position.set(o[0] || 0, o[1] || 0, o[2] || 0), this.meshe[0].scaling.set(i[0] || 1, i[1] || 1, i[2] || 1), this.meshe[0].rotation = new u(a[0] || 0, a[1] || 0, a[2] || 0);
          }
        }
        run() {
          return this.engine.runRenderLoop(() => this.scene.render()), this;
        }
        dispose() {
          this.scene && this.engine && (this.scene.dispose(), this.engine.dispose());
        }
        playAnimation(e, o = {
          loop: !1,
          speedRatio: 1
        }) {
          if (this.scene) {
            this.scene.stopAllAnimations();
            const i = this.scene.getAnimationGroupByName(e);
            i && (C("on-play-animation"), oe.parseEvents(n.useEvents, "on-play-animation"), i.start(o.loop, o.speedRatio, i.from, i.to, !1));
          }
        }
      }
      const f = P();
      return J(() => {
        t.meshs && (f.value = new D(h.value, t, r).run(), te(h.value, (z) => {
          f.value && f.value.engine.resize();
        }));
      }), Z(() => {
        f.value && (f.value.dispose(), f.value.meshe = []);
      }), {
        canvasRef: h,
        babylon: f,
        Babylon: D,
        babylonLoadingStatus: E,
        babylonLoadingTitle: L
      };
    }, { canvasRef: A, babylon: s, Babylon: F, babylonLoadingStatus: B, babylonLoadingTitle: _ } = H(n.basicOption, n.basicEvents);
    return d({
      playAnimation: (t, r) => {
        const h = r[0].value, L = {
          loop: r[1].keys[0].defaultValue,
          speedRatio: r[1].keys[1].defaultValue
        };
        s.value.playAnimation(h, L);
      }
    }), m(() => l(n.basicOption.camera), (t, r) => {
      !p(t, r) && s.value && s.value.updateCamera(t);
    }, {
      deep: !0
    }), m(() => l(n.basicOption.scene), (t, r) => {
      !p(t, r) && s.value && s.value.updateScene(t);
    }, {
      deep: !0
    }), m(() => l(n.basicOption.lights), (t, r) => {
      !p(t, r) && s.value && s.value.createLights(t, s.value.scene);
    }, {
      deep: !0
    }), m(() => l(n.basicOption.meshs.url), (t, r) => {
      !p(t, r) && s.value && (s.value.dispose(), s.value = new F(A.value, n.basicOption, n.basicEvents).run());
    }, {
      deep: !0
    }), m(() => l(n.basicOption.meshs.position), (t, r) => {
      !p(t, r) && s.value && s.value.meshe[0] && s.value.meshe[0].position.set(t[0], t[1], t[2]);
    }, {
      deep: !0
    }), m(() => l(n.basicOption.meshs.scaling), (t, r) => {
      !p(t, r) && s.value && s.value.meshe[0] && s.value.meshe[0].scaling.set(t[0], t[1], t[2]);
    }, {
      deep: !0
    }), m(() => l(n.basicOption.meshs.rotation), (t, r) => {
      !p(t, r) && s.value && s.value.meshe[0] && (s.value.meshe[0].rotation = new u(t[0], t[1], t[2]));
    }, {
      deep: !0
    }), m(() => l(n.basicOption.meshs.autoSize), (t, r) => {
      !p(t, r) && s.value && s.value.meshe[0] && s.value.setMeshSize(n.basicOption.meshs);
    }, {
      deep: !0
    }), m(() => l(n.basicOption.defaultAnimation), (t, r) => {
      !p(t, r) && s.value && (s.value.dispose(), s.value = new F(A.value, n.basicOption, n.basicEvents).run());
    }, {
      deep: !0
    }), m(() => l(n.basicOption.pipelineOption), (t, r) => {
      !p(t, r) && s.value && s.value.updateScenePipeline(t);
    }, {
      deep: !0
    }), (t, r) => (M(), T("div", se, [
      V("canvas", {
        ref_key: "canvasRef",
        ref: A,
        class: N(["widget", { show: !R(B) }])
      }, null, 2),
      R(B) ? (M(), T("div", {
        key: 0,
        ref: "babylonLoadingRef",
        class: "babylon-loading"
      }, " 正在加载模型...(" + K(R(_)) + "%) ", 513)) : q("", !0)
    ]));
  }
});
export {
  _o as default
};
