@anov/3d 0.0.13 → 0.0.15

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 (49) hide show
  1. package/dist/factory/3d.d.ts +23 -14
  2. package/dist/factory/3d.js +143 -55
  3. package/dist/factory/3d.js.map +1 -1
  4. package/dist/factory/regionData.d.ts +8 -0
  5. package/dist/factory/regionData.js +59 -6
  6. package/dist/factory/regionData.js.map +1 -1
  7. package/dist/factory/unit/CameraPoi.d.ts +52 -4
  8. package/dist/factory/unit/CameraPoi.js +701 -55
  9. package/dist/factory/unit/CameraPoi.js.map +1 -1
  10. package/dist/factory/unit/glsl/heat/frag.d.ts +2 -0
  11. package/dist/factory/unit/glsl/heat/frag.glsl +37 -0
  12. package/dist/factory/unit/glsl/heat/frag.js +3 -0
  13. package/dist/factory/unit/glsl/heat/frag.js.map +1 -0
  14. package/dist/factory/unit/glsl/heat/ver.d.ts +2 -0
  15. package/dist/factory/unit/glsl/heat/ver.glsl +15 -0
  16. package/dist/factory/unit/glsl/heat/ver.js +3 -0
  17. package/dist/factory/unit/glsl/heat/ver.js.map +1 -0
  18. package/dist/factory/unit/handle.d.ts +4 -0
  19. package/dist/factory/unit/handle.js +20 -14
  20. package/dist/factory/unit/handle.js.map +1 -1
  21. package/dist/factory/unit/index.js +23 -13
  22. package/dist/factory/unit/index.js.map +1 -1
  23. package/dist/factory/unit/inspection/InspectionObject.d.ts +26 -0
  24. package/dist/factory/unit/{inspection.js → inspection/InspectionObject.js} +275 -133
  25. package/dist/factory/unit/inspection/InspectionObject.js.map +1 -0
  26. package/dist/factory/unit/{inspection.d.ts → inspection/index.d.ts} +8 -9
  27. package/dist/factory/unit/inspection/index.js +160 -0
  28. package/dist/factory/unit/inspection/index.js.map +1 -0
  29. package/dist/factory/unit/inspection/lineData.d.ts +21 -0
  30. package/dist/factory/unit/inspection/lineData.js +32 -0
  31. package/dist/factory/unit/inspection/lineData.js.map +1 -0
  32. package/dist/factory/unit/poi.d.ts +1 -0
  33. package/dist/factory/unit/poi.js +28 -14
  34. package/dist/factory/unit/poi.js.map +1 -1
  35. package/dist/factory/utils/constant.d.ts +0 -1
  36. package/dist/factory/utils/constant.js +0 -1
  37. package/dist/factory/utils/constant.js.map +1 -1
  38. package/dist/factory/utils/finirMaterial.d.ts +1 -0
  39. package/dist/factory/utils/finirMaterial.js +19 -1
  40. package/dist/factory/utils/finirMaterial.js.map +1 -1
  41. package/dist/index.js +1 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/module/environment/time/index.d.ts +1 -1
  44. package/dist/utils/index.d.ts +1 -1
  45. package/package.json +4 -3
  46. package/dist/factory/unit/inspection.js.map +0 -1
  47. package/dist/factory/unit/poi copy.d.ts +0 -15
  48. package/dist/factory/unit/poi copy.js +0 -144
  49. package/dist/factory/unit/poi copy.js.map +0 -1
@@ -8,59 +8,125 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
8
8
  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; }
9
9
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
10
10
  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); }
11
- import { PerspectiveCamera, Sprite, SpriteMaterial, utils } from '@anov/3d-core';
12
- var createDomTexture = utils.createDomTexture;
13
- var data = [{
14
- position: [386.24, 7.73, 143.96],
15
- name: '摄像1',
16
- type: 'camera'
17
- }];
18
- var dom = document.createElement('img');
19
- dom.src = './camera.png';
11
+ import { AdditiveBlending, Box3, CircleGeometry, Color, DoubleSide, Group, MathUtils, Matrix4, Mesh, MeshBasicMaterial, ModelLoader, PerspectiveCamera, PlaneGeometry, ShaderMaterial, Sprite, SpriteMaterial, Texture, TextureLoader, Vector3, use } from '@anov/3d-core';
12
+ import { Css2DPoi, SpritePoi } from '@anov/3d-ability';
13
+
14
+ // @ts-ignore
15
+ import heatMap from 'anov-heat-map';
16
+ // @ts-ignore
17
+ import { regionMap } from "../regionData";
18
+ import { usePath } from "../3d";
19
+ var load = new ModelLoader();
20
20
  var CameraPoi = /*#__PURE__*/function () {
21
21
  function CameraPoi(gobal) {
22
22
  _classCallCheck(this, CameraPoi);
23
23
  _defineProperty(this, "gobal", void 0);
24
- _defineProperty(this, "spriteCameraPoi", new Map());
24
+ _defineProperty(this, "cameraMesh", new Map());
25
+ _defineProperty(this, "warnMesh", new Map());
26
+ _defineProperty(this, "headMap", void 0);
27
+ _defineProperty(this, "dialogManage", void 0);
28
+ _defineProperty(this, "eventListener", new Set());
25
29
  this.gobal = gobal;
26
- this.generateObject();
30
+ this.dialogManage = new Dialog(this);
31
+ this.dialogManage.addStyle();
27
32
  }
28
33
  _createClass(CameraPoi, [{
29
34
  key: "generateObject",
30
35
  value: function () {
31
- var _generateObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
36
+ var _generateObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
32
37
  var _this = this;
33
- var texture, baseSprite;
34
- return _regeneratorRuntime().wrap(function _callee$(_context) {
35
- while (1) switch (_context.prev = _context.next) {
38
+ var model, rotatingRight, unFrame;
39
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
40
+ while (1) switch (_context2.prev = _context2.next) {
36
41
  case 0:
37
- _context.next = 2;
38
- return createDomTexture(dom, {
39
- width: 62,
40
- height: 62
42
+ _context2.next = 2;
43
+ return load.loadGLTF("".concat(usePath, "shexiang.glb"), false, true, './draco/', function (gltf) {
44
+ return gltf;
41
45
  });
42
46
  case 2:
43
- texture = _context.sent;
44
- baseSprite = new Sprite(new SpriteMaterial({
45
- map: texture,
46
- depthTest: false,
47
- depthWrite: false
48
- }));
49
- baseSprite.scale.set(10, 10, 10);
50
- baseSprite.center.set(0.5, 0);
51
- data.forEach(function (poi) {
52
- var sprite = baseSprite.clone();
53
- sprite.position.fromArray(poi.position);
54
- _this.gobal.interactionManager.add(sprite);
55
- _this.bindEvent(sprite);
56
- _this.spriteCameraPoi.set(poi.name, sprite);
57
- _this.gobal.scene.add(sprite);
47
+ model = _context2.sent;
48
+ Object.keys(regionMap).forEach( /*#__PURE__*/function () {
49
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key) {
50
+ var _region$probePoint;
51
+ var region, group, sprite, position, scan, point;
52
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
53
+ while (1) switch (_context.prev = _context.next) {
54
+ case 0:
55
+ // 摄像机
56
+ region = regionMap[key];
57
+ group = new Group();
58
+ group.name = region.camera.name;
59
+ sprite = new SpritePoi("".concat(usePath, "camera.png"), {
60
+ scale: [10, 10, 1]
61
+ });
62
+ sprite.rotation.y = Math.PI;
63
+ position = new Vector3().fromArray(region.camera.position);
64
+ sprite.position.copy(position);
65
+ group.add(sprite);
66
+ scan = model.scene.clone();
67
+ scan.scale.addScalar(5);
68
+ scan.rotation.x = -Math.PI / 2 + 0.5;
69
+ scan.position.copy(position.clone().add(new Vector3(0, -2, 0)));
70
+ group.add(scan);
71
+ _this.cameraMesh.set(region.title, group);
72
+ _this.gobal.interactionManager.add(group);
73
+ _this.cameraEvent(group, region);
74
+ _this.gobal.scene.add(group);
75
+
76
+ // 甲烷检测点
77
+ point = new MethanePoint();
78
+ (_region$probePoint = region.probePoint) === null || _region$probePoint === void 0 ? void 0 : _region$probePoint.forEach(function (item) {
79
+ var mesh;
80
+ if (item.warn) {
81
+ mesh = new SpritePoi("".concat(usePath, "p4/warn.png"), {
82
+ scale: [10, 10, 1]
83
+ });
84
+ _this.gobal.interactionManager.add(mesh);
85
+ _this.probeEvent(mesh, region);
86
+ } else {
87
+ mesh = point.create();
88
+ }
89
+ mesh.position.copy(new Vector3().fromArray(item.position));
90
+ _this.warnMesh.set(region.title, mesh);
91
+ _this.gobal.scene.add(mesh);
92
+ });
93
+ case 19:
94
+ case "end":
95
+ return _context.stop();
96
+ }
97
+ }, _callee);
98
+ }));
99
+ return function (_x) {
100
+ return _ref.apply(this, arguments);
101
+ };
102
+ }());
103
+ // 设置左右旋转的标志位和旋转速度
104
+ rotatingRight = true; // 是否正在向右转动
105
+ unFrame = use.useframe(function () {
106
+ _this.cameraMesh.forEach(function (group) {
107
+ var scan = group.children[1];
108
+ // 更新相机的旋转角度
109
+ if (rotatingRight) {
110
+ // 向右旋转
111
+ scan.rotation.z += 0.005;
112
+ } else {
113
+ // 向左旋转
114
+ scan.rotation.z -= 0.005;
115
+ }
116
+
117
+ // 检查是否达到目标旋转角度
118
+ if (Math.abs(scan.rotation.z) >= Math.abs(Math.PI / 4)) {
119
+ // 到达目标角度,切换旋转方向并更新目标角度
120
+ rotatingRight = !rotatingRight;
121
+ }
122
+ });
58
123
  });
124
+ this.eventListener.add(unFrame);
59
125
  case 7:
60
126
  case "end":
61
- return _context.stop();
127
+ return _context2.stop();
62
128
  }
63
- }, _callee);
129
+ }, _callee2, this);
64
130
  }));
65
131
  function generateObject() {
66
132
  return _generateObject.apply(this, arguments);
@@ -68,36 +134,616 @@ var CameraPoi = /*#__PURE__*/function () {
68
134
  return generateObject;
69
135
  }()
70
136
  }, {
71
- key: "bindEvent",
72
- value: function bindEvent(sprite) {
137
+ key: "cameraEvent",
138
+ value: function cameraEvent(sprite, region) {
73
139
  var _this2 = this;
74
- sprite.addEventListener('click', function () {
75
- var camera = new PerspectiveCamera(90, window.innerWidth / window.innerHeight, 0.1, 100000000);
76
- camera.position.set(373.72, 7.73, 144.75);
77
- camera.lookAt(407.48, 0.03, 177.44);
78
- var _this2$gobal$scene$se = _this2.gobal.scene.setCustomPerspective(camera),
79
- texture = _this2$gobal$scene$se.texture;
80
- var baseSprite = new Sprite(new SpriteMaterial({
81
- map: texture,
82
- depthTest: false,
83
- depthWrite: false
84
- }));
85
- baseSprite.scale.set(70, 50, 50);
86
- baseSprite.center.set(0.5, 0);
87
- baseSprite.position.set(349.80, 0.00, 129.74);
88
- _this2.gobal.scene.add(baseSprite);
140
+ var _use$useScene = use.useScene(),
141
+ camera = _use$useScene.camera;
142
+ var unClick = sprite.addEventListener('click', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
143
+ var position, targetPosition, camaraPosition, startPosition, cameraLookAt, dialogMesh;
144
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
145
+ while (1) switch (_context3.prev = _context3.next) {
146
+ case 0:
147
+ position = new Vector3().fromArray(region.camera.position);
148
+ targetPosition = position.clone().toArray();
149
+ camaraPosition = position.clone().add(new Vector3(0, 40, 80)).toArray();
150
+ startPosition = camera.position.clone(); // 获取相机朝向
151
+ cameraLookAt = new Vector3(); // 创建一个向量来存储相机朝向
152
+ camera.getWorldDirection(cameraLookAt); // 获取相机朝向并存储在向量中
153
+ _this2.gobal.cameraUtil.set({
154
+ position: camaraPosition,
155
+ target: targetPosition
156
+ });
157
+ _context3.next = 9;
158
+ return _this2.dialogManage.getMesh(position, position.clone().add(new Vector3(0, -15, 5)));
159
+ case 9:
160
+ dialogMesh = _context3.sent;
161
+ _this2.dialogManage.addEventListener('close', function () {
162
+ // 初始相机到原始位置
163
+ _this2.gobal.cameraUtil.set({
164
+ position: startPosition.toArray(),
165
+ target: cameraLookAt.toArray()
166
+ });
167
+ });
168
+ _this2.gobal.scene.add(dialogMesh);
169
+ case 12:
170
+ case "end":
171
+ return _context3.stop();
172
+ }
173
+ }, _callee3);
174
+ })));
175
+ // this.eventListener.add(unClick)
176
+ }
177
+ }, {
178
+ key: "probeEvent",
179
+ value: function probeEvent(sprite, region) {
180
+ var _this3 = this;
181
+ var _use$useScene2 = use.useScene(),
182
+ camera = _use$useScene2.camera;
183
+ sprite.addEventListener('click', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
184
+ var position, targetPosition, camaraPosition, startPosition, cameraLookAt, mesh;
185
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
186
+ while (1) switch (_context4.prev = _context4.next) {
187
+ case 0:
188
+ if (sprite.visible) {
189
+ _context4.next = 2;
190
+ break;
191
+ }
192
+ return _context4.abrupt("return");
193
+ case 2:
194
+ sprite.visible = false;
195
+ _this3.togglePoi(false);
196
+ position = new Vector3().fromArray(region.probePoint[0].position);
197
+ targetPosition = position.clone().toArray();
198
+ camaraPosition = position.clone().add(new Vector3(0, 30, 0)).toArray();
199
+ startPosition = camera.position.clone(); // 获取相机朝向
200
+ cameraLookAt = new Vector3(); // 创建一个向量来存储相机朝向
201
+ camera.getWorldDirection(cameraLookAt); // 获取相机朝向并存储在向量中
202
+ _this3.gobal.cameraUtil.set({
203
+ position: camaraPosition,
204
+ target: targetPosition
205
+ });
206
+ _this3.headMap = new HeadMap();
207
+ mesh = _this3.headMap.create();
208
+ mesh.position.copy(sprite.position);
209
+ mesh.position.y = 0.5;
210
+ _this3.gobal.scene.add(mesh);
211
+ _this3.headMap.addBack();
212
+ _this3.headMap.addEventListener('close', function () {
213
+ _this3.togglePoi(true);
214
+ _this3.gobal.cameraUtil.set({
215
+ position: startPosition.toArray(),
216
+ target: cameraLookAt.toArray()
217
+ });
218
+ });
219
+ case 18:
220
+ case "end":
221
+ return _context4.stop();
222
+ }
223
+ }, _callee4);
224
+ })));
225
+ }
226
+ }, {
227
+ key: "togglePoi",
228
+ value: function togglePoi() {
229
+ var visible = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
230
+ this.warnMesh.forEach(function (sprite) {
231
+ sprite.visible = visible;
232
+ });
233
+ this.cameraMesh.forEach(function (sprite) {
234
+ sprite.visible = visible;
89
235
  });
90
236
  }
91
237
  }, {
92
238
  key: "remove",
93
239
  value: function remove() {
94
- this.spriteCameraPoi.forEach(function (sprite) {
240
+ // 删除摄像机POI点
241
+ this.cameraMesh.forEach(function (sprite) {
242
+ sprite.removeFromParent();
243
+ sprite.remove();
244
+ });
245
+ this.cameraMesh.clear();
246
+ this.warnMesh.forEach(function (sprite) {
95
247
  sprite.removeFromParent();
248
+ sprite.remove();
96
249
  });
97
- this.spriteCameraPoi.clear();
250
+ this.warnMesh.clear();
251
+ this.eventListener.forEach(function (fn) {
252
+ fn();
253
+ });
254
+ // 热力图
255
+ if (this.headMap) this.headMap.remove();
256
+ this.eventListener.clear();
257
+ this.dialogManage.close();
98
258
  }
99
259
  }]);
100
260
  return CameraPoi;
101
261
  }();
102
262
  export default CameraPoi;
263
+ var MethanePoint = /*#__PURE__*/function () {
264
+ function MethanePoint() {
265
+ _classCallCheck(this, MethanePoint);
266
+ }
267
+ _createClass(MethanePoint, [{
268
+ key: "create",
269
+ value: function create() {
270
+ // 定义Shader的uniform变量
271
+
272
+ var geometry = new PlaneGeometry(10, 10);
273
+ var texture = new TextureLoader().load("".concat(usePath, "p4/monitor.png"));
274
+ var circle = new Mesh(geometry, new MeshBasicMaterial({
275
+ map: texture,
276
+ side: DoubleSide,
277
+ transparent: true
278
+ }));
279
+ circle.rotateX(-Math.PI / 3);
280
+ return circle;
281
+ }
282
+
283
+ // 随机多点的方案
284
+ }, {
285
+ key: "createBack",
286
+ value: function createBack() {
287
+ // 定义Shader的uniform变量
288
+
289
+ var group = new Group();
290
+ var geometry = new CircleGeometry(2, 32);
291
+ // 创建自定义着色器材质
292
+ var material = new ShaderMaterial({
293
+ vertexShader: "\n void main() {\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n gl_PointSize = 20.0; // \u8BBE\u7F6E\u70B9\u7684\u5927\u5C0F\n }\n ",
294
+ fragmentShader: "\n void main() {\n vec2 center = vec2(0.5, 0.5); // \u5706\u5FC3\u5750\u6807\n vec2 toCenter = gl_PointCoord - center; // \u8BA1\u7B97\u70B9\u5230\u5706\u5FC3\u7684\u5411\u91CF\n float distance = length(toCenter); // \u8BA1\u7B97\u70B9\u5230\u5706\u5FC3\u7684\u8DDD\u79BB\n if (distance > 0.5) discard; // \u8D85\u51FA\u534A\u5F84\u8303\u56F4\u7684\u70B9\u76F4\u63A5\u4E22\u5F03\n vec3 innerColor = vec3(1.0, .8, 0.0); // \u5185\u5708\u989C\u8272\u4E3A\u9EC4\u8272\n vec3 outerColor = vec3(0.8, 0.4, 0.0); // \u5916\u5708\u989C\u8272\u4E3A\u6DF1\u6A58\u8272\n \n vec3 finalColor = mix(innerColor, outerColor, smoothstep(0.1, 0.23, distance)); // \u6839\u636E\u8DDD\u79BB\u6DF7\u5408\u989C\u8272\n if(distance>0.3) finalColor = mix(finalColor, vec3(0.75, 0.4, 0.0), smoothstep(0.25, 0.3, distance)); // \u6839\u636E\u8DDD\u79BB\u6DF7\u5408\u989C\u8272\n gl_FragColor = vec4(finalColor, 1.0); // \u8BBE\u7F6E\u7247\u6BB5\u989C\u8272\n }\n ",
295
+ blending: AdditiveBlending,
296
+ depthTest: false,
297
+ transparent: true,
298
+ side: DoubleSide
299
+ });
300
+ var circle = new Mesh(geometry, new MeshBasicMaterial({
301
+ color: '#f7a157'
302
+ }));
303
+ var numPoints = 100; // 点的数量
304
+
305
+ for (var i = 0; i < numPoints; i++) {
306
+ var x = Math.random() * 700 - 322; // 随机生成 x 坐标
307
+ var z = Math.random() * 340 - 144; // 随机生成 z 坐标
308
+ var point = circle.clone();
309
+ point.position.copy(new Vector3(x, 20.55, z));
310
+ point.rotateX(-Math.PI / 2);
311
+ group.add(point);
312
+ }
313
+ return group;
314
+ }
315
+ }]);
316
+ return MethanePoint;
317
+ }();
318
+ var Dialog = /*#__PURE__*/function () {
319
+ function Dialog(cameraManage) {
320
+ _classCallCheck(this, Dialog);
321
+ _defineProperty(this, "manage", void 0);
322
+ _defineProperty(this, "camera", void 0);
323
+ _defineProperty(this, "cameraPosition", void 0);
324
+ _defineProperty(this, "cameraTargetPosition", void 0);
325
+ _defineProperty(this, "borderMesh", void 0);
326
+ _defineProperty(this, "cuteSprite", void 0);
327
+ _defineProperty(this, "eventListener", new Set());
328
+ _defineProperty(this, "eventList", new Map());
329
+ this.manage = cameraManage;
330
+ }
331
+ _createClass(Dialog, [{
332
+ key: "getMesh",
333
+ value: function () {
334
+ var _getMesh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(position, cameraPosition) {
335
+ var _this4 = this;
336
+ var target, _this$manage$gobal$sc, texture, close, unFrame;
337
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
338
+ while (1) switch (_context5.prev = _context5.next) {
339
+ case 0:
340
+ this.camera = new PerspectiveCamera(90, window.innerWidth / window.innerHeight, 0.1, 100000000);
341
+ this.camera.position.copy(cameraPosition);
342
+ target = this.getTarget(cameraPosition);
343
+ this.camera.lookAt(target);
344
+ _this$manage$gobal$sc = this.manage.gobal.scene.setCustomPerspective(this.camera), texture = _this$manage$gobal$sc.texture, close = _this$manage$gobal$sc.close;
345
+ this.cuteSprite = new Sprite(new SpriteMaterial({
346
+ map: texture,
347
+ depthTest: false,
348
+ depthWrite: false
349
+ }));
350
+ this.cuteSprite.center.set(0.5, 0.5);
351
+ this.cuteSprite.position.copy(position);
352
+ unFrame = use.useframe(function () {
353
+ _this4.updateScale(_this4.cuteSprite);
354
+ });
355
+ this.eventListener.add(unFrame);
356
+ return _context5.abrupt("return", new Promise(function (reslove) {
357
+ setTimeout(function () {
358
+ _this4.getBorderMesh(_this4.camera, _this4.cuteSprite);
359
+ var group = new Group();
360
+ group.add(_this4.borderMesh);
361
+ group.add(_this4.cuteSprite);
362
+ close();
363
+ reslove(group);
364
+ }, 1000);
365
+ }));
366
+ case 11:
367
+ case "end":
368
+ return _context5.stop();
369
+ }
370
+ }, _callee5, this);
371
+ }));
372
+ function getMesh(_x2, _x3) {
373
+ return _getMesh.apply(this, arguments);
374
+ }
375
+ return getMesh;
376
+ }()
377
+ }, {
378
+ key: "getTarget",
379
+ value: function getTarget(cameraPosition) {
380
+ var rotation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [-30, 0, 0];
381
+ // 将旋转角度转换为弧度
382
+ var angleX = MathUtils.degToRad(rotation[0]);
383
+ var angleY = MathUtils.degToRad(rotation[1]);
384
+ var angleZ = MathUtils.degToRad(rotation[2]);
385
+
386
+ // 创建旋转矩阵
387
+ var rotationMatrix = new Matrix4();
388
+ rotationMatrix.makeRotationX(angleX);
389
+ rotationMatrix.multiply(new Matrix4().makeRotationY(angleY));
390
+ rotationMatrix.multiply(new Matrix4().makeRotationZ(angleZ));
391
+
392
+ // 定义相机的方向向量(例如,相机的方向默认为(0, 0, -1))
393
+ var cameraDirection = new Vector3(0, 0, 1);
394
+
395
+ // 将相机的方向向量乘以旋转矩阵,得到相机目标位置的向量
396
+ var targetDirection = cameraDirection.clone().applyMatrix4(rotationMatrix);
397
+
398
+ // 计算相机的目标位置
399
+ return cameraPosition.clone().add(targetDirection);
400
+ }
401
+ }, {
402
+ key: "getBoxSize",
403
+ value: function getBoxSize(sprite) {
404
+ var _use$useScene3 = use.useScene(),
405
+ camera = _use$useScene3.camera;
406
+
407
+ // 获取设备像素比
408
+ var devicePixelRatio = window.devicePixelRatio || 1;
409
+ // 获取精灵对象的边界框
410
+ var bbox = new Box3().setFromObject(sprite);
411
+ // 将边界框的最小和最大顶点转换为屏幕坐标
412
+ var min = bbox.min.project(camera);
413
+ var max = bbox.max.project(camera);
414
+
415
+ // 计算精灵在屏幕中的宽度和高度像素值
416
+ var width = (max.x - min.x) * window.innerWidth / devicePixelRatio * 0.9458;
417
+ var height = (max.y - min.y) * window.innerHeight / devicePixelRatio * 1.0617;
418
+
419
+ // 定义设备像素比和对应的缩放系数的映射关系
420
+ var scaleFactors = {
421
+ 1: 0.5,
422
+ 1.5: 0.75,
423
+ 2: 1
424
+ };
425
+ var scaleFactor = scaleFactors[devicePixelRatio] || 1;
426
+ // 应用缩放系数
427
+ width *= scaleFactor;
428
+ height *= scaleFactor;
429
+ return {
430
+ width: width,
431
+ height: height
432
+ };
433
+ }
434
+ }, {
435
+ key: "updateScale",
436
+ value: function updateScale(sprite) {
437
+ var _use$useScene4 = use.useScene(),
438
+ camera = _use$useScene4.camera;
439
+ // 距离限制范围的值,用于计算缩放比例
440
+ var minDistance = 0.1;
441
+ var maxDistance = 1000000;
442
+ // 获取相机和物体的世界坐标位置
443
+ var cameraPosition = camera === null || camera === void 0 ? void 0 : camera.position;
444
+ var objectPosition = sprite.position;
445
+
446
+ // 计算相机和物体之间的距离
447
+ var distance = (cameraPosition === null || cameraPosition === void 0 ? void 0 : cameraPosition.distanceTo(objectPosition)) || 0.1;
448
+
449
+ // 使用 Math.min() 和 Math.max() 方法限制 resultDistance 的范围
450
+ var clampedDistance = Math.max(minDistance, Math.min(maxDistance, distance));
451
+ // console.log('clampedDistance:',clampedDistance)
452
+ // 按照缩放系数和距离进行缩放,缩放系数应该约定好一个固定值
453
+
454
+ sprite.scale.copy(new Vector3(clampedDistance * 1.5, 1.05 * clampedDistance, 1));
455
+ }
456
+ }, {
457
+ key: "addEventListener",
458
+ value: function addEventListener(eventName, fn) {
459
+ if (this.eventList.has(eventName)) this.eventList[eventName] = fn;else this.eventList.set(eventName, fn);
460
+ }
461
+ }, {
462
+ key: "getBorderMesh",
463
+ value: function getBorderMesh(camera, sprite) {
464
+ var _this5 = this;
465
+ var _this$getBoxSize = this.getBoxSize(sprite),
466
+ width = _this$getBoxSize.width,
467
+ height = _this$getBoxSize.height;
468
+
469
+ // 弹窗容器
470
+ var dialogDiv = document.createElement('div');
471
+ width += 5;
472
+ height += 5;
473
+ Object.assign(dialogDiv.style, {
474
+ width: "".concat(width, "px"),
475
+ height: "".concat(height, "px"),
476
+ zIndex: 2,
477
+ backgroundImage: "url(".concat(usePath, "p4/border.png)"),
478
+ backgroundSize: '100% 100%',
479
+ backgroundRepeat: 'no-repeat',
480
+ position: 'releate'
481
+ // left: `${(window.innerWidth - width) / 2}px`,
482
+ // top: `${(window.innerHeight - height) / 2}px`,
483
+ });
484
+
485
+ var maskingDiv = document.createElement('div');
486
+ maskingDiv.className = 'dialog-masking';
487
+ dialogDiv.appendChild(maskingDiv);
488
+
489
+ // 关闭按钮
490
+ var closeSpan = document.createElement('span');
491
+ closeSpan.className = 'dialog-close';
492
+ closeSpan.addEventListener('click', function () {
493
+ _this5.eventList.has('close') && _this5.eventList.get('close')();
494
+ _this5.close();
495
+ });
496
+ var hLine = document.createElement('span');
497
+ hLine.className = 'dialog-close-line dialog-close-h-line';
498
+ closeSpan.appendChild(hLine);
499
+ var vLine = document.createElement('span');
500
+ vLine.className = 'dialog-close-line dialog-close-v-line';
501
+ closeSpan.appendChild(vLine);
502
+ dialogDiv.appendChild(closeSpan);
503
+
504
+ // 操作按钮
505
+ var op = document.createElement('div');
506
+ op.className = 'dialog-operate';
507
+ dialogDiv.appendChild(op);
508
+ var opList = ['left', 'right', 'top', 'bottom'];
509
+ opList.forEach(function (key) {
510
+ var btnSpan = document.createElement('span');
511
+ btnSpan.className = "dialog-operate-btn dialog-operate-".concat(key);
512
+ btnSpan.addEventListener('click', function () {
513
+ switch (key) {
514
+ case 'top':
515
+ camera.rotation.x -= 0.01;
516
+ break;
517
+ case 'bottom':
518
+ camera.rotation.x += 0.01;
519
+ break;
520
+ case 'left':
521
+ camera.rotation.y -= 0.01;
522
+ break;
523
+ case 'right':
524
+ camera.rotation.y += 0.01;
525
+ break;
526
+ }
527
+ var _this5$manage$gobal$s = _this5.manage.gobal.scene.setCustomPerspective(camera),
528
+ texture = _this5$manage$gobal$s.texture,
529
+ close = _this5$manage$gobal$s.close;
530
+ sprite.material = new SpriteMaterial({
531
+ map: texture,
532
+ depthTest: false,
533
+ depthWrite: false
534
+ });
535
+ setTimeout(function () {
536
+ return close();
537
+ }, 800);
538
+ });
539
+ op.appendChild(btnSpan);
540
+ });
541
+
542
+ // 滑动条
543
+ var sliderDiv = document.createElement('div');
544
+ sliderDiv.className = 'dialog-slider-container';
545
+ var sliderBar = document.createElement('input');
546
+ sliderBar.type = 'range';
547
+ sliderBar.min = '30';
548
+ sliderBar.max = '120';
549
+ sliderBar.value = '90';
550
+ sliderBar.className = 'dialog-slider';
551
+ sliderBar.addEventListener('input', function () {
552
+ camera.fov = sliderBar.value;
553
+ camera.updateProjectionMatrix();
554
+ var _this5$manage$gobal$s2 = _this5.manage.gobal.scene.setCustomPerspective(camera),
555
+ texture = _this5$manage$gobal$s2.texture,
556
+ close = _this5$manage$gobal$s2.close;
557
+ sprite.material = new SpriteMaterial({
558
+ map: texture,
559
+ depthTest: false,
560
+ depthWrite: false
561
+ });
562
+ setTimeout(function () {
563
+ return close();
564
+ }, 800);
565
+ });
566
+ sliderDiv.appendChild(sliderBar);
567
+ dialogDiv.appendChild(sliderDiv);
568
+ this.borderMesh = new Css2DPoi(dialogDiv);
569
+ this.borderMesh.position.copy(sprite.position);
570
+ return this.borderMesh;
571
+ }
572
+ }, {
573
+ key: "addStyle",
574
+ value: function addStyle() {
575
+ // 设置 CSS 规则
576
+ var css = "\n .dialog-masking{\n position: absolute;\n top: 8px;\n left: 6px;\n width: calc(100% - 12px);\n height: calc(100% - 16px);\n background: linear-gradient(90deg, rgba(0, 0, 0,.4) 0%,rgba(0, 0, 0,.2) 10%, rgba(0, 0, 0,0) 20%, rgba(0,0,0, 0) 50%, rgba(0, 0, 0,0) 80%, rgba(0, 0, 0,0.2) 90%, rgba(0, 0, 0,.4) 100%);\n pointer-events: auto;\n opacity: 1;\n transform: perspective(100px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n transform-origin: center center;\n }\n .hot-back{\n width: 70px;\n height: 25px;\n border-radius: 2px;\n color: #fff;\n font-weight: bold;\n font-size: 14px;\n border:1px solid #d1ae6d;\n background-color: #c8ab75;\n cursor: pointer; /* \u9F20\u6807\u6307\u9488\u6837\u5F0F */\n display: flex;\n justify-content: center;\n align-items: center;\n position: absolute;\n left: 30px;\n top: 30px;\n pointer-events: auto;\n }\n .hot-back:hover{\n background-color:#c8a158;\n }\n .dialog-close{\n width: 20px;\n height: 20px;\n border-radius: 2px;\n color: #fff;\n background-color: #c8ab75;\n cursor: pointer; /* \u9F20\u6807\u6307\u9488\u6837\u5F0F */\n display: flex;\n justify-content: center;\n align-items: center;\n position: absolute;\n right: 20px;\n top: 15px;\n pointer-events: auto;\n }\n\n .dialog-close:hover{\n background-color:#c8a158;\n }\n\n .dialog-close-line{\n width: 14px;\n height: 2px;\n background-color: #fff;\n position: absolute;\n top: 9px;\n display: block;\n }\n\n .dialog-close-h-line{\n transform: rotate(-45deg);\n }\n\n .dialog-close-v-line{\n transform: rotate(45deg);\n }\n\n .dialog-operate{\n width: 120px;\n height: 120px;\n background-image: url(".concat(usePath, "p4/operate.png);\n background-size: 100% 100%;\n background-repeat: no-repeat;\n position: absolute;\n right: 15px;\n bottom: 10px;\n pointer-events: auto;\n }\n\n .dialog-operate-btn{\n width: 0;\n height: 0;\n position: absolute;\n cursor: pointer;\n pointer-events: auto;\n }\n\n .dialog-operate-top{\n border-left: 8px solid transparent; /* \u5DE6\u8FB9\u900F\u660E */\n border-right: 8px solid transparent; /* \u53F3\u8FB9\u900F\u660E */\n border-bottom: 8px solid #f2c67d; /* \u5E95\u8FB9\u5B9E\u5FC3 */\n left: calc(50% - 9px);\n top: 20px;\n }\n .dialog-operate-top:hover{\n border-bottom-color:#fff2dd;\n }\n\n .dialog-operate-bottom{\n border-left: 8px solid transparent; /* \u5DE6\u8FB9\u900F\u660E */\n border-right: 8px solid transparent; /* \u53F3\u8FB9\u900F\u660E */\n border-top: 8px solid #f2c67d; /* \u5E95\u8FB9\u5B9E\u5FC3 */\n left: calc(50% - 9px);\n bottom: 20px;\n }\n\n .dialog-operate-bottom:hover{\n border-top-color:#fff2dd;\n }\n\n .dialog-operate-left{\n border-top: 8px solid transparent; /* \u5DE6\u8FB9\u900F\u660E */\n border-bottom: 8px solid transparent; /* \u53F3\u8FB9\u900F\u660E */\n border-right: 8px solid #f2c67d; /* \u5E95\u8FB9\u5B9E\u5FC3 */\n top: calc(50% - 9px);\n left: 20px;\n }\n .dialog-operate-left:hover{\n border-right-color:#fff2dd;\n }\n\n .dialog-operate-right{\n border-top: 8px solid transparent; /* \u5DE6\u8FB9\u900F\u660E */\n border-bottom: 8px solid transparent; /* \u53F3\u8FB9\u900F\u660E */\n border-left: 8px solid #f2c67d; /* \u5E95\u8FB9\u5B9E\u5FC3 */\n top: calc(50% - 9px);\n right: 20px;\n }\n\n .dialog-operate-right:hover{\n border-left-color:#fff2dd;\n }\n \n .dialog-slider-container {\n width: 13px;\n height: 300px;\n background: url(").concat(usePath, "p4/slider.png);\n background-size: 100% 100%;\n position:absolute;\n right:23px;\n top:50px;\n }\n\n .dialog-slider {\n -webkit-appearance: none;\n width: 300px;\n height: 13px;\n background: transparent;\n outline: none;\n opacity: 0.7;\n -webkit-transition: .2s;\n transition: opacity .2s;\n transform: rotate(-90deg);\n margin-left: -144px;\n margin-top: 144px;\n pointer-events: auto;\n }\n\n .dialog-slider::-webkit-slider-thumb {\n -webkit-appearance: none;\n appearance: none;\n width: 7px;\n height: 20px;\n background: #eebe76;\n cursor: pointer;\n border-radius: 5px;\n }\n\n .dialog-slider::-moz-range-thumb {\n width: 7px;\n height: 20px;\n background: #eebe76;\n cursor: pointer;\n border-radius: 5px;\n }\n");
577
+ // 创建一个 <style> 元素
578
+ var styleElement = document.createElement('style');
579
+ styleElement.appendChild(document.createTextNode(css));
580
+ // 将 <style> 元素添加到 <head> 中
581
+ document.head.appendChild(styleElement);
582
+ }
583
+ }, {
584
+ key: "close",
585
+ value: function close() {
586
+ // 删除弹窗POI
587
+ if (this.borderMesh) {
588
+ this.borderMesh.remove();
589
+ this.borderMesh.removeFromParent();
590
+ }
591
+ if (this.cuteSprite) {
592
+ this.cuteSprite.remove();
593
+ this.cuteSprite.removeFromParent();
594
+ }
595
+ // 移除事件监听
596
+ this.eventListener.forEach(function (fn) {
597
+ fn();
598
+ });
599
+ this.eventListener.clear();
600
+ this.eventList.clear();
601
+ }
602
+ }]);
603
+ return Dialog;
604
+ }();
605
+ var HeadMap = /*#__PURE__*/function () {
606
+ function HeadMap() {
607
+ _classCallCheck(this, HeadMap);
608
+ _defineProperty(this, "TemperatureColorStops", {
609
+ 1.0: '#f00',
610
+ 0.9: '#e2fa00',
611
+ 0.6: '#33f900',
612
+ 0.3: '#0349df',
613
+ 0.0: '#0f00ff'
614
+ });
615
+ _defineProperty(this, "eventList", new Map());
616
+ _defineProperty(this, "backEle", void 0);
617
+ _defineProperty(this, "heatMapPlane", void 0);
618
+ _defineProperty(this, "canvasList", []);
619
+ }
620
+
621
+ // 热力图
622
+ _createClass(HeadMap, [{
623
+ key: "create",
624
+ value: function create() {
625
+ var heatmap = heatMap.create({
626
+ container: this.createDom(),
627
+ gradient: this.TemperatureColorStops
628
+ });
629
+ var len = 1200;
630
+ var width = 2000;
631
+ var height = 1000;
632
+ var points = [];
633
+ var max = 0;
634
+ while (len--) {
635
+ var val = Math.floor(Math.random() * 10);
636
+ max = Math.max(max, val);
637
+ var point = {
638
+ x: Math.floor(Math.random() * width),
639
+ y: Math.floor(Math.random() * height),
640
+ value: val
641
+ };
642
+ points.push(point);
643
+ }
644
+ heatmap.setData({
645
+ max: max,
646
+ data: points
647
+ });
648
+
649
+ // 灰度图
650
+ var greymap = heatMap.create({
651
+ container: this.createDom(),
652
+ gradient: {
653
+ '0': 'black',
654
+ '1.0': 'white'
655
+ }
656
+ });
657
+ greymap.setData({
658
+ max: max,
659
+ data: points
660
+ });
661
+ var heatMapMaterial = new ShaderMaterial({
662
+ transparent: true,
663
+ depthTest: false,
664
+ side: DoubleSide,
665
+ vertexShader: "varying vec2 vUv;\n uniform float Zscale;\n uniform sampler2D greyMap;\n void main() {\n vUv = uv;\n vec4 frgColor = texture2D(greyMap, uv);//\u83B7\u53D6\u7070\u5EA6\u56FE\u70B9\u4F4D\u4FE1\u606F\n float height = Zscale * frgColor.a;//\u901A\u8FC7\u7070\u5EA6\u56FE\u7684rgb*\u9700\u8981\u8BBE\u7F6E\u7684\u9AD8\u5EA6\u8BA1\u7B97\u51FA\u70ED\u529B\u56FE\u6BCF\u4E2A\u70B9\u4F4D\u6700\u7EC8\u5728z\u8F74\u9AD8\u5EA6\n vec3 transformed = vec3( position.x, position.y, height);//\u91CD\u65B0\u7EC4\u88C5\u70B9\u5750\u6807\n gl_Position = projectionMatrix * modelViewMatrix * vec4(transformed, 1.0);//\u6E32\u67D3\u70B9\u4F4D\n \n }\n ",
666
+ fragmentShader: "varying vec2 vUv;\n uniform sampler2D heatMap;//\u70ED\u529B\u56FE\n uniform vec3 u_color;//\u57FA\u7840\u989C\u8272\n uniform float u_opacity; // \u900F\u660E\u5EA6\n void main() {\n //vec4 alphaColor = texture2D(heatMap, vUv);\n // gl_FragColor = alphaColor;\n gl_FragColor = vec4(u_color, u_opacity) * texture2D(heatMap, vUv);//\u628A\u70ED\u529B\u56FE\u989C\u8272\u548C\u900F\u660E\u5EA6\u8FDB\u884C\u6E32\u67D3\n }",
667
+ uniforms: {
668
+ heatMap: {
669
+ value: {
670
+ value: undefined
671
+ }
672
+ },
673
+ greyMap: {
674
+ value: {
675
+ value: undefined
676
+ }
677
+ },
678
+ Zscale: {
679
+ value: 0
680
+ },
681
+ // 高度参数
682
+ u_color: {
683
+ value: new Color('rgb(255, 255, 255)')
684
+ },
685
+ u_opacity: {
686
+ value: 0.8
687
+ }
688
+ }
689
+ });
690
+ var texture = new Texture(heatmap._renderer.canvas);
691
+ texture.needsUpdate = true;
692
+ var greyTexture = new Texture(greymap._renderer.canvas);
693
+ greyTexture.needsUpdate = true;
694
+ heatMapMaterial.uniforms.heatMap.value = texture;
695
+ heatMapMaterial.uniforms.greyMap.value = greyTexture;
696
+ var heatMapGeometry = new PlaneGeometry(200, 100, 100, 100); // 3d热力图大小,及分块数量
697
+ var heatMapPlane = new Mesh(heatMapGeometry, heatMapMaterial);
698
+ heatMapPlane.rotation.set(-Math.PI / 2, 0, 0);
699
+ // heatMapPlane.position.set(0, 0, 0) // 3d热力图中心点位置
700
+
701
+ this.heatMapPlane = heatMapPlane;
702
+ return heatMapPlane;
703
+ }
704
+ }, {
705
+ key: "addEventListener",
706
+ value: function addEventListener(eventName, fn) {
707
+ if (this.eventList.has(eventName)) this.eventList[eventName] = fn;else this.eventList.set(eventName, fn);
708
+ }
709
+ }, {
710
+ key: "addBack",
711
+ value: function addBack() {
712
+ var _this6 = this;
713
+ this.backEle = document.createElement('div');
714
+ this.backEle.className = 'hot-back';
715
+ this.backEle.innerHTML = '返回';
716
+ document.body.appendChild(this.backEle);
717
+ this.backEle.addEventListener('click', function () {
718
+ _this6.eventList.has('close') && _this6.eventList.get('close')();
719
+ _this6.remove();
720
+ });
721
+ }
722
+ }, {
723
+ key: "createDom",
724
+ value: function createDom() {
725
+ // 创建一个新的 canvas 元素
726
+ var canvas = document.createElement('canvas');
727
+ canvas.style.zIndex = '-1';
728
+ // 设置 canvas 元素的宽度和高度
729
+ canvas.width = window.innerWidth;
730
+ canvas.height = window.innerHeight;
731
+ document.body.appendChild(canvas);
732
+ this.canvasList.push(canvas);
733
+ return canvas;
734
+ }
735
+ }, {
736
+ key: "remove",
737
+ value: function remove() {
738
+ this.canvasList.forEach(function (canvas) {
739
+ canvas.remove();
740
+ });
741
+ this.canvasList.length = 0;
742
+ this.backEle && this.backEle.remove();
743
+ this.heatMapPlane.removeFromParent();
744
+ this.heatMapPlane.remove();
745
+ }
746
+ }]);
747
+ return HeadMap;
748
+ }();
103
749
  //# sourceMappingURL=CameraPoi.js.map