@anov/3d 0.0.4-alpha14 → 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.
@@ -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,32 +24,45 @@ 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
- 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
+ });
51
66
  } catch (error) {
52
67
  sendToMessage(MessageType.Api, req.name, EMessageStatus.EventHandleFailed, req.id);
53
68
  }
@@ -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.js CHANGED
@@ -1,43 +1,20 @@
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 _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
- 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
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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 { SceneControl, Vector3, utils } from '@anov/3d-core';
9
- import Environment from "./environment";
10
- import { EWeatherType } from "./environment/weather/type";
11
1
  import registerHooks from "./hooksManager";
12
- var Anov3D = /*#__PURE__*/_createClass(function Anov3D(opts) {
13
- var _opts$size$width, _opts$size, _opts$size$height, _opts$size2;
14
- _classCallCheck(this, Anov3D);
15
- _defineProperty(this, "opts", void 0);
16
- _defineProperty(this, "sceneControl", void 0);
17
- _defineProperty(this, "Environment", void 0);
18
- _defineProperty(this, "EWeatherType", EWeatherType);
19
- this.opts = opts;
20
- var scene = new SceneControl({
21
- orbitControls: true,
22
- defCameraOps: {
23
- position: new Vector3(0, 100, 2000),
24
- far: 1000000
25
- },
26
- rendererOps: {
27
- shadowMap: true,
28
- 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
31
- }
32
- },
33
- reset: true,
34
- ambientLight: true
35
- });
36
- scene.render(opts.container);
37
- utils.emitter.emit('scene-completed', scene);
38
- this.sceneControl = scene;
39
- this.Environment = new Environment();
40
- });
2
+ import Anov3D from "./sdkEntry";
3
+ export var defaultCameraParams = {
4
+ fov: 45,
5
+ near: 0.1,
6
+ far: 1000000,
7
+ position: {
8
+ x: 0,
9
+ y: 100,
10
+ z: 200
11
+ },
12
+ lookAt: {
13
+ x: 0,
14
+ y: 0,
15
+ z: 0
16
+ }
17
+ };
41
18
  registerHooks();
42
19
  export { createInstance } from "./applicationApi";
43
20
  export default Anov3D;
@@ -0,0 +1,210 @@
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
+ _defineProperty(this, "isTransitionPeriod", false);
18
+ this.camera = camera;
19
+ this.controls = controls;
20
+ this.handleChanged();
21
+ }
22
+
23
+ /**
24
+ * caclCurrentPos
25
+ * @param currentPos
26
+ * @returns
27
+ */
28
+ _createClass(Camera, [{
29
+ key: "caclCurrentPos",
30
+ value: function caclCurrentPos(currentPos) {
31
+ var box = new Box3();
32
+ box.setFromPoints(currentPos.map(function (item) {
33
+ return new Vector3(item[0], item[1], item[2]);
34
+ }));
35
+ var center = box.getCenter(new Vector3());
36
+ var size = box.getSize(new Vector3());
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(); // 相机指向物体中心的向量
41
+
42
+ var lastPosition = directionVector.multiplyScalar(cameraToCenterDistance).add(center);
43
+ var lastLookat = center;
44
+
45
+ // const box3helper = new Box3Helper(box, new Color(0xFFFF00))
46
+ // use.useScene().scene!.add(box3helper)
47
+
48
+ return {
49
+ lastPosition: lastPosition,
50
+ lastLookat: lastLookat
51
+ };
52
+ }
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
+
73
+ /**
74
+ * focus On Position
75
+ * @param params
76
+ */
77
+ }, {
78
+ key: "focusOnPosition",
79
+ value: function focusOnPosition(params) {
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
+ });
116
+ }
117
+
118
+ /**
119
+ * set camera
120
+ * @param params
121
+ */
122
+ }, {
123
+ key: "setCamera",
124
+ value: function setCamera(params) {
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
+ });
145
+ });
146
+ }
147
+
148
+ /**
149
+ * get Camera info
150
+ * @returns
151
+ */
152
+ }, {
153
+ key: "getCamera",
154
+ value: function getCamera() {
155
+ return {
156
+ position: [this.camera.position.x, this.camera.position.y, this.camera.position.z],
157
+ target: [this.controls.target.x, this.controls.target.y, this.controls.target.z]
158
+ };
159
+ }
160
+
161
+ /**
162
+ * interpolation move camera
163
+ * @param position
164
+ * @param target
165
+ * @param options
166
+ */
167
+ }, {
168
+ key: "moveCameraTo",
169
+ value: function moveCameraTo(position, target, options) {
170
+ var _this4 = this;
171
+ var currentPoition = this.camera.position.clone();
172
+ var currentPositionInterpolation = new Vector3();
173
+ if ((options === null || options === void 0 ? void 0 : options.duration) === 0) {
174
+ this.camera.position.copy(position);
175
+ this.controls.target.copy(target);
176
+ (options === null || options === void 0 ? void 0 : options.onComplate) && options.onComplate();
177
+ return;
178
+ }
179
+ new TWEEN.Tween({
180
+ t: 0,
181
+ lookat: this.controls.target.clone()
182
+ }).to({
183
+ t: 1,
184
+ lookat: target
185
+ }, (options === null || options === void 0 ? void 0 : options.duration) || 1000).onStart(function () {
186
+ (options === null || options === void 0 ? void 0 : options.onStart) && options.onStart();
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);
193
+ var currentPosition = currentPositionInterpolation.lerpVectors(currentPoition, position, t);
194
+ _this4.camera.position.copy(currentPosition);
195
+ (options === null || options === void 0 ? void 0 : options.onUpdate) && options.onUpdate({
196
+ position: currentPosition,
197
+ lookat: lookat
198
+ });
199
+ }).onComplete(function () {
200
+ (options === null || options === void 0 ? void 0 : options.onComplate) && options.onComplate();
201
+ _this4.controls.enabled = true;
202
+ setTimeout(function () {
203
+ _this4.isTransitionPeriod = false;
204
+ });
205
+ }).start();
206
+ }
207
+ }]);
208
+ return Camera;
209
+ }();
210
+ export default Camera;
@@ -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,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,29 @@ 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("eventBus.".concat(params.eventName), true);
25
+ return {
26
+ eventName: params.eventName
27
+ };
28
+ }
17
29
  }, {
18
- key: "removeEventListener",
19
- value: function removeEventListener() {}
30
+ key: "off",
31
+ value: function off(params) {
32
+ this.eventMap.set("eventBus.".concat(params.eventName), false);
33
+ return {
34
+ eventName: params.eventName
35
+ };
36
+ }
20
37
  }]);
21
38
  return EventBus;
22
39
  }();
@@ -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;
@@ -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,12 +1,20 @@
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';
9
+ import { codeMessageMap } from "../messageStatus";
3
10
  export var MessageType;
4
11
  (function (MessageType) {
5
12
  MessageType[MessageType["Event"] = 0] = "Event";
6
13
  MessageType[MessageType["Api"] = 1] = "Api";
7
14
  })(MessageType || (MessageType = {}));
8
15
  var getResponseMsg = function getResponseMsg(status) {
9
- return '';
16
+ var _codeMessageMap$statu;
17
+ return (_codeMessageMap$statu = codeMessageMap[status]) !== null && _codeMessageMap$statu !== void 0 ? _codeMessageMap$statu : '未知错误';
10
18
  };
11
19
 
12
20
  /**
@@ -17,6 +25,7 @@ var getResponseMsg = function getResponseMsg(status) {
17
25
  * @returns
18
26
  */
19
27
  export var sendToMessage = function sendToMessage(messageType, messageName, status, id, res) {
28
+ var _ref;
20
29
  var uid = uuidv4();
21
30
  var responseMsg = getResponseMsg(status);
22
31
  var response = {
@@ -24,11 +33,13 @@ export var sendToMessage = function sendToMessage(messageType, messageName, stat
24
33
  name: messageName,
25
34
  code: status,
26
35
  msg: responseMsg,
27
- result: {
36
+ result: _objectSpread(_objectSpread({}, (_ref = res) !== null && _ref !== void 0 ? _ref : {}), {}, {
28
37
  version: '0.0.4',
29
38
  engineType: 'WEBGL',
30
39
  engineVersion: '0.0.4'
31
- }
40
+ })
32
41
  };
33
- if (messageType === MessageType.Api) utils.emitter.emit('message', 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
+ }));
34
45
  };
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-alpha16",
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-alpha13",
21
- "@anov/3d-utils": "^0.0.4-alpha1"
21
+ "@anov/3d-ability": "^0.0.4-alpha2",
22
+ "@anov/3d-core": "^0.0.4-alpha14"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@types/uuid": "^9.0.7"
@@ -1,21 +0,0 @@
1
- declare type ApplicationOptions = {
2
- el: HTMLElement;
3
- };
4
- declare class Application {
5
- private container;
6
- private iEngine;
7
- constructor(opts: ApplicationOptions);
8
- private init;
9
- sendMessage(req: {
10
- name: string;
11
- id: string;
12
- params: any;
13
- }): void;
14
- receiveMessage(eventName: string, cb: (params: any) => void): void;
15
- }
16
- /**
17
- * createInstance
18
- * @returns
19
- */
20
- export declare const createInstance: (opts: ApplicationOptions) => Application;
21
- export {};
@@ -1,28 +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
- }): void;
18
- /**
19
- * setWeather
20
- * @param type
21
- * @param changeTime
22
- */
23
- setWeather(params: {
24
- weatherType: string;
25
- duration?: number;
26
- }): void;
27
- }
28
- 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,12 +0,0 @@
1
- /**
2
- * notes: 区别于前端概念,3端统一API特定
3
- */
4
- declare class EventBus {
5
- constructor();
6
- addEventListener(params: {
7
- eventName: string;
8
- entityId?: string;
9
- }): void;
10
- removeEventListener(): void;
11
- }
12
- export default EventBus;
@@ -1,2 +0,0 @@
1
- declare const registerHooks: () => void;
2
- export default registerHooks;
package/dist/index.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import { SceneControl } from '@anov/3d-core';
2
- import Environment from './environment';
3
- import { EWeatherType } from './environment/weather/type';
4
- declare type Anov3DOptions = {
5
- container: HTMLElement;
6
- size?: {
7
- width: number;
8
- height: number;
9
- };
10
- };
11
- declare class Anov3D {
12
- private opts;
13
- sceneControl: SceneControl;
14
- Environment: Environment;
15
- EWeatherType: typeof EWeatherType;
16
- constructor(opts: Anov3DOptions);
17
- }
18
- export { createInstance } from './applicationApi';
19
- 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,18 +0,0 @@
1
- import type Anov3D from '..';
2
- interface ObjectType {
3
- [key: string]: any;
4
- }
5
- /**
6
- * get value by key
7
- * notic: to mark proxy, so need take it layer by layer
8
- * @param obj
9
- * @param key
10
- */
11
- export declare const getValueByKey: <T extends ObjectType>(obj: T, key: string) => T | undefined;
12
- /**
13
- * getFnByFnkey
14
- * @param iEngine
15
- * @param fnkey
16
- */
17
- export declare const getFnByFnkey: (iEngine: Anov3D, fnkey: string) => any;
18
- 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;