hart-estate-widget 0.0.18 → 0.0.21
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.
@@ -33,6 +33,9 @@ const ModelTab = (0, _mobxReactLite.observer)(_ref => {
|
|
33
33
|
} = _modelStore.default;
|
34
34
|
(0, _react.useEffect)(() => {
|
35
35
|
const container = document.querySelector('.widget-tab__model-scene');
|
36
|
+
|
37
|
+
_modelStore.default.setContainer(container);
|
38
|
+
|
36
39
|
container.appendChild(_modelStore.default.renderer.domElement);
|
37
40
|
|
38
41
|
_modelStore.default.setCurrentControlsType('orbit');
|
@@ -11,6 +11,8 @@ require("core-js/modules/es.array.reduce.js");
|
|
11
11
|
|
12
12
|
require("core-js/modules/es.promise.js");
|
13
13
|
|
14
|
+
require("core-js/modules/es.string.includes.js");
|
15
|
+
|
14
16
|
var _react = _interopRequireDefault(require("react"));
|
15
17
|
|
16
18
|
var _mobx = require("mobx");
|
@@ -55,6 +57,8 @@ const doorMaterialOptions = {
|
|
55
57
|
};
|
56
58
|
const modelLoader = new _FBXLoader.FBXLoader();
|
57
59
|
|
60
|
+
const createDefaultMaterial = options => new THREE.MeshPhongMaterial(options);
|
61
|
+
|
58
62
|
class HouseStore {
|
59
63
|
constructor(modelStore) {
|
60
64
|
_defineProperty(this, "modelStore", null);
|
@@ -259,14 +263,14 @@ class HouseStore {
|
|
259
263
|
const vertices = this.getVerticesFromParsedWalls(walls);
|
260
264
|
const shape = new THREE.Shape(vertices);
|
261
265
|
const geometry = new THREE.ShapeGeometry(shape);
|
262
|
-
const material =
|
266
|
+
const material = createDefaultMaterial({
|
263
267
|
color: params.color,
|
264
268
|
side: THREE.DoubleSide
|
265
269
|
});
|
266
270
|
const mesh = new THREE.Mesh(geometry, material);
|
267
271
|
mesh.name = 'FloorMesh';
|
268
272
|
this.loadTexture(params.texture, [0.5, 0.5], texture => {
|
269
|
-
const textureMaterial =
|
273
|
+
const textureMaterial = createDefaultMaterial({
|
270
274
|
color: params.color,
|
271
275
|
side: THREE.DoubleSide,
|
272
276
|
map: texture
|
@@ -305,11 +309,11 @@ class HouseStore {
|
|
305
309
|
depth,
|
306
310
|
bevelEnabled: false
|
307
311
|
});
|
308
|
-
const clippedMaterial =
|
312
|
+
const clippedMaterial = createDefaultMaterial({
|
309
313
|
side: THREE.DoubleSide,
|
310
314
|
color: '#5C5C5C'
|
311
315
|
});
|
312
|
-
const material =
|
316
|
+
const material = createDefaultMaterial(_objectSpread(_objectSpread({}, this.wallMaterialOptions), {}, {
|
313
317
|
color: '#5C5C5C'
|
314
318
|
}));
|
315
319
|
const clippedMesh = new THREE.Mesh(clippedGeometry, clippedMaterial);
|
@@ -345,10 +349,10 @@ class HouseStore {
|
|
345
349
|
bevelEnabled: false
|
346
350
|
});
|
347
351
|
const wallMaterial = isExterior ? this.exteriorWallsMaterial : this.wallsMaterial;
|
348
|
-
const wallPadMaterial =
|
352
|
+
const wallPadMaterial = createDefaultMaterial(_objectSpread(_objectSpread({}, this.wallMaterialOptions), {}, {
|
349
353
|
color: '#5C5C5C'
|
350
354
|
}));
|
351
|
-
const wallClippedPadMaterial =
|
355
|
+
const wallClippedPadMaterial = createDefaultMaterial({
|
352
356
|
side: THREE.DoubleSide,
|
353
357
|
color: '#5C5C5C'
|
354
358
|
});
|
@@ -411,7 +415,7 @@ class HouseStore {
|
|
411
415
|
} = _ref9;
|
412
416
|
const isDoor = Type === 'Door';
|
413
417
|
const apertureGeometry = new THREE.BoxGeometry((Width + additionalWidth) * this.sceneScale, Depth * this.sceneScale + 1, (isDoor ? this.doorsHeight : this.wallsHeight / 2) + additionalWidth * this.sceneScale);
|
414
|
-
const apertureMaterial =
|
418
|
+
const apertureMaterial = createDefaultMaterial({
|
415
419
|
color: '#00B4F7'
|
416
420
|
});
|
417
421
|
const apertureMesh = new THREE.Mesh(apertureGeometry, apertureMaterial);
|
@@ -464,7 +468,7 @@ class HouseStore {
|
|
464
468
|
image: _wallTexture.default,
|
465
469
|
texture: texture
|
466
470
|
});
|
467
|
-
this.wallsMaterial =
|
471
|
+
this.wallsMaterial = createDefaultMaterial(_objectSpread(_objectSpread({}, this.wallMaterialOptions), {}, {
|
468
472
|
map: texture
|
469
473
|
}));
|
470
474
|
}
|
@@ -476,7 +480,7 @@ class HouseStore {
|
|
476
480
|
image: _exteriorWallTexture.default,
|
477
481
|
texture: texture
|
478
482
|
});
|
479
|
-
this.exteriorWallsMaterial =
|
483
|
+
this.exteriorWallsMaterial = createDefaultMaterial(_objectSpread(_objectSpread({}, this.wallMaterialOptions), {}, {
|
480
484
|
map: texture,
|
481
485
|
color: '#FFFFFF'
|
482
486
|
}));
|
@@ -485,7 +489,7 @@ class HouseStore {
|
|
485
489
|
img: _doorTexture.default,
|
486
490
|
repeat: [1, 1],
|
487
491
|
callback: texture => {
|
488
|
-
this.doorMaterial =
|
492
|
+
this.doorMaterial = createDefaultMaterial(_objectSpread(_objectSpread({}, doorMaterialOptions), {}, {
|
489
493
|
map: texture
|
490
494
|
}));
|
491
495
|
}
|
@@ -522,7 +526,7 @@ class HouseStore {
|
|
522
526
|
const modelPath = "".concat(this.apiStore.API_URL, "/storage/furniture/").concat(mesh);
|
523
527
|
const {
|
524
528
|
Location,
|
525
|
-
|
529
|
+
WEB_Rotation,
|
526
530
|
Model: ModelName
|
527
531
|
} = furniture;
|
528
532
|
const {
|
@@ -538,33 +542,76 @@ class HouseStore {
|
|
538
542
|
});
|
539
543
|
|
540
544
|
const onTexturesLoaded = (result, model) => {
|
541
|
-
const
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
545
|
+
const materialsCount = result.reduce((acc, _ref11) => {
|
546
|
+
let {
|
547
|
+
image
|
548
|
+
} = _ref11;
|
549
|
+
if (!image.currentSrc.includes('_D.') && !image.currentSrc.includes('_DA.')) return acc;
|
550
|
+
return acc += 1;
|
551
|
+
}, 0);
|
552
|
+
|
553
|
+
const createMaterial = num => {
|
554
|
+
const map = result.find(_ref12 => {
|
555
|
+
let {
|
556
|
+
image
|
557
|
+
} = _ref12;
|
558
|
+
return image.currentSrc.includes("".concat(num, "_D.")) || image.currentSrc.includes("".concat(num, "_DA."));
|
559
|
+
});
|
560
|
+
const envMap = result.find(_ref13 => {
|
561
|
+
let {
|
562
|
+
image
|
563
|
+
} = _ref13;
|
564
|
+
return image.currentSrc.includes("".concat(num, "_RMO."));
|
565
|
+
});
|
566
|
+
const normalMap = result.find(_ref14 => {
|
567
|
+
let {
|
568
|
+
image
|
569
|
+
} = _ref14;
|
570
|
+
return image.currentSrc.includes("".concat(num, "_N."));
|
571
|
+
});
|
572
|
+
const material = new THREE.MeshStandardMaterial({
|
573
|
+
roughness: 1,
|
574
|
+
transparent: true
|
575
|
+
});
|
576
|
+
material.depthWrite = !(ModelName === 'Flower' && num === '01');
|
577
|
+
if (map) material.map = map;
|
578
|
+
if (envMap) material.envMap = envMap;
|
579
|
+
if (normalMap) material.normalMap = normalMap;
|
580
|
+
return material;
|
581
|
+
};
|
582
|
+
|
583
|
+
let materials = new THREE.MeshPhysicalMaterial({
|
584
|
+
roughness: 1,
|
585
|
+
clearcoat: 1,
|
586
|
+
clearcoatRoughness: 1,
|
587
|
+
reflectivity: 0,
|
588
|
+
fog: false
|
589
|
+
});
|
590
|
+
|
591
|
+
if (materialsCount === 1) {
|
592
|
+
materials = createMaterial('');
|
593
|
+
}
|
594
|
+
|
595
|
+
if (materialsCount > 1) {
|
596
|
+
materials = [...Array(materialsCount).keys()].map(i => {
|
597
|
+
const num = i + 1;
|
598
|
+
const realNum = num < 10 ? "0".concat(num) : num;
|
599
|
+
return createMaterial(realNum);
|
600
|
+
});
|
601
|
+
}
|
602
|
+
|
546
603
|
model.traverse(node => {
|
547
604
|
if (node.isMesh) node.material = materials;
|
548
605
|
});
|
549
606
|
this.houseGroup.add(model);
|
550
607
|
this.loadFurniture(index + 1);
|
551
|
-
const opacityInterval = setInterval(() => {
|
552
|
-
model.children[0].material.forEach(material => {
|
553
|
-
material.opacity += 0.01;
|
554
|
-
|
555
|
-
if (material.opacity >= 1) {
|
556
|
-
clearInterval(opacityInterval);
|
557
|
-
material.opacity = 1;
|
558
|
-
}
|
559
|
-
});
|
560
|
-
}, 1);
|
561
608
|
};
|
562
609
|
|
563
610
|
const onModelLoaded = originalModel => {
|
564
611
|
const model = originalModel.clone();
|
565
612
|
model.scale.set(this.sceneScale, this.sceneScale, this.sceneScale);
|
566
613
|
model.position.set(X * this.sceneScale, Y * this.sceneScale, Z * this.sceneScale);
|
567
|
-
model.rotation.set(Math.PI / 2, THREE.Math.degToRad(
|
614
|
+
model.rotation.set(Math.PI / 2, THREE.Math.degToRad(WEB_Rotation.Yaw), 0);
|
568
615
|
const loadedTextures = this.loadedTextures[ModelName];
|
569
616
|
|
570
617
|
if (loadedTextures) {
|
@@ -599,11 +646,11 @@ class HouseStore {
|
|
599
646
|
|
600
647
|
setCurrentWallsMaterialType(value) {
|
601
648
|
this.wallsMaterialType = value;
|
602
|
-
this.wallsGroup.children.forEach(
|
649
|
+
this.wallsGroup.children.forEach(_ref15 => {
|
603
650
|
let {
|
604
651
|
children,
|
605
652
|
isExterior
|
606
|
-
} =
|
653
|
+
} = _ref15;
|
607
654
|
const wall = children[0];
|
608
655
|
|
609
656
|
if (value === 'texture') {
|
@@ -612,7 +659,7 @@ class HouseStore {
|
|
612
659
|
}
|
613
660
|
|
614
661
|
const color = isExterior ? '#FFFFFF' : this.wallsColor;
|
615
|
-
wall.material =
|
662
|
+
wall.material = createDefaultMaterial(_objectSpread(_objectSpread({}, this.wallMaterialOptions), {}, {
|
616
663
|
color
|
617
664
|
}));
|
618
665
|
});
|
@@ -622,18 +669,18 @@ class HouseStore {
|
|
622
669
|
return;
|
623
670
|
}
|
624
671
|
|
625
|
-
door.material =
|
672
|
+
door.material = createDefaultMaterial(doorMaterialOptions);
|
626
673
|
});
|
627
674
|
}
|
628
675
|
|
629
676
|
setCurrentWallColor(color) {
|
630
677
|
this.wallsColor = color;
|
631
678
|
this.wallsMaterial.color.set(color);
|
632
|
-
this.wallsGroup.children.forEach(
|
679
|
+
this.wallsGroup.children.forEach(_ref16 => {
|
633
680
|
let {
|
634
681
|
children,
|
635
682
|
isExterior
|
636
|
-
} =
|
683
|
+
} = _ref16;
|
637
684
|
if (isExterior) return;
|
638
685
|
const wall = children[0];
|
639
686
|
wall.material.color.set(color);
|
@@ -641,7 +688,7 @@ class HouseStore {
|
|
641
688
|
}
|
642
689
|
|
643
690
|
setCurrentWallTexture(texture) {
|
644
|
-
this.wallsMaterial =
|
691
|
+
this.wallsMaterial = createDefaultMaterial(_objectSpread(_objectSpread({}, this.wallMaterialOptions), {}, {
|
645
692
|
map: texture
|
646
693
|
}));
|
647
694
|
this.setCurrentWallsMaterialType('texture');
|
@@ -660,10 +707,10 @@ class HouseStore {
|
|
660
707
|
setFullBuildingVisibility(value) {
|
661
708
|
this.isFullBuildingVisible = value;
|
662
709
|
this.globalPlane.constant = this.isFullBuildingVisible ? 1 : clippedBuildingConstant;
|
663
|
-
this.wallsGroup.children.forEach(
|
710
|
+
this.wallsGroup.children.forEach(_ref17 => {
|
664
711
|
let {
|
665
712
|
children
|
666
|
-
} =
|
713
|
+
} = _ref17;
|
667
714
|
return children[2].visible = !value;
|
668
715
|
});
|
669
716
|
}
|
@@ -15,7 +15,7 @@ var THREE = _interopRequireWildcard(require("three"));
|
|
15
15
|
|
16
16
|
var _cameraControls = _interopRequireDefault(require("camera-controls"));
|
17
17
|
|
18
|
-
var _houseStore = _interopRequireDefault(require("
|
18
|
+
var _houseStore = _interopRequireDefault(require("../store/houseStore"));
|
19
19
|
|
20
20
|
var _grass = _interopRequireDefault(require("../assets/img/grass.png"));
|
21
21
|
|
@@ -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,22 +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.
|
122
|
+
this.updateRendererSize();
|
117
123
|
this.renderer.localClippingEnabled = true;
|
118
124
|
return this;
|
119
125
|
});
|
120
126
|
|
127
|
+
_defineProperty(this, "updateRendererSize", () => {
|
128
|
+
this.renderer.setSize(this.width, this.height);
|
129
|
+
});
|
130
|
+
|
121
131
|
_defineProperty(this, "createCamera", () => {
|
122
|
-
this.camera = new THREE.PerspectiveCamera(75,
|
132
|
+
this.camera = new THREE.PerspectiveCamera(75, this.width / this.height, 0.1, 1000);
|
123
133
|
this.camera.position.set(0, 0, 0);
|
124
134
|
window.addEventListener('resize', () => {
|
125
|
-
this.
|
126
|
-
this.
|
127
|
-
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
135
|
+
this.updateCameraSize();
|
136
|
+
this.updateRendererSize();
|
128
137
|
});
|
129
138
|
return this;
|
130
139
|
});
|
131
140
|
|
141
|
+
_defineProperty(this, "updateCameraSize", () => {
|
142
|
+
this.camera.aspect = this.width / this.height;
|
143
|
+
this.camera.updateProjectionMatrix();
|
144
|
+
});
|
145
|
+
|
132
146
|
_defineProperty(this, "createControls", () => {
|
133
147
|
this.controls = new _cameraControls.default(this.camera, this.renderer.domElement);
|
134
148
|
this.controls.minDistance = 0.5;
|
@@ -173,7 +187,7 @@ class ModelStore {
|
|
173
187
|
this.controls.moveTo(0, 0, 0, true);
|
174
188
|
this.controls.mouseButtons.wheel = _cameraControls.default.ACTION.DOLLY;
|
175
189
|
this.controls.touches.two = _cameraControls.default.ACTION.TOUCH_DOLLY_TRUCK;
|
176
|
-
this.controls.rotateTo(0, angle, true);
|
190
|
+
this.controls.rotateTo(0, angle, true);
|
177
191
|
});
|
178
192
|
|
179
193
|
_defineProperty(this, "setCurrentControlsType", type => {
|
@@ -227,6 +241,18 @@ class ModelStore {
|
|
227
241
|
this.createScene().createRenderer().createCamera().createControls().addKeyEvents();
|
228
242
|
}
|
229
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
|
+
|
230
256
|
}
|
231
257
|
|
232
258
|
var _default = new ModelStore();
|