hart-estate-widget 0.0.19 → 0.0.20

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.
@@ -34,7 +34,7 @@ const ModelTab = (0, _mobxReactLite.observer)(_ref => {
34
34
  (0, _react.useEffect)(() => {
35
35
  const container = document.querySelector('.widget-tab__model-scene');
36
36
 
37
- _modelStore.default.setRendererSize(container.offsetWidth, container.offsetHeight);
37
+ _modelStore.default.setContainer(container);
38
38
 
39
39
  container.appendChild(_modelStore.default.renderer.domElement);
40
40
 
@@ -84,6 +84,12 @@ class ModelStore {
84
84
  this.joystickDirections = directions;
85
85
  });
86
86
 
87
+ _defineProperty(this, "setContainer", container => {
88
+ this.container = container;
89
+ this.updateRendererSize();
90
+ this.updateCameraSize();
91
+ });
92
+
87
93
  _defineProperty(this, "createScene", () => {
88
94
  this.scene = new THREE.Scene();
89
95
  const light = new THREE.AmbientLight(0xffffff);
@@ -113,26 +119,30 @@ class ModelStore {
113
119
  _defineProperty(this, "createRenderer", () => {
114
120
  this.renderer = new THREE.WebGLRenderer();
115
121
  this.renderer.setPixelRatio(window.devicePixelRatio);
116
- this.setRendererSize(window.innerWidth, window.innerHeight);
122
+ this.updateRendererSize();
117
123
  this.renderer.localClippingEnabled = true;
118
124
  return this;
119
125
  });
120
126
 
121
- _defineProperty(this, "setRendererSize", (width, height) => {
122
- this.renderer.setSize(width, height);
127
+ _defineProperty(this, "updateRendererSize", () => {
128
+ this.renderer.setSize(this.width, this.height);
123
129
  });
124
130
 
125
131
  _defineProperty(this, "createCamera", () => {
126
- this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
132
+ this.camera = new THREE.PerspectiveCamera(75, this.width / this.height, 0.1, 1000);
127
133
  this.camera.position.set(0, 0, 0);
128
134
  window.addEventListener('resize', () => {
129
- this.camera.aspect = window.innerWidth / window.innerHeight;
130
- this.camera.updateProjectionMatrix();
131
- this.renderer.setSize(window.innerWidth, window.innerHeight);
135
+ this.updateCameraSize();
136
+ this.updateRendererSize();
132
137
  });
133
138
  return this;
134
139
  });
135
140
 
141
+ _defineProperty(this, "updateCameraSize", () => {
142
+ this.camera.aspect = this.width / this.height;
143
+ this.camera.updateProjectionMatrix();
144
+ });
145
+
136
146
  _defineProperty(this, "createControls", () => {
137
147
  this.controls = new _cameraControls.default(this.camera, this.renderer.domElement);
138
148
  this.controls.minDistance = 0.5;
@@ -231,6 +241,18 @@ class ModelStore {
231
241
  this.createScene().createRenderer().createCamera().createControls().addKeyEvents();
232
242
  }
233
243
 
244
+ get width() {
245
+ var _this$container;
246
+
247
+ return ((_this$container = this.container) === null || _this$container === void 0 ? void 0 : _this$container.offsetWidth) || window.innerWidth;
248
+ }
249
+
250
+ get height() {
251
+ var _this$container2;
252
+
253
+ return ((_this$container2 = this.container) === null || _this$container2 === void 0 ? void 0 : _this$container2.offsetHeight) || window.innerHeight;
254
+ }
255
+
234
256
  }
235
257
 
236
258
  var _default = new ModelStore();
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.19",
6
+ "version": "0.0.20",
7
7
  "private": false,
8
8
  "main": "build/index.js",
9
9
  "module": "build/index.js",