hart-estate-widget 0.0.22 → 0.0.25

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.
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -23,6 +23,8 @@ var _Loader = _interopRequireDefault(require("./Loader"));
23
23
 
24
24
  var _panoramaHelpers = require("../utils/panoramaHelpers");
25
25
 
26
+ var _geometric = require("geometric");
27
+
26
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
29
 
28
30
  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); }
@@ -63,21 +65,22 @@ const getPanoramas = (json, images, setLoadingState) => {
63
65
 
64
66
  const getPanoramaRooms = (json, panoramas) => {
65
67
  return panoramas.map((panorama, index) => {
66
- let currentRoom = {
67
- Type: "Room - ".concat(panorama['panorama_id'])
68
+ panorama['panorama_index'] = index;
69
+ const type = "Room - ".concat(panorama['panorama_id']);
70
+ if (!json) return {
71
+ type,
72
+ id: index,
73
+ panorama,
74
+ left: 0,
75
+ top: 0
68
76
  };
77
+ const currentRoom = json.Floors[0].Units[0].Rooms.find(room => room.ID === panorama['room_id']);
78
+ const [left, top] = (0, _geometric.polygonMean)((0, _panoramaHelpers.getRoomCoordinates)(currentRoom, json.Floors[0].Walls, json.Vertices));
69
79
 
70
- if (json) {
71
- currentRoom = json.Floors[0].Units[0].Rooms.find(room => room.ID === panorama['room_id']);
80
+ if (!panorama.linkedSpots.length) {
81
+ setPanoramaLinks(json, currentRoom, [left, top], panorama, panoramas);
72
82
  }
73
83
 
74
- const {
75
- left,
76
- top
77
- } = json ? (0, _panoramaHelpers.findRoomCenter)(currentRoom, json.Floors[0].Walls, json.Vertices) : {
78
- left: 0,
79
- top: 0
80
- };
81
84
  return {
82
85
  type: currentRoom.Type,
83
86
  id: index,
@@ -88,6 +91,39 @@ const getPanoramaRooms = (json, panoramas) => {
88
91
  }, []);
89
92
  };
90
93
 
94
+ const setPanoramaLinks = (json, currentRoom, center, panorama, panoramas) => {
95
+ json.Floors[0].Doors.forEach(_ref => {
96
+ let {
97
+ Location,
98
+ Walls
99
+ } = _ref;
100
+ if (!Walls.some(doorWallId => currentRoom.Walls.some(roomWallId => roomWallId === doorWallId))) return;
101
+ const connectedRoom = json.Floors[0].Units[0].Rooms.find(room => {
102
+ const roomHasSameWall = room.Walls.some(roomWallId => Walls.some(doorWallId => roomWallId === doorWallId));
103
+ const isSameRoom = room.ID === currentRoom.ID;
104
+ return roomHasSameWall && !isSameRoom;
105
+ });
106
+ if (!connectedRoom) return;
107
+ const connectedPanorama = panoramas.find(_ref2 => {
108
+ let {
109
+ room_id
110
+ } = _ref2;
111
+ return room_id === connectedRoom.ID;
112
+ });
113
+ if (!connectedPanorama) return;
114
+ const locationX = Location.X - center[0];
115
+ const locationY = -(Location.Y - center[1]);
116
+ const defaultScale = 20;
117
+ const maxScale = 50;
118
+ const defaultLength = 120;
119
+ const length = (0, _geometric.lineLength)([[0, 0], [locationX, locationY]]);
120
+ const scale = length / defaultLength * defaultScale;
121
+ const finalScale = scale > maxScale ? maxScale : scale;
122
+ const position = new THREE.Vector3(locationX, -10, locationY);
123
+ panorama.link(connectedPanorama, position, finalScale);
124
+ });
125
+ };
126
+
91
127
  const initPanorama = () => {
92
128
  let camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1100);
93
129
  let controls = new _threeDeviceOrientation.default(camera);
@@ -113,12 +149,12 @@ const initPanorama = () => {
113
149
  };
114
150
  };
115
151
 
116
- const PanoramaTab = _ref => {
152
+ const PanoramaTab = _ref3 => {
117
153
  let {
118
154
  json,
119
155
  planImage,
120
156
  images
121
- } = _ref;
157
+ } = _ref3;
122
158
  const [menuState, setMenuState] = (0, _react.useState)(false);
123
159
  const [loadingState, setLoadingState] = (0, _react.useState)(true);
124
160
  const [isMapActive, setMapState] = (0, _react.useState)(false);
@@ -178,6 +214,12 @@ const PanoramaTab = _ref => {
178
214
  });
179
215
  panoramas.forEach(panorama => {
180
216
  if (!panorama.panorama_id) return;
217
+ panorama.addEventListener('enter', _ref4 => {
218
+ let {
219
+ target
220
+ } = _ref4;
221
+ return setCurrentRoomIndex(target['panorama_index']);
222
+ });
181
223
  newViewer.add(panorama);
182
224
  });
183
225
  setViewer(newViewer);
@@ -492,23 +492,23 @@ class HouseStore {
492
492
  } = (0, _modelHelpers.getMinMaxCoordinates)(walls);
493
493
  const centerX = (maxX + minX) / 2;
494
494
  const centerY = (maxY + minY) / 2;
495
- const longerValue = centerX > centerY ? centerX : centerY;
495
+ const lightsOffset = 25;
496
496
  this.houseGroup.position.set(-centerX, -centerY);
497
497
  const lights = [{
498
- x: centerX - longerValue,
499
- y: centerY - longerValue,
498
+ x: centerX - lightsOffset,
499
+ y: centerY - lightsOffset,
500
500
  z: this.wallsHeight * 3,
501
501
  power: 0.4,
502
502
  castShadow: true
503
503
  }, {
504
- x: centerX - longerValue,
505
- y: centerY - longerValue,
504
+ x: centerX - lightsOffset,
505
+ y: centerY - lightsOffset,
506
506
  z: this.wallsHeight * 2,
507
507
  power: 1,
508
508
  castShadow: false
509
509
  }, {
510
- x: centerX + longerValue,
511
- y: centerY + longerValue,
510
+ x: centerX + lightsOffset,
511
+ y: centerY + lightsOffset,
512
512
  z: this.wallsHeight * 2,
513
513
  power: 1.1,
514
514
  castShadow: false
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ require("core-js/modules/es.promise.js");
9
+
8
10
  require("core-js/modules/web.dom-collections.iterator.js");
9
11
 
10
12
  var _react = _interopRequireDefault(require("react"));
@@ -94,20 +96,26 @@ class ModelStore {
94
96
  this.scene = new THREE.Scene();
95
97
  this.scene.rotation.x = -Math.PI / 2;
96
98
  this.scene.scale.y = -1;
97
- this.scene.background = new THREE.Color('#FAFAFA');
99
+ this.scene.background = new THREE.Color('#E7E7E7');
100
+ this.scene.fog = new THREE.Fog('#E7E7E7', 5, 200);
98
101
  this.createGround();
99
102
  return this;
100
103
  });
101
104
 
102
105
  _defineProperty(this, "createGround", () => {
103
- this.textureLoader.load(_grass.default, texture => {
104
- texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
105
- texture.repeat.set(50, 50);
106
+ const textures = {};
107
+ const assets = [new Promise(resolve => this.loadTexture(_grass.default, [75, 75], texture => {
108
+ textures.map = texture;
109
+ resolve();
110
+ }))];
111
+ Promise.all(assets).then(() => {
106
112
  let groundMaterial = new THREE.MeshStandardMaterial({
107
- map: texture,
108
- color: 0xffffff
113
+ map: textures.map,
114
+ normalMap: textures.normalMap,
115
+ envMap: textures.envMap,
116
+ color: 0xe7e7e7
109
117
  });
110
- let groundMesh = new THREE.Mesh(new THREE.CircleGeometry(100, 100), groundMaterial);
118
+ let groundMesh = new THREE.Mesh(new THREE.CircleGeometry(250, 100), groundMaterial);
111
119
  groundMesh.position.z = -0.01;
112
120
  groundMesh.receiveShadow = true;
113
121
  this.scene.add(groundMesh);
@@ -254,6 +262,17 @@ class ModelStore {
254
262
  return ((_this$container2 = this.container) === null || _this$container2 === void 0 ? void 0 : _this$container2.offsetHeight) || window.innerHeight;
255
263
  }
256
264
 
265
+ loadTexture(img) {
266
+ let repeat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [1, 1];
267
+ let callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : () => {};
268
+ this.textureLoader.load(img, texture => {
269
+ texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
270
+ texture.repeat.set(repeat[0], repeat[1]);
271
+ texture.flipY = false;
272
+ callback(texture);
273
+ });
274
+ }
275
+
257
276
  }
258
277
 
259
278
  var _default = new ModelStore();
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getVerticesLocations = exports.getScale = exports.findWallVertices = exports.findRoomCenter = exports.findMinMaxCoordinates = void 0;
6
+ exports.getScale = exports.getRoomCoordinates = exports.findWallVertices = void 0;
7
7
 
8
- require("core-js/modules/web.dom-collections.iterator.js");
8
+ require("core-js/modules/es.array.reduce.js");
9
9
 
10
10
  var _react = _interopRequireDefault(require("react"));
11
11
 
@@ -13,59 +13,24 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
13
13
 
14
14
  const findWallVertices = (walls, wall, vertices) => {
15
15
  const currentWall = walls.find(el => el.ID === wall);
16
- return currentWall.Vertices.map(vertex => vertices.find(el => el.ID === vertex));
17
- };
18
-
19
- exports.findWallVertices = findWallVertices;
20
-
21
- const getVerticesLocations = vertices => vertices.map(vertex => vertex.Location);
22
-
23
- exports.getVerticesLocations = getVerticesLocations;
24
-
25
- const findMinMaxCoordinates = (room, walls, vertices) => {
26
- let maxX = 0;
27
- let minX = Infinity;
28
- let maxY = 0;
29
- let minY = Infinity;
30
- room.Walls.forEach(wall => {
31
- const [coord1, coord2] = getVerticesLocations(findWallVertices(walls, wall, vertices)); // CALCULATE MAX COORDS
32
-
33
- if (coord1.X > maxX) maxX = coord1.X;
34
- if (coord1.X > maxX) maxX = coord1.X;
35
- if (coord2.Y > maxY) maxY = coord2.Y;
36
- if (coord2.Y > maxY) maxY = coord2.Y; // CALCULATE MIN COORDS
37
-
38
- if (coord1.X < minX) minX = coord1.X;
39
- if (coord1.X < minX) minX = coord1.X;
40
- if (coord2.Y < minY) minY = coord2.Y;
41
- if (coord2.Y < minY) minY = coord2.Y;
16
+ return currentWall.Vertices.map(vertexId => {
17
+ const vertex = vertices.find(el => el.ID === vertexId);
18
+ return [vertex.Location.X, vertex.Location.Y];
42
19
  });
43
- return {
44
- maxX,
45
- minX,
46
- maxY,
47
- minY
48
- };
49
20
  };
50
21
 
51
- exports.findMinMaxCoordinates = findMinMaxCoordinates;
22
+ exports.findWallVertices = findWallVertices;
52
23
 
53
- const findRoomCenter = (room, walls, vertices) => {
54
- const {
55
- maxX,
56
- minX,
57
- maxY,
58
- minY
59
- } = findMinMaxCoordinates(room, walls, vertices);
60
- const left = (maxX + minX) / 2;
61
- const top = (maxY + minY) / 2;
62
- return {
63
- left,
64
- top
65
- };
24
+ const getRoomCoordinates = (room, walls, vertices) => {
25
+ const points = room.Walls.reduce((acc, wallId) => {
26
+ const wall = walls.find(wallObject => wallObject.ID === wallId);
27
+ findWallVertices(walls, wall.ID, vertices).forEach(vertex => acc.push(vertex));
28
+ return acc;
29
+ }, []);
30
+ return points;
66
31
  };
67
32
 
68
- exports.findRoomCenter = findRoomCenter;
33
+ exports.getRoomCoordinates = getRoomCoordinates;
69
34
 
70
35
  const getScale = (image, json) => {
71
36
  if (!json) return {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "HART Estate widget",
4
4
  "author": "HART",
5
5
  "keywords": [],
6
- "version": "0.0.22",
6
+ "version": "0.0.25",
7
7
  "private": false,
8
8
  "main": "build/index.js",
9
9
  "module": "build/index.js",
@@ -20,6 +20,7 @@
20
20
  "dependencies": {
21
21
  "camera-controls": "^1.34.1",
22
22
  "core-js": "^3.21.0",
23
+ "geometric": "^2.2.10",
23
24
  "hold-event": "^0.1.0",
24
25
  "mobx": "^6.3.13",
25
26
  "mobx-react-lite": "^3.2.3",