import { defineComponent as z, computed as q, ref as K, onMounted as N, onBeforeUnmount as W, watch as d, createElementBlock as Y, openBlock as _ } from "vue";
import "@babylonjs/loaders/glTF";
import * as t from "@babylonjs/core";
import { cloneDeep as h, isEqual as f } from "lodash";
/* empty css                                     */
/* empty css                                     */
import "../../../Interaction/components/Tabs/index.mjs";
import "../../../Interaction/components/Tabs-icon/index.mjs";
import "../../../Interaction/components/Button/index.mjs";
import "../../../Interaction/components/DatePicker/index.mjs";
import "../../../Interaction/components/DatePickerRange/index.mjs";
import "../../../Interaction/components/Switch/index.mjs";
import "../../../Interaction/components/Input/index.mjs";
import "../../../Interaction/components/Select/index.mjs";
import "../../../Interaction/components/Slider/index.mjs";
import "../../../Text/components/List/index.mjs";
import "../../../Text/components/Text/index.mjs";
import "../../../Text/components/TextDynamic/index.mjs";
import "../../../Text/components/TableBasic/index.mjs";
import "../../../Text/components/TableScroll/index.mjs";
import "../../../Text/components/RowScroll/index.mjs";
import "../../../Text/components/RealTime/index.mjs";
import "../../../Text/components/OverNumber/index.mjs";
import "../../../Text/components/CountDown/index.mjs";
import "../../../Text/components/TextCarousel/index.mjs";
import "../../../Media/components/Audio/index.mjs";
import "../../../Media/components/Video/index.mjs";
import "../../../Media/components/Carousel/index.mjs";
import "../../../Media/components/Flv/index.mjs";
import "../../../Media/components/Iframe/index.mjs";
import "../../../Media/components/IframeCarousel/index.mjs";
import "../../../Media/components/Image/index.mjs";
import "../../../Media/components/ImageDynamic/index.mjs";
import "../../../Media/components/M3u8/index.mjs";
import "../../../Media/components/Wavesurfer/index.mjs";
import "../../../Media/components/Weather/index.mjs";
import "../../../Media/components/Qrcode/index.mjs";
import "../../../Chart/components/bar/basic/index.mjs";
import "../../../Chart/components/bar/animation/index.mjs";
import "../../../Chart/components/bar/contrast/index.mjs";
import "../../../Chart/components/bar/contrast2/index.mjs";
import "../../../Chart/components/bar/contrast3/index.mjs";
import "../../../Chart/components/bar/gradient-column-chart/index.mjs";
import "../../../Chart/components/bar/horizontal/index.mjs";
import "../../../Chart/components/bar/horizontal-stack/index.mjs";
import "../../../Chart/components/bar/line-bar/index.mjs";
import "../../../Chart/components/bar/line-bar2/index.mjs";
import "../../../Chart/components/bar/loop/index.mjs";
import "../../../Chart/components/bar/mini/index.mjs";
import "../../../Chart/components/bar/polar/index.mjs";
import "../../../Chart/components/bar/polar-stack/index.mjs";
import "../../../Chart/components/bar/polar2/index.mjs";
import "../../../Chart/components/bar/radius-circle/index.mjs";
import "../../../Chart/components/bar/rank/index.mjs";
import "../../../Chart/components/bar/segmented-progress/index.mjs";
import "../../../Chart/components/bar/spire/index.mjs";
import "../../../Chart/components/bar/stack/index.mjs";
import "../../../Chart/components/bar/stack-line/index.mjs";
import "../../../Chart/components/bar/stack2/index.mjs";
import "../../../Chart/components/bar/stack3/index.mjs";
import "../../../Chart/components/bar/staggered/index.mjs";
import "../../../Chart/components/bar/three/index.mjs";
import "../../../Chart/components/bar/waterfall/index.mjs";
import "../../../Chart/components/bar/zebra/index.mjs";
import "../../../Chart/components/line/area-gradient/index.mjs";
import "../../../Chart/components/line/area-highlight/index.mjs";
import "../../../Chart/components/line/area-highlight2/index.mjs";
import "../../../Chart/components/line/basic/index.mjs";
import "../../../Chart/components/line/bump/index.mjs";
import "../../../Chart/components/line/dashed/index.mjs";
import "../../../Chart/components/line/ladder/index.mjs";
import "../../../Chart/components/line/logarithm/index.mjs";
import "../../../Chart/components/line/multix/index.mjs";
import "../../../Chart/components/line/polar-double/index.mjs";
import "../../../Chart/components/line/rain-flow/index.mjs";
import "../../../Chart/components/line/scale/index.mjs";
import "../../../Chart/components/line/smooth/index.mjs";
import "../../../Chart/components/line/smooth-area/index.mjs";
import "../../../Chart/components/line/stack/index.mjs";
import "../../../Chart/components/line/stack-area/index.mjs";
import "../../../Chart/components/line/temp/index.mjs";
import "../../../Chart/components/line/vertical/index.mjs";
import "../../../Chart/components/map/basic/index.mjs";
import "../../../Chart/components/map/bmap-basic/index.mjs";
import "../../../Chart/components/map/bmap-heatmap/index.mjs";
import "../../../Chart/components/map/bmap-rich/index.mjs";
import "../../../Chart/components/map/customize/index.mjs";
import "../../../Chart/components/map/lines/index.mjs";
import "../../../Chart/components/map/scatter/index.mjs";
import "../../../Chart/components/pie/3d/index.mjs";
import "../../../Chart/components/pie/basic/index.mjs";
import "../../../Chart/components/pie/basic2/index.mjs";
import "../../../Chart/components/pie/customized/index.mjs";
import "../../../Chart/components/pie/index/index.mjs";
import "../../../Chart/components/pie/interval/index.mjs";
import "../../../Chart/components/pie/legend-scroll/index.mjs";
import "../../../Chart/components/pie/radius/index.mjs";
import "../../../Chart/components/pie/rose/index.mjs";
import "../../../Chart/components/pie/round/index.mjs";
import "../../../Chart/components/pie/sunburst/index.mjs";
import "../../../Chart/components/scatter/basic/index.mjs";
import "../../../Chart/components/scatter/basic2/index.mjs";
import "../../../Chart/components/scatter/bubble/index.mjs";
import "../../../Chart/components/scatter/ripples/index.mjs";
import "../../../Chart/components/other/candlestick-basic/index.mjs";
import "../../../Chart/components/other/sunburst-basic/index.mjs";
import "../../../Chart/components/other/sunburst-basic2/index.mjs";
import "../../../Chart/components/other/sunburst-basic3/index.mjs";
import "../../../Chart/components/other/sunburst-basic4/index.mjs";
import "../../../Chart/components/other/sunburst-book/index.mjs";
import "../../../Chart/components/other/sunburst-flavors/index.mjs";
import "../../../Chart/components/other/sunburst-radius/index.mjs";
import "../../../Chart/components/other/funnel/index.mjs";
import "../../../Chart/components/other/funnel-contrast/index.mjs";
import "../../../Chart/components/other/funnel-split/index.mjs";
import "../../../Chart/components/other/funnel2/index.mjs";
import "../../../Chart/components/other/force/index.mjs";
import "../../../Chart/components/other/force2/index.mjs";
import "../../../Chart/components/other/gauge/index.mjs";
import "../../../Chart/components/other/gauge-grade/index.mjs";
import "../../../Chart/components/other/gauge-stage/index.mjs";
import "../../../Chart/components/other/graph-basic/index.mjs";
import "../../../Chart/components/other/graph-basic2/index.mjs";
import "../../../Chart/components/other/graph-calendar/index.mjs";
import "../../../Chart/components/other/circular-graph/index.mjs";
import "../../../Chart/components/other/heatmap/index.mjs";
import "../../../Chart/components/other/liquidfill/index.mjs";
import "../../../Chart/components/other/parallel-basic/index.mjs";
import "../../../Chart/components/other/parallel-mul/index.mjs";
import "../../../Chart/components/other/radar-stack/index.mjs";
import "../../../Chart/components/other/tree/index.mjs";
import "../../../Chart/components/other/tree-line/index.mjs";
import "../../../Chart/components/other/word-cloud/index.mjs";
import "../../../Chart/components/other/treemap/index.mjs";
import "../../../Chart/components/other/treemap-basic/index.mjs";
import "../../../Chart/components/other/label-gauge/index.mjs";
import "../../../Chart/components/other/grid-percentage/index.mjs";
import "../../../Chart/components/other/radar/index.mjs";
import "../CustomComponentRender/index.mjs";
import "../Graphical/index.mjs";
import "../Svg/index.mjs";
import "./index.mjs";
import "../VrVideo/index.mjs";
import "../VrPhoto/index.mjs";
import "../Babylon/index.mjs";
import "../Echarts/index.mjs";
import "../GSViewer/index.mjs";
import "../../../Scene/components/Amap2d/index.mjs";
import "../../../Scene/components/Amap3d/index.mjs";
import "../../../Scene/components/Default/index.mjs";
import "../../../Scene/components/Map2d/index.mjs";
import "../../../Scene/components/Map3d/index.mjs";
import "../../../Scene/components/UeIframe/index.mjs";
import "../../../Scene/components/UeShj/index.mjs";
import "../../../Scene/components/UnityIframe/index.mjs";
import "../../../Scene/components/UnityWebgl/index.mjs";
import "../../../Scene/components/Vr/index.mjs";
import "../../../Scene/components/Earth/index.mjs";
import { SHJParseEvent as k } from "../../../../commons/plugins/event/index.mjs";
import "../../../../commons/plugins/datasource/utils/request.mjs";
import "mqtt";
import "nanoid";
import { upgradeModelViewer as j } from "./version.mjs";
const J = z({ name: "ShjModelViewer" }), Ut = /* @__PURE__ */ z({
  ...J,
  props: {
    option: {},
    sources: {},
    useEvents: {},
    basicEvents: {}
  },
  emits: ["on-load-success", "on-play-animation"],
  setup(y, { expose: P, emit: H }) {
    const e = q(() => j(y.option)), E = H;
    let T, o, n, p, v, s, w, g, u, b, l, a;
    const B = () => {
      n || (n = new t.ArcRotateCamera(
        "Camera",
        e.value.camera.alpha,
        e.value.camera.beta,
        e.value.camera.radius,
        new t.Vector3(
          e.value.camera.target[0],
          e.value.camera.target[1],
          e.value.camera.target[2]
        ),
        o
      )), n.alpha = e.value.camera.alpha, n.beta = e.value.camera.beta, n.radius = e.value.camera.radius, n.target = new t.Vector3(
        e.value.camera.target[0],
        e.value.camera.target[1],
        e.value.camera.target[2]
      ), n.lowerRadiusLimit = e.value.camera.lowerRadiusLimit, n.upperRadiusLimit = e.value.camera.upperRadiusLimit, n.lowerBetaLimit = t.Tools.ToRadians(
        e.value.camera.lowerBetaLimit
      ), n.upperBetaLimit = t.Tools.ToRadians(
        e.value.camera.upperBetaLimit
      ), n.useBouncingBehavior = e.value.camera.useBouncingBehavior, n.wheelDeltaPercentage = e.value.camera.wheelDeltaPercentage || 0.01, n.useAutoRotationBehavior = e.value.camera.autoRotation, n.panningSensibility = 1 / (e.value.camera.panningSensibility || 0.01), n.attachControl(A.value, !0);
    }, F = () => {
      o || (o = new t.Scene(T)), o.environmentTexture = t.CubeTexture.CreateFromPrefilteredData(
        e.value.scene.environmentTexture,
        o
      ), o.environmentIntensity = e.value.scene.environmentIntensity, e.value.scene.colorShow ? o.clearColor = t.Color4.FromHexString(
        e.value.scene.color || "#000000"
      ) : o.clearColor = new t.Color4(0, 0, 0, 0), o.fogEnabled = e.value.scene.fogEnabled, o.fogMode = e.value.scene.fogMode || 1, o.fogColor = t.Color3.FromHexString(
        e.value.scene.fogColor || "#ffffff"
      ), o.fogEnd = e.value.scene.fogEnd || 2e3, o.fogStart = e.value.scene.fogStart || 1, o.fogDensity = e.value.scene.fogDensity * 1e-4;
    }, R = () => {
      if (p || (p = new t.DirectionalLight(
        "dirLight",
        new t.Vector3(
          e.value.directionalLight.direction[0],
          e.value.directionalLight.direction[1],
          e.value.directionalLight.direction[2]
        ),
        o
      )), p.direction = new t.Vector3(
        e.value.directionalLight.direction[0],
        e.value.directionalLight.direction[1],
        e.value.directionalLight.direction[2]
      ), p.position = new t.Vector3(
        e.value.directionalLight.position[0],
        e.value.directionalLight.position[1],
        e.value.directionalLight.position[2]
      ), p.diffuse = t.Color3.FromHexString(
        e.value.directionalLight.diffuse || "#ffffff"
      ), p.intensity = e.value.directionalLight.intensity, p.shadowMinZ = e.value.directionalLight.shadowMinZ, p.shadowMaxZ = e.value.directionalLight.shadowMaxZ, p.autoCalcShadowZBounds = e.value.directionalLight.autoCalcShadowZBounds, e.value.directionalLight.shadowGenerator.enable) {
        const { mapSize: i, transparencyShadow: r, usePercentageCloserFiltering: m, bias: c } = e.value.directionalLight.shadowGenerator;
        if (!s && (s = new t.ShadowGenerator(i, p), l))
          for (let L = 0; L < l.length; L++)
            e.value.meshes.isCasterShadow && s && s.addShadowCaster(l[L], !0);
        s.mapSize = i, s.transparencyShadow = r, s.usePercentageCloserFiltering = m, s.bias = c;
      } else
        s && (s.dispose(), s = null);
      e.value.directionalLight.lightGizmo && e.value.directionalLight.lightGizmo.enable ? (v || (v = new t.LightGizmo(), v.light = p), v.scaleRatio = e.value.directionalLight.lightGizmo.scaleRatio) : v && (v.dispose(), v = null);
    }, G = () => {
      w || (w = new t.HemisphericLight(
        "light",
        new t.Vector3(
          e.value.hemisphericLight.direction[0],
          e.value.hemisphericLight.direction[1],
          e.value.hemisphericLight.direction[2]
        ),
        o
      )), w.direction = new t.Vector3(
        e.value.hemisphericLight.direction[0],
        e.value.hemisphericLight.direction[1],
        e.value.hemisphericLight.direction[2]
      ), w.intensity = e.value.hemisphericLight.intensity, w.diffuse = t.Color3.FromHexString(
        e.value.hemisphericLight.diffuse || "#ffffff"
      ), e.value.hemisphericLight.lightGizmo && e.value.hemisphericLight.lightGizmo.enable ? (g || (g = new t.LightGizmo(), g.light = w), g.scaleRatio = e.value.hemisphericLight.lightGizmo.scaleRatio) : g && (g.dispose(), g = null);
    }, O = () => {
      if (e.value.ground.enable) {
        const {
          width: i,
          height: r,
          position: m,
          rotation: c,
          scaling: L,
          material: C,
          receiveShadows: Z
        } = e.value.ground;
        u || (u = t.MeshBuilder.CreateGround(
          "ground",
          { width: i, height: r },
          o
        )), u.position = new t.Vector3(
          m[0],
          m[1],
          m[2]
        ), u.rotation = new t.Vector3(
          t.Tools.ToRadians(c[0]),
          t.Tools.ToRadians(c[1]),
          t.Tools.ToRadians(c[2])
        ), u.scaling = new t.Vector3(L[0], L[1], L[2]);
        const x = new t.StandardMaterial("", o);
        x.emissiveTexture = new t.Texture(
          C.emissiveTexture,
          o
        ), x.diffuseTexture = new t.Texture(
          C.emissiveTexture,
          o
        ), x.ambientTexture = new t.Texture(
          C.emissiveTexture,
          o
        ), x.diffuseColor = new t.Color3(1, 1, 1), x.opacityTexture = new t.Texture(
          C.opacityTexture,
          o
        ), u.material = x, u.receiveShadows = Z;
      } else
        u && (u.dispose(), u = null);
    }, M = () => {
      if (e.value.skybox.enable) {
        const { size: i } = e.value.skybox;
        b || (b = t.MeshBuilder.CreateBox("skyBox", { size: i }, o));
        const r = new t.StandardMaterial("skyBox", o);
        r.backFaceCulling = !1, r.reflectionTexture = t.CubeTexture.CreateFromPrefilteredData(
          e.value.scene.environmentTexture,
          o
        ), r.reflectionTexture.coordinatesMode = t.Texture.SKYBOX_MODE, r.diffuseColor = new t.Color3(1, 1, 1), r.specularColor = new t.Color3(1, 1, 1), r.disableLighting = !0, b.material = r, b.isPickable = !1;
      } else
        b && (b.dispose(), b = null);
    }, D = (i, r = {
      loop: !1,
      speedRatio: 1
    }) => {
      if (o) {
        o.stopAllAnimations();
        const m = o.getAnimationGroupByName(i);
        m && (E("on-play-animation"), k.parseEvents(y.useEvents, "on-play-animation"), m.start(
          r.loop,
          r.speedRatio,
          m.from,
          m.to,
          !1
        ));
      }
    }, S = async () => {
      l || (l = (await t.ImportMeshAsync(
        e.value.meshes.url,
        o
      )).meshes), l[0].position = new t.Vector3(
        e.value.meshes.position[0],
        e.value.meshes.position[1],
        e.value.meshes.position[2]
      ), l[0].scaling = new t.Vector3(
        e.value.meshes.scaling[0],
        e.value.meshes.scaling[1],
        e.value.meshes.scaling[2]
      ), l[0].rotation = new t.Vector3(
        t.Tools.ToRadians(e.value.meshes.rotation[0]),
        t.Tools.ToRadians(e.value.meshes.rotation[1]),
        t.Tools.ToRadians(e.value.meshes.rotation[2])
      );
      for (let i = 0; i < l.length; i++)
        l[i].isPickable = !1, l[i].receiveShadows = e.value.meshes.isCasterShadow, e.value.meshes.isCasterShadow && s && s.addShadowCaster(l[i], !0);
      e.value.animation.animationGroups = o.animationGroups.map((i) => ({ uniqueId: i.uniqueId, name: i.name })), y.basicEvents && (y.basicEvents.function[0].args[0].select = o.animationGroups.map(
        (i) => ({ name: i.name, value: i.name })
      )), e.value.animation.defaultAnimation && e.value.animation.defaultAnimation.name ? D(e.value.animation.defaultAnimation.name, {
        loop: e.value.animation.defaultAnimation.loop,
        speedRatio: e.value.animation.defaultAnimation.speedRatio
      }) : o.animationGroups && o.animationGroups[0] && o.animationGroups[0].stop();
    }, V = () => {
      const i = e.value.pipelineOption;
      i && i.enabled ? (a || (a = new t.DefaultRenderingPipeline(
        "defaultPipeline",
        !0,
        o,
        [n]
      )), a.samples = i.samples ? 4 : 1, a.fxaaEnabled = i.fxaaEnabled, a.grainEnabled = i.grainEnabled, a.grain.intensity = i.grainIntensity, a.grain.animated = i.grainAnimated, a.bloomEnabled = i.bloomEnabled, a.bloomThreshold = i.bloomThreshold, a.bloomWeight = i.bloomWeight, a.bloomKernel = i.bloomKernel, a.bloomScale = i.bloomScale, a.depthOfFieldEnabled = i.depthOfFieldEnabled, i.depthOfFieldBlurLevel < 1 ? a.depthOfFieldBlurLevel = t.DepthOfFieldEffectBlurLevel.Low : i.depthOfFieldBlurLevel < 2 ? a.depthOfFieldBlurLevel = t.DepthOfFieldEffectBlurLevel.Medium : i.depthOfFieldBlurLevel < 3 && (a.depthOfFieldBlurLevel = t.DepthOfFieldEffectBlurLevel.High), a.depthOfField.focusDistance = i.depthOfFieldFocusDistance, a.depthOfField.fStop = i.depthOfFieldFStop, a.depthOfField.focalLength = i.depthOfFieldFocalLength, a.chromaticAberrationEnabled = i.chromaticAberrationEnabled, a.chromaticAberration.aberrationAmount = i.chromaticAberrationAberrationAmount, a.chromaticAberration.radialIntensity = i.chromaticAberrationRadialIntensity, i.chromaticAberrationDirection === 0 ? (a.chromaticAberration.direction.x = 0, a.chromaticAberration.direction.y = 0) : (a.chromaticAberration.direction.x = Math.sin(
        i.chromaticAberrationDirection
      ), a.chromaticAberration.direction.y = Math.cos(
        i.chromaticAberrationDirection
      )), a.sharpenEnabled = i.sharpenEnabled, a.sharpen.edgeAmount = i.sharpenEdgeAmount, a.sharpen.colorAmount = i.sharpenColorAmount) : a && (a.dispose(), a = null);
    }, I = function() {
      F(), B(), G(), R(), O(), M(), S(), V(), E("on-load-success"), k.parseEvents(y.useEvents, "on-load-success");
    }, A = K();
    return N(() => {
      T = new t.Engine(A.value, !0), T && e.value.meshes.url && (I(), T.runRenderLoop(function() {
        o && o.render();
      }));
    }), W(() => {
      o.dispose(), T.dispose();
    }), P({
      playAnimation: (i, r) => {
        const m = r[0].value, c = {
          loop: r[1].keys[0].defaultValue,
          speedRatio: r[1].keys[1].defaultValue
        };
        D(m, c);
      }
    }), d(
      () => h(e.value.camera),
      (i, r) => {
        !f(i, r) && n && B();
      },
      {
        deep: !0
      }
    ), d(
      () => h(e.value.scene),
      (i, r) => {
        !f(i, r) && o && F();
      },
      {
        deep: !0
      }
    ), d(
      () => h(e.value.directionalLight),
      (i, r) => {
        f(i, r) || R();
      },
      {
        deep: !0
      }
    ), d(
      () => h(e.value.hemisphericLight),
      (i, r) => {
        f(i, r) || G();
      },
      {
        deep: !0
      }
    ), d(
      () => h(e.value.ground),
      (i, r) => {
        f(i, r) || O();
      },
      {
        deep: !0
      }
    ), d(
      () => h(e.value.skybox),
      (i, r) => {
        f(i, r) || M();
      },
      {
        deep: !0
      }
    ), d(
      () => h(e.value.meshes),
      (i, r) => {
        !f(i, r) && l && i.url === r.url && S();
      },
      {
        deep: !0
      }
    ), d(
      () => h(e.value.meshes.url),
      (i, r) => {
        f(i, r) || (o.meshes.forEach((m, c) => {
          c > 1 && m.dispose();
        }), l = null, S());
      },
      {
        deep: !0
      }
    ), d(
      () => h(e.value.pipelineOption),
      (i, r) => {
        f(i, r) || V();
      },
      {
        deep: !0
      }
    ), (i, r) => (_(), Y("canvas", {
      ref_key: "canvasRef",
      ref: A,
      class: "babylon-canvas"
    }, null, 512));
  }
});
export {
  Ut as default
};
