@anov/3d 0.0.4-alpha13 → 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,7 +1,8 @@
1
+ import Anov3D from './index';
1
2
  declare type ApplicationOptions = {
2
3
  el: HTMLElement;
3
4
  };
4
- declare type InitOptions = {
5
+ export declare type InitOptions = {
5
6
  camera?: {
6
7
  fov?: number;
7
8
  near?: number;
@@ -17,13 +18,21 @@ declare type InitOptions = {
17
18
  z: number;
18
19
  };
19
20
  };
21
+ size?: {
22
+ width: number;
23
+ height: number;
24
+ };
20
25
  };
21
26
  declare class Application {
22
27
  private container;
23
- private iEngine;
28
+ iEngine: Anov3D | undefined;
24
29
  constructor(opts: ApplicationOptions);
25
- init(params?: InitOptions): void;
26
- sendMessage(fnkey: string, req: any): void;
30
+ private init;
31
+ sendMessage(req: {
32
+ name: string;
33
+ id: string;
34
+ params: any;
35
+ }): void;
27
36
  receiveMessage(eventName: string, cb: (params: any) => void): void;
28
37
  }
29
38
  /**
@@ -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);
@@ -20,36 +22,48 @@ var Application = /*#__PURE__*/function () {
20
22
  }
21
23
  _createClass(Application, [{
22
24
  key: "init",
23
- value: function init(params) {
25
+ value: function init(params, id) {
24
26
  try {
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
+ };
25
38
  var anov3D = new Anov3D({
26
- container: this.container
39
+ container: this.container,
40
+ size: {
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,
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
43
+ },
44
+ camera: _objectSpread({}, cameraParams)
27
45
  });
28
46
  this.iEngine = anov3D;
29
- sendToMessage(MessageType.Api, 'init', EMessageStatus.Success);
47
+ sendToMessage(MessageType.Api, 'core.init', EMessageStatus.Success, id);
30
48
  } catch (error) {
31
- sendToMessage(MessageType.Api, 'init', EMessageStatus.EventHandleFailed);
49
+ sendToMessage(MessageType.Api, 'core.init', EMessageStatus.EventHandleFailed);
32
50
  }
33
51
  }
34
52
  }, {
35
53
  key: "sendMessage",
36
- value: function sendMessage(fnkey, req) {
54
+ value: function sendMessage(req) {
55
+ if (req.name === 'Core.init' || req.name === 'core.init') {
56
+ this.init(req.params, req.id);
57
+ return;
58
+ }
37
59
  if (!this.iEngine) throw new Error('please init first');
38
-
39
- // let params: unknown
40
-
41
- // if (req) {
42
- // try {
43
- // params = JSON.parse(req)
44
- // }
45
- // catch (error) {
46
- // // utils.emitter.emit()
47
- // }
48
- // }
49
-
50
- var fn = getFnByFnkey(this.iEngine, fnkey);
51
- var res = fn(req);
52
- sendToMessage(MessageType.Api, fnkey, res);
60
+ var fn = getFnByFnkey(this.iEngine, req.name, req.id);
61
+ try {
62
+ var res = fn(req.params);
63
+ sendToMessage(MessageType.Api, req.name, EMessageStatus.Success, req.id, res);
64
+ } catch (error) {
65
+ sendToMessage(MessageType.Api, req.name, EMessageStatus.EventHandleFailed, req.id);
66
+ }
53
67
  }
54
68
  }, {
55
69
  key: "receiveMessage",
@@ -2,7 +2,13 @@ import { utils } from '@anov/3d-core';
2
2
  var registerHooks = function registerHooks() {
3
3
  // 应用级别
4
4
  utils.emitter.on('scene-completed', function (scene) {
5
- console.log('场景编译完成', scene);
5
+ // console.log('场景编译完成', scene)
6
+ });
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);
6
12
  });
7
13
 
8
14
  // 应用sdk
package/dist/index.d.ts CHANGED
@@ -1,14 +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;
9
+ size?: {
10
+ width: number;
11
+ height: number;
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
+ };
6
29
  };
7
30
  declare class Anov3D {
8
31
  private opts;
9
32
  sceneControl: SceneControl;
10
- Environment: Environment;
33
+ environment: Environment;
34
+ eventBus: EventBus;
11
35
  EWeatherType: typeof EWeatherType;
36
+ camera: Camera;
12
37
  constructor(opts: Anov3DOptions);
13
38
  }
14
39
  export { createInstance } from './applicationApi';
package/dist/index.js CHANGED
@@ -1,37 +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) {
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;
13
34
  _classCallCheck(this, Anov3D);
14
35
  _defineProperty(this, "opts", void 0);
15
36
  _defineProperty(this, "sceneControl", void 0);
16
- _defineProperty(this, "Environment", void 0);
37
+ _defineProperty(this, "environment", void 0);
38
+ _defineProperty(this, "eventBus", void 0);
17
39
  _defineProperty(this, "EWeatherType", EWeatherType);
40
+ _defineProperty(this, "camera", void 0);
18
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
+ };
19
51
  var scene = new SceneControl({
20
52
  orbitControls: true,
21
- defCameraOps: {
22
- position: new Vector3(0, 100, 2000),
23
- far: 1000000
24
- },
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),
25
56
  rendererOps: {
26
- shadowMap: true
57
+ shadowMap: true,
58
+ size: {
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
61
+ }
27
62
  },
28
63
  reset: true,
29
64
  ambientLight: true
30
65
  });
31
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));
32
69
  utils.emitter.emit('scene-completed', scene);
33
70
  this.sceneControl = scene;
34
- 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);
35
75
  });
36
76
  registerHooks();
37
77
  export { createInstance } from "./applicationApi";
@@ -47,3 +47,6 @@ export declare enum EMessageStatus {
47
47
  ModuleNotRegister = 404,
48
48
  EventHandleFailed = 422
49
49
  }
50
+ export declare const codeMessageMap: {
51
+ 200: string;
52
+ };
@@ -47,4 +47,7 @@ export var EMessageStatus;
47
47
  EMessageStatus[EMessageStatus["EventNotRegister"] = 400] = "EventNotRegister";
48
48
  EMessageStatus[EMessageStatus["ModuleNotRegister"] = 404] = "ModuleNotRegister";
49
49
  EMessageStatus[EMessageStatus["EventHandleFailed"] = 422] = "EventHandleFailed";
50
- })(EMessageStatus || (EMessageStatus = {}));
50
+ })(EMessageStatus || (EMessageStatus = {}));
51
+ export var codeMessageMap = {
52
+ 200: '成功响应'
53
+ };
@@ -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;
@@ -3,6 +3,7 @@ declare class Environment {
3
3
  private snow;
4
4
  private rain;
5
5
  private cloudReturn;
6
+ private sky;
6
7
  constructor();
7
8
  private setWeatherStrategy;
8
9
  /**
@@ -13,7 +14,9 @@ declare class Environment {
13
14
  setTime(params: {
14
15
  newTime: number;
15
16
  duration?: number;
16
- }): void;
17
+ }): {
18
+ newTime: number;
19
+ };
17
20
  /**
18
21
  * setWeather
19
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() {
@@ -21,6 +21,7 @@ var Environment = /*#__PURE__*/function () {
21
21
  _defineProperty(this, "snow", null);
22
22
  _defineProperty(this, "rain", null);
23
23
  _defineProperty(this, "cloudReturn", null);
24
+ _defineProperty(this, "sky", void 0);
24
25
  _defineProperty(this, "setWeatherStrategy", {
25
26
  Snow: function Snow() {
26
27
  !_this.snow && (_this.snow = new _Snow());
@@ -29,7 +30,10 @@ var Environment = /*#__PURE__*/function () {
29
30
  Rain: function Rain() {
30
31
  !_this.rain && (_this.rain = new _Rain());
31
32
  _this.rain.continue();
33
+
34
+ // renderer.toneMappingExposure
32
35
  },
36
+
33
37
  Cloudy: function Cloudy() {
34
38
  !_this.cloudReturn && (_this.cloudReturn = createSkyCloud());
35
39
  },
@@ -47,9 +51,12 @@ var Environment = /*#__PURE__*/function () {
47
51
  }
48
52
  });
49
53
  var _createTimeSkySystem = createTimeSkySystem(new Date(), 40, 116, 100),
50
- _createTimeSkySystem2 = _slicedToArray(_createTimeSkySystem, 1),
51
- setDate = _createTimeSkySystem2[0];
54
+ _createTimeSkySystem2 = _slicedToArray(_createTimeSkySystem, 3),
55
+ setDate = _createTimeSkySystem2[0],
56
+ sun = _createTimeSkySystem2[1],
57
+ sky = _createTimeSkySystem2[2];
52
58
  this.setDate = setDate;
59
+ this.sky = sky;
53
60
  }
54
61
  _createClass(Environment, [{
55
62
  key: "setTime",
@@ -65,6 +72,9 @@ var Environment = /*#__PURE__*/function () {
65
72
  date.setHours(0, 0, 0, 0);
66
73
  date.setTime(date.getTime() + Math.floor(86400000 * params.newTime / 2400));
67
74
  this.setDate(date);
75
+ return {
76
+ newTime: params.newTime
77
+ };
68
78
  }
69
79
 
70
80
  /**
@@ -0,0 +1,10 @@
1
+ /**
2
+ * create time sky system
3
+ * @param date
4
+ * @param latitude
5
+ * @param longitude
6
+ * @param sunRadius
7
+ * @returns
8
+ */
9
+ declare const createTimeSkySystem: (date: Date, latitude?: number, longitude?: number, sunRadius?: number) => any[];
10
+ export default createTimeSkySystem;
@@ -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
@@ -19,9 +19,10 @@ var createTimeSkySystem = function createTimeSkySystem(date) {
19
19
  var longitude = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 116;
20
20
  var sunRadius = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 100;
21
21
  var _createSkySystem = createSkySystem(date, latitude, longitude, sunRadius),
22
- _createSkySystem2 = _slicedToArray(_createSkySystem, 2),
22
+ _createSkySystem2 = _slicedToArray(_createSkySystem, 3),
23
23
  setDate = _createSkySystem2[0],
24
- sun = _createSkySystem2[1];
25
- return [setDate, sun];
24
+ sun = _createSkySystem2[1],
25
+ sky = _createSkySystem2[2];
26
+ return [setDate, sun, sky];
26
27
  };
27
28
  export default createTimeSkySystem;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * notes: 区别于前端概念,3端统一API特定
3
+ */
4
+ declare class EventBus {
5
+ eventMap: Map<string, boolean>;
6
+ constructor();
7
+ /**
8
+ * open event
9
+ * @param params
10
+ */
11
+ on(params: {
12
+ eventName: string;
13
+ entityId?: string;
14
+ }): void;
15
+ off(params: {
16
+ eventName: string;
17
+ entityId?: string;
18
+ }): void;
19
+ }
20
+ export default EventBus;
@@ -0,0 +1,34 @@
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
+ /**
9
+ * notes: 区别于前端概念,3端统一API特定
10
+ */
11
+ var EventBus = /*#__PURE__*/function () {
12
+ function EventBus() {
13
+ _classCallCheck(this, EventBus);
14
+ _defineProperty(this, "eventMap", new Map());
15
+ }
16
+
17
+ /**
18
+ * open event
19
+ * @param params
20
+ */
21
+ _createClass(EventBus, [{
22
+ key: "on",
23
+ value: function on(params) {
24
+ this.eventMap.set(params.eventName, true);
25
+ }
26
+ }, {
27
+ key: "off",
28
+ value: function off(params) {
29
+ this.eventMap.set(params.eventName, false);
30
+ }
31
+ }]);
32
+ return EventBus;
33
+ }();
34
+ export default EventBus;
@@ -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
  };
@@ -9,4 +9,4 @@ export declare enum MessageType {
9
9
  * @param res
10
10
  * @returns
11
11
  */
12
- export declare const sendToMessage: (messageType: MessageType, messageName: string, status: number, res?: unknown) => void;
12
+ export declare const sendToMessage: (messageType: MessageType, messageName: string, status: number, id?: string, res?: unknown) => void;
@@ -1,6 +1,19 @@
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;
10
+ (function (MessageType) {
11
+ MessageType[MessageType["Event"] = 0] = "Event";
12
+ MessageType[MessageType["Api"] = 1] = "Api";
13
+ })(MessageType || (MessageType = {}));
14
+ var getResponseMsg = function getResponseMsg(status) {
15
+ return '';
16
+ };
4
17
 
5
18
  /**
6
19
  * sendToMessage
@@ -9,25 +22,20 @@ export var MessageType;
9
22
  * @param res
10
23
  * @returns
11
24
  */
12
- (function (MessageType) {
13
- MessageType[MessageType["Event"] = 0] = "Event";
14
- MessageType[MessageType["Api"] = 1] = "Api";
15
- })(MessageType || (MessageType = {}));
16
- export var sendToMessage = function sendToMessage(messageType, messageName, status, res) {
25
+ export var sendToMessage = function sendToMessage(messageType, messageName, status, id, res) {
26
+ var _ref;
17
27
  var uid = uuidv4();
28
+ var responseMsg = getResponseMsg(status);
18
29
  var response = {
19
- id: uid,
20
- // 业务无关,请求消息唯一标识
30
+ id: id !== null && id !== void 0 ? id : uid,
21
31
  name: messageName,
22
32
  code: status,
23
- // 状态码,200 请求成功
24
- msg: '',
25
- // 错误描述
26
- result: {
33
+ msg: responseMsg,
34
+ result: _objectSpread(_objectSpread({}, (_ref = res) !== null && _ref !== void 0 ? _ref : {}), {}, {
27
35
  version: '0.0.4',
28
36
  engineType: 'WEBGL',
29
37
  engineVersion: '0.0.4'
30
- }
38
+ })
31
39
  };
32
- 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);
33
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anov/3d",
3
- "version": "0.0.4-alpha13",
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
- "@anov/3d-core": "^0.0.4-alpha12",
21
- "@anov/3d-utils": "^0.0.4-alpha0"
21
+ "@anov/3d-core": "^0.0.4-alpha13",
22
+ "@anov/3d-ability": "^0.0.4-alpha1"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@types/uuid": "^9.0.7"
@@ -1,12 +0,0 @@
1
- /**
2
- * create time sky system
3
- * @param date
4
- * @param latitude
5
- * @param longitude
6
- * @param sunRadius
7
- * @returns
8
- */
9
- declare const createTimeSkySystem: (date: Date, latitude?: number, longitude?: number, sunRadius?: number) => (((currentDate?: Date | undefined) => import("@anov/3d-core").Vector3) | (import("@anov/3d-core/dist/core/group").default & {
10
- sunPosition: import("@anov/3d-core").Vector3;
11
- }))[];
12
- export default createTimeSkySystem;