"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = exports.DEFAULT_CAMERA_STATE = void 0;
var _react = _interopRequireWildcard(require("react"));
var React = _react;
var THREE = _interopRequireWildcard(require("three"));
var _GLTFLoader = require("three/examples/jsm/loaders/GLTFLoader");
var _OrbitControls = require("three/examples/jsm/controls/OrbitControls");
require("./index.scss");
var _lightGroup = _interopRequireDefault(require("./scene/light-group"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
/* eslint-disable @typescript-eslint/no-unused-vars */

var DEFAULT_CAMERA_STATE = exports.DEFAULT_CAMERA_STATE = {
  distance: 20,
  perspective: true,
  phi: 60,
  target: [0, 0, 0],
  targetOffset: [0, 0, 0],
  targetOrientation: [0, 0, 0, 1],
  thetaOffset: 45,
  fovy: 45,
  near: 0.5,
  far: 2000
};
var Three = function Three(props) {
  console.log('=======');
  console.log(props);
  var _props$style = props.style,
    style = _props$style === void 0 ? {} : _props$style;
  var canvasRef = (0, _react.useRef)(null);
  // 场景
  var currentScene = (0, _react.useRef)();

  // 模型的缩放比例
  var CAR_SCALE = 0.012;
  (0, _react.useEffect)(function () {
    setTimeout(function () {
      init();
    }, 1000);
  }, []);
  var init = function init() {
    var scene = new THREE.Scene();
    scene.background = new THREE.Color(0xade1fe);
    var width = canvasRef.current.offsetWidth;
    var height = canvasRef.current.offsetHeight;

    // 创建相机
    var camera = new THREE.PerspectiveCamera(DEFAULT_CAMERA_STATE.fovy, width / height);
    camera.position.set(15, 8, 5);
    camera.lookAt(0, 0, 0);

    // 创建渲染器
    var renderer = new THREE.WebGLRenderer({
      canvas: canvasRef.current,
      antialias: true
    });
    renderer.setSize(width, height);

    // 灯光
    var lightGroup = new _lightGroup["default"]();
    scene.add(lightGroup.getLightGroup());
    var controls = new _OrbitControls.OrbitControls(camera, canvasRef.current);
    controls.enableDamping = true;
    controls.dampingFactor = 0.25;
    controls.screenSpacePanning = false;
    controls.keyPanSpeed = 20.0;

    // 加载 glb 模型
    var loader = new _GLTFLoader.GLTFLoader().setPath('');
    loader.load('http://static.ks.x/kernelsoft-lowcode-material@0.1.1-alpha2/kernelSoftCar.glb', function (gltf) {
      gltf.scene.children[0].scale.set(CAR_SCALE, CAR_SCALE, CAR_SCALE);
      scene.add(gltf.scene.children[0]);
    });

    // 渲染循环
    function animate() {
      requestAnimationFrame(animate);
      // 更新控制器
      controls.update();
      renderer.render(scene, camera);
    }
    animate();
    currentScene.current = scene;
  };
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("canvas", {
    ref: canvasRef,
    className: "three-material",
    style: style
  }));
};
Three.displayName = 'Three';
var _default = exports["default"] = Three;