@realsee/dnalogel 0.1.0 → 0.1.1

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.
Files changed (32) hide show
  1. package/data/PrXel3aqGbp34JQn.js +10 -2
  2. package/package.json +1 -1
  3. package/plugins/TreasurePlugin/Controller.d.ts +42 -9
  4. package/plugins/TreasurePlugin/Controller.js +88 -52
  5. package/plugins/TreasurePlugin/TreasureFaceAnime.d.ts +8 -6
  6. package/plugins/TreasurePlugin/TreasureFaceAnime.js +4 -4
  7. package/plugins/TreasurePlugin/TreasureObject.d.ts +19 -11
  8. package/plugins/TreasurePlugin/TreasureObject.js +145 -51
  9. package/plugins/TreasurePlugin/TreasureOpenAnime.d.ts +4 -2
  10. package/plugins/TreasurePlugin/TreasureOpenAnime.js +10 -5
  11. package/plugins/TreasurePlugin/constants.d.ts +32 -11
  12. package/plugins/TreasurePlugin/constants.js +52 -17
  13. package/plugins/TreasurePlugin/index.d.ts +5 -5
  14. package/plugins/TreasurePlugin/index.js +8 -0
  15. package/plugins/floorplan/typings/floorplanData.d.ts +5 -1
  16. package/plugins/floorplan/utils/formatData.js +1 -22
  17. package/shared-utils/isNil.d.ts +10 -0
  18. package/shared-utils/isNil.js +24 -0
  19. package/shared-utils/three/getExtraModelLoader.d.ts +6 -0
  20. package/shared-utils/three/getExtraModelLoader.js +31 -0
  21. package/shared-utils/three/getTextureLoader.d.ts +6 -0
  22. package/shared-utils/three/getTextureLoader.js +34 -0
  23. package/shared-utils/three/loadFbxObj.d.ts +1 -2
  24. package/shared-utils/three/loadFbxObj.js +6 -2
  25. package/shared-utils/to.d.ts +0 -1
  26. package/shared-utils/to.js +45 -7
  27. package/typedoc/plugins.d.ts +1 -1
  28. package/typedoc/plugins.js +24 -12
  29. package/plugins/TreasurePlugin/treasureDataMap.d.ts +0 -7
  30. package/plugins/TreasurePlugin/treasureDataMap.js +0 -20
  31. package/plugins/TreasurePlugin/utils/loadTreasureTextures.d.ts +0 -7
  32. package/plugins/TreasurePlugin/utils/loadTreasureTextures.js +0 -115
@@ -4629,11 +4629,19 @@ var treasurePluginData = {
4629
4629
  treasures: [{
4630
4630
  id: 'a',
4631
4631
  type: 0,
4632
- position: [3.4688, 0.51802, 2.48252]
4632
+ position: {
4633
+ x: 3.4688,
4634
+ y: -0.5180200000000003,
4635
+ z: -2.48252
4636
+ }
4633
4637
  }, {
4634
4638
  id: 'b',
4635
4639
  type: 1,
4636
- position: [2.80488, 0.867187, -0.866459]
4640
+ position: {
4641
+ x: 2.80488,
4642
+ y: -0.867187,
4643
+ z: 0.866459
4644
+ }
4637
4645
  }]
4638
4646
  };
4639
4647
  exports.treasurePluginData = treasurePluginData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realsee/dnalogel",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Realsee Components(React) & Plugins(Five).",
5
5
  "author": "BEIKE REALSEE TECHNOLOGY (HK) LIMITED",
6
6
  "peerDependencies": {
@@ -1,13 +1,35 @@
1
- import { Five } from '@realsee/five';
2
- import { TreasureType } from './constants';
1
+ import * as THREE from 'three';
2
+ import { Five, Subscribe } from '@realsee/five';
3
+ import { TREASURE_TYPE } from './constants';
4
+ export declare type TreasureObjectAssetMap = Map<string, Promise<THREE.Group>>;
5
+ /** 对每个宝箱实例的配置 */
6
+ export interface TreasurePluginItemConfigData {
7
+ scale?: number;
8
+ /** 宝箱模型地址 */
9
+ object_url?: string;
10
+ /** 宝箱盒子使用的贴图
11
+ * @description
12
+ * * 默认使用 object_url 文件中的盒子贴图
13
+ * * 如果传了 box_texture_url 会替换默认贴图
14
+ */
15
+ box_texture_url?: string;
16
+ /** 宝箱表情动画使用的贴图列表 */
17
+ face_anime_texture_urls?: string[];
18
+ }
3
19
  /** 宝箱数据 */
4
20
  export interface TreasurePluginItemData {
5
21
  /** 宝箱 ID */
6
22
  id: string;
7
- /** 宝箱位置:[x, y, z] */
8
- position: number[];
9
- /** 宝箱类型 */
10
- type: TreasureType;
23
+ /** 宝箱位置 */
24
+ position: {
25
+ x: number;
26
+ y: number;
27
+ z: number;
28
+ };
29
+ /** 使用预设的宝箱类型 */
30
+ type?: TREASURE_TYPE;
31
+ /** 如果不想使用预设的宝箱,可以传入自定义的宝箱配置 */
32
+ config?: TreasurePluginItemConfigData;
11
33
  }
12
34
  export interface TreasurePluginData {
13
35
  treasures: TreasurePluginItemData[];
@@ -17,16 +39,27 @@ export declare type TreasurePluginEvents = {
17
39
  /** 点击宝箱事件
18
40
  * @param id: 宝箱 ID
19
41
  */
20
- tap: (id: string) => void;
42
+ tap: (params: {
43
+ id: string;
44
+ }) => void;
45
+ /** 宝箱打开的动画执行完毕 */
46
+ openAnimationEnded: (params: {
47
+ id: string;
48
+ }) => void;
21
49
  };
22
50
  export declare class TreasurePluginController {
51
+ hooks: Subscribe<TreasurePluginEvents>;
23
52
  private five;
24
53
  private selfGroup;
25
- private hooks;
26
- private fbxLoader;
27
54
  private treasures;
55
+ private textureLoader;
56
+ private modelLoader;
28
57
  constructor(five: Five);
29
58
  load(data: TreasurePluginData): Promise<boolean>;
59
+ dispose(): void;
30
60
  removeTreasureByID(id: string): boolean;
31
61
  private onTreasureClick;
62
+ private getTextureObjectParams;
63
+ private onTreasureOpenAnimationEnded;
64
+ private getConfig;
32
65
  }
@@ -7,21 +7,23 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.TreasurePluginController = void 0;
9
9
 
10
- var _five = require("@realsee/five");
11
-
12
10
  var THREE = _interopRequireWildcard(require("three"));
13
11
 
14
- var _FBXLoader = require("three/examples/jsm/loaders/FBXLoader");
12
+ var _five = require("@realsee/five");
13
+
14
+ var _isNil = require("../../shared-utils/isNil");
15
15
 
16
16
  var _constants = require("./constants");
17
17
 
18
18
  var _TreasureObject = require("./TreasureObject");
19
19
 
20
- var _loadFbxObj = require("../../shared-utils/three/loadFbxObj");
20
+ var _getTextureLoader = require("../../shared-utils/three/getTextureLoader");
21
+
22
+ var _getExtraModelLoader = require("../../shared-utils/three/getExtraModelLoader");
21
23
 
22
- var _loadTreasureTextures = require("./utils/loadTreasureTextures");
24
+ var _to = _interopRequireDefault(require("../../shared-utils/to"));
23
25
 
24
- var _loadTexture = require("../../shared-utils/three/loadTexture");
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
25
27
 
26
28
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
29
 
@@ -59,10 +61,6 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
59
61
 
60
62
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
61
63
 
62
- // load 时才开始加载资源
63
- // 根据传入的数据判断需要加载哪些资源
64
- // 先写死宝箱类型,后续改成配置表,然后根据表里面的类型加载数据
65
- // FBX 文件里面的贴图默认用的是黄色贴图,所以对于默认的贴图逻辑有特殊处理
66
64
  var TreasurePluginController = /*#__PURE__*/function () {
67
65
  function TreasurePluginController(five) {
68
66
  var _this = this;
@@ -71,12 +69,38 @@ var TreasurePluginController = /*#__PURE__*/function () {
71
69
 
72
70
  _defineProperty(this, "hooks", new _five.Subscribe());
73
71
 
74
- _defineProperty(this, "fbxLoader", new _FBXLoader.FBXLoader());
75
-
76
72
  _defineProperty(this, "treasures", []);
77
73
 
74
+ _defineProperty(this, "textureLoader", (0, _getTextureLoader.getTextureLoader)());
75
+
76
+ _defineProperty(this, "modelLoader", (0, _getExtraModelLoader.getExtraModelLoader)());
77
+
78
78
  _defineProperty(this, "onTreasureClick", function (id) {
79
- _this.hooks.emit('tap', id);
79
+ _this.hooks.emit('tap', {
80
+ id: id
81
+ });
82
+ });
83
+
84
+ _defineProperty(this, "getTextureObjectParams", function (data) {
85
+ var config = _this.getConfig(data);
86
+
87
+ var position = new THREE.Vector3().fromArray(Object.values(data.position));
88
+ return {
89
+ config: config,
90
+ position: position,
91
+ id: data.id,
92
+ five: _this.five,
93
+ loadTexture: _this.textureLoader.load,
94
+ loadModelGroup: _this.modelLoader.load,
95
+ clickCallback: _this.onTreasureClick,
96
+ onOpenAnimationEnded: _this.onTreasureOpenAnimationEnded
97
+ };
98
+ });
99
+
100
+ _defineProperty(this, "onTreasureOpenAnimationEnded", function (id) {
101
+ _this.hooks.emit('openAnimationEnded', {
102
+ id: id
103
+ });
80
104
  });
81
105
 
82
106
  this.five = five; // ========== self group ==========
@@ -90,57 +114,39 @@ var TreasurePluginController = /*#__PURE__*/function () {
90
114
  key: "load",
91
115
  value: function () {
92
116
  var _load = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(data) {
93
- var _this2 = this,
94
- _this$selfGroup;
117
+ var _this$selfGroup;
95
118
 
96
- var baseFbxObjPromise, treasureTexturesPromise, faceTexturesPromise, _yield$Promise$all, _yield$Promise$all2, fbxGroup, treasureTextures, treasures;
119
+ var _yield$to, _yield$to2, error, treasures;
97
120
 
98
121
  return regeneratorRuntime.wrap(function _callee$(_context) {
99
122
  while (1) {
100
123
  switch (_context.prev = _context.next) {
101
124
  case 0:
102
- baseFbxObjPromise = (0, _loadFbxObj.loadFbxObj)(this.fbxLoader, _constants.TREASURE_FBX_URL);
103
- treasureTexturesPromise = (0, _loadTreasureTextures.loadTreasureTextures)(data, baseFbxObjPromise);
104
- faceTexturesPromise = Promise.all(_constants.TREASURE_FACE_ANIMATION_URLS.map(_loadTexture.loadTexture));
105
- _context.next = 5;
106
- return Promise.all([baseFbxObjPromise, treasureTexturesPromise]);
107
-
108
- case 5:
109
- _yield$Promise$all = _context.sent;
110
- _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
111
- fbxGroup = _yield$Promise$all2[0];
112
- treasureTextures = _yield$Promise$all2[1];
113
- treasures = data.treasures.map(function (_ref) {
114
- var _treasureTextures$fin;
115
-
116
- var id = _ref.id,
117
- type = _ref.type,
118
- positionArray = _ref.position;
119
- var texture = (_treasureTextures$fin = treasureTextures.find(function (_ref2) {
120
- var treasureMapItem = _ref2.treasureMapItem;
121
- return treasureMapItem.type === type;
122
- })) === null || _treasureTextures$fin === void 0 ? void 0 : _treasureTextures$fin.texture;
123
- if (!texture) throw new Error('数据初始化失败,未能找到预期的 Texture');
124
- var position = new THREE.Vector3().fromArray(positionArray).applyAxisAngle(new THREE.Vector3(1, 0, 0), Math.PI);
125
- var treasure = new _TreasureObject.TreasureObject({
126
- id: id,
127
- fbxGroup: fbxGroup,
128
- position: position,
129
- five: _this2.five,
130
- faceTexturesPromise: faceTexturesPromise,
131
- baseTexture: texture,
132
- clickCallback: _this2.onTreasureClick
133
- });
134
- treasure.scale.fromArray([0.008, 0.008, 0.008]);
135
- return treasure;
136
- });
125
+ _context.next = 2;
126
+ return (0, _to["default"])(Promise.all(data.treasures.map(this.getTextureObjectParams).filter(_isNil.notNil).map(function (params) {
127
+ return new _TreasureObject.TreasureObject(params).load();
128
+ })));
129
+
130
+ case 2:
131
+ _yield$to = _context.sent;
132
+ _yield$to2 = _slicedToArray(_yield$to, 2);
133
+ error = _yield$to2[0];
134
+ treasures = _yield$to2[1];
135
+
136
+ if (!(error || !treasures)) {
137
+ _context.next = 8;
138
+ break;
139
+ }
140
+
141
+ throw error;
137
142
 
143
+ case 8:
138
144
  (_this$selfGroup = this.selfGroup).add.apply(_this$selfGroup, _toConsumableArray(treasures));
139
145
 
140
146
  this.treasures = treasures;
141
147
  return _context.abrupt("return", true);
142
148
 
143
- case 13:
149
+ case 11:
144
150
  case "end":
145
151
  return _context.stop();
146
152
  }
@@ -154,6 +160,15 @@ var TreasurePluginController = /*#__PURE__*/function () {
154
160
 
155
161
  return load;
156
162
  }()
163
+ }, {
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();
170
+ });
171
+ }
157
172
  }, {
158
173
  key: "removeTreasureByID",
159
174
  value: function removeTreasureByID(id) {
@@ -167,6 +182,27 @@ var TreasurePluginController = /*#__PURE__*/function () {
167
182
  this.treasures.slice(treasureIndex, 1);
168
183
  return true;
169
184
  }
185
+ }, {
186
+ key: "getConfig",
187
+ value: function getConfig(data) {
188
+ var _DEFAULT_TREASURE_CON, _ref2, _data$config$scale, _data$config, _data$config2, _data$config3, _data$config4;
189
+
190
+ var typeConfig = (_DEFAULT_TREASURE_CON = _constants.DEFAULT_TREASURE_CONFIGS.find(function (_ref) {
191
+ var type = _ref.type;
192
+ return type === data.type;
193
+ })) === null || _DEFAULT_TREASURE_CON === void 0 ? void 0 : _DEFAULT_TREASURE_CON.config;
194
+ var defaultConfig = _constants.DEFAULT_TREASURE_CONFIG;
195
+ var scale = (_ref2 = (_data$config$scale = data === null || data === void 0 ? void 0 : (_data$config = data.config) === null || _data$config === void 0 ? void 0 : _data$config.scale) !== null && _data$config$scale !== void 0 ? _data$config$scale : typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.scale) !== null && _ref2 !== void 0 ? _ref2 : defaultConfig.scale;
196
+ var objectUrl = (data === null || data === void 0 ? void 0 : (_data$config2 = data.config) === null || _data$config2 === void 0 ? void 0 : _data$config2.object_url) || (typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.objectUrl) || defaultConfig.objectUrl;
197
+ var boxTextureUrl = (data === null || data === void 0 ? void 0 : (_data$config3 = data.config) === null || _data$config3 === void 0 ? void 0 : _data$config3.box_texture_url) || (typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.boxTextureUrl) || defaultConfig.boxTextureUrl;
198
+ var faceAnimeTextureUrls = (data === null || data === void 0 ? void 0 : (_data$config4 = data.config) === null || _data$config4 === void 0 ? void 0 : _data$config4.face_anime_texture_urls) || (typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.faceAnimeTextureUrls) || defaultConfig.faceAnimeTextureUrls;
199
+ return {
200
+ scale: scale,
201
+ objectUrl: objectUrl,
202
+ boxTextureUrl: boxTextureUrl,
203
+ faceAnimeTextureUrls: faceAnimeTextureUrls
204
+ };
205
+ }
170
206
  }]);
171
207
 
172
208
  return TreasurePluginController;
@@ -1,20 +1,22 @@
1
+ import * as THREE from 'three';
1
2
  import { Five } from '@realsee/five';
2
- import { Group, Texture } from 'three';
3
- export interface TreasureFaceAnimeParam {
3
+ import { Group } from 'three';
4
+ export interface TreasureFaceAnimeParams {
4
5
  five: Five;
5
6
  treasureGroup: Group;
6
- faceTexturesPromise: Promise<Texture[]>;
7
+ textureUrls: string[];
8
+ loadTexture: (url: string) => Promise<THREE.Texture>;
7
9
  }
8
10
  export declare class TreasureFaceAnime {
9
11
  paused: boolean;
10
12
  private five;
11
- private treasureGroup;
12
13
  private faceAnimeStep;
14
+ private treasureGroup;
15
+ private initialFaceTexture;
13
16
  private faceAnimeTimer?;
14
17
  private faceTexturesPromise;
15
- private initialFaceTexture;
16
18
  private faceMesh;
17
- constructor(param: TreasureFaceAnimeParam);
19
+ constructor(params: TreasureFaceAnimeParams);
18
20
  play: () => Promise<boolean>;
19
21
  pause(): boolean;
20
22
  dispose(): void;
@@ -26,7 +26,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
26
26
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
27
 
28
28
  var TreasureFaceAnime = /*#__PURE__*/function () {
29
- function TreasureFaceAnime(param) {
29
+ function TreasureFaceAnime(params) {
30
30
  var _this = this;
31
31
 
32
32
  _classCallCheck(this, TreasureFaceAnime);
@@ -85,9 +85,9 @@ var TreasureFaceAnime = /*#__PURE__*/function () {
85
85
  }, _callee);
86
86
  })));
87
87
 
88
- this.five = param.five;
89
- this.treasureGroup = param.treasureGroup;
90
- this.faceTexturesPromise = param.faceTexturesPromise;
88
+ this.five = params.five;
89
+ this.treasureGroup = params.treasureGroup;
90
+ this.faceTexturesPromise = Promise.all(params.textureUrls.map(params.loadTexture));
91
91
  this.faceMesh = this.treasureGroup.getObjectByName('face');
92
92
  var initialFaceTexture = this.faceMesh.material.map;
93
93
  if (!initialFaceTexture) throw new Error('初始化失败,不能从模型文件中找到对应的动画贴图');
@@ -1,35 +1,43 @@
1
1
  import * as THREE from 'three';
2
2
  import { Five } from '@realsee/five';
3
+ export interface TreasureObjectConfig {
4
+ scale: number;
5
+ objectUrl: string;
6
+ boxTextureUrl?: string;
7
+ faceAnimeTextureUrls: string[];
8
+ }
3
9
  /** 宝箱实例
4
10
  * @description
5
11
  * 点击宝箱可以打开宝箱
6
12
  * @description
7
13
  * 在宝箱未打开时,靠近宝箱或点击宝箱,宝箱会转动到朝向用户的方向
8
14
  */
9
- export interface TreasureObjectParam {
15
+ export interface TreasureObjectParams {
10
16
  id: string;
11
17
  five: Five;
12
- fbxGroup: THREE.Group;
13
18
  position: THREE.Vector3;
14
- baseTexture: THREE.Texture;
15
- faceTexturesPromise: Promise<THREE.Texture[]>;
19
+ config: TreasureObjectConfig;
16
20
  clickCallback?: (id: string) => unknown;
21
+ onOpenAnimationEnded?: (id: string) => unknown;
22
+ loadTexture: (url: string) => Promise<THREE.Texture>;
23
+ loadModelGroup: (url: string) => Promise<THREE.Group>;
17
24
  }
18
25
  export declare class TreasureObject extends THREE.Object3D {
19
26
  readonly treasureID: string;
20
27
  readonly name = "treasureObject";
21
28
  protected opened: boolean;
22
29
  private five;
23
- private texture;
24
- private modelGroup;
25
- private faceAnime;
26
- private openAnime;
27
- private clickCallback?;
28
- constructor(params: TreasureObjectParam);
30
+ private params;
31
+ private faceAnime?;
32
+ private openAnime?;
33
+ constructor(params: TreasureObjectParams);
34
+ /** 销毁当前宝箱实例
35
+ * @description 注意 dispose 并不会销毁所使用的贴图,因为贴图会有共用关系,需要在最外层销毁
36
+ */
29
37
  dispose(): void;
30
38
  rotateToCamera(): void;
31
39
  private open;
32
- private init;
40
+ load(): Promise<TreasureObject>;
33
41
  private onFiveWantsTapGesture;
34
42
  private onFivePanoArrived;
35
43
  }