@anov/3d 0.0.4-alpha14 → 0.0.4-alpha15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,31 @@
1
+ import Anov3D from './index';
1
2
  declare type ApplicationOptions = {
2
3
  el: HTMLElement;
3
4
  };
5
+ export declare type InitOptions = {
6
+ camera?: {
7
+ fov?: number;
8
+ near?: number;
9
+ far?: number;
10
+ position?: {
11
+ x: number;
12
+ y: number;
13
+ z: number;
14
+ };
15
+ lookAt?: {
16
+ x: number;
17
+ y: number;
18
+ z: number;
19
+ };
20
+ };
21
+ size?: {
22
+ width: number;
23
+ height: number;
24
+ };
25
+ };
4
26
  declare class Application {
5
27
  private container;
6
- private iEngine;
28
+ iEngine: Anov3D | undefined;
7
29
  constructor(opts: ApplicationOptions);
8
30
  private init;
9
31
  sendMessage(req: {
@@ -1,4 +1,6 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2
4
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
5
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
6
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -6,10 +8,10 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
6
8
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
9
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
10
  import { utils } from '@anov/3d-core';
9
- import { getFnByFnkey } from "./utils/index";
11
+ import { getFnByFnkey, object2Vector3 } from "./utils/index";
10
12
  import { MessageType, sendToMessage } from "./utils/messageFn";
11
13
  import { EMessageStatus } from "./messageStatus";
12
- import Anov3D from "./index";
14
+ import Anov3D, { defaultCameraParams } from "./index";
13
15
  var Application = /*#__PURE__*/function () {
14
16
  function Application(opts) {
15
17
  _classCallCheck(this, Application);
@@ -22,30 +24,41 @@ var Application = /*#__PURE__*/function () {
22
24
  key: "init",
23
25
  value: function init(params, id) {
24
26
  try {
25
- var _params$size$width, _params$size, _params$size$height, _params$size2;
27
+ var _camera$fov, _camera$near, _camera$far, _camera$position, _camera$lookAt, _params$size$width, _params$size, _params$size$height, _params$size2;
28
+ var _ref = params || {},
29
+ _ref$camera = _ref.camera,
30
+ camera = _ref$camera === void 0 ? {} : _ref$camera;
31
+ var cameraParams = {
32
+ fov: (_camera$fov = camera.fov) !== null && _camera$fov !== void 0 ? _camera$fov : defaultCameraParams.fov,
33
+ near: (_camera$near = camera.near) !== null && _camera$near !== void 0 ? _camera$near : defaultCameraParams.near,
34
+ far: (_camera$far = camera.far) !== null && _camera$far !== void 0 ? _camera$far : defaultCameraParams.far,
35
+ position: object2Vector3((_camera$position = camera.position) !== null && _camera$position !== void 0 ? _camera$position : defaultCameraParams.position),
36
+ lookAt: object2Vector3((_camera$lookAt = camera.lookAt) !== null && _camera$lookAt !== void 0 ? _camera$lookAt : defaultCameraParams.lookAt)
37
+ };
26
38
  var anov3D = new Anov3D({
27
39
  container: this.container,
28
40
  size: {
29
41
  width: (_params$size$width = params === null || params === void 0 ? void 0 : (_params$size = params.size) === null || _params$size === void 0 ? void 0 : _params$size.width) !== null && _params$size$width !== void 0 ? _params$size$width : this.container.clientWidth,
30
42
  height: (_params$size$height = params === null || params === void 0 ? void 0 : (_params$size2 = params.size) === null || _params$size2 === void 0 ? void 0 : _params$size2.height) !== null && _params$size$height !== void 0 ? _params$size$height : this.container.clientHeight
31
- }
43
+ },
44
+ camera: _objectSpread({}, cameraParams)
32
45
  });
33
46
  this.iEngine = anov3D;
34
- sendToMessage(MessageType.Api, 'Core.init', EMessageStatus.Success, id);
47
+ sendToMessage(MessageType.Api, 'core.init', EMessageStatus.Success, id);
35
48
  } catch (error) {
36
- sendToMessage(MessageType.Api, 'Core.init', EMessageStatus.EventHandleFailed);
49
+ sendToMessage(MessageType.Api, 'core.init', EMessageStatus.EventHandleFailed);
37
50
  }
38
51
  }
39
52
  }, {
40
53
  key: "sendMessage",
41
54
  value: function sendMessage(req) {
42
- if (req.name === 'Core.init') {
55
+ if (req.name === 'Core.init' || req.name === 'core.init') {
43
56
  this.init(req.params, req.id);
44
57
  return;
45
58
  }
46
59
  if (!this.iEngine) throw new Error('please init first');
60
+ var fn = getFnByFnkey(this.iEngine, req.name, req.id);
47
61
  try {
48
- var fn = getFnByFnkey(this.iEngine, req.name);
49
62
  var res = fn(req.params);
50
63
  sendToMessage(MessageType.Api, req.name, EMessageStatus.Success, req.id, res);
51
64
  } catch (error) {
@@ -5,6 +5,12 @@ var registerHooks = function registerHooks() {
5
5
  // console.log('场景编译完成', scene)
6
6
  });
7
7
 
8
+ // 事件
9
+ utils.emitter.on('event', function (res) {
10
+ var eventBus = utils.storeManagement.get('event-bus');
11
+ if (eventBus && eventBus.eventMap.get(res.name)) utils.emitter.emit('message', res);
12
+ });
13
+
8
14
  // 应用sdk
9
15
  utils.emitter.on('message', function (res) {
10
16
  var _utils$storeManagemen;
package/dist/index.d.ts CHANGED
@@ -1,18 +1,39 @@
1
1
  import { SceneControl } from '@anov/3d-core';
2
- import Environment from './environment';
3
- import { EWeatherType } from './environment/weather/type';
2
+ import Environment from './module/environment';
3
+ import EventBus from './module/eventBus';
4
+ import Camera from './module/camera';
5
+ import { EWeatherType } from './module/environment/weather/type';
6
+ import type { InitOptions } from './applicationApi';
4
7
  declare type Anov3DOptions = {
5
8
  container: HTMLElement;
6
9
  size?: {
7
10
  width: number;
8
11
  height: number;
9
12
  };
13
+ camera?: InitOptions['camera'];
14
+ };
15
+ export declare const defaultCameraParams: {
16
+ fov: number;
17
+ near: number;
18
+ far: number;
19
+ position: {
20
+ x: number;
21
+ y: number;
22
+ z: number;
23
+ };
24
+ lookAt: {
25
+ x: number;
26
+ y: number;
27
+ z: number;
28
+ };
10
29
  };
11
30
  declare class Anov3D {
12
31
  private opts;
13
32
  sceneControl: SceneControl;
14
- Environment: Environment;
33
+ environment: Environment;
34
+ eventBus: EventBus;
15
35
  EWeatherType: typeof EWeatherType;
36
+ camera: Camera;
16
37
  constructor(opts: Anov3DOptions);
17
38
  }
18
39
  export { createInstance } from './applicationApi';
package/dist/index.js CHANGED
@@ -1,42 +1,77 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2
4
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
3
5
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
6
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
7
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
8
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
9
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
- import { SceneControl, Vector3, utils } from '@anov/3d-core';
9
- import Environment from "./environment";
10
- import { EWeatherType } from "./environment/weather/type";
10
+ import { SceneControl, utils } from '@anov/3d-core';
11
+ import Environment from "./module/environment";
12
+ import EventBus from "./module/eventBus";
13
+ import Camera from "./module/camera";
14
+ import { EWeatherType } from "./module/environment/weather/type";
11
15
  import registerHooks from "./hooksManager";
16
+ import { object2Vector3 } from "./utils/index";
17
+ export var defaultCameraParams = {
18
+ fov: 45,
19
+ near: 0.1,
20
+ far: 1000000,
21
+ position: {
22
+ x: 0,
23
+ y: 100,
24
+ z: 200
25
+ },
26
+ lookAt: {
27
+ x: 0,
28
+ y: 0,
29
+ z: 0
30
+ }
31
+ };
12
32
  var Anov3D = /*#__PURE__*/_createClass(function Anov3D(opts) {
13
- var _opts$size$width, _opts$size, _opts$size$height, _opts$size2;
33
+ var _camera$fov, _camera$near, _camera$far, _camera$position, _opts$size$width, _opts$size, _opts$size$height, _opts$size2, _opts$size$width2, _opts$size3, _opts$size$height2, _opts$size4, _opts$camera, _scene$controls, _camera$lookAt;
14
34
  _classCallCheck(this, Anov3D);
15
35
  _defineProperty(this, "opts", void 0);
16
36
  _defineProperty(this, "sceneControl", void 0);
17
- _defineProperty(this, "Environment", void 0);
37
+ _defineProperty(this, "environment", void 0);
38
+ _defineProperty(this, "eventBus", void 0);
18
39
  _defineProperty(this, "EWeatherType", EWeatherType);
40
+ _defineProperty(this, "camera", void 0);
19
41
  this.opts = opts;
42
+ var _ref = opts || {},
43
+ _ref$camera = _ref.camera,
44
+ camera = _ref$camera === void 0 ? {} : _ref$camera;
45
+ var cameraParams = {
46
+ fov: (_camera$fov = camera.fov) !== null && _camera$fov !== void 0 ? _camera$fov : defaultCameraParams.fov,
47
+ near: (_camera$near = camera.near) !== null && _camera$near !== void 0 ? _camera$near : defaultCameraParams.near,
48
+ far: (_camera$far = camera.far) !== null && _camera$far !== void 0 ? _camera$far : defaultCameraParams.far,
49
+ position: object2Vector3((_camera$position = camera.position) !== null && _camera$position !== void 0 ? _camera$position : defaultCameraParams.position)
50
+ };
20
51
  var scene = new SceneControl({
21
52
  orbitControls: true,
22
- defCameraOps: {
23
- position: new Vector3(0, 100, 2000),
24
- far: 1000000
25
- },
53
+ defCameraOps: _objectSpread({
54
+ aspect: ((_opts$size$width = opts === null || opts === void 0 ? void 0 : (_opts$size = opts.size) === null || _opts$size === void 0 ? void 0 : _opts$size.width) !== null && _opts$size$width !== void 0 ? _opts$size$width : opts.container.clientWidth) / ((_opts$size$height = opts === null || opts === void 0 ? void 0 : (_opts$size2 = opts.size) === null || _opts$size2 === void 0 ? void 0 : _opts$size2.height) !== null && _opts$size$height !== void 0 ? _opts$size$height : opts.container.clientHeight)
55
+ }, cameraParams),
26
56
  rendererOps: {
27
57
  shadowMap: true,
28
58
  size: {
29
- width: (_opts$size$width = opts === null || opts === void 0 ? void 0 : (_opts$size = opts.size) === null || _opts$size === void 0 ? void 0 : _opts$size.width) !== null && _opts$size$width !== void 0 ? _opts$size$width : opts.container.clientWidth,
30
- height: (_opts$size$height = opts === null || opts === void 0 ? void 0 : (_opts$size2 = opts.size) === null || _opts$size2 === void 0 ? void 0 : _opts$size2.height) !== null && _opts$size$height !== void 0 ? _opts$size$height : opts.container.clientHeight
59
+ width: (_opts$size$width2 = opts === null || opts === void 0 ? void 0 : (_opts$size3 = opts.size) === null || _opts$size3 === void 0 ? void 0 : _opts$size3.width) !== null && _opts$size$width2 !== void 0 ? _opts$size$width2 : opts.container.clientWidth,
60
+ height: (_opts$size$height2 = opts === null || opts === void 0 ? void 0 : (_opts$size4 = opts.size) === null || _opts$size4 === void 0 ? void 0 : _opts$size4.height) !== null && _opts$size$height2 !== void 0 ? _opts$size$height2 : opts.container.clientHeight
31
61
  }
32
62
  },
33
63
  reset: true,
34
64
  ambientLight: true
35
65
  });
36
66
  scene.render(opts.container);
67
+ console.log((_opts$camera = opts.camera) === null || _opts$camera === void 0 ? void 0 : _opts$camera.lookAt);
68
+ (_scene$controls = scene.controls) === null || _scene$controls === void 0 ? void 0 : _scene$controls.target.copy(object2Vector3((_camera$lookAt = camera.lookAt) !== null && _camera$lookAt !== void 0 ? _camera$lookAt : defaultCameraParams.lookAt));
37
69
  utils.emitter.emit('scene-completed', scene);
38
70
  this.sceneControl = scene;
39
- this.Environment = new Environment();
71
+ this.environment = new Environment();
72
+ this.eventBus = new EventBus();
73
+ this.camera = new Camera(scene.camera, scene.controls);
74
+ utils.storeManagement.set('event-bus', this.eventBus);
40
75
  });
41
76
  registerHooks();
42
77
  export { createInstance } from "./applicationApi";
@@ -0,0 +1,48 @@
1
+ import type { OrbitControls, PerspectiveCamera } from '@anov/3d-core';
2
+ declare type vector3Array = [number, number, number];
3
+ declare class Camera {
4
+ private camera;
5
+ private controls;
6
+ constructor(camera: PerspectiveCamera, controls: OrbitControls);
7
+ /**
8
+ * caclCurrentPos
9
+ * @param currentPos
10
+ * @returns
11
+ */
12
+ private caclCurrentPos;
13
+ /**
14
+ * focus On Position
15
+ * @param params
16
+ */
17
+ focusOnPosition(params: {
18
+ position: vector3Array | vector3Array[];
19
+ pitch?: number;
20
+ duration?: number;
21
+ }): void;
22
+ /**
23
+ * set camera
24
+ * @param params
25
+ */
26
+ setCamera(params: {
27
+ position: vector3Array;
28
+ target: vector3Array;
29
+ isTrigger?: boolean;
30
+ duration?: number;
31
+ }): void;
32
+ /**
33
+ * get Camera info
34
+ * @returns
35
+ */
36
+ getCamera(): {
37
+ position: number[];
38
+ target: number[];
39
+ };
40
+ /**
41
+ * interpolation move camera
42
+ * @param position
43
+ * @param target
44
+ * @param options
45
+ */
46
+ private moveCameraTo;
47
+ }
48
+ export default Camera;
@@ -0,0 +1,153 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ import { Box3, Vector3 } from '@anov/3d-core';
9
+ import * as TWEEN from '@tweenjs/tween.js';
10
+ import { MessageType, sendToMessage } from "../../utils/messageFn";
11
+ import { EMessageStatus } from "../../messageStatus";
12
+ var Camera = /*#__PURE__*/function () {
13
+ function Camera(camera, controls) {
14
+ _classCallCheck(this, Camera);
15
+ _defineProperty(this, "camera", void 0);
16
+ _defineProperty(this, "controls", void 0);
17
+ this.camera = camera;
18
+ this.controls = controls;
19
+ }
20
+
21
+ /**
22
+ * caclCurrentPos
23
+ * @param currentPos
24
+ * @returns
25
+ */
26
+ _createClass(Camera, [{
27
+ key: "caclCurrentPos",
28
+ value: function caclCurrentPos(currentPos) {
29
+ var box = new Box3();
30
+ box.setFromPoints(currentPos.map(function (item) {
31
+ return new Vector3(item[0], item[1], item[2]);
32
+ }));
33
+ var center = box.getCenter(new Vector3());
34
+ var size = box.getSize(new Vector3());
35
+ var maxDim = Math.max(size.x, size.y, size.z) / 2;
36
+ var maxDistance = maxDim / Math.tan(this.camera.fov / 2 * Math.PI / 180);
37
+ var cameraToCenterDistance = maxDistance * 2;
38
+ var directionVector = this.camera.position.clone().sub(center).normalize(); // 相机指向物体中心的向量
39
+
40
+ var lastPosition = directionVector.multiplyScalar(cameraToCenterDistance).add(center);
41
+ var lastLookat = center;
42
+ return {
43
+ lastPosition: lastPosition,
44
+ lastLookat: lastLookat
45
+ };
46
+ }
47
+
48
+ /**
49
+ * focus On Position
50
+ * @param params
51
+ */
52
+ }, {
53
+ key: "focusOnPosition",
54
+ value: function focusOnPosition(params) {
55
+ var position = params.position,
56
+ pitch = params.pitch,
57
+ duration = params.duration;
58
+ if (Array.isArray(position[0])) {
59
+ var _ref;
60
+ var currentPos = position;
61
+ var _this$caclCurrentPos = this.caclCurrentPos(currentPos),
62
+ lastPosition = _this$caclCurrentPos.lastPosition,
63
+ lastLookat = _this$caclCurrentPos.lastLookat;
64
+ this.moveCameraTo(lastPosition, lastLookat, {
65
+ duration: (_ref = duration && duration * 1000) !== null && _ref !== void 0 ? _ref : 1000
66
+ });
67
+ } else {
68
+ var _currentPos = position;
69
+
70
+ // this.moveCameraTo(this.camera.position, new Vector3(currentPos[0], currentPos[1], currentPos[2]), { duration: (duration && duration * 1000) ?? 1000 })
71
+ this.controls.target.copy(new Vector3(_currentPos[0], _currentPos[1], _currentPos[2]));
72
+ }
73
+ }
74
+
75
+ /**
76
+ * set camera
77
+ * @param params
78
+ */
79
+ }, {
80
+ key: "setCamera",
81
+ value: function setCamera(params) {
82
+ var _ref2;
83
+ this.moveCameraTo(new Vector3(params.position[0], params.position[1], params.position[2]), new Vector3(params.target[0], params.target[1], params.target[2]), {
84
+ duration: (_ref2 = params.duration && params.duration * 1000) !== null && _ref2 !== void 0 ? _ref2 : 1000,
85
+ onUpdate: function onUpdate(_ref3) {
86
+ var position = _ref3.position,
87
+ lookat = _ref3.lookat;
88
+ params.isTrigger && sendToMessage(MessageType.Event, 'onCameraChanged', EMessageStatus.Success, undefined, {
89
+ position: [position.x, position.y, position.z],
90
+ target: [lookat.x, lookat.y, lookat.z]
91
+ });
92
+ }
93
+ });
94
+ }
95
+
96
+ /**
97
+ * get Camera info
98
+ * @returns
99
+ */
100
+ }, {
101
+ key: "getCamera",
102
+ value: function getCamera() {
103
+ return {
104
+ position: [this.camera.position.x, this.camera.position.y, this.camera.position.z],
105
+ target: [this.controls.target.x, this.controls.target.y, this.controls.target.z]
106
+ };
107
+ }
108
+
109
+ /**
110
+ * interpolation move camera
111
+ * @param position
112
+ * @param target
113
+ * @param options
114
+ */
115
+ }, {
116
+ key: "moveCameraTo",
117
+ value: function moveCameraTo(position, target, options) {
118
+ var _this = this;
119
+ var currentPoition = this.camera.position.clone();
120
+ var currentPositionInterpolation = new Vector3();
121
+ if ((options === null || options === void 0 ? void 0 : options.duration) === 0) {
122
+ this.camera.position.copy(position);
123
+ this.controls.target.copy(target);
124
+ return;
125
+ }
126
+ new TWEEN.Tween({
127
+ t: 0,
128
+ lookat: this.controls.target.clone()
129
+ }).to({
130
+ t: 1,
131
+ lookat: target
132
+ }, (options === null || options === void 0 ? void 0 : options.duration) || 1000).onStart(function () {
133
+ (options === null || options === void 0 ? void 0 : options.onStart) && options.onStart();
134
+ _this.controls.enabled = false;
135
+ }).easing(TWEEN.Easing.Quadratic.InOut).onUpdate(function (_ref4) {
136
+ var t = _ref4.t,
137
+ lookat = _ref4.lookat;
138
+ _this.controls.target.copy(lookat);
139
+ var currentPosition = currentPositionInterpolation.lerpVectors(currentPoition, position, t);
140
+ _this.camera.position.copy(currentPosition);
141
+ (options === null || options === void 0 ? void 0 : options.onUpdate) && options.onUpdate({
142
+ position: currentPosition,
143
+ lookat: lookat
144
+ });
145
+ }).onComplete(function () {
146
+ (options === null || options === void 0 ? void 0 : options.onComplate) && options.onComplate();
147
+ _this.controls.enabled = true;
148
+ }).start();
149
+ }
150
+ }]);
151
+ return Camera;
152
+ }();
153
+ export default Camera;
@@ -14,7 +14,9 @@ declare class Environment {
14
14
  setTime(params: {
15
15
  newTime: number;
16
16
  duration?: number;
17
- }): void;
17
+ }): {
18
+ newTime: number;
19
+ };
18
20
  /**
19
21
  * setWeather
20
22
  * @param type
@@ -11,7 +11,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
11
11
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
12
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
13
13
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
14
- import { Rain as _Rain, Snow as _Snow, createSkyCloud } from '@anov/3d-utils';
14
+ import { Rain as _Rain, Snow as _Snow, createSkyCloud } from '@anov/3d-ability';
15
15
  import createTimeSkySystem from "./time";
16
16
  var Environment = /*#__PURE__*/function () {
17
17
  function Environment() {
@@ -57,7 +57,6 @@ var Environment = /*#__PURE__*/function () {
57
57
  sky = _createTimeSkySystem2[2];
58
58
  this.setDate = setDate;
59
59
  this.sky = sky;
60
- console.log(sky);
61
60
  }
62
61
  _createClass(Environment, [{
63
62
  key: "setTime",
@@ -73,6 +72,9 @@ var Environment = /*#__PURE__*/function () {
73
72
  date.setHours(0, 0, 0, 0);
74
73
  date.setTime(date.getTime() + Math.floor(86400000 * params.newTime / 2400));
75
74
  this.setDate(date);
75
+ return {
76
+ newTime: params.newTime
77
+ };
76
78
  }
77
79
 
78
80
  /**
@@ -4,7 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
5
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import { createSkySystem } from '@anov/3d-utils';
7
+ import { createSkySystem } from '@anov/3d-ability';
8
8
 
9
9
  /**
10
10
  * create time sky system
@@ -2,11 +2,19 @@
2
2
  * notes: 区别于前端概念,3端统一API特定
3
3
  */
4
4
  declare class EventBus {
5
+ eventMap: Map<string, boolean>;
5
6
  constructor();
6
- addEventListener(params: {
7
+ /**
8
+ * open event
9
+ * @param params
10
+ */
11
+ on(params: {
12
+ eventName: string;
13
+ entityId?: string;
14
+ }): void;
15
+ off(params: {
7
16
  eventName: string;
8
17
  entityId?: string;
9
18
  }): void;
10
- removeEventListener(): void;
11
19
  }
12
20
  export default EventBus;
@@ -2,6 +2,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2
2
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
3
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
4
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
6
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
7
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
8
  /**
@@ -10,13 +11,23 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
10
11
  var EventBus = /*#__PURE__*/function () {
11
12
  function EventBus() {
12
13
  _classCallCheck(this, EventBus);
14
+ _defineProperty(this, "eventMap", new Map());
13
15
  }
16
+
17
+ /**
18
+ * open event
19
+ * @param params
20
+ */
14
21
  _createClass(EventBus, [{
15
- key: "addEventListener",
16
- value: function addEventListener(params) {}
22
+ key: "on",
23
+ value: function on(params) {
24
+ this.eventMap.set(params.eventName, true);
25
+ }
17
26
  }, {
18
- key: "removeEventListener",
19
- value: function removeEventListener() {}
27
+ key: "off",
28
+ value: function off(params) {
29
+ this.eventMap.set(params.eventName, false);
30
+ }
20
31
  }]);
21
32
  return EventBus;
22
33
  }();
@@ -1,3 +1,4 @@
1
+ import { Vector3 } from '@anov/3d-core';
1
2
  import type Anov3D from '..';
2
3
  interface ObjectType {
3
4
  [key: string]: any;
@@ -14,5 +15,10 @@ export declare const getValueByKey: <T extends ObjectType>(obj: T, key: string)
14
15
  * @param iEngine
15
16
  * @param fnkey
16
17
  */
17
- export declare const getFnByFnkey: (iEngine: Anov3D, fnkey: string) => any;
18
+ export declare const getFnByFnkey: (iEngine: Anov3D, fnkey: string, id: string) => any;
19
+ export declare const object2Vector3: (obj: {
20
+ x: number;
21
+ y: number;
22
+ z: number;
23
+ }) => Vector3;
18
24
  export {};
@@ -1,4 +1,5 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ import { Vector3 } from '@anov/3d-core';
2
3
  import { messageStatus } from "../messageStatus";
3
4
  import { MessageType, sendToMessage } from "./messageFn";
4
5
  /**
@@ -27,14 +28,17 @@ export var getValueByKey = function getValueByKey(obj, key) {
27
28
  * @param iEngine
28
29
  * @param fnkey
29
30
  */
30
- export var getFnByFnkey = function getFnByFnkey(iEngine, fnkey) {
31
+ export var getFnByFnkey = function getFnByFnkey(iEngine, fnkey, id) {
31
32
  var handleFunction = getValueByKey(iEngine, fnkey);
32
33
  if (typeof handleFunction !== 'function') {
33
- sendToMessage(MessageType.Api, fnkey, messageStatus.ModuleNotRegister.code);
34
+ sendToMessage(MessageType.Api, fnkey, messageStatus.ModuleNotRegister.code, id);
34
35
  throw new Error('this function is not exist');
35
36
  }
36
37
  var fnkeyArrary = fnkey.split('.');
37
38
  var context = iEngine;
38
39
  if (fnkeyArrary.length > 1) context = getValueByKey(iEngine, fnkeyArrary.slice(0, fnkeyArrary.length - 1).join('.'));
39
40
  return handleFunction.bind(context);
41
+ };
42
+ export var object2Vector3 = function object2Vector3(obj) {
43
+ return new Vector3(obj.x, obj.y, obj.z);
40
44
  };
@@ -1,3 +1,9 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1
7
  import { v4 as uuidv4 } from 'uuid';
2
8
  import { utils } from '@anov/3d-core';
3
9
  export var MessageType;
@@ -17,6 +23,7 @@ var getResponseMsg = function getResponseMsg(status) {
17
23
  * @returns
18
24
  */
19
25
  export var sendToMessage = function sendToMessage(messageType, messageName, status, id, res) {
26
+ var _ref;
20
27
  var uid = uuidv4();
21
28
  var responseMsg = getResponseMsg(status);
22
29
  var response = {
@@ -24,11 +31,11 @@ export var sendToMessage = function sendToMessage(messageType, messageName, stat
24
31
  name: messageName,
25
32
  code: status,
26
33
  msg: responseMsg,
27
- result: {
34
+ result: _objectSpread(_objectSpread({}, (_ref = res) !== null && _ref !== void 0 ? _ref : {}), {}, {
28
35
  version: '0.0.4',
29
36
  engineType: 'WEBGL',
30
37
  engineVersion: '0.0.4'
31
- }
38
+ })
32
39
  };
33
- if (messageType === MessageType.Api) utils.emitter.emit('message', response);
40
+ if (messageType === MessageType.Api) utils.emitter.emit('message', response);else if (messageType === MessageType.Event) utils.emitter.emit('event', response);
34
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anov/3d",
3
- "version": "0.0.4-alpha14",
3
+ "version": "0.0.4-alpha15",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -16,9 +16,10 @@
16
16
  "package.json"
17
17
  ],
18
18
  "dependencies": {
19
+ "@tweenjs/tween.js": "^21.0.0",
19
20
  "uuid": "^9.0.1",
20
21
  "@anov/3d-core": "^0.0.4-alpha13",
21
- "@anov/3d-utils": "^0.0.4-alpha1"
22
+ "@anov/3d-ability": "^0.0.4-alpha1"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@types/uuid": "^9.0.7"