@realsee/dnalogel 0.1.1 → 0.1.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realsee/dnalogel",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Realsee Components(React) & Plugins(Five).",
5
5
  "author": "BEIKE REALSEE TECHNOLOGY (HK) LIMITED",
6
6
  "peerDependencies": {
@@ -1,36 +1,35 @@
1
1
  import { FivePlugin } from '@realsee/five';
2
2
  import { Vector3 } from 'three';
3
3
  import { CSS3DObject } from 'three/examples/jsm/renderers/CSS3DRenderer';
4
- export interface CSS3DRenderPluginParameterType {
5
- }
4
+ export declare type CSS3DRenderPluginParameterType = undefined;
6
5
  export interface CSS3DRenderPluginExportType {
7
6
  /**
8
7
  * @description: 根据传入的四个点位创建一个3d dom容器,可以通过ReactDom.render()的方式将react组件放到容器中
9
8
  * @param {Five} five
10
9
  * @param {Vector3[]} points: 矩形四个点坐标
11
- * @param {HTMLElement} container: HTMLElement
12
10
  * @param {number} config.ratio: 1px对应多少米,默认为 0.002,即1px对应2mm
13
11
  * @param {number} config.dpr: dpr, 默认为1
12
+ * @param {HTMLElement} config.container: HTMLElement
14
13
  * @param {number} config.autoRender: 默认为true,如果需要手动render则传false
15
14
  * @param {'front' | 'behind'} config.mode: 两种模式
16
- * @param {HTMLElement} config.behindFiveContainer: 如果config.mode为'behind',需要传入容器,并确保此容器的层级小于five层级
15
+ * @param {HTMLElement} config.behindFiveContainer: 如果config.mode为'behind',需要传入容器,并确保此容器位five下方,且中间没有其他dom元素遮挡
17
16
  * @return {{ container: HTMLElement; dispose: () => void }}: container: dom容器, dispose: 清理函数
18
17
  */
19
- create3DDomContainer: (points: [Vector3, Vector3, Vector3, Vector3], container?: HTMLElement, config?: {
18
+ create3DDomContainer: (points: Vector3[], config?: {
20
19
  ratio?: number;
21
20
  dpr?: number;
22
21
  autoRender?: boolean;
22
+ container?: HTMLElement;
23
+ [key: string]: any;
24
+ } & ({
23
25
  mode?: 'front';
24
26
  } | {
25
- ratio?: number;
26
- dpr?: number;
27
- autoRender?: boolean;
28
27
  mode: 'behind';
29
28
  behindFiveContainer: HTMLElement;
30
- }) => {
29
+ })) => {
31
30
  container: HTMLElement;
32
31
  dispose: () => void;
33
- object: CSS3DObject;
32
+ css3DObject: CSS3DObject;
34
33
  render?: () => void;
35
34
  } | void;
36
35
  /**
@@ -21,55 +21,184 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
21
21
 
22
22
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
23
 
24
- function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure undefined"); }
25
-
26
24
  /**
27
25
  * **CSS3DRenderPlugin** 提供矩形区域(三维空间四个坐标点),你可以在此矩形区域中渲染 DOM 内容。
28
26
  * 实现原理参考[CSS3DRenderer](https://threejs.org/docs/index.html?q=CSS3D#examples/en/renderers/CSS3DRenderer)。
29
27
  *
30
28
  * @returns
31
29
  */
32
- var CSS3DRenderPlugin = function CSS3DRenderPlugin(five, _ref) {
33
- _objectDestructuringEmpty(_ref);
34
-
30
+ var CSS3DRenderPlugin = function CSS3DRenderPlugin(five) {
35
31
  var state = {
36
32
  disposeCallbacks: []
37
33
  };
38
34
 
39
- var create3DDomContainer = function create3DDomContainer(points, container, config) {
40
- var _five$model;
35
+ var create3DDomContainer = function create3DDomContainer() {
36
+ var _five$model, _five$model2, _config$autoRender;
41
37
 
42
- if ((points === null || points === void 0 ? void 0 : points.length) < 3) {
43
- return console.error('points must be equal or greater than than 3');
38
+ for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
39
+ params[_key] = arguments[_key];
44
40
  }
45
41
 
46
- if (!(five !== null && five !== void 0 && (_five$model = five.model) !== null && _five$model !== void 0 && _five$model.loaded)) {
47
- var _five$model2;
42
+ var points = params[0],
43
+ config = params[1];
44
+ if ((points === null || points === void 0 ? void 0 : points.length) < 4) return console.error('points must be equal or greater than than 4');
45
+ if (!(five !== null && five !== void 0 && (_five$model = five.model) !== null && _five$model !== void 0 && _five$model.loaded)) return console.error('five.model.loaded is: ', five === null || five === void 0 ? void 0 : (_five$model2 = five.model) === null || _five$model2 === void 0 ? void 0 : _five$model2.loaded);
46
+ var fiveElement = five.getElement();
47
+ if (!fiveElement) return console.error('five.getElement() is ' + fiveElement);
48
+ var disposers = [];
49
+ var ratio = (config === null || config === void 0 ? void 0 : config.ratio) || 0.00216;
50
+ if (ratio <= 0.00215) console.warn('if you need click css3DElement on safari, ratio must be greater than 0.00215');
51
+ var dpr = (config === null || config === void 0 ? void 0 : config.dpr) || 1;
52
+ var mode = (config === null || config === void 0 ? void 0 : config.mode) || 'front';
53
+ var autoRender = (_config$autoRender = config === null || config === void 0 ? void 0 : config.autoRender) !== null && _config$autoRender !== void 0 ? _config$autoRender : true;
54
+ var behindFiveContainer = (config === null || config === void 0 ? void 0 : config.behindFiveContainer) || fiveElement.parentElement || document.body;
55
+ var container = (config === null || config === void 0 ? void 0 : config.container) || document.createElement('div'); // 获取css3DObject, 如果mode为behind的话,一起获取mesh
56
+
57
+ var _createObject = createObject(points, {
58
+ ratio: ratio,
59
+ dpr: dpr,
60
+ container: container,
61
+ mode: mode
62
+ }),
63
+ css3DObject = _createObject.css3DObject,
64
+ mesh = _createObject.mesh; // ======= INIT START =======
65
+
66
+
67
+ var resizeObserver;
68
+ var frontModeUnInited = mode === 'front' && !state.frontMode;
69
+ var behindModeUnInited = mode === 'behind' && !state.behindMode;
70
+ var inited = !(frontModeUnInited || behindModeUnInited);
71
+ var stopRenderFlag = false;
72
+ var requestAnimationFrameId = null;
73
+
74
+ var render = function render() {};
48
75
 
49
- return console.error('five.model.loaded is: ', five === null || five === void 0 ? void 0 : (_five$model2 = five.model) === null || _five$model2 === void 0 ? void 0 : _five$model2.loaded);
76
+ if (behindModeUnInited) {
77
+ state.behindMode = {
78
+ scene: new THREE.Scene(),
79
+ css3DRenderer: new _CSS3DRenderer.CSS3DRenderer()
80
+ };
50
81
  }
51
82
 
52
- var fiveElement = five.getElement();
83
+ if (frontModeUnInited) {
84
+ state.frontMode = {
85
+ scene: new THREE.Scene(),
86
+ css3DRenderer: new _CSS3DRenderer.CSS3DRenderer()
87
+ };
88
+ }
89
+
90
+ var _ref = mode === 'behind' ? state.behindMode : state.frontMode,
91
+ scene = _ref.scene,
92
+ css3DRenderer = _ref.css3DRenderer;
93
+
94
+ if (!inited) {
95
+ var css3DRendererSetSize = function css3DRendererSetSize() {
96
+ var rendererWidth = (0, _evenNumber["default"])(fiveElement.clientWidth);
97
+ var rendererHeight = (0, _evenNumber["default"])(fiveElement.clientHeight);
98
+ css3DRenderer.setSize(rendererWidth, rendererHeight);
99
+ };
100
+
101
+ css3DRendererSetSize();
102
+ resizeObserver = new ResizeObserver(css3DRendererSetSize);
103
+ css3DRenderer.domElement.style.position = 'absolute';
104
+ css3DRenderer.domElement.style.top = '0';
105
+ css3DRenderer.domElement.style.userSelect = 'none';
106
+ css3DRenderer.domElement.style.pointerEvents = 'none';
107
+
108
+ var renderEveryFrame = function renderEveryFrame() {
109
+ if (stopRenderFlag) return;
110
+ requestAnimationFrameId = requestAnimationFrame(renderEveryFrame);
111
+ css3DRenderer.render(scene, five.camera);
112
+ };
113
+
114
+ render = function render() {
115
+ var _resizeObserver;
116
+
117
+ scene.add(css3DObject);
118
+ (_resizeObserver = resizeObserver) === null || _resizeObserver === void 0 ? void 0 : _resizeObserver.observe(fiveElement);
119
+ renderEveryFrame();
120
+
121
+ if (mode === 'behind' && mesh) {
122
+ five.scene.add(mesh);
123
+ disposers.push(function () {
124
+ return mesh && five.scene.remove(mesh);
125
+ });
126
+ }
127
+ };
128
+ } else {
129
+ render = function render() {
130
+ scene.add(css3DObject);
131
+ };
132
+ }
53
133
 
54
- if (!fiveElement) {
55
- return console.error('five.getElement() is ' + fiveElement);
134
+ if (frontModeUnInited) {
135
+ var wrapper = fiveElement.parentElement || document.body;
136
+ wrapper.appendChild(css3DRenderer.domElement);
56
137
  }
57
138
 
58
- var disposers = [];
59
- var ratio = (config === null || config === void 0 ? void 0 : config.ratio) || 0.002; // 0.72 / 354 0.72m宽的窗户,UI稿上是354像素
139
+ if (behindModeUnInited) {
140
+ var _wrapper = behindFiveContainer;
60
141
 
61
- var dpr = (config === null || config === void 0 ? void 0 : config.dpr) || 1;
62
- var mode = (config === null || config === void 0 ? void 0 : config.mode) || 'front';
63
- var autoRender = (config === null || config === void 0 ? void 0 : config.autoRender) || true;
64
- var behindFiveContainer = (config === null || config === void 0 ? void 0 : config.behindFiveContainer) || fiveElement.parentElement || document.body;
142
+ _wrapper.appendChild(css3DRenderer.domElement);
143
+ } // ======= INIT END =======
144
+
145
+
146
+ var dispose = function dispose() {
147
+ stopRenderFlag = true;
148
+ disposers.forEach(function (d) {
149
+ return d === null || d === void 0 ? void 0 : d();
150
+ });
151
+ scene.remove(css3DObject);
152
+ if (typeof requestAnimationFrameId === 'number') cancelAnimationFrame(requestAnimationFrameId);
153
+
154
+ if (scene.children.length === 0) {
155
+ css3DRenderer.domElement.remove();
156
+ if (mode === 'front') state.frontMode = undefined;
157
+ if (mode === 'behind') state.behindMode = undefined;
158
+
159
+ if (!state.behindMode && !state.frontMode) {
160
+ var _resizeObserver2;
161
+
162
+ (_resizeObserver2 = resizeObserver) === null || _resizeObserver2 === void 0 ? void 0 : _resizeObserver2.unobserve(fiveElement);
163
+ }
164
+ }
165
+
166
+ return true;
167
+ };
168
+
169
+ var idx = state.disposeCallbacks.findIndex(function (item) {
170
+ return item === dispose;
171
+ });
172
+
173
+ if (idx !== -1) {
174
+ state.disposeCallbacks.splice(idx, 1);
175
+ } else {
176
+ state.disposeCallbacks.push(dispose);
177
+ }
178
+
179
+ console.log({
180
+ autoRender: autoRender
181
+ });
182
+ if (autoRender) render();
183
+ return {
184
+ container: container,
185
+ dispose: dispose,
186
+ css3DObject: css3DObject,
187
+ render: autoRender ? undefined : render
188
+ };
189
+ };
190
+
191
+ var createObject = function createObject(points, config) {
192
+ var ratio = config.ratio,
193
+ dpr = config.dpr,
194
+ element = config.container,
195
+ mode = config.mode;
65
196
  var planeWidth = points[0].distanceTo(points[1]);
66
197
  var planeHeight = points[1].distanceTo(points[2]);
67
198
  var domWidthPx = (0, _evenNumber["default"])(planeWidth / ratio * dpr);
68
199
  var domHeightPx = (0, _evenNumber["default"])(planeHeight / ratio * dpr);
69
- var css3DScene = new THREE.Scene();
70
- var element = container || document.createElement('div');
71
- var object = new _CSS3DRenderer.CSS3DObject(element);
72
- object.scale.set(ratio, ratio, ratio);
200
+ var css3DObject = new _CSS3DRenderer.CSS3DObject(element);
201
+ css3DObject.scale.set(ratio, ratio, ratio);
73
202
  element.style.width = domWidthPx + 'px';
74
203
  element.style.height = domHeightPx + 'px';
75
204
  element.style.pointerEvents = 'none';
@@ -91,14 +220,13 @@ var CSS3DRenderPlugin = function CSS3DRenderPlugin(five, _ref) {
91
220
  var rolateX = (vector12.z > 0 ? 1 : -1) * rotateXAngle;
92
221
  var rolateY = (vector01.z < 0 ? 1 : -1) * rotateYAngle;
93
222
  var rolateZ = (vector01.x > 0 && vector01.y < 0 || vector01.x < 0 && vector01.y > 0 ? -1 : 1) * rotateZAngle;
94
- object.rotateOnWorldAxis(new THREE.Vector3(1, 0, 0), rolateX); // x
223
+ css3DObject.rotateOnWorldAxis(new THREE.Vector3(1, 0, 0), rolateX); // x
95
224
 
96
- object.rotateOnWorldAxis(new THREE.Vector3(0, 1, 0), rolateY); // y
225
+ css3DObject.rotateOnWorldAxis(new THREE.Vector3(0, 1, 0), rolateY); // y
97
226
 
98
- object.rotateOnWorldAxis(new THREE.Vector3(0, 0, 1), rolateZ); // z
227
+ css3DObject.rotateOnWorldAxis(new THREE.Vector3(0, 0, 1), rolateZ); // z
99
228
 
100
- object.position.set(centerPosition.x, centerPosition.y, centerPosition.z);
101
- css3DScene.add(object);
229
+ css3DObject.position.set(centerPosition.x, centerPosition.y, centerPosition.z);
102
230
  var mesh;
103
231
 
104
232
  if (mode === 'behind') {
@@ -110,105 +238,22 @@ var CSS3DRenderPlugin = function CSS3DRenderPlugin(five, _ref) {
110
238
  var geometry = new THREE.PlaneGeometry(domWidthPx, domHeightPx);
111
239
  mesh = new THREE.Mesh(geometry, material);
112
240
  mesh.name = 'CSS3DRenderPlugin-mesh';
113
- mesh.position.copy(object.position);
114
- mesh.rotation.copy(object.rotation);
115
- mesh.scale.copy(object.scale);
116
- }
117
-
118
- var css3DRenderer = new _CSS3DRenderer.CSS3DRenderer();
119
-
120
- var css3DRendererSetSize = function css3DRendererSetSize() {
121
- var rendererWidth = (0, _evenNumber["default"])(fiveElement.clientWidth);
122
- var rendererHeight = (0, _evenNumber["default"])(fiveElement.clientHeight);
123
- css3DRenderer.setSize(rendererWidth, rendererHeight);
124
- };
125
-
126
- css3DRendererSetSize();
127
- var resizeObserver = new ResizeObserver(css3DRendererSetSize);
128
- css3DRenderer.domElement.style.position = 'absolute';
129
- css3DRenderer.domElement.style.top = '0';
130
- css3DRenderer.domElement.style.userSelect = 'none';
131
- css3DRenderer.domElement.style.pointerEvents = 'none';
132
-
133
- if (mode === 'front') {
134
- var wrapper = fiveElement.parentElement || document.body;
135
- wrapper.appendChild(css3DRenderer.domElement);
136
- } else {
137
- var _wrapper = behindFiveContainer;
138
-
139
- _wrapper.appendChild(css3DRenderer.domElement);
140
- }
141
-
142
- var stopRenderFlag = false;
143
- var requestAnimationFrameId = null;
144
-
145
- var dispose = function dispose() {
146
- stopRenderFlag = true;
147
-
148
- try {
149
- disposers.forEach(function (d) {
150
- return d === null || d === void 0 ? void 0 : d();
151
- });
152
- element.remove();
153
-
154
- if (typeof requestAnimationFrameId === 'number') {
155
- cancelAnimationFrame(requestAnimationFrameId);
156
- }
157
-
158
- css3DScene.remove(object);
159
- css3DScene.dispose();
160
- css3DRenderer.domElement.remove();
161
- resizeObserver.unobserve(fiveElement);
162
- return true;
163
- } catch (e) {
164
- console.warn('error:', e);
165
- }
166
-
167
- return false;
168
- };
169
-
170
- var idx = state.disposeCallbacks.findIndex(function (item) {
171
- return item === dispose;
172
- });
173
-
174
- if (idx !== -1) {
175
- state.disposeCallbacks.splice(idx, 1);
176
- } else {
177
- state.disposeCallbacks.push(dispose);
241
+ mesh.position.copy(css3DObject.position);
242
+ mesh.rotation.copy(css3DObject.rotation);
243
+ mesh.scale.copy(css3DObject.scale);
178
244
  }
179
245
 
180
- var renderEveryFrame = function renderEveryFrame() {
181
- if (stopRenderFlag) return;
182
- requestAnimationFrameId = requestAnimationFrame(renderEveryFrame);
183
- css3DRenderer.render(css3DScene, five.camera);
184
- };
185
-
186
- var render = function render() {
187
- resizeObserver.observe(fiveElement);
188
- renderEveryFrame();
189
-
190
- if (mode === 'behind' && mesh) {
191
- five.scene.add(mesh);
192
- disposers.push(function () {
193
- return mesh && five.scene.remove(mesh);
194
- });
195
- }
196
- };
197
-
198
- if (autoRender) render();
199
246
  return {
200
- container: element,
201
- dispose: dispose,
202
- object: object,
203
- render: autoRender ? undefined : render
247
+ css3DObject: css3DObject,
248
+ mesh: mesh
204
249
  };
205
250
  };
206
251
 
207
252
  return {
208
253
  create3DDomContainer: create3DDomContainer,
209
254
  disposeAll: function disposeAll() {
210
- state.disposeCallbacks.forEach(function (dispose) {
211
- return dispose === null || dispose === void 0 ? void 0 : dispose();
255
+ state.disposeCallbacks.forEach(function (d) {
256
+ return d === null || d === void 0 ? void 0 : d();
212
257
  });
213
258
  state.disposeCallbacks = [];
214
259
  }
@@ -1,6 +1,7 @@
1
1
  import * as THREE from 'three';
2
2
  import { Five, Subscribe } from '@realsee/five';
3
3
  import { TREASURE_TYPE } from './constants';
4
+ import { TreasureObject } from './TreasureObject';
4
5
  export declare type TreasureObjectAssetMap = Map<string, Promise<THREE.Group>>;
5
6
  /** 对每个宝箱实例的配置 */
6
7
  export interface TreasurePluginItemConfigData {
@@ -37,29 +38,36 @@ export interface TreasurePluginData {
37
38
  export declare type TreasurePluginParameterType = undefined;
38
39
  export declare type TreasurePluginEvents = {
39
40
  /** 点击宝箱事件
40
- * @param id: 宝箱 ID
41
+ * @param params.id: 宝箱 ID
41
42
  */
42
43
  tap: (params: {
43
44
  id: string;
44
45
  }) => void;
45
- /** 宝箱打开的动画执行完毕 */
46
+ /** 宝箱打开的动画执行完毕
47
+ * @param params.id: 宝箱 ID
48
+ */
46
49
  openAnimationEnded: (params: {
47
50
  id: string;
48
51
  }) => void;
49
52
  };
50
53
  export declare class TreasurePluginController {
51
- hooks: Subscribe<TreasurePluginEvents>;
54
+ readonly hooks: Subscribe<TreasurePluginEvents>;
55
+ readonly treasures: TreasureObject[];
52
56
  private five;
53
57
  private selfGroup;
54
- private treasures;
55
58
  private textureLoader;
56
59
  private modelLoader;
57
60
  constructor(five: Five);
58
- load(data: TreasurePluginData): Promise<boolean>;
59
- dispose(): void;
61
+ load(data: TreasurePluginData, options?: {
62
+ appendTreasuresAfterLoaded?: boolean;
63
+ }): Promise<TreasureObject[]>;
64
+ dispose: () => void;
65
+ appendChild(child: TreasureObject): TreasurePluginController;
66
+ appendChildByID(childID: string): TreasurePluginController;
67
+ getTreasureByID(id: string): TreasureObject | undefined;
60
68
  removeTreasureByID(id: string): boolean;
61
69
  private onTreasureClick;
62
- private getTextureObjectParams;
70
+ private getTreasureObjectParams;
63
71
  private onTreasureOpenAnimationEnded;
64
72
  private getConfig;
65
73
  }
@@ -75,13 +75,25 @@ var TreasurePluginController = /*#__PURE__*/function () {
75
75
 
76
76
  _defineProperty(this, "modelLoader", (0, _getExtraModelLoader.getExtraModelLoader)());
77
77
 
78
+ _defineProperty(this, "dispose", function () {
79
+ _this.modelLoader.dispose();
80
+
81
+ _this.textureLoader.dispose();
82
+
83
+ _this.five.scene.remove(_this.selfGroup);
84
+
85
+ _this.treasures.forEach(function (treasure) {
86
+ return treasure.dispose();
87
+ });
88
+ });
89
+
78
90
  _defineProperty(this, "onTreasureClick", function (id) {
79
91
  _this.hooks.emit('tap', {
80
92
  id: id
81
93
  });
82
94
  });
83
95
 
84
- _defineProperty(this, "getTextureObjectParams", function (data) {
96
+ _defineProperty(this, "getTreasureObjectParams", function (data) {
85
97
  var config = _this.getConfig(data);
86
98
 
87
99
  var position = new THREE.Vector3().fromArray(Object.values(data.position));
@@ -108,22 +120,23 @@ var TreasurePluginController = /*#__PURE__*/function () {
108
120
  this.selfGroup = new THREE.Group();
109
121
  this.selfGroup.name = 'treasure-plugin-group';
110
122
  this.five.scene.add(this.selfGroup);
123
+ this.five.once('dispose', this.dispose);
111
124
  }
112
125
 
113
126
  _createClass(TreasurePluginController, [{
114
127
  key: "load",
115
128
  value: function () {
116
- var _load = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(data) {
117
- var _this$selfGroup;
129
+ var _load = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(data, options) {
130
+ var _this$treasures;
118
131
 
119
- var _yield$to, _yield$to2, error, treasures;
132
+ var _yield$to, _yield$to2, error, treasures, appendTreasuresAfterLoaded, _this$selfGroup;
120
133
 
121
134
  return regeneratorRuntime.wrap(function _callee$(_context) {
122
135
  while (1) {
123
136
  switch (_context.prev = _context.next) {
124
137
  case 0:
125
138
  _context.next = 2;
126
- return (0, _to["default"])(Promise.all(data.treasures.map(this.getTextureObjectParams).filter(_isNil.notNil).map(function (params) {
139
+ return (0, _to["default"])(Promise.all(data.treasures.map(this.getTreasureObjectParams).filter(_isNil.notNil).map(function (params) {
127
140
  return new _TreasureObject.TreasureObject(params).load();
128
141
  })));
129
142
 
@@ -141,12 +154,19 @@ var TreasurePluginController = /*#__PURE__*/function () {
141
154
  throw error;
142
155
 
143
156
  case 8:
144
- (_this$selfGroup = this.selfGroup).add.apply(_this$selfGroup, _toConsumableArray(treasures));
157
+ (_this$treasures = this.treasures).push.apply(_this$treasures, _toConsumableArray(treasures));
145
158
 
146
- this.treasures = treasures;
147
- return _context.abrupt("return", true);
159
+ appendTreasuresAfterLoaded = (options === null || options === void 0 ? void 0 : options.appendTreasuresAfterLoaded) || true;
148
160
 
149
- case 11:
161
+ if (appendTreasuresAfterLoaded) {
162
+ (_this$selfGroup = this.selfGroup).add.apply(_this$selfGroup, _toConsumableArray(treasures));
163
+
164
+ this.five.needsRender = true;
165
+ }
166
+
167
+ return _context.abrupt("return", treasures);
168
+
169
+ case 12:
150
170
  case "end":
151
171
  return _context.stop();
152
172
  }
@@ -154,19 +174,32 @@ var TreasurePluginController = /*#__PURE__*/function () {
154
174
  }, _callee, this);
155
175
  }));
156
176
 
157
- function load(_x) {
177
+ function load(_x, _x2) {
158
178
  return _load.apply(this, arguments);
159
179
  }
160
180
 
161
181
  return load;
162
182
  }()
163
183
  }, {
164
- key: "dispose",
165
- value: function dispose() {
166
- this.modelLoader.dispose();
167
- this.textureLoader.dispose();
168
- this.treasures.forEach(function (treasure) {
169
- return treasure.dispose();
184
+ key: "appendChild",
185
+ value: function appendChild(child) {
186
+ this.selfGroup.add(child);
187
+ this.five.needsRender = true;
188
+ return this;
189
+ }
190
+ }, {
191
+ key: "appendChildByID",
192
+ value: function appendChildByID(childID) {
193
+ var treasure = this.getTreasureByID(childID);
194
+ if (!treasure) throw new Error('can not find treasure which has ID ' + childID);
195
+ this.appendChild(treasure);
196
+ return this;
197
+ }
198
+ }, {
199
+ key: "getTreasureByID",
200
+ value: function getTreasureByID(id) {
201
+ return this.treasures.find(function (treasure) {
202
+ return treasure.treasureID === id;
170
203
  });
171
204
  }
172
205
  }, {
@@ -30,14 +30,24 @@ export declare class TreasureObject extends THREE.Object3D {
30
30
  private params;
31
31
  private faceAnime?;
32
32
  private openAnime?;
33
+ private modelGroupPromise;
33
34
  constructor(params: TreasureObjectParams);
35
+ load(): Promise<TreasureObject>;
36
+ show(params?: {
37
+ duration?: number;
38
+ }): Promise<boolean>;
39
+ hide(params?: {
40
+ duration?: number;
41
+ }): Promise<boolean>;
34
42
  /** 销毁当前宝箱实例
35
43
  * @description 注意 dispose 并不会销毁所使用的贴图,因为贴图会有共用关系,需要在最外层销毁
36
44
  */
37
45
  dispose(): void;
46
+ /** 旋转宝箱朝向用户 */
38
47
  rotateToCamera(): void;
39
- private open;
40
- load(): Promise<TreasureObject>;
48
+ /** 打开宝箱 */
49
+ open(): boolean;
50
+ private getModelPromise;
41
51
  private onFiveWantsTapGesture;
42
52
  private onFivePanoArrived;
43
53
  }
@@ -9,6 +9,8 @@ exports.TreasureObject = void 0;
9
9
 
10
10
  var THREE = _interopRequireWildcard(require("three"));
11
11
 
12
+ var TWEEN = _interopRequireWildcard(require("@tweenjs/tween.js"));
13
+
12
14
  var _TreasureFaceAnime = require("./TreasureFaceAnime");
13
15
 
14
16
  var _TreasureOpenAnime = require("./TreasureOpenAnime");
@@ -86,6 +88,11 @@ var TreasureObject = /*#__PURE__*/function (_THREE$Object3D) {
86
88
 
87
89
  _defineProperty(_assertThisInitialized(_this), "opened", false);
88
90
 
91
+ _defineProperty(_assertThisInitialized(_this), "modelGroupPromise", Promise.resolve({
92
+ modelGroup: new THREE.Group(),
93
+ originGroup: new THREE.Group()
94
+ }));
95
+
89
96
  _defineProperty(_assertThisInitialized(_this), "onFiveWantsTapGesture", function (raycaster) {
90
97
  var _this$params$clickCal, _this$params;
91
98
 
@@ -117,12 +124,158 @@ var TreasureObject = /*#__PURE__*/function (_THREE$Object3D) {
117
124
 
118
125
  return _this;
119
126
  }
120
- /** 销毁当前宝箱实例
121
- * @description 注意 dispose 并不会销毁所使用的贴图,因为贴图会有共用关系,需要在最外层销毁
122
- */
123
-
124
127
 
125
128
  _createClass(TreasureObject, [{
129
+ key: "load",
130
+ value: function () {
131
+ var _load = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
132
+ var _this2 = this;
133
+
134
+ var _yield$this$modelGrou, modelGroup, originGroup;
135
+
136
+ return regeneratorRuntime.wrap(function _callee$(_context) {
137
+ while (1) {
138
+ switch (_context.prev = _context.next) {
139
+ case 0:
140
+ this.modelGroupPromise = this.getModelPromise();
141
+ _context.next = 3;
142
+ return this.modelGroupPromise;
143
+
144
+ case 3:
145
+ _yield$this$modelGrou = _context.sent;
146
+ modelGroup = _yield$this$modelGrou.modelGroup;
147
+ originGroup = _yield$this$modelGrou.originGroup;
148
+ this.add(modelGroup); // ========== openAnime ==========
149
+
150
+ this.openAnime = new _TreasureOpenAnime.TreasurePluginOpenAnime({
151
+ five: this.five,
152
+ treasureGroup: modelGroup,
153
+ onComplete: function onComplete() {
154
+ var _this2$params$onOpenA, _this2$params;
155
+
156
+ return (_this2$params$onOpenA = (_this2$params = _this2.params).onOpenAnimationEnded) === null || _this2$params$onOpenA === void 0 ? void 0 : _this2$params$onOpenA.call(_this2$params, _this2.treasureID);
157
+ },
158
+ animationClip: originGroup.animations[0]
159
+ }); // ========== faceAnime ==========
160
+
161
+ this.faceAnime = new _TreasureFaceAnime.TreasureFaceAnime({
162
+ five: this.five,
163
+ treasureGroup: modelGroup,
164
+ loadTexture: this.params.loadTexture,
165
+ textureUrls: this.params.config.faceAnimeTextureUrls
166
+ });
167
+ this.faceAnime.play(); // ========== addEventListener ==========
168
+
169
+ this.five.on('panoArrived', this.onFivePanoArrived);
170
+ this.five.on('wantsTapGesture', this.onFiveWantsTapGesture);
171
+ this.five.needsRender = true;
172
+ return _context.abrupt("return", this);
173
+
174
+ case 14:
175
+ case "end":
176
+ return _context.stop();
177
+ }
178
+ }
179
+ }, _callee, this);
180
+ }));
181
+
182
+ function load() {
183
+ return _load.apply(this, arguments);
184
+ }
185
+
186
+ return load;
187
+ }()
188
+ }, {
189
+ key: "show",
190
+ value: function () {
191
+ var _show = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(params) {
192
+ var _params$duration,
193
+ _this3 = this;
194
+
195
+ var _yield$this$modelGrou2, modelGroup;
196
+
197
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
198
+ while (1) {
199
+ switch (_context2.prev = _context2.next) {
200
+ case 0:
201
+ _context2.next = 2;
202
+ return this.modelGroupPromise;
203
+
204
+ case 2:
205
+ _yield$this$modelGrou2 = _context2.sent;
206
+ modelGroup = _yield$this$modelGrou2.modelGroup;
207
+ (0, _BetterTween.tweenProgress)().duration((_params$duration = params === null || params === void 0 ? void 0 : params.duration) !== null && _params$duration !== void 0 ? _params$duration : 300).easing(TWEEN.Easing.Quadratic.InOut).onUpdate(function (_ref) {
208
+ var progress = _ref.progress;
209
+ modelGroup.children.forEach(function (child) {
210
+ var obj = child;
211
+ obj.material && (obj.material.opacity = progress);
212
+ _this3.five.needsRender = true;
213
+ });
214
+ }).play();
215
+ return _context2.abrupt("return", true);
216
+
217
+ case 6:
218
+ case "end":
219
+ return _context2.stop();
220
+ }
221
+ }
222
+ }, _callee2, this);
223
+ }));
224
+
225
+ function show(_x) {
226
+ return _show.apply(this, arguments);
227
+ }
228
+
229
+ return show;
230
+ }()
231
+ }, {
232
+ key: "hide",
233
+ value: function () {
234
+ var _hide = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(params) {
235
+ var _params$duration2,
236
+ _this4 = this;
237
+
238
+ var _yield$this$modelGrou3, modelGroup;
239
+
240
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
241
+ while (1) {
242
+ switch (_context3.prev = _context3.next) {
243
+ case 0:
244
+ _context3.next = 2;
245
+ return this.modelGroupPromise;
246
+
247
+ case 2:
248
+ _yield$this$modelGrou3 = _context3.sent;
249
+ modelGroup = _yield$this$modelGrou3.modelGroup;
250
+ (0, _BetterTween.tweenProgress)().duration((_params$duration2 = params === null || params === void 0 ? void 0 : params.duration) !== null && _params$duration2 !== void 0 ? _params$duration2 : 300).easing(TWEEN.Easing.Quadratic.InOut).onUpdate(function (_ref2) {
251
+ var progress = _ref2.progress;
252
+ modelGroup.children.forEach(function (child) {
253
+ var obj = child;
254
+ obj.material && (obj.material.opacity = 1 - progress);
255
+ _this4.five.needsRender = true;
256
+ });
257
+ }).play();
258
+ return _context3.abrupt("return", true);
259
+
260
+ case 6:
261
+ case "end":
262
+ return _context3.stop();
263
+ }
264
+ }
265
+ }, _callee3, this);
266
+ }));
267
+
268
+ function hide(_x2) {
269
+ return _hide.apply(this, arguments);
270
+ }
271
+
272
+ return hide;
273
+ }()
274
+ /** 销毁当前宝箱实例
275
+ * @description 注意 dispose 并不会销毁所使用的贴图,因为贴图会有共用关系,需要在最外层销毁
276
+ */
277
+
278
+ }, {
126
279
  key: "dispose",
127
280
  value: function dispose() {
128
281
  var _this$faceAnime, _this$openAnime;
@@ -132,10 +285,12 @@ var TreasureObject = /*#__PURE__*/function (_THREE$Object3D) {
132
285
  this.five.off('panoArrived', this.onFivePanoArrived);
133
286
  this.five.off('wantsTapGesture', this.onFiveWantsTapGesture);
134
287
  }
288
+ /** 旋转宝箱朝向用户 */
289
+
135
290
  }, {
136
291
  key: "rotateToCamera",
137
292
  value: function rotateToCamera() {
138
- var _this2 = this;
293
+ var _this5 = this;
139
294
 
140
295
  if (this.opened) return; // 宝箱朝向
141
296
 
@@ -150,11 +305,13 @@ var TreasureObject = /*#__PURE__*/function (_THREE$Object3D) {
150
305
  var speed = 8;
151
306
  var duration = Math.ceil(deltaRadY / speed * 1000);
152
307
  var rotationStartY = this.rotation.y;
153
- (0, _BetterTween.tweenProgress)(duration).onUpdate(function (_ref) {
154
- var progress = _ref.progress;
155
- _this2.rotation.y = rotationStartY + progress * deltaRadY * rotateDirection;
308
+ (0, _BetterTween.tweenProgress)(duration).onUpdate(function (_ref3) {
309
+ var progress = _ref3.progress;
310
+ _this5.rotation.y = rotationStartY + progress * deltaRadY * rotateDirection;
156
311
  }).play();
157
312
  }
313
+ /** 打开宝箱 */
314
+
158
315
  }, {
159
316
  key: "open",
160
317
  value: function open() {
@@ -169,36 +326,22 @@ var TreasureObject = /*#__PURE__*/function (_THREE$Object3D) {
169
326
  return true;
170
327
  }
171
328
  }, {
172
- key: "load",
329
+ key: "getModelPromise",
173
330
  value: function () {
174
- var _load = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
175
- var _this3 = this;
176
-
177
- var _yield$to, _yield$to2, loadError, orginModelGroup, group, _yield$to3, _yield$to4, boxTextureError, boxTexture;
331
+ var _getModelPromise = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
332
+ var originGroup, modelGroup, _yield$to, _yield$to2, boxTextureError, boxTexture;
178
333
 
179
- return regeneratorRuntime.wrap(function _callee$(_context) {
334
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
180
335
  while (1) {
181
- switch (_context.prev = _context.next) {
336
+ switch (_context4.prev = _context4.next) {
182
337
  case 0:
183
- _context.next = 2;
184
- return (0, _to["default"])(this.params.loadModelGroup(this.params.config.objectUrl));
338
+ _context4.next = 2;
339
+ return this.params.loadModelGroup(this.params.config.objectUrl);
185
340
 
186
341
  case 2:
187
- _yield$to = _context.sent;
188
- _yield$to2 = _slicedToArray(_yield$to, 2);
189
- loadError = _yield$to2[0];
190
- orginModelGroup = _yield$to2[1];
191
-
192
- if (!(loadError || !orginModelGroup)) {
193
- _context.next = 8;
194
- break;
195
- }
196
-
197
- throw loadError;
198
-
199
- case 8:
200
- group = orginModelGroup.clone();
201
- group.traverse(function (obj) {
342
+ originGroup = _context4.sent;
343
+ modelGroup = originGroup.clone();
344
+ modelGroup.traverse(function (obj) {
202
345
  if (!(obj instanceof THREE.Mesh)) return;
203
346
  obj.material = copyMaterial(obj.material);
204
347
  if (obj.material.map) obj.material.map.encoding = THREE.sRGBEncoding;
@@ -206,71 +349,50 @@ var TreasureObject = /*#__PURE__*/function (_THREE$Object3D) {
206
349
  });
207
350
 
208
351
  if (!this.params.config.boxTextureUrl) {
209
- _context.next = 22;
352
+ _context4.next = 17;
210
353
  break;
211
354
  }
212
355
 
213
- _context.next = 13;
356
+ _context4.next = 8;
214
357
  return (0, _to["default"])(this.params.loadTexture(this.params.config.boxTextureUrl));
215
358
 
216
- case 13:
217
- _yield$to3 = _context.sent;
218
- _yield$to4 = _slicedToArray(_yield$to3, 2);
219
- boxTextureError = _yield$to4[0];
220
- boxTexture = _yield$to4[1];
359
+ case 8:
360
+ _yield$to = _context4.sent;
361
+ _yield$to2 = _slicedToArray(_yield$to, 2);
362
+ boxTextureError = _yield$to2[0];
363
+ boxTexture = _yield$to2[1];
221
364
 
222
365
  if (!(boxTextureError || !boxTexture)) {
223
- _context.next = 19;
366
+ _context4.next = 14;
224
367
  break;
225
368
  }
226
369
 
227
370
  throw new Error('加载盒子贴图失败');
228
371
 
229
- case 19:
372
+ case 14:
230
373
  boxTexture.encoding = THREE.sRGBEncoding;
231
- group.getObjectByName('box').material.map = boxTexture;
232
- group.getObjectByName('box2').material.map = boxTexture;
374
+ modelGroup.getObjectByName('box').material.map = boxTexture;
375
+ modelGroup.getObjectByName('box2').material.map = boxTexture;
233
376
 
234
- case 22:
235
- this.add(group); // ========== openAnime ==========
236
-
237
- this.openAnime = new _TreasureOpenAnime.TreasurePluginOpenAnime({
238
- five: this.five,
239
- treasureGroup: group,
240
- onComplete: function onComplete() {
241
- var _this3$params$onOpenA, _this3$params;
242
-
243
- return (_this3$params$onOpenA = (_this3$params = _this3.params).onOpenAnimationEnded) === null || _this3$params$onOpenA === void 0 ? void 0 : _this3$params$onOpenA.call(_this3$params, _this3.treasureID);
244
- },
245
- animationClip: orginModelGroup.animations[0]
246
- }); // ========== faceAnime ==========
247
-
248
- this.faceAnime = new _TreasureFaceAnime.TreasureFaceAnime({
249
- five: this.five,
250
- treasureGroup: group,
251
- loadTexture: this.params.loadTexture,
252
- textureUrls: this.params.config.faceAnimeTextureUrls
377
+ case 17:
378
+ return _context4.abrupt("return", {
379
+ modelGroup: modelGroup,
380
+ originGroup: originGroup
253
381
  });
254
- this.faceAnime.play(); // ========== addEventListener ==========
255
-
256
- this.five.on('panoArrived', this.onFivePanoArrived);
257
- this.five.on('wantsTapGesture', this.onFiveWantsTapGesture);
258
- this.five.needsRender = true;
259
- return _context.abrupt("return", this);
260
382
 
261
- case 30:
383
+ case 18:
262
384
  case "end":
263
- return _context.stop();
385
+ return _context4.stop();
264
386
  }
265
387
  }
266
- }, _callee, this);
388
+ }, _callee4, this);
267
389
  }));
268
390
 
269
- function load() {
270
- return _load.apply(this, arguments);
391
+ function getModelPromise() {
392
+ return _getModelPromise.apply(this, arguments);
271
393
  }
272
394
 
273
- return load;
395
+ return getModelPromise;
274
396
  }()
275
397
  }]);
276
398
 
@@ -1,14 +1,14 @@
1
1
  import { Five } from '@realsee/five';
2
- import { Vector2 } from '../../../typings/math.type';
2
+ import { Vector2Position } from '../../../typings/math.type';
3
3
  import { FloorplanData } from '../typings/floorplanData';
4
4
  import { FloorplanBounding } from '../typings/floorplanData';
5
- export declare function pathD(points: Vector2[], options?: {
5
+ export declare function pathD(points: Vector2Position[], options?: {
6
6
  needZ?: boolean;
7
7
  needA?: Record<number, string>;
8
- format?: (vector: Vector2) => Vector2;
8
+ format?: (vector: Vector2Position) => Vector2Position;
9
9
  }): string;
10
10
  /** 把户型图上点点位转换到 SVG 上的点位 */
11
- export default function formatFloorplanPoint({ x, y }: Vector2, pxmm: number, bounding: FloorplanBounding): {
11
+ export default function formatFloorplanPoint({ x, y }: Vector2Position, pxmm: number, bounding: FloorplanBounding): {
12
12
  x: number;
13
13
  y: number;
14
14
  };
@@ -0,0 +1,7 @@
1
+ import { Vector3 } from 'three';
2
+ declare const transformPositionToVector3: ({ x, y, z }: {
3
+ x: number;
4
+ y: number;
5
+ z: number;
6
+ }) => Vector3;
7
+ export default transformPositionToVector3;
@@ -7,12 +7,12 @@ exports["default"] = void 0;
7
7
 
8
8
  var _three = require("three");
9
9
 
10
- var vector3 = function vector3(_ref) {
10
+ var transformPositionToVector3 = function transformPositionToVector3(_ref) {
11
11
  var x = _ref.x,
12
12
  y = _ref.y,
13
13
  z = _ref.z;
14
14
  return new _three.Vector3(x, y, z);
15
15
  };
16
16
 
17
- var _default = vector3;
17
+ var _default = transformPositionToVector3;
18
18
  exports["default"] = _default;
@@ -1,3 +1,3 @@
1
1
  export type { FloorplanData, FloorplanOutlineItem, FloorplanEntrance, FloorplanBounding, FloorplanObserver, FloorplanRoomItem, FloorplanRoomLabelItem, FloorplanPosition, FloorplanImagePosition, } from '../plugins/floorplan/typings/floorplanData';
2
- export type { Vector3, Vector3WithArray, Vector2, Vector2WithArray, Matrix4_4 } from '../typings/math.type';
2
+ export type { Vector3Position, Vector3WithArray, Vector2Position, Vector2WithArray, Matrix4_4, } from '../typings/math.type';
3
3
  export type { Omit, Overwrite } from '../typings/utils.type';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 三维向量
3
3
  */
4
- export interface Vector3 {
4
+ export interface Vector3Position {
5
5
  x: number;
6
6
  y: number;
7
7
  z: number;
@@ -13,7 +13,7 @@ export declare type Vector3WithArray = [number, number, number];
13
13
  /**
14
14
  * 二维向量
15
15
  */
16
- export interface Vector2 {
16
+ export interface Vector2Position {
17
17
  x: number;
18
18
  y: number;
19
19
  }
@@ -1,7 +0,0 @@
1
- import { Vector3 } from 'three';
2
- declare const vector3: ({ x, y, z }: {
3
- x: number;
4
- y: number;
5
- z: number;
6
- }) => Vector3;
7
- export default vector3;
@@ -1,7 +0,0 @@
1
- import { Vector3 } from 'three';
2
- declare const vector3: ({ x, y, z }: {
3
- x: number;
4
- y: number;
5
- z: number;
6
- }) => Vector3;
7
- export default vector3;
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
-
8
- var _three = require("three");
9
-
10
- var vector3 = function vector3(_ref) {
11
- var x = _ref.x,
12
- y = _ref.y,
13
- z = _ref.z;
14
- return new _three.Vector3(x, y, z);
15
- };
16
-
17
- var _default = vector3;
18
- exports["default"] = _default;