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

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.
@@ -60,7 +60,9 @@ var Application = /*#__PURE__*/function () {
60
60
  var fn = getFnByFnkey(this.iEngine, req.name, req.id);
61
61
  try {
62
62
  var res = fn(req.params);
63
- sendToMessage(MessageType.Api, req.name, EMessageStatus.Success, req.id, res);
63
+ Promise.resolve(res).then(function (res) {
64
+ sendToMessage(MessageType.Api, req.name, EMessageStatus.Success, req.id, res);
65
+ });
64
66
  } catch (error) {
65
67
  sendToMessage(MessageType.Api, req.name, EMessageStatus.EventHandleFailed, req.id);
66
68
  }
package/dist/index.js CHANGED
@@ -1,19 +1,5 @@
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 _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); } }
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; }
6
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
8
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
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); }
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";
15
1
  import registerHooks from "./hooksManager";
16
- import { object2Vector3 } from "./utils/index";
2
+ import Anov3D from "./sdkEntry";
17
3
  export var defaultCameraParams = {
18
4
  fov: 45,
19
5
  near: 0.1,
@@ -29,50 +15,6 @@ export var defaultCameraParams = {
29
15
  z: 0
30
16
  }
31
17
  };
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;
34
- _classCallCheck(this, Anov3D);
35
- _defineProperty(this, "opts", void 0);
36
- _defineProperty(this, "sceneControl", void 0);
37
- _defineProperty(this, "environment", void 0);
38
- _defineProperty(this, "eventBus", void 0);
39
- _defineProperty(this, "EWeatherType", EWeatherType);
40
- _defineProperty(this, "camera", void 0);
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
- };
51
- var scene = new SceneControl({
52
- orbitControls: true,
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),
56
- rendererOps: {
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
- }
62
- },
63
- reset: true,
64
- ambientLight: true
65
- });
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));
69
- utils.emitter.emit('scene-completed', scene);
70
- this.sceneControl = scene;
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);
75
- });
76
18
  registerHooks();
77
19
  export { createInstance } from "./applicationApi";
78
20
  export default Anov3D;
@@ -14,8 +14,10 @@ var Camera = /*#__PURE__*/function () {
14
14
  _classCallCheck(this, Camera);
15
15
  _defineProperty(this, "camera", void 0);
16
16
  _defineProperty(this, "controls", void 0);
17
+ _defineProperty(this, "isTransitionPeriod", false);
17
18
  this.camera = camera;
18
19
  this.controls = controls;
20
+ this.handleChanged();
19
21
  }
20
22
 
21
23
  /**
@@ -32,19 +34,42 @@ var Camera = /*#__PURE__*/function () {
32
34
  }));
33
35
  var center = box.getCenter(new Vector3());
34
36
  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(); // 相机指向物体中心的向量
37
+ var halfDiagonal = size.length() * 0.5;
38
+ var maxDistance = halfDiagonal / Math.tan(this.camera.fov / 2 * Math.PI / 180);
39
+ var cameraToCenterDistance = maxDistance;
40
+ var directionVector = this.camera.position.clone().sub(this.controls.target).normalize(); // 相机指向物体中心的向量
39
41
 
40
42
  var lastPosition = directionVector.multiplyScalar(cameraToCenterDistance).add(center);
41
43
  var lastLookat = center;
44
+
45
+ // const box3helper = new Box3Helper(box, new Color(0xFFFF00))
46
+ // use.useScene().scene!.add(box3helper)
47
+
42
48
  return {
43
49
  lastPosition: lastPosition,
44
50
  lastLookat: lastLookat
45
51
  };
46
52
  }
47
53
 
54
+ /**
55
+ * handle camera changed
56
+ */
57
+ }, {
58
+ key: "handleChanged",
59
+ value: function handleChanged() {
60
+ var _this = this;
61
+ this.controls.addEventListener('change', function () {
62
+ if (!_this.isTransitionPeriod) {
63
+ var lookat = _this.controls.target;
64
+ var position = _this.camera.position;
65
+ sendToMessage(MessageType.Event, 'onCameraChanged', EMessageStatus.Success, undefined, {
66
+ position: [position.x, position.y, position.z],
67
+ target: [lookat.x, lookat.y, lookat.z]
68
+ });
69
+ }
70
+ });
71
+ }
72
+
48
73
  /**
49
74
  * focus On Position
50
75
  * @param params
@@ -52,24 +77,42 @@ var Camera = /*#__PURE__*/function () {
52
77
  }, {
53
78
  key: "focusOnPosition",
54
79
  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
- }
80
+ var _this2 = this;
81
+ // eslint-disable-next-line promise/param-names
82
+ return new Promise(function (res, _) {
83
+ var position = params.position,
84
+ pitch = params.pitch,
85
+ duration = params.duration;
86
+ var moveOptions = function moveOptions() {
87
+ var _ref;
88
+ return {
89
+ duration: (_ref = duration && duration * 1000) !== null && _ref !== void 0 ? _ref : 1000,
90
+ onUpdate: function onUpdate(_ref2) {
91
+ var position = _ref2.position,
92
+ lookat = _ref2.lookat;
93
+ sendToMessage(MessageType.Event, 'onCameraChanged', EMessageStatus.Success, undefined, {
94
+ position: [position.x, position.y, position.z],
95
+ target: [lookat.x, lookat.y, lookat.z]
96
+ });
97
+ },
98
+ onComplate: function onComplate() {
99
+ res({
100
+ success: true
101
+ });
102
+ }
103
+ };
104
+ };
105
+ if (Array.isArray(position[0])) {
106
+ var currentPos = position;
107
+ var _this2$caclCurrentPos = _this2.caclCurrentPos(currentPos),
108
+ lastPosition = _this2$caclCurrentPos.lastPosition,
109
+ lastLookat = _this2$caclCurrentPos.lastLookat;
110
+ _this2.moveCameraTo(lastPosition, lastLookat, moveOptions());
111
+ } else {
112
+ var _currentPos = position;
113
+ _this2.moveCameraTo(_this2.camera.position, new Vector3(_currentPos[0], _currentPos[1], _currentPos[2]), moveOptions());
114
+ }
115
+ });
73
116
  }
74
117
 
75
118
  /**
@@ -79,17 +122,26 @@ var Camera = /*#__PURE__*/function () {
79
122
  }, {
80
123
  key: "setCamera",
81
124
  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
- }
125
+ var _this3 = this;
126
+ // eslint-disable-next-line promise/param-names
127
+ return new Promise(function (res, _) {
128
+ var _ref3;
129
+ _this3.moveCameraTo(new Vector3(params.position[0], params.position[1], params.position[2]), new Vector3(params.target[0], params.target[1], params.target[2]), {
130
+ duration: (_ref3 = params.duration && params.duration * 1000) !== null && _ref3 !== void 0 ? _ref3 : 1000,
131
+ onUpdate: function onUpdate(_ref4) {
132
+ var position = _ref4.position,
133
+ lookat = _ref4.lookat;
134
+ params.isTrigger && sendToMessage(MessageType.Event, 'onCameraChanged', EMessageStatus.Success, undefined, {
135
+ position: [position.x, position.y, position.z],
136
+ target: [lookat.x, lookat.y, lookat.z]
137
+ });
138
+ },
139
+ onComplate: function onComplate() {
140
+ res({
141
+ success: true
142
+ });
143
+ }
144
+ });
93
145
  });
94
146
  }
95
147
 
@@ -115,12 +167,13 @@ var Camera = /*#__PURE__*/function () {
115
167
  }, {
116
168
  key: "moveCameraTo",
117
169
  value: function moveCameraTo(position, target, options) {
118
- var _this = this;
170
+ var _this4 = this;
119
171
  var currentPoition = this.camera.position.clone();
120
172
  var currentPositionInterpolation = new Vector3();
121
173
  if ((options === null || options === void 0 ? void 0 : options.duration) === 0) {
122
174
  this.camera.position.copy(position);
123
175
  this.controls.target.copy(target);
176
+ (options === null || options === void 0 ? void 0 : options.onComplate) && options.onComplate();
124
177
  return;
125
178
  }
126
179
  new TWEEN.Tween({
@@ -131,20 +184,24 @@ var Camera = /*#__PURE__*/function () {
131
184
  lookat: target
132
185
  }, (options === null || options === void 0 ? void 0 : options.duration) || 1000).onStart(function () {
133
186
  (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);
187
+ _this4.controls.enabled = false;
188
+ _this4.isTransitionPeriod = true;
189
+ }).easing(TWEEN.Easing.Quadratic.InOut).onUpdate(function (_ref5) {
190
+ var t = _ref5.t,
191
+ lookat = _ref5.lookat;
192
+ _this4.controls.target.copy(lookat);
139
193
  var currentPosition = currentPositionInterpolation.lerpVectors(currentPoition, position, t);
140
- _this.camera.position.copy(currentPosition);
194
+ _this4.camera.position.copy(currentPosition);
141
195
  (options === null || options === void 0 ? void 0 : options.onUpdate) && options.onUpdate({
142
196
  position: currentPosition,
143
197
  lookat: lookat
144
198
  });
145
199
  }).onComplete(function () {
146
200
  (options === null || options === void 0 ? void 0 : options.onComplate) && options.onComplate();
147
- _this.controls.enabled = true;
201
+ _this4.controls.enabled = true;
202
+ setTimeout(function () {
203
+ _this4.isTransitionPeriod = false;
204
+ });
148
205
  }).start();
149
206
  }
150
207
  }]);
@@ -21,12 +21,18 @@ var EventBus = /*#__PURE__*/function () {
21
21
  _createClass(EventBus, [{
22
22
  key: "on",
23
23
  value: function on(params) {
24
- this.eventMap.set(params.eventName, true);
24
+ this.eventMap.set("eventBus.".concat(params.eventName), true);
25
+ return {
26
+ eventName: params.eventName
27
+ };
25
28
  }
26
29
  }, {
27
30
  key: "off",
28
31
  value: function off(params) {
29
- this.eventMap.set(params.eventName, false);
32
+ this.eventMap.set("eventBus.".concat(params.eventName), false);
33
+ return {
34
+ eventName: params.eventName
35
+ };
30
36
  }
31
37
  }]);
32
38
  return EventBus;
@@ -0,0 +1,60 @@
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 _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); } }
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; }
6
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
8
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
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); }
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";
15
+ import { object2Vector3 } from "./utils/index";
16
+ import { defaultCameraParams } from "./index";
17
+ var Anov3D = /*#__PURE__*/_createClass(function Anov3D(opts) {
18
+ 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, _scene$controls, _camera$lookAt;
19
+ _classCallCheck(this, Anov3D);
20
+ _defineProperty(this, "opts", void 0);
21
+ _defineProperty(this, "sceneControl", void 0);
22
+ _defineProperty(this, "environment", void 0);
23
+ _defineProperty(this, "eventBus", void 0);
24
+ _defineProperty(this, "EWeatherType", EWeatherType);
25
+ _defineProperty(this, "camera", void 0);
26
+ this.opts = opts;
27
+ var _ref = opts || {},
28
+ _ref$camera = _ref.camera,
29
+ camera = _ref$camera === void 0 ? {} : _ref$camera;
30
+ var cameraParams = {
31
+ fov: (_camera$fov = camera.fov) !== null && _camera$fov !== void 0 ? _camera$fov : defaultCameraParams.fov,
32
+ near: (_camera$near = camera.near) !== null && _camera$near !== void 0 ? _camera$near : defaultCameraParams.near,
33
+ far: (_camera$far = camera.far) !== null && _camera$far !== void 0 ? _camera$far : defaultCameraParams.far,
34
+ position: object2Vector3((_camera$position = camera.position) !== null && _camera$position !== void 0 ? _camera$position : defaultCameraParams.position)
35
+ };
36
+ var scene = new SceneControl({
37
+ orbitControls: true,
38
+ defCameraOps: _objectSpread({
39
+ 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)
40
+ }, cameraParams),
41
+ rendererOps: {
42
+ shadowMap: true,
43
+ size: {
44
+ 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,
45
+ 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
46
+ }
47
+ },
48
+ reset: true,
49
+ ambientLight: true
50
+ });
51
+ scene.render(opts.container);
52
+ (_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));
53
+ utils.emitter.emit('scene-completed', scene);
54
+ this.sceneControl = scene;
55
+ this.environment = new Environment();
56
+ this.eventBus = new EventBus();
57
+ this.camera = new Camera(scene.camera, scene.controls);
58
+ utils.storeManagement.set('event-bus', this.eventBus);
59
+ });
60
+ export default Anov3D;
@@ -6,13 +6,15 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
6
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); }
7
7
  import { v4 as uuidv4 } from 'uuid';
8
8
  import { utils } from '@anov/3d-core';
9
+ import { codeMessageMap } from "../messageStatus";
9
10
  export var MessageType;
10
11
  (function (MessageType) {
11
12
  MessageType[MessageType["Event"] = 0] = "Event";
12
13
  MessageType[MessageType["Api"] = 1] = "Api";
13
14
  })(MessageType || (MessageType = {}));
14
15
  var getResponseMsg = function getResponseMsg(status) {
15
- return '';
16
+ var _codeMessageMap$statu;
17
+ return (_codeMessageMap$statu = codeMessageMap[status]) !== null && _codeMessageMap$statu !== void 0 ? _codeMessageMap$statu : '未知错误';
16
18
  };
17
19
 
18
20
  /**
@@ -37,5 +39,7 @@ export var sendToMessage = function sendToMessage(messageType, messageName, stat
37
39
  engineVersion: '0.0.4'
38
40
  })
39
41
  };
40
- if (messageType === MessageType.Api) utils.emitter.emit('message', response);else if (messageType === MessageType.Event) utils.emitter.emit('event', response);
42
+ if (messageType === MessageType.Api) utils.emitter.emit('message', response);else if (messageType === MessageType.Event) utils.emitter.emit('event', _objectSpread(_objectSpread({}, response), {}, {
43
+ name: "eventBus.".concat(response.name)
44
+ }));
41
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anov/3d",
3
- "version": "0.0.4-alpha15",
3
+ "version": "0.0.4-alpha16",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -18,8 +18,8 @@
18
18
  "dependencies": {
19
19
  "@tweenjs/tween.js": "^21.0.0",
20
20
  "uuid": "^9.0.1",
21
- "@anov/3d-core": "^0.0.4-alpha13",
22
- "@anov/3d-ability": "^0.0.4-alpha1"
21
+ "@anov/3d-ability": "^0.0.4-alpha2",
22
+ "@anov/3d-core": "^0.0.4-alpha14"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/uuid": "^9.0.7"
@@ -1,43 +0,0 @@
1
- import Anov3D from './index';
2
- declare type ApplicationOptions = {
3
- el: HTMLElement;
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
- };
26
- declare class Application {
27
- private container;
28
- iEngine: Anov3D | undefined;
29
- constructor(opts: ApplicationOptions);
30
- private init;
31
- sendMessage(req: {
32
- name: string;
33
- id: string;
34
- params: any;
35
- }): void;
36
- receiveMessage(eventName: string, cb: (params: any) => void): void;
37
- }
38
- /**
39
- * createInstance
40
- * @returns
41
- */
42
- export declare const createInstance: (opts: ApplicationOptions) => Application;
43
- export {};
@@ -1,2 +0,0 @@
1
- declare const registerHooks: () => void;
2
- export default registerHooks;
package/dist/index.d.ts DELETED
@@ -1,40 +0,0 @@
1
- import { SceneControl } from '@anov/3d-core';
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';
7
- declare type Anov3DOptions = {
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
- };
29
- };
30
- declare class Anov3D {
31
- private opts;
32
- sceneControl: SceneControl;
33
- environment: Environment;
34
- eventBus: EventBus;
35
- EWeatherType: typeof EWeatherType;
36
- camera: Camera;
37
- constructor(opts: Anov3DOptions);
38
- }
39
- export { createInstance } from './applicationApi';
40
- export default Anov3D;
@@ -1,52 +0,0 @@
1
- export declare const messageStatus: {
2
- Success: {
3
- code: number;
4
- msg: string;
5
- };
6
- SerializeFailed: {
7
- code: number;
8
- msg: string;
9
- };
10
- NameNotFound: {
11
- code: number;
12
- msg: string;
13
- };
14
- IDNotFound: {
15
- code: number;
16
- msg: string;
17
- };
18
- ParamsNotFound: {
19
- code: number;
20
- msg: string;
21
- };
22
- MissingKeyField: {
23
- code: number;
24
- msg: string;
25
- };
26
- EventNotRegister: {
27
- code: number;
28
- msg: string;
29
- };
30
- ModuleNotRegister: {
31
- code: number;
32
- msg: string;
33
- };
34
- EventHandleFailed: {
35
- code: number;
36
- msg: string;
37
- };
38
- };
39
- export declare enum EMessageStatus {
40
- Success = 200,
41
- SerializeFailed = 500,
42
- NameNotFound = 400,
43
- IDNotFound = 400,
44
- ParamsNotFound = 400,
45
- MissingKeyField = 400,
46
- EventNotRegister = 400,
47
- ModuleNotRegister = 404,
48
- EventHandleFailed = 422
49
- }
50
- export declare const codeMessageMap: {
51
- 200: string;
52
- };
@@ -1,48 +0,0 @@
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;
@@ -1,30 +0,0 @@
1
- declare class Environment {
2
- private setDate;
3
- private snow;
4
- private rain;
5
- private cloudReturn;
6
- private sky;
7
- constructor();
8
- private setWeatherStrategy;
9
- /**
10
- * setTime
11
- * @param newTime
12
- * @param changeTime
13
- */
14
- setTime(params: {
15
- newTime: number;
16
- duration?: number;
17
- }): {
18
- newTime: number;
19
- };
20
- /**
21
- * setWeather
22
- * @param type
23
- * @param changeTime
24
- */
25
- setWeather(params: {
26
- weatherType: string;
27
- duration?: number;
28
- }): void;
29
- }
30
- export default Environment;
@@ -1,10 +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) => any[];
10
- export default createTimeSkySystem;
@@ -1,15 +0,0 @@
1
- export declare const EWeatherType: {
2
- Clear_Skies: string;
3
- Cloudy: string;
4
- Foggy: string;
5
- Overcast: string;
6
- Partly_Cloudy: string;
7
- Rain: string;
8
- Rain_Light: string;
9
- Rain_Thunderstorm: string;
10
- Sand_Dust_Calm: string;
11
- Sand_Dust_Storm: string;
12
- Snow: string;
13
- Snow_Blizzard: string;
14
- Snow_Light: string;
15
- };
@@ -1,20 +0,0 @@
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;
@@ -1,24 +0,0 @@
1
- import { Vector3 } from '@anov/3d-core';
2
- import type Anov3D from '..';
3
- interface ObjectType {
4
- [key: string]: any;
5
- }
6
- /**
7
- * get value by key
8
- * notic: to mark proxy, so need take it layer by layer
9
- * @param obj
10
- * @param key
11
- */
12
- export declare const getValueByKey: <T extends ObjectType>(obj: T, key: string) => T | undefined;
13
- /**
14
- * getFnByFnkey
15
- * @param iEngine
16
- * @param fnkey
17
- */
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;
24
- export {};
@@ -1,12 +0,0 @@
1
- export declare enum MessageType {
2
- Event = 0,
3
- Api = 1
4
- }
5
- /**
6
- * sendToMessage
7
- * @param messageName
8
- * @param status
9
- * @param res
10
- * @returns
11
- */
12
- export declare const sendToMessage: (messageType: MessageType, messageName: string, status: number, id?: string, res?: unknown) => void;