kitchen-simulator 5.0.0-test.7 → 5.0.0-test.9

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 (170) hide show
  1. package/package.json +12 -3
  2. package/src/components/export.js +16 -23
  3. package/src/components/catalog-view/catalog-breadcrumb.jsx +0 -53
  4. package/src/components/catalog-view/catalog-item.jsx +0 -229
  5. package/src/components/catalog-view/catalog-list.jsx +0 -173
  6. package/src/components/catalog-view/catalog-page-item.jsx +0 -110
  7. package/src/components/catalog-view/catalog-turn-back-page-item.jsx +0 -80
  8. package/src/components/configurator/custom-configurator.jsx +0 -77
  9. package/src/components/configurator/project-configurator.jsx +0 -120
  10. package/src/components/firstsetting/button/styles.js +0 -223
  11. package/src/components/firstsetting/export.js +0 -9
  12. package/src/components/firstsetting/firstsetting-content-button.jsx +0 -198
  13. package/src/components/firstsetting/firstsetting-toggle-button.jsx +0 -101
  14. package/src/components/firstsetting/firstsetting.jsx +0 -814
  15. package/src/components/footerbar/button/ControlButton.jsx +0 -43
  16. package/src/components/footerbar/button/DirectionButton.jsx +0 -54
  17. package/src/components/footerbar/button/DirectionPanSpinButton.jsx +0 -36
  18. package/src/components/footerbar/button/ToggleButton.jsx +0 -58
  19. package/src/components/footerbar/button/ToggleConvertButton.jsx +0 -48
  20. package/src/components/footerbar/button/ToggleMeasureButton.jsx +0 -33
  21. package/src/components/footerbar/button/styles.js +0 -217
  22. package/src/components/footerbar/export.js +0 -9
  23. package/src/components/footerbar/footer-content-button.jsx +0 -198
  24. package/src/components/footerbar/footer-toggle-button.jsx +0 -101
  25. package/src/components/footerbar/footerbar.jsx +0 -1103
  26. package/src/components/footerbar/styles.js +0 -263
  27. package/src/components/header/button/MenuButton.jsx +0 -46
  28. package/src/components/header/button/SaveButton.jsx +0 -54
  29. package/src/components/header/button/styles.js +0 -181
  30. package/src/components/header/export.js +0 -5
  31. package/src/components/header/header.jsx +0 -631
  32. package/src/components/header/header.style.css +0 -47
  33. package/src/components/header/styles.js +0 -320
  34. package/src/components/login/Login.js +0 -77
  35. package/src/components/login/LoginForm/index.js +0 -108
  36. package/src/components/login/Register.js +0 -83
  37. package/src/components/login/RegisterForm/index.js +0 -171
  38. package/src/components/login/jwtService.js +0 -201
  39. package/src/components/login/style.css +0 -158
  40. package/src/components/login/style.scss +0 -260
  41. package/src/components/myprojects/export.js +0 -5
  42. package/src/components/myprojects/index.jsx +0 -445
  43. package/src/components/myprojects/styles.js +0 -241
  44. package/src/components/sidebar/custom-accordion.jsx +0 -48
  45. package/src/components/sidebar/export.js +0 -15
  46. package/src/components/sidebar/panel-element-editor/attributes-editor/attributes-editor.jsx +0 -73
  47. package/src/components/sidebar/panel-element-editor/attributes-editor/confirm-popup.jsx +0 -101
  48. package/src/components/sidebar/panel-element-editor/attributes-editor/hole-attributes-editor.jsx +0 -149
  49. package/src/components/sidebar/panel-element-editor/attributes-editor/item-attributes-editor.jsx +0 -316
  50. package/src/components/sidebar/panel-element-editor/attributes-editor/line-attributes-editor.jsx +0 -108
  51. package/src/components/sidebar/panel-element-editor/element-editor.jsx +0 -1070
  52. package/src/components/sidebar/panel-element-editor/multi-elements-editor.jsx +0 -0
  53. package/src/components/sidebar/panel-element-editor/panel-element-editor.jsx +0 -104
  54. package/src/components/sidebar/panel-element-editor/panel-multi-elements-editor.jsx +0 -155
  55. package/src/components/sidebar/panel-group-editor.jsx +0 -272
  56. package/src/components/sidebar/panel-groups.jsx +0 -310
  57. package/src/components/sidebar/panel-guides.jsx +0 -192
  58. package/src/components/sidebar/panel-layer-elements.jsx +0 -298
  59. package/src/components/sidebar/panel-layers.jsx +0 -381
  60. package/src/components/sidebar/panel.jsx +0 -71
  61. package/src/components/sidebar/sidebar.jsx +0 -106
  62. package/src/components/sidebar/toolbar-panel.jsx +0 -139
  63. package/src/components/sign/export.js +0 -7
  64. package/src/components/sign/main/index.jsx +0 -523
  65. package/src/components/sign/main/styles.js +0 -163
  66. package/src/components/toolbar/button/ControlButton.jsx +0 -41
  67. package/src/components/toolbar/button/DirectionButton.jsx +0 -34
  68. package/src/components/toolbar/button/RightButton.jsx +0 -103
  69. package/src/components/toolbar/button/ToggleButton.jsx +0 -41
  70. package/src/components/toolbar/button/index.jsx +0 -55
  71. package/src/components/toolbar/button/styles.js +0 -127
  72. package/src/components/toolbar/components/DoorStyleMenu.jsx +0 -103
  73. package/src/components/toolbar/components/Pricing.jsx +0 -126
  74. package/src/components/toolbar/components/ReviewForQuote.jsx +0 -635
  75. package/src/components/toolbar/export.js +0 -21
  76. package/src/components/toolbar/main/Alert.js +0 -122
  77. package/src/components/toolbar/main/TakePictureModal.jsx +0 -104
  78. package/src/components/toolbar/main/confirm-popup.jsx +0 -99
  79. package/src/components/toolbar/main/index.jsx +0 -5627
  80. package/src/components/toolbar/main/lShaped.json +0 -311
  81. package/src/components/toolbar/main/longNarrow.json +0 -238
  82. package/src/components/toolbar/main/myComponents.js +0 -123
  83. package/src/components/toolbar/main/oRectangle.json +0 -220
  84. package/src/components/toolbar/main/rectangle.json +0 -238
  85. package/src/components/toolbar/main/style.css +0 -107
  86. package/src/components/toolbar/main/styles.js +0 -696
  87. package/src/components/toolbar/plugin-item.jsx +0 -123
  88. package/src/components/toolbar/popup/appliance/appliance-category/index.jsx +0 -73
  89. package/src/components/toolbar/popup/appliance/choose-appliance/index.jsx +0 -102
  90. package/src/components/toolbar/popup/appliance/index.jsx +0 -83
  91. package/src/components/toolbar/popup/autosaveprompt/index.jsx +0 -150
  92. package/src/components/toolbar/popup/autosaveprompt/styles.css +0 -64
  93. package/src/components/toolbar/popup/autosaveprompt/styles.js +0 -40
  94. package/src/components/toolbar/popup/cabinet/cabinet-category/index.jsx +0 -73
  95. package/src/components/toolbar/popup/cabinet/choose-product/index.jsx +0 -119
  96. package/src/components/toolbar/popup/cabinet/index.jsx +0 -85
  97. package/src/components/toolbar/popup/doorStyle/choose-style/index.jsx +0 -63
  98. package/src/components/toolbar/popup/doorStyle/index.jsx +0 -71
  99. package/src/components/toolbar/popup/doorStyle/style-category/index.jsx +0 -139
  100. package/src/components/toolbar/popup/downloadsummary/downloadSummaryContext.js +0 -2
  101. package/src/components/toolbar/popup/downloadsummary/downloadSummaryTemp.jsx +0 -157
  102. package/src/components/toolbar/popup/downloadsummary/index.jsx +0 -643
  103. package/src/components/toolbar/popup/downloadsummary/show2D/show2DView.jsx +0 -51
  104. package/src/components/toolbar/popup/downloadsummary/show2D/viewer2DDownLoad.jsx +0 -175
  105. package/src/components/toolbar/popup/downloadsummary/show3D/show3DView.jsx +0 -283
  106. package/src/components/toolbar/popup/downloadsummary/show3D/viewer3DDownLoad.jsx +0 -2257
  107. package/src/components/toolbar/popup/downloadsummary/showCabinetInfo.js +0 -93
  108. package/src/components/toolbar/popup/downloadsummary/showElevation/showElevationView.jsx +0 -132
  109. package/src/components/toolbar/popup/downloadsummary/showElevation/viewer3DElevationDownload.jsx +0 -2198
  110. package/src/components/toolbar/popup/downloadsummary/showElevation/viewerElevationDownload.jsx +0 -152
  111. package/src/components/toolbar/popup/downloadsummary/showWarranty.jsx +0 -149
  112. package/src/components/toolbar/popup/downloadsummary/styles.css +0 -177
  113. package/src/components/toolbar/popup/downloadsummary/styles.js +0 -453
  114. package/src/components/toolbar/popup/finishingtouch/category/index.jsx +0 -34
  115. package/src/components/toolbar/popup/finishingtouch/index.jsx +0 -58
  116. package/src/components/toolbar/popup/finishingtouch/material-edit.jsx +0 -112
  117. package/src/components/toolbar/popup/finishingtouch/product/index.jsx +0 -116
  118. package/src/components/toolbar/popup/floorplan/choose-floor/confirm-popup.jsx +0 -101
  119. package/src/components/toolbar/popup/floorplan/choose-floor/index.jsx +0 -254
  120. package/src/components/toolbar/popup/floorplan/choose-floor/lShaped.json +0 -311
  121. package/src/components/toolbar/popup/floorplan/choose-floor/longNarrow.json +0 -238
  122. package/src/components/toolbar/popup/floorplan/choose-floor/oRectangle.json +0 -220
  123. package/src/components/toolbar/popup/floorplan/choose-floor/rectangle.json +0 -238
  124. package/src/components/toolbar/popup/floorplan/choose-floor/styles.js +0 -86
  125. package/src/components/toolbar/popup/floorplan/floor-category/index.jsx +0 -109
  126. package/src/components/toolbar/popup/floorplan/index.jsx +0 -60
  127. package/src/components/toolbar/popup/index.jsx +0 -241
  128. package/src/components/toolbar/popup/newproject/index.jsx +0 -59
  129. package/src/components/toolbar/popup/newproject/styles.css +0 -64
  130. package/src/components/toolbar/popup/newproject/styles.js +0 -41
  131. package/src/components/toolbar/popup/product/appliance.jsx +0 -54
  132. package/src/components/toolbar/popup/product/cabinetproduct.jsx +0 -15
  133. package/src/components/toolbar/popup/product/doorstyle.jsx +0 -58
  134. package/src/components/toolbar/popup/product/doorstyleproduct.jsx +0 -47
  135. package/src/components/toolbar/popup/product/floor.jsx +0 -36
  136. package/src/components/toolbar/popup/product/floorproduct.jsx +0 -42
  137. package/src/components/toolbar/popup/product/index.jsx +0 -36
  138. package/src/components/toolbar/popup/product/primary.jsx +0 -77
  139. package/src/components/toolbar/popup/product/productline.jsx +0 -93
  140. package/src/components/toolbar/popup/product/reviewItem.jsx +0 -427
  141. package/src/components/toolbar/popup/product/reviewMolding.jsx +0 -310
  142. package/src/components/toolbar/popup/product/style.css +0 -54
  143. package/src/components/toolbar/popup/product/styles.js +0 -260
  144. package/src/components/toolbar/popup/savedesign/FullPictureForm.jsx +0 -146
  145. package/src/components/toolbar/popup/savedesign/index.jsx +0 -495
  146. package/src/components/toolbar/popup/savedesign/savedesign.style.css +0 -16
  147. package/src/components/toolbar/popup/savedesign/styles.js +0 -151
  148. package/src/components/toolbar/popup/setDoorStyleOption/index.jsx +0 -87
  149. package/src/components/toolbar/popup/styles.js +0 -909
  150. package/src/components/toolbar/popup/submitforquote/AddToCartOptions.jsx +0 -192
  151. package/src/components/toolbar/popup/submitforquote/CustomerRequestsForm.jsx +0 -96
  152. package/src/components/toolbar/popup/submitforquote/SkipDesignerReview.jsx +0 -54
  153. package/src/components/toolbar/popup/submitforquote/StepDots.jsx +0 -25
  154. package/src/components/toolbar/popup/submitforquote/cart-choice.jsx +0 -116
  155. package/src/components/toolbar/popup/submitforquote/doorstyle-menus.js +0 -38
  156. package/src/components/toolbar/popup/submitforquote/index.jsx +0 -698
  157. package/src/components/toolbar/popup/submitforquote/styles.css +0 -105
  158. package/src/components/toolbar/popup/submitforquote/styles.js +0 -294
  159. package/src/components/toolbar/popup/submitprompt/index.jsx +0 -89
  160. package/src/components/toolbar/popup/submitprompt/styles.css +0 -64
  161. package/src/components/toolbar/popup/submitprompt/styles.js +0 -42
  162. package/src/components/toolbar/toolbar-button.jsx +0 -90
  163. package/src/components/toolbar/toolbar-load-button.jsx +0 -36
  164. package/src/components/toolbar/toolbar-save-button.jsx +0 -32
  165. package/src/components/wizardstep/button/styles.js +0 -677
  166. package/src/components/wizardstep/export.js +0 -5
  167. package/src/components/wizardstep/index.jsx +0 -1372
  168. package/src/components/wizardstep/styles.js +0 -688
  169. package/src/components/wizardstep/wizardstep-content-button.jsx +0 -198
  170. package/src/components/wizardstep/wizardstep-toggle-button.jsx +0 -101
@@ -1,2257 +0,0 @@
1
- 'use strict';
2
-
3
- import React from 'react';
4
- import PropTypes from 'prop-types';
5
- import ReactDOM from 'react-dom';
6
- import * as Three from 'three';
7
- import {
8
- parseData,
9
- updateScene,
10
- visibleTransformBox,
11
- getDistances,
12
- fVLine,
13
- deleteSpecifiedMeshObjects,
14
- createBacksplash,
15
- checkCabinetOverlap
16
- } from '../../../../viewer3d/scene-creator';
17
- import { disposeScene } from '../../../../viewer3d/three-memory-cleaner';
18
- import { disposeObject } from '../../../../viewer3d/three-memory-cleaner';
19
- import diff from 'immutablediff';
20
- import * as SharedStyle from '../../../../../shared-style';
21
- import {
22
- MODE_DRAWING_ITEM_3D,
23
- UNIT_CENTIMETER,
24
- MODE_DRAWING_HOLE_3D,
25
- SECONDARY_PURPLE_COLOR,
26
- ARRAY_ELEVATION_VIEW_MODES,
27
- MODE_FRONT_ELEVATION_VIEW,
28
- MODE_RIGHT_ELEVATION_VIEW,
29
- MODE_LEFT_ELEVATION_VIEW,
30
- MODE_BACK_ELEVATION_VIEW,
31
- MODE_3D_VIEW,
32
- BASE_CABINET_LAYOUTPOS,
33
- WALL_CABINET_LAYOUTPOS,
34
- TALL_CABINET_LAYOUTPOS
35
- } from '../../../../../constants';
36
- import { isUndefined } from 'util';
37
- import { verticesDistance, almostEqual } from '../../../../../utils/geometry';
38
- import convert from 'convert-units';
39
- import { GeometryUtils } from '../../../../../utils/export';
40
- import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader';
41
- import CameraControls from 'camera-controls';
42
- CameraControls.install({ THREE: Three });
43
- import { returnReplaceableDeepSearchType } from '../../../../viewer2d/utils';
44
- import {
45
- getAllMeshes,
46
- vectorIntersectWithMesh
47
- } from '../../../../../utils/objects-utils';
48
-
49
- export default class Viewer3DDownLoad extends React.Component {
50
- constructor(props) {
51
- super(props);
52
- this.state = {
53
- isLoading: false,
54
- showflag: true,
55
- toolObj: null,
56
- angleObj: null,
57
- waitForRender: 0
58
- };
59
- this.lastMousePosition = {};
60
- this.width = props.width;
61
- this.height = props.height;
62
- this.renderingID = 0;
63
-
64
- let { mode } = props.state;
65
-
66
- if (!window.__elevationRendererDownload) {
67
- window.__elevationRendererDownload = {};
68
- }
69
-
70
- this.renderer =
71
- (mode == 'MODE_3D_VIEW'
72
- ? window.__threeRendererDownload
73
- : window.__elevationRendererDownload[mode]) ||
74
- new Three.WebGLRenderer({
75
- preserveDrawingBuffer: true,
76
- alpha: true,
77
- antialias: true
78
- });
79
-
80
- this.renderer.shadowMap.enabled = true;
81
- this.renderer.shadowMapSoft = true;
82
- if (mode == 'MODE_3D_VIEW') {
83
- window.__threeRendererDownload = this.renderer;
84
- } else {
85
- window.__elevationRendererDownload[mode] = this.renderer;
86
- }
87
-
88
- this.renderer.domElement.style.display = 'none';
89
- }
90
-
91
- componentDidMount(nextProps) {
92
- let scene3D, camera, pivot, cameraControls, clock;
93
-
94
- const actions = {
95
- areaActions: this.context.areaActions,
96
- holesActions: this.context.holesActions,
97
- itemsActions: this.context.itemsActions,
98
- sceneActions: this.context.sceneActions,
99
- linesActions: this.context.linesActions,
100
- projectActions: this.context.projectActions,
101
- catalog: this.context.catalog
102
- };
103
-
104
- const self = this;
105
- const { state } = this.props;
106
- const { mode, scene } = state;
107
- function setupLight(scene, inbBox) {
108
- if (ARRAY_ELEVATION_VIEW_MODES.includes(mode)) {
109
- const ambilight = new Three.AmbientLight('0xffffff', 3);
110
- scene.add(ambilight);
111
- } else {
112
- const shadowMapSize = 2048;
113
- const shadowCameraSize =
114
- Math.max(
115
- Math.abs(inbBox.min.x - inbBox.max.x),
116
- Math.abs(inbBox.min.y - inbBox.max.y),
117
- Math.abs(inbBox.min.z - inbBox.max.z)
118
- ) / 2;
119
- const shadowCameraFar = shadowCameraSize * 10;
120
- const bboxCenter = new Three.Vector3(
121
- (inbBox.min.x + inbBox.max.x) / 2,
122
- inbBox.min.y,
123
- (inbBox.min.z + inbBox.max.z) / 2
124
- );
125
- function addDirLight(inColor, inIntensity, inPosition) {
126
- const dirLight = new Three.DirectionalLight(inColor, inIntensity);
127
- dirLight.castShadow = true;
128
- dirLight.shadow.mapSize.x = shadowMapSize;
129
- dirLight.shadow.mapSize.y = shadowMapSize;
130
- dirLight.shadow.camera.near = 0;
131
- dirLight.shadow.camera.far = shadowCameraFar;
132
-
133
- dirLight.shadow.camera.top = shadowCameraSize * 1.5;
134
- dirLight.shadow.camera.bottom = -shadowCameraSize * 1.5;
135
- dirLight.shadow.camera.left = -shadowCameraSize * 1.5;
136
- dirLight.shadow.camera.right = shadowCameraSize * 1.5;
137
- dirLight.position.copy(inPosition);
138
-
139
- const targetObject = new Three.Object3D();
140
- targetObject.position.copy(bboxCenter);
141
- scene.add(targetObject);
142
-
143
- dirLight.target = targetObject;
144
- dirLight.target.updateMatrixWorld();
145
-
146
- scene.add(dirLight);
147
- }
148
- function addSpotLight(
149
- inColor,
150
- inIntensity,
151
- inPosition,
152
- inTarget,
153
- inDistance
154
- ) {
155
- const spotLight = new Three.SpotLight();
156
- spotLight.intensity = inIntensity;
157
- spotLight.color.setHex(inColor);
158
- spotLight.position.copy(inPosition);
159
- spotLight.angle = 1.3;
160
- spotLight.distance = inDistance;
161
- spotLight.penumbra = 1.8;
162
- spotLight.decay = 0.01;
163
-
164
- spotLight.castShadow = true;
165
- spotLight.shadow.intensity = 2;
166
- spotLight.shadow.mapSize.width = 4096;
167
- spotLight.shadow.mapSize.height = 4096;
168
-
169
- const targetObject = new Three.Object3D();
170
- targetObject.position.copy(
171
- new Three.Vector3(inTarget.x, 0, inTarget.z)
172
- );
173
- scene.add(targetObject);
174
-
175
- spotLight.target = targetObject;
176
- spotLight.target.updateMatrixWorld();
177
- scene.add(spotLight);
178
- }
179
-
180
- const dirLightPos = new Three.Vector3(
181
- inbBox.max.x,
182
- inbBox.max.y + 1.8 * Math.abs(inbBox.max.y - inbBox.min.y),
183
- inbBox.min.z - 0.5 * Math.abs(inbBox.max.z - inbBox.min.z)
184
- );
185
-
186
- addDirLight('white', 1.5, dirLightPos);
187
-
188
- const ceiling = scene3D.getObjectByName('ceil');
189
- if (ceiling) {
190
- const ceilBBox = new Three.Box3().setFromObject(ceiling);
191
-
192
- const spot1 = new Three.Vector3(
193
- ceilBBox.min.x + Math.abs(ceilBBox.min.x - ceilBBox.max.x) / 4,
194
- ceilBBox.max.y - 0.5,
195
- ceilBBox.min.z + Math.abs(ceilBBox.min.z - inbBox.max.z) / 4
196
- );
197
- const spot2 = new Three.Vector3(
198
- ceilBBox.min.x + Math.abs(ceilBBox.min.x - ceilBBox.max.x) / 4,
199
- ceilBBox.max.y - 0.5,
200
- ceilBBox.max.z - Math.abs(ceilBBox.min.z - ceilBBox.max.z) / 4
201
- );
202
-
203
- const spot3 = new Three.Vector3(
204
- ceilBBox.max.x - Math.abs(ceilBBox.min.x - ceilBBox.max.x) / 4,
205
- ceilBBox.max.y - 0.5,
206
- ceilBBox.min.z + Math.abs(ceilBBox.min.z - ceilBBox.max.z) / 4
207
- );
208
- const spot4 = new Three.Vector3(
209
- ceilBBox.max.x - Math.abs(ceilBBox.min.x - ceilBBox.max.x) / 4,
210
- ceilBBox.max.y - 0.5,
211
- ceilBBox.max.z - Math.abs(ceilBBox.min.z - ceilBBox.max.z) / 4
212
- );
213
-
214
- const spotlightDis = 1.5 * Math.abs(inbBox.min.y - inbBox.max.y);
215
-
216
- // check if spotlight is inside the room
217
- vectorIntersectWithMesh(spot1, scene3D.getObjectByName('floor')) &&
218
- addSpotLight('0xffffff', 0.8, spot1, spot1, spotlightDis);
219
- vectorIntersectWithMesh(spot2, scene3D.getObjectByName('floor')) &&
220
- addSpotLight('0xffffff', 0.8, spot2, spot2, spotlightDis);
221
- vectorIntersectWithMesh(spot3, scene3D.getObjectByName('floor')) &&
222
- addSpotLight('0xffffff', 0.8, spot3, spot3, spotlightDis);
223
- vectorIntersectWithMesh(spot4, scene3D.getObjectByName('floor')) &&
224
- addSpotLight('0xffffff', 0.8, spot4, spot4, spotlightDis);
225
- }
226
- }
227
- }
228
-
229
- // Load data
230
- this.setState({ isLoading: true, waitForRender: 0 });
231
- switch (self.props.state.mode) {
232
- case MODE_FRONT_ELEVATION_VIEW:
233
- self.props.setIsLoadingElevation('front', true);
234
- break;
235
- case MODE_BACK_ELEVATION_VIEW:
236
- self.props.setIsLoadingElevation('back', true);
237
- break;
238
- case MODE_LEFT_ELEVATION_VIEW:
239
- self.props.setIsLoadingElevation('left', true);
240
- break;
241
- case MODE_RIGHT_ELEVATION_VIEW:
242
- self.props.setIsLoadingElevation('right', true);
243
- break;
244
- case MODE_3D_VIEW:
245
- self.props.setIsLoading3D(true);
246
- break;
247
- }
248
- const { promise, planData } = parseData(
249
- scene,
250
- actions,
251
- this.context.catalog,
252
- camera,
253
- this.renderer,
254
- state.mode
255
- );
256
-
257
- promise.then(() => {
258
- let objToRemove = [];
259
- planData.plan.traverse(obj => {
260
- if (obj.geometry === null) {
261
- objToRemove.push(obj);
262
- }
263
- });
264
- objToRemove.forEach(obj => {
265
- obj.removeFromParent();
266
- });
267
- const bbox = new Three.Box3().setFromObject(planData.plan);
268
- if (!ARRAY_ELEVATION_VIEW_MODES.includes(state.mode)) {
269
- //cameraControls.fitToBox(bbox, true);
270
- if (cameraControls) {
271
- const radius = 400; // Distance from target
272
- const angleInDegrees = 5;
273
- const angleInRadians = (angleInDegrees * Math.PI) / 180;
274
-
275
- // Calculate a position angleInDegrees to the right on the horizontal circle
276
- const eyeX = Math.sin(angleInRadians) * radius;
277
- const eyeZ = Math.cos(angleInRadians) * radius;
278
-
279
- cameraControls.setLookAt(eyeX, 0, eyeZ, 0, 0, 0); // Set camera with Y elevation
280
- }
281
- }
282
- setupLight(scene3D, planData.boundingBox);
283
-
284
- self.setState({ waitForRender: 1 });
285
- });
286
-
287
- const area = scene.getIn(['layers', scene.selectedLayer, 'areas']);
288
- const layer = scene.getIn(['layers', scene.selectedLayer]);
289
- const areas = [],
290
- lights = [];
291
-
292
- let snapBox = null;
293
-
294
- // Check for data
295
- let msg = '';
296
- scene.layers.forEach(layer => {
297
- if (layer.id === scene.selectedLayer || layer.visible) {
298
- layer.items.forEach(item => {
299
- if (item.doorStyle === null) {
300
- if (!msg.includes(item.name + "'s doorStyle is null."))
301
- msg += item.name + "'s doorStyle is null.\n";
302
- }
303
- });
304
- }
305
- });
306
- if (msg !== '') {
307
- confirm(msg);
308
- }
309
-
310
- init();
311
- render();
312
-
313
- area.forEach(data => {
314
- areas.push(data);
315
- });
316
- for (let i = 0; i < areas.length; i++) {
317
- let aVertices = [];
318
- let lines = [];
319
- let height = 100;
320
- areas[i].vertices.forEach(data => {
321
- aVertices.push(data);
322
- });
323
- layer.lines.forEach(data => {
324
- lines.push(data);
325
- });
326
- for (let i = 0; i < lines.length; i++) {
327
- let data = lines[i];
328
- let realVec = [];
329
- data.vertices.forEach(vec => {
330
- realVec.push(vec);
331
- });
332
- if (aVertices.includes(realVec[0]) && aVertices.includes(realVec[1])) {
333
- height = convert(layer.ceilHeight)
334
- .from(layer.unit)
335
- .to(UNIT_CENTIMETER);
336
- // height = data.properties.getIn(['height', 'length']);
337
- break;
338
- }
339
- }
340
- let vertices = [];
341
- areas[i].vertices.forEach(datas => {
342
- let vertex = scene.getIn([
343
- 'layers',
344
- scene.selectedLayer,
345
- 'vertices',
346
- datas
347
- ]);
348
- vertices.push(vertex);
349
- });
350
- vertices.push(vertices[0]);
351
- let fLen = vertices.length - 1;
352
- for (let i = 0; i < fLen; i++) {
353
- let sX = vertices[i].x;
354
- let sY = vertices[i].y;
355
- let eX = vertices[i + 1].x;
356
- let eY = vertices[i + 1].y;
357
- let len = Math.sqrt((eX - sX) * (eX - sX) + (eY - sY) * (eY - sY));
358
- for (let cLen = 200; cLen < len; cLen += 200) {
359
- let cX = sX + ((eX - sX) * cLen) / len;
360
- let cY = sY + ((eY - sY) * cLen) / len;
361
- let endLen = Math.sqrt((eX - cX) * (eX - cX) + (eY - cY) * (eY - cY));
362
- if (endLen <= 100) continue;
363
- let vec2 = new Three.Vector2(cX - sX, cY - sY);
364
- let angle = vec2.angle() + Math.PI / 2;
365
- cX = Math.cos(angle) * 30 + cX;
366
- cY = Math.sin(angle) * 30 + cY;
367
- let spotLight = new Three.SpotLight(0xeeeeee, 1.7);
368
- spotLight.angle = 0.76;
369
- spotLight.castShadow = true;
370
- spotLight.penumbra = 1;
371
- spotLight.decay = 1.7;
372
- spotLight.distance = height - 20;
373
- let target = new Three.Object3D();
374
- spotLight.target = target;
375
- lights.push({
376
- light: spotLight,
377
- target: target,
378
- x: cX,
379
- y: cY,
380
- height: height
381
- });
382
- }
383
- }
384
- }
385
- // //////////////////////////
386
-
387
- // OBJECT PICKING
388
- let toIntersect = [planData.plan];
389
- let mouse = new Three.Vector2();
390
- let gridPlane = planData.grid;
391
- let raycaster = new Three.Raycaster();
392
- let selectedObject = {};
393
- let currentObject = null;
394
- let isSelected = false;
395
- let bRotate = false;
396
- let bMove = false;
397
- let bMoveUP = false;
398
- /** Transformation matrix of grid */
399
- const gridMatrix = new Three.Matrix4();
400
- let rayDirection = new Three.Vector3();
401
- /** World position of grid plane */
402
- let gridPlanOrigin = new Three.Vector3();
403
- let Point = new Three.Vector2();
404
- let sPoint = new Three.Vector2();
405
-
406
- // SNAP FUNCTION VARIABLE
407
- let snapFlag = false;
408
- let snapAnimI = 0;
409
- let snapDelta = 6;
410
- let t_i = 0;
411
- let targetPoint = new Three.Vector3();
412
- let targetRot = 0;
413
- let targetUVec = new Three.Vector3();
414
- let targetCRotation = 0;
415
- let targetObj = null;
416
- let targetNumber = 0;
417
-
418
- let allItemRect;
419
- let allItemSnap;
420
- let allLines;
421
- let allLineRects;
422
- let allLineSnap;
423
- let allRect;
424
- let allArea;
425
-
426
- // end snap function variable///////////////////////
427
- let backsplashVisible = false;
428
- let holeItems = GeometryUtils.getHoleItems(layer);
429
-
430
- let removeSnapBox = () => {
431
- if (snapBox != null) {
432
- planData.plan.remove(snapBox);
433
- disposeObject(snapBox);
434
- snapBox = null;
435
- targetObj = null;
436
- snapFlag = false;
437
- }
438
- };
439
-
440
- const camToGrid = new Three.Vector3();
441
- let camPos = camera.position;
442
-
443
- const mapCursorPosition = (e, altitude) => {
444
- camToGrid.subVectors(gridPlanOrigin, camPos);
445
-
446
- let camD = camToGrid.y + (altitude ? altitude : 0);
447
- let rayD = rayDirection.y;
448
-
449
- const intersectPt = rayDirection.multiplyScalar(camD / rayD).add(camPos);
450
- intersectPt.y = gridPlanOrigin.y;
451
- intersectPt.applyMatrix4(gridMatrix);
452
-
453
- return { x: intersectPt.x, y: -intersectPt.z };
454
- };
455
-
456
- /* for Snap Functions*/
457
-
458
- let pointLineDistance = function (point, line) {
459
- // return distance from point to line and directional point of line
460
- let pX = point.x;
461
- let pY = point.y;
462
- let l1x = line[0].x;
463
- let l1y = line[0].y;
464
- let l2x = line[1].x;
465
- let l2y = line[1].y;
466
- let pLine = new Three.Vector2(l1x - pX, l1y - pY);
467
- let Line = new Three.Vector2(l1x - l2x, l1y - l2y);
468
- let pAngle = pLine.angle();
469
- let lAngle = Line.angle();
470
- let pDistance = pLine.length();
471
- let oDistance = Line.length();
472
- let directDistance = Math.sin(pAngle - lAngle) * pDistance;
473
- let lineDistance = Math.cos(pAngle - lAngle) * pDistance;
474
- let dX = l1x + ((l2x - l1x) * lineDistance) / oDistance;
475
- let dY = l1y + ((l2y - l1y) * lineDistance) / oDistance;
476
- let dPoint = { x: dX, y: dY };
477
- return { distance: directDistance, point: dPoint };
478
- };
479
- let getInterSect = function (shape1, shape2) {
480
- // return result of intersect of two shape
481
- let count = 0;
482
- for (let i = 0; i < shape1.length - 1; i++) {
483
- let sl1 = { x: shape1[i].x, y: shape1[i].y };
484
- let sl2 = { x: shape1[i + 1].x, y: shape1[i + 1].y };
485
- for (let j = 0; j < shape2.length - 1; j++) {
486
- let el1 = { x: shape2[j].x, y: shape2[j].y };
487
- let el2 = { x: shape2[j + 1].x, y: shape2[j + 1].y };
488
- let flag = GeometryUtils.getLineInterSect(
489
- sl1.x,
490
- sl1.y,
491
- sl2.x,
492
- sl2.y,
493
- el1.x,
494
- el1.y,
495
- el2.x,
496
- el2.y
497
- );
498
- if (flag) {
499
- count++;
500
- if (count > 1) return true;
501
- }
502
- }
503
- }
504
- return false;
505
- };
506
-
507
- this.getRectPoints = function (width, height, pos, rot) {
508
- // return 4 points from it's position, width, height, and rotation info
509
- let rX = width / 2;
510
- let rY = height / 2;
511
- let vertices = [];
512
- let cRot = rot;
513
- let pX = pos.x + Math.cos(cRot) * rX + Math.cos(cRot + Math.PI / 2) * rY;
514
- let pY = pos.y + Math.sin(cRot) * rX + Math.sin(cRot + Math.PI / 2) * rY;
515
- vertices.push({ x: Math.floor(pX + 0.5), y: Math.floor(pY + 0.5) });
516
- rX = -rX;
517
- pX = pos.x + Math.cos(cRot) * rX + Math.cos(cRot + Math.PI / 2) * rY;
518
- pY = pos.y + Math.sin(cRot) * rX + Math.sin(cRot + Math.PI / 2) * rY;
519
- vertices.push({ x: Math.floor(pX + 0.5), y: Math.floor(pY + 0.5) });
520
- rY = -rY;
521
- pX = pos.x + Math.cos(cRot) * rX + Math.cos(cRot + Math.PI / 2) * rY;
522
- pY = pos.y + Math.sin(cRot) * rX + Math.sin(cRot + Math.PI / 2) * rY;
523
- vertices.push({ x: Math.floor(pX + 0.5), y: Math.floor(pY + 0.5) });
524
- rX = -rX;
525
- pX = pos.x + Math.cos(cRot) * rX + Math.cos(cRot + Math.PI / 2) * rY;
526
- pY = pos.y + Math.sin(cRot) * rX + Math.sin(cRot + Math.PI / 2) * rY;
527
- vertices.push({ x: Math.floor(pX + 0.5), y: Math.floor(pY + 0.5) });
528
- vertices.push(vertices[0]);
529
- vertices.push(vertices[2]);
530
- return vertices;
531
- };
532
-
533
- const prepareSnap = layer => {
534
- allLines = GeometryUtils.getAllLines(layer);
535
- allLineRects = GeometryUtils.buildRectFromLines(layer, allLines);
536
- allItemRect = GeometryUtils.getAllItems(
537
- this.props.state.scene,
538
- actions.catalog,
539
- allLineRects
540
- );
541
- allItemSnap = GeometryUtils.getAllItemSnap(allItemRect);
542
- allLineSnap = GeometryUtils.getAllLineSnap(allLineRects, allItemRect.cur);
543
- allRect = allItemRect.others.concat(allLineRects);
544
- allItemSnap = GeometryUtils.validateSnaps(allItemSnap, allRect);
545
- allLineSnap = GeometryUtils.validateSnaps(allLineSnap, allRect);
546
- allArea = GeometryUtils.getAllArea(layer);
547
- };
548
-
549
- // prepareSnapSpec(layer);
550
- let lineRect = layer => {
551
- let areainfo = [];
552
- layer.areas.forEach(area => {
553
- let sz = area.vertices.size;
554
- for (var i = 0; i < sz; i++) {
555
- areainfo.push(area.vertices.get(i));
556
- }
557
- });
558
- let rect = [];
559
- areainfo.forEach(area => {
560
- let vert = layer.vertices.get(area);
561
- rect.push(vert.x, vert.y);
562
- });
563
- return rect;
564
- };
565
-
566
- this.collisionCheck = function (obj, pos, rot, tObj, item = null, catalog) {
567
- //collision check from one object to every other object excpet target object
568
- let layer = this.props.state.scene.getIn([
569
- 'layers',
570
- obj.userData.layerId
571
- ]);
572
- let layoutpos = 'utype';
573
- if (item !== null) {
574
- let catid = item.type;
575
- let cat = catalog.elements[catid];
576
- layoutpos = cat.info.layoutpos;
577
- }
578
- let oPos = new Three.Vector2(pos.clone().x, pos.clone().y);
579
- let sBounding = obj.children[0].userData;
580
- let width = sBounding.max.x - sBounding.min.x;
581
- let depth = sBounding.max.z - sBounding.min.z;
582
- let oVertices = this.getRectPoints(
583
- width,
584
- depth,
585
- oPos.clone(),
586
- ((rot % 360) / 180) * Math.PI
587
- );
588
- let datas = [];
589
- layer.items.forEach(data => {
590
- datas.push(data);
591
- });
592
- for (let i = 0; i < datas.length; i++) {
593
- let data = datas[i];
594
- if (data.id == obj.userData.itemId || data.id == tObj.userData.itemId)
595
- continue;
596
- let target =
597
- planData.sceneGraph.layers[obj.userData.layerId].items[data.id];
598
- if (target === undefined) {
599
- console.log(
600
- data.id +
601
- ' does not exist in viewer3d/viewer3d.js collisionCheck function'
602
- );
603
- return false;
604
- }
605
- let item = layer.items.getIn([data.id]);
606
- let ocatid = item.type;
607
- let ocat = catalog.elements[ocatid];
608
- let olayoutpos = ocat.info.layoutpos;
609
- if (
610
- !(
611
- (layoutpos === BASE_CABINET_LAYOUTPOS &&
612
- olayoutpos === WALL_CABINET_LAYOUTPOS) ||
613
- (layoutpos === WALL_CABINET_LAYOUTPOS &&
614
- olayoutpos === BASE_CABINET_LAYOUTPOS)
615
- )
616
- ) {
617
- let tRot = item.rotation;
618
- let tPos = new Three.Vector2(item.x, item.y);
619
- let tBounding = target.children[0].userData;
620
- let twidth = tBounding.max.x - tBounding.min.x;
621
- let tdepth = tBounding.max.z - tBounding.min.z;
622
- let tVertices = this.getRectPoints(
623
- twidth,
624
- tdepth,
625
- tPos.clone(),
626
- ((tRot % 360) / 180) * Math.PI
627
- );
628
- if (getInterSect(oVertices, tVertices)) {
629
- return false;
630
- }
631
- }
632
- }
633
- datas = [];
634
- layer.lines.forEach(data => {
635
- datas.push(data);
636
- });
637
- for (let i = 0; i < datas.length; i++) {
638
- let data = datas[i];
639
- if (data.id == obj.userData.itemId || data.id == tObj.userData.itemId)
640
- continue;
641
- let item = layer.lines.getIn([data.id]);
642
- // let llayoutpos = catalog.elements[item.type].info.layoutpos;
643
- let vertices = [];
644
- item.vertices.forEach(data => {
645
- let vertex = layer.vertices.get(data);
646
- vertices.push({ x: vertex.x, y: vertex.y });
647
- });
648
- let vec = new Three.Vector2(
649
- vertices[1].x - vertices[0].x,
650
- vertices[1].y - vertices[0].y
651
- );
652
- let tRot = vec.angle();
653
- let tPos = new Three.Vector2(
654
- (vertices[0].x + vertices[1].x) / 2,
655
- (vertices[0].y + vertices[1].y) / 2
656
- );
657
- let tdepth = item.properties.getIn(['thickness', 'length']);
658
- let twidth = Math.sqrt(vec.x * vec.x + vec.y * vec.y);
659
- let tVertices = this.getRectPoints(twidth, tdepth, tPos.clone(), tRot);
660
- if (getInterSect(oVertices, tVertices)) {
661
- return false;
662
- }
663
- }
664
- return true;
665
- };
666
-
667
- this.collisionHoleCheck = function (
668
- obj,
669
- pos,
670
- rot,
671
- tObj,
672
- item = null,
673
- catalog
674
- ) {
675
- let layer = this.props.state.scene.getIn([
676
- 'layers',
677
- obj.userData.layerId
678
- ]);
679
- let currentItem;
680
- if (item !== null) {
681
- let catid = item.type;
682
- let cat = catalog.elements[catid];
683
- currentItem = {
684
- selectedItem: item,
685
- cat
686
- };
687
- }
688
- let oPos = new Three.Vector2(pos.clone().x, pos.clone().y);
689
- let sBounding = obj.children[0].userData;
690
- let width = sBounding.max.x - sBounding.min.x;
691
- let depth = sBounding.max.z - sBounding.min.z;
692
- let oVertices = this.getRectPoints(
693
- width,
694
- depth,
695
- oPos.clone(),
696
- ((rot % 360) / 180) * Math.PI
697
- );
698
-
699
- let datas = [];
700
- layer.items.forEach(data => {
701
- datas.push(data);
702
- });
703
- for (let i = 0; i < datas.length; i++) {
704
- let data = datas[i];
705
- if (data.id == obj.userData.itemId || data.id == tObj.userData.itemId)
706
- continue;
707
- let target =
708
- planData.sceneGraph.layers[obj.userData.layerId].items[data.id];
709
- if (target === undefined) {
710
- console.log(
711
- data.id +
712
- ' does not exist in viewer3d/viewer3d.js collisionCheck function'
713
- );
714
- return false;
715
- }
716
- let item = layer.items.getIn([data.id]);
717
- let ocatid = item.type;
718
- let ocat = catalog.elements[ocatid];
719
- if (!ocat)
720
- ocat = catalog.elements[returnReplaceableDeepSearchType(ocatid)];
721
- let otherItem = {
722
- item,
723
- cat: ocat
724
- };
725
-
726
- if (
727
- GeometryUtils.needSnap(currentItem, otherItem) &&
728
- otherItem.cat.type != 'cabinet'
729
- ) {
730
- let tRot = item.rotation;
731
- let tPos = new Three.Vector2(item.x, item.y);
732
- let tBounding = target.children[0].userData;
733
- let twidth = tBounding.max.x - tBounding.min.x;
734
- let tdepth = tBounding.max.z - tBounding.min.z;
735
- let tVertices = this.getRectPoints(
736
- twidth,
737
- tdepth,
738
- tPos.clone(),
739
- ((tRot % 360) / 180) * Math.PI
740
- );
741
- if (getInterSect(oVertices, tVertices)) {
742
- return false;
743
- }
744
- }
745
- }
746
-
747
- let holes = [];
748
- layer.lines.forEach(line => {
749
- line.holes.forEach(holeID => {
750
- let hole = layer.holes.get(holeID);
751
- holes.push(hole);
752
- });
753
- });
754
- let i = 0;
755
- for (; i < holes.length; i++) {
756
- let tPos = new Three.Vector2(holes[i].x, holes[i].y);
757
- let twidth = holes[i].properties.getIn(['width', 'length']);
758
- let theight = holes[i].properties.getIn(['thickness', 'length']);
759
- let trot = holes[i].rotation;
760
- let tVertices = this.getRectPoints(twidth, theight, tPos.clone(), trot);
761
- if (getInterSect(oVertices, tVertices)) {
762
- return false;
763
- }
764
- }
765
- return true;
766
- };
767
-
768
- this.collisionSlide = function (
769
- item3D,
770
- originPos,
771
- layer,
772
- sVertices,
773
- tPos,
774
- item
775
- ) {
776
- let items = [];
777
-
778
- let cur_category = '';
779
- let catalog = actions.catalog;
780
- if (layer.selected.items.size > 0) {
781
- let selectedItem = layer.getIn(['items', layer.selected.items.get(0)]);
782
- let catid = selectedItem.type;
783
- let cat = catalog.elements[catid];
784
- if (cat === undefined || cat === null)
785
- cat = catalog.getIn(['elements', catid]);
786
- cur_category = cat.obj.category;
787
- }
788
-
789
- layer.items.forEach(data => {
790
- if (data.id == selectedObject.itemID) {
791
- return;
792
- }
793
-
794
- items.push(data.toJS());
795
- });
796
- let oPos = new Three.Vector2(originPos.x, -originPos.z);
797
-
798
- // sort from distance
799
- for (let i = 0; i < items.length - 1; i++) {
800
- for (let j = i + 1; j < items.length; j++) {
801
- if (
802
- verticesDistance(oPos, new Three.Vector2(items[i].x, items[i].y)) >
803
- verticesDistance(oPos, new Three.Vector2(items[j].x, items[j].y))
804
- ) {
805
- let exchange = items[j];
806
- items[j] = items[i];
807
- items[i] = exchange;
808
- }
809
- }
810
- }
811
- let i = 0;
812
-
813
- for (; i < items.length; i++) {
814
- if (!items[i]) return;
815
- let target =
816
- planData.sceneGraph.layers[selectedObject.layerID].items[items[i].id];
817
- if (target === undefined) {
818
- return false;
819
- }
820
- let targetData = layer.items.getIn([items[i].id]);
821
- let tRot = targetData.rotation;
822
- let tPos = new Three.Vector2(targetData.x, targetData.y);
823
- let tBounding = target.children[0].userData;
824
- let twidth = tBounding.max.x - tBounding.min.x;
825
- let tdepth = tBounding.max.z - tBounding.min.z;
826
- let tVertices = this.getRectPoints(
827
- twidth,
828
- tdepth,
829
- tPos.clone(),
830
- ((tRot % 360) / 180) * Math.PI
831
- );
832
- if (getInterSect(sVertices, tVertices)) {
833
- break;
834
- }
835
- }
836
- if (items.length == 0 || !items[i]) return;
837
- let target =
838
- planData.sceneGraph.layers[selectedObject.layerID].items[items[i].id];
839
- let targetData = layer.items.getIn([items[i].id]);
840
- let targetPos = new Three.Vector2(targetData.x, targetData.y);
841
- let tRot = targetData.rotation;
842
- let tBounding = target.children[0].userData;
843
- let twidth = tBounding.max.x - tBounding.min.x;
844
- let tdepth = tBounding.max.z - tBounding.min.z;
845
- let tVertices = this.getRectPoints(
846
- twidth,
847
- tdepth,
848
- targetPos.clone(),
849
- ((tRot % 360) / 180) * Math.PI
850
- );
851
- // ////////////////////////
852
- let vArray = [];
853
- let dteArray = [];
854
- let lineArray = [];
855
- let vdistanceArray = [];
856
- let cVecArray = [];
857
- let inFlag = false;
858
- for (let i = 0; i < 4; i++) {
859
- let v1 = tVertices[i];
860
- let v2 = tVertices[i + 1];
861
- let data = pointLineDistance({ x: tPos.x, y: tPos.y }, [
862
- { x: v1.x, y: v1.y },
863
- { x: v2.x, y: v2.y }
864
- ]);
865
- dteArray.push(data.distance);
866
- vArray.push(data.point);
867
- lineArray.push([v1, v2]);
868
- }
869
- // if tPos in target object
870
- let tPosDistance =
871
- Math.abs(pointLineDistance(tPos, lineArray[0]).distance) +
872
- Math.abs(pointLineDistance(tPos, lineArray[2]).distance);
873
- let realDistance = new Three.Vector2(
874
- lineArray[1][0].x - lineArray[1][1].x,
875
- lineArray[1][0].y - lineArray[1][1].y
876
- ).length();
877
- let tPosDistance1 =
878
- Math.abs(pointLineDistance(tPos, lineArray[1]).distance) +
879
- Math.abs(pointLineDistance(tPos, lineArray[3]).distance);
880
- let realDistance1 = new Three.Vector2(
881
- lineArray[0][0].x - lineArray[0][1].x,
882
- lineArray[0][0].y - lineArray[0][1].y
883
- ).length();
884
- if (
885
- Math.abs(Math.abs(tPosDistance) - Math.abs(realDistance)) < 0.01 &&
886
- Math.abs(Math.abs(tPosDistance1) - Math.abs(realDistance1)) < 0.01
887
- )
888
- inFlag = true;
889
- // ////////////////////
890
- let key = 0;
891
- // sort distance from origin point
892
- for (let j = 0; j < dteArray.length - 1; j++) {
893
- for (let k = j + 1; k < dteArray.length; k++) {
894
- if (Math.abs(dteArray[j]) > Math.abs(dteArray[k])) {
895
- let temp = dteArray[k];
896
- dteArray[j] = dteArray[k];
897
- dteArray[k] = temp;
898
- let temp1 = vArray[k];
899
- vArray[j] = vArray[k];
900
- vArray[k] = temp1;
901
- let temp2 = lineArray[k];
902
- lineArray[j] = lineArray[k];
903
- lineArray[k] = temp2;
904
- }
905
- }
906
- }
907
- // //////////////////////////////
908
- for (let i = 0; i < 4; i++) {
909
- let data = pointLineDistance(sVertices[i], lineArray[key]);
910
- vdistanceArray.push(data.distance);
911
- cVecArray.push({
912
- x: data.point.x - sVertices[i].x,
913
- y: data.point.y - sVertices[i].y
914
- });
915
- }
916
-
917
- for (let j = 0; j < vdistanceArray.length; j++) {
918
- let tX = tPos.x + cVecArray[j].x;
919
- let tY = tPos.y + cVecArray[j].y;
920
- if (
921
- this.collisionCheck(
922
- item3D,
923
- new Three.Vector2(tX, tY),
924
- item.rotation,
925
- {
926
- userData: { itemId: null }
927
- },
928
- item,
929
- this.context.catalog
930
- )
931
- ) {
932
- item3D.position.set(tX, originPos.y, -tY);
933
- sPoint.set(tX, tY);
934
- break;
935
- }
936
- }
937
- };
938
-
939
- this.snap = function (obj, layer) {
940
- // snap operation
941
- let target = obj.userData.target;
942
- for (; target.parent != null; ) {
943
- if (target.name == 'pivot') break;
944
- target = target.parent;
945
- }
946
- let source = obj.parent.parent.parent;
947
- if (target.userData.type == 'item') {
948
- let sRot = layer.getIn(['items', source.userData.itemId]).rotation;
949
- let tRot = layer.getIn(['items', target.userData.itemId])
950
- ? layer.getIn(['items', target.userData.itemId]).rotation
951
- : 0;
952
- let item = layer.getIn(['items', source.userData.itemId]);
953
- let layoutType = item.layoutpos;
954
- let altitudeLength = convert(
955
- item.properties.getIn(['altitude', '_length'])
956
- )
957
- .from('in')
958
- .to('cm');
959
- let sBounding = source.children[0].userData;
960
- let tBounding = target.children[0].userData;
961
- let tPos = target.position.clone();
962
- let width = sBounding.max.x - sBounding.min.x;
963
- let height = sBounding.max.y - sBounding.min.y;
964
- let depth = sBounding.max.z - sBounding.min.z;
965
- let snapBoxGeom = new Three.BoxGeometry(width, height, depth);
966
- let snapBoxObj = new Three.Mesh(
967
- snapBoxGeom,
968
- new Three.MeshBasicMaterial({
969
- // color: 0x2cde6b,
970
- // opacity: 0.7,
971
- transparent: true,
972
- blending: Three.MultiplyBlending
973
- })
974
- );
975
- let removeSnapBoxObj = () => {
976
- if (snapBoxObj) {
977
- planData.plan.remove(snapBoxObj);
978
- disposeObject(snapBoxObj);
979
- }
980
- snapFlag = false;
981
- };
982
- let box = new Three.BoxHelper(snapBoxObj, 0xffffff);
983
- box.material.linewidth = 2;
984
- box.material.depthTest = false;
985
- box.renderOrder = 200;
986
- snapBoxObj.add(box);
987
- snapBoxObj.position.set(
988
- source.position.x,
989
- layoutType === WALL_CABINET_LAYOUTPOS
990
- ? altitudeLength + source.position.y + height / 2
991
- : source.position.y + height / 2,
992
- source.position.z
993
- );
994
- snapBoxObj.rotation.set(
995
- source.rotation.x,
996
- source.rotation.y,
997
- source.rotation.z
998
- );
999
- snapBoxObj.name = 'TransformBox';
1000
- planData.plan.add(snapBoxObj);
1001
- let deltaX =
1002
- (tBounding.max.x - tBounding.min.x) / 2 +
1003
- (sBounding.max.x - sBounding.min.x) / 2;
1004
- let deltaZ =
1005
- (tBounding.max.z - tBounding.min.z) / 2 -
1006
- (sBounding.max.z - sBounding.min.z) / 2;
1007
- let sPos = snapBoxObj.position.clone();
1008
- // avaliable snap place///////////////
1009
- let tPoses = [];
1010
- let pX =
1011
- tPos.x +
1012
- deltaX * Math.cos((tRot / 180) * Math.PI) +
1013
- deltaZ * Math.sin((tRot / 180) * Math.PI);
1014
- let pZ =
1015
- tPos.z -
1016
- deltaX * Math.sin((tRot / 180) * Math.PI) +
1017
- deltaZ * Math.cos((tRot / 180) * Math.PI);
1018
- tPoses.push(new Three.Vector3(pX, 0, pZ));
1019
- deltaX = -deltaX;
1020
- pX =
1021
- tPos.x +
1022
- deltaX * Math.cos((tRot / 180) * Math.PI) +
1023
- deltaZ * Math.sin((tRot / 180) * Math.PI);
1024
- pZ =
1025
- tPos.z -
1026
- deltaX * Math.sin((tRot / 180) * Math.PI) +
1027
- deltaZ * Math.cos((tRot / 180) * Math.PI);
1028
- tPoses.push(new Three.Vector3(pX, 0, pZ));
1029
- deltaX =
1030
- (tBounding.max.x - tBounding.min.x) / 2 -
1031
- (sBounding.max.x - sBounding.min.x) / 2;
1032
- deltaZ =
1033
- -(tBounding.max.z - tBounding.min.z) / 2 -
1034
- (sBounding.max.z - sBounding.min.z) / 2;
1035
- pX =
1036
- tPos.x +
1037
- deltaX * Math.cos((tRot / 180) * Math.PI) +
1038
- deltaZ * Math.sin((tRot / 180) * Math.PI);
1039
- pZ =
1040
- tPos.z -
1041
- deltaX * Math.sin((tRot / 180) * Math.PI) +
1042
- deltaZ * Math.cos((tRot / 180) * Math.PI);
1043
- tPoses.push(new Three.Vector3(pX, 0, pZ));
1044
- deltaX = -deltaX;
1045
- pX =
1046
- tPos.x +
1047
- deltaX * Math.cos((tRot / 180) * Math.PI) +
1048
- deltaZ * Math.sin((tRot / 180) * Math.PI);
1049
- pZ =
1050
- tPos.z -
1051
- deltaX * Math.sin((tRot / 180) * Math.PI) +
1052
- deltaZ * Math.cos((tRot / 180) * Math.PI);
1053
- tPoses.push(new Three.Vector3(pX, 0, pZ));
1054
- let distance = Math.sqrt(
1055
- (sPos.x - tPoses[0].x) * (sPos.x - tPoses[0].x) +
1056
- (sPos.z - tPoses[0].z) * (sPos.z - tPoses[0].z)
1057
- );
1058
- let tNum = 1;
1059
- tPos = tPoses[0].clone();
1060
- for (let i = 1; i < tPoses.length; i++) {
1061
- let curDis = Math.sqrt(
1062
- (sPos.x - tPoses[i].x) * (sPos.x - tPoses[i].x) +
1063
- (sPos.z - tPoses[i].z) * (sPos.z - tPoses[i].z)
1064
- );
1065
- if (curDis < distance) {
1066
- distance = curDis;
1067
- tNum = i + 1;
1068
- tPos = tPoses[i].clone();
1069
- }
1070
- }
1071
- // //////////////////////////////////
1072
- if (
1073
- targetObj != null &&
1074
- targetObj.userData.itemId == target.userData.itemId &&
1075
- tNum == targetNumber
1076
- ) {
1077
- removeSnapBoxObj();
1078
- return;
1079
- } else {
1080
- removeSnapBox();
1081
- }
1082
- // //////////////////////////////////
1083
- if (tNum >= 3) tRot += 180;
1084
-
1085
- snapAnimI = 0;
1086
- t_i = 0;
1087
- targetObj = target;
1088
- targetNumber = tNum;
1089
- targetRot = tRot;
1090
- targetPoint = tPos;
1091
- snapBox = snapBoxObj;
1092
- let cx = sPos.x - tPos.x;
1093
- let cz = sPos.z - tPos.z;
1094
- targetUVec = new Three.Vector3(cx, 0, cz);
1095
- targetCRotation = (((tRot - sRot) % 360) / 180) * Math.PI;
1096
- } else {
1097
- let item = layer.getIn(['items', source.userData.itemId]);
1098
- if (holeItems.length) {
1099
- let i;
1100
- for (i = 0; i < holeItems.length; i++) {
1101
- let hole = holeItems[i];
1102
- if (Math.abs(Math.sin(selectedObj.rotRad)) === 1) {
1103
- if (
1104
- item.y + selectedObj.size.width / 2 >=
1105
- hole.y - hole.width / 2 &&
1106
- item.y - selectedObj.size.width / 2 <=
1107
- hole.y + hole.width / 2 &&
1108
- (selectedObj.rotRad == 0 || selectedObj.rotRad == -Math.PI / 2
1109
- ? item.x <= hole.x &&
1110
- item.x + selectedObj.size.height >= hole.x
1111
- : item.x >= hole.x &&
1112
- item.x - selectedObj.size.height <= hole.x)
1113
- )
1114
- break;
1115
- } else {
1116
- if (
1117
- item.x + selectedObj.size.width / 2 >=
1118
- hole.x - hole.width / 2 &&
1119
- item.x - selectedObj.size.width / 2 <=
1120
- hole.x + hole.width / 2 &&
1121
- (selectedObj.rotRad == 0 || selectedObj.rotRad == -Math.PI / 2
1122
- ? item.y <= hole.y &&
1123
- item.y + selectedObj.size.height >= hole.y
1124
- : item.y >= hole.y &&
1125
- item.y - selectedObj.size.height <= hole.y)
1126
- )
1127
- break;
1128
- }
1129
- }
1130
- if (i != holeItems.length) return;
1131
- }
1132
- if (target.userData.type == 'hole') {
1133
- snapFlag = false;
1134
- return;
1135
- } else {
1136
- let layoutType = item.layoutpos;
1137
- let altitudeLength = convert(
1138
- item.properties.getIn(['altitude', '_length'])
1139
- )
1140
- .from('in')
1141
- .to('cm');
1142
- let sBounding = source.children[0].userData;
1143
- let width = sBounding.max.x - sBounding.min.x;
1144
- let height = sBounding.max.y - sBounding.min.y;
1145
- let depth = sBounding.max.z - sBounding.min.z;
1146
- let snapBoxGeom = new Three.BoxGeometry(width, height, depth);
1147
- let snapBoxObj = new Three.Mesh(
1148
- snapBoxGeom,
1149
- new Three.MeshBasicMaterial({
1150
- // color: 0x2cde6b,
1151
- // opacity: 0.7,
1152
- transparent: true,
1153
- blending: Three.MultiplyBlending
1154
- })
1155
- );
1156
- let removeSnapBoxObj = () => {
1157
- if (snapBoxObj) {
1158
- planData.plan.remove(snapBoxObj);
1159
- disposeObject(snapBoxObj);
1160
- }
1161
- snapFlag = false;
1162
- };
1163
- let box = new Three.BoxHelper(snapBoxObj, 0xffffff);
1164
- box.material.linewidth = 2;
1165
- box.material.depthTest = false;
1166
- box.renderOrder = 100;
1167
- snapBoxObj.add(box);
1168
-
1169
- snapBoxObj.position.set(
1170
- source.position.x,
1171
- layoutType === WALL_CABINET_LAYOUTPOS
1172
- ? altitudeLength + source.position.y + height / 2
1173
- : source.position.y + height / 2,
1174
- source.position.z
1175
- );
1176
- snapBoxObj.rotation.set(
1177
- source.rotation.x,
1178
- source.rotation.y,
1179
- source.rotation.z
1180
- );
1181
- snapBoxObj.name = 'TransformBox';
1182
- planData.plan.add(snapBoxObj);
1183
-
1184
- let snapLine = layer.getIn(['lines', target.userData.lineId]);
1185
- // let snapLineThickness = snapLine.properties.getIn([
1186
- // 'thickness',
1187
- // 'length'
1188
- // ]);
1189
- let snapLineThickness = 10.64;
1190
- let vertices = [];
1191
- if (snapLine === undefined) return;
1192
- snapLine.vertices.forEach(data => {
1193
- let vec = layer.getIn(['vertices', data]);
1194
- vertices.push(vec);
1195
- });
1196
- let iX = source.position.clone().x;
1197
- let iY = -source.position.clone().z;
1198
- let lineVec = new Three.Vector2(
1199
- vertices[1].x - vertices[0].x,
1200
- vertices[1].y - vertices[0].y
1201
- );
1202
- let oLength = Math.sqrt(
1203
- lineVec.x * lineVec.x + lineVec.y * lineVec.y
1204
- );
1205
- lineVec.normalize();
1206
- let vec2 = new Three.Vector2(iX - vertices[0].x, iY - vertices[0].y);
1207
- let vec2Legnth = Math.sqrt(vec2.x * vec2.x + vec2.y * vec2.y);
1208
- let angle = Math.abs(lineVec.angle() - vec2.angle());
1209
- angle = angle > Math.PI ? 2 * Math.PI - angle : angle;
1210
- let lineLength = Math.cos(angle) * vec2Legnth;
1211
- let transLength = 0;
1212
- if (lineLength < 100) {
1213
- transLength = -lineLength + (snapLineThickness + width) / 2;
1214
- }
1215
- if (lineLength > oLength - 100) {
1216
- transLength =
1217
- -lineLength - (snapLineThickness + width) / 2 + oLength;
1218
- }
1219
- let directPoint = new Three.Vector2(
1220
- lineVec.x * lineLength + vertices[0].x,
1221
- lineVec.y * lineLength + vertices[0].y
1222
- );
1223
- let directLine = new Three.Vector2(
1224
- directPoint.x - iX,
1225
- directPoint.y - iY
1226
- );
1227
- let dLength = Math.sqrt(
1228
- (iX - directPoint.x) * (iX - directPoint.x) +
1229
- (iY - directPoint.y) * (iY - directPoint.y)
1230
- );
1231
- let reduceLen = (snapLineThickness + depth) / 2;
1232
- let scale = (dLength - reduceLen) / dLength;
1233
- let tPos = new Three.Vector2(
1234
- iX + (directPoint.x - iX) * scale + lineVec.x * transLength,
1235
- iY + (directPoint.y - iY) * scale + lineVec.y * transLength
1236
- );
1237
- let realAngle = directLine.angle() - Math.PI / 2;
1238
- let tRot = (realAngle * 180) / Math.PI;
1239
- let sPos = new Three.Vector2(iX, iY);
1240
- let sRot = item.rotation;
1241
- let tNum = 0;
1242
- // //////////////////////////////////////
1243
- // check part////
1244
- let result = this.collisionCheck(
1245
- source,
1246
- tPos,
1247
- tRot,
1248
- target,
1249
- item,
1250
- this.context.catalog
1251
- );
1252
- // console.log('result', result);
1253
- if (result == false) {
1254
- removeSnapBoxObj();
1255
- removeSnapBox();
1256
- return;
1257
- }
1258
- // ////////////////
1259
- if (targetObj === target && snapBox !== null) {
1260
- removeSnapBoxObj();
1261
- snapAnimI = 20;
1262
- targetPoint = new Three.Vector3(tPos.x, 0, -tPos.y);
1263
- let sourcePos = snapBox.position.clone();
1264
- let cx = sourcePos.x - targetPoint.x;
1265
- let cz = sourcePos.z - targetPoint.z;
1266
- targetUVec = new Three.Vector3(cx, 0, cz);
1267
- targetRot = tRot;
1268
- targetCRotation = (((tRot - sRot) % 360) / 180) * Math.PI;
1269
- snapFlag = false;
1270
- return;
1271
- } else {
1272
- removeSnapBox();
1273
- }
1274
- // //////////////////////////////////////
1275
- snapAnimI = 0;
1276
- t_i = 0;
1277
- targetObj = target;
1278
- targetNumber = tNum;
1279
- targetRot = tRot;
1280
- targetPoint = new Three.Vector3(tPos.x, 0, -tPos.y);
1281
- snapBox = snapBoxObj;
1282
- let sourcePos = snapBox.position.clone();
1283
- let cx = sourcePos.x - targetPoint.x;
1284
- let cz = sourcePos.z - targetPoint.z;
1285
- targetUVec = new Three.Vector3(cx, 0, cz);
1286
- targetRot = tRot;
1287
- targetCRotation = (((tRot - sRot) % 360) / 180) * Math.PI;
1288
- }
1289
- }
1290
- };
1291
-
1292
- /*end of snap functions*/
1293
- let selectedObj = null;
1294
- let firstMove = false;
1295
- let prevX, prevY;
1296
-
1297
- let selObj = null;
1298
-
1299
- let createToolObject = () => {
1300
- const canvas = document.createElement('canvas');
1301
- canvas.width = 100;
1302
- canvas.height = 200;
1303
- canvas.style.width = 50 + 'px';
1304
- canvas.style.height = 100 + 'px';
1305
- const ctx = canvas.getContext('2d');
1306
- ctx.fillStyle = '#FFFFFF';
1307
- ctx.strokeStyle = '#000000';
1308
- ctx.beginPath();
1309
- ctx.arc(50, 50, 40, 0, 4 * Math.PI);
1310
- ctx.fill();
1311
- ctx.stroke();
1312
- let img1 = new Image();
1313
- img1.crossOrigin = 'anonymous';
1314
- img1.src = '/assets/img/svg/3d_item_rotation.svg';
1315
- img1.onload = function () {
1316
- ctx.drawImage(img1, 16, 16, 68, 68);
1317
- };
1318
-
1319
- ctx.beginPath();
1320
- ctx.arc(50, 150, 40, 0, 4 * Math.PI);
1321
- ctx.fill();
1322
- ctx.stroke();
1323
- let img2 = new Image();
1324
- img2.crossOrigin = 'anonymous';
1325
- img2.src = '/assets/img/svg/3d_item_move.svg';
1326
- img2.onload = function () {
1327
- ctx.drawImage(img2, 16, 116, 68, 68);
1328
- };
1329
-
1330
- return canvas;
1331
- };
1332
-
1333
- let clockWise = true;
1334
- let lastAngle = 0;
1335
-
1336
- let createAngleObject = rotate => {
1337
- const canvas = document.createElement('canvas');
1338
- canvas.width = 100;
1339
- canvas.height = 100;
1340
- canvas.style.width = 100 + 'px';
1341
- canvas.style.height = 100 + 'px';
1342
- const ctx = canvas.getContext('2d');
1343
- ctx.strokeStyle = '#FFFFFF';
1344
- ctx.lineWidth = 10;
1345
- ctx.beginPath();
1346
- ctx.arc(50, 50, 45, 0, 2 * Math.PI);
1347
- ctx.stroke();
1348
-
1349
- ctx.strokeStyle = SECONDARY_PURPLE_COLOR;
1350
- ctx.lineWidth = 6;
1351
- ctx.beginPath();
1352
- if (lastAngle < 15 && lastAngle > -15) {
1353
- if (rotate >= 0) {
1354
- clockWise = false;
1355
- } else {
1356
- clockWise = true;
1357
- }
1358
- if (lastAngle === 0) {
1359
- if (rotate > -180) {
1360
- clockWise = true;
1361
- } else {
1362
- clockWise = false;
1363
- }
1364
- }
1365
- }
1366
-
1367
- ctx.arc(50, 50, 45, 0, (rotate / 180.0) * Math.PI, clockWise);
1368
- ctx.stroke();
1369
-
1370
- lastAngle = rotate;
1371
-
1372
- return canvas;
1373
- };
1374
-
1375
- let toolTexture = new Three.Texture(createToolObject());
1376
- toolTexture.needsUpdate = true;
1377
-
1378
- let toolObj = new Three.Sprite(
1379
- new Three.SpriteMaterial({ map: toolTexture, sizeAttenuation: true })
1380
- );
1381
- toolObj.material.transparent = true;
1382
- toolObj.material.depthTest = false;
1383
- toolObj.scale.set(20, 40, 20);
1384
- toolObj.renderOrder = 3;
1385
- toolObj.name = 'toolObj';
1386
-
1387
- let angleTexture = new Three.Texture(createAngleObject(0));
1388
- angleTexture.needsUpdate = true;
1389
-
1390
- let angleObj = new Three.Sprite(
1391
- new Three.SpriteMaterial({ map: angleTexture, sizeAttenuation: false })
1392
- );
1393
-
1394
- angleObj.scale.set(0.075, 0.075, 0.075);
1395
- angleObj.material.transparent = true;
1396
- angleObj.material.depthTest = false;
1397
- angleObj.renderOrder = 3;
1398
- angleObj.name = 'angleObj';
1399
-
1400
- /**
1401
- * Calculate plane point of mouse with `event` & `altitude`
1402
- * * Calculate mouse.x & mouse.y
1403
- * * Set raycaster from camera & Set raycaster direction
1404
- * * Calculate Point & dispatch an action
1405
- */
1406
- const getPoint = (e, alti) => {
1407
- mouse.x = (e.offsetX / this.width) * 2 - 1;
1408
- mouse.y = (-e.offsetY / this.height) * 2 + 1;
1409
-
1410
- raycaster.setFromCamera(mouse, camera);
1411
- rayDirection = raycaster.ray.direction;
1412
-
1413
- Point = mapCursorPosition(e, alti);
1414
- this.context.projectActions.updateMouseCoord(Point);
1415
- };
1416
-
1417
- const getIntersectWallPoint = e => {
1418
- mouse.x = (e.offsetX / this.width) * 2 - 1;
1419
- mouse.y = (-e.offsetY / this.height) * 2 + 1;
1420
-
1421
- raycaster.setFromCamera(mouse, camera);
1422
- rayDirection = raycaster.ray.direction;
1423
-
1424
- let lines = planData.sceneGraph.layers[scene.selectedLayer].lines;
1425
- let keys = Object.keys(lines);
1426
- let arrMesh = [];
1427
- keys.forEach(key => {
1428
- lines[key].children[0].children.forEach(mesh => {
1429
- if (mesh.name == 'soul' && mesh.visible) arrMesh.push(mesh);
1430
- });
1431
- });
1432
- if (arrMesh.length > 0) {
1433
- const intersects = raycaster.intersectObjects(arrMesh);
1434
- if (intersects.length > 0) {
1435
- let intersectPt = intersects[0].point;
1436
- intersectPt.applyMatrix4(gridMatrix);
1437
-
1438
- Point = { x: intersectPt.x, y: -intersectPt.z };
1439
- this.context.projectActions.updateMouseCoord(Point);
1440
- return true;
1441
- }
1442
- }
1443
-
1444
- return false;
1445
- };
1446
-
1447
- this.mouseDownEvent = event => {
1448
- gridPlanOrigin = gridPlane.position;
1449
- gridMatrix.copy(gridPlane.matrixWorld).invert();
1450
- let altitude = 0;
1451
- if (
1452
- allItemRect &&
1453
- allItemRect.cur &&
1454
- allItemRect.cur.itemInfo !== undefined
1455
- ) {
1456
- let properties = allItemRect.cur.itemInfo.properties;
1457
- altitude = properties.getIn(['altitude', '_length']);
1458
- let unit = properties.getIn(['altitude', '_unit']) || 'in';
1459
- altitude = convert(altitude).from(unit).to(this.props.state.scene.unit);
1460
- }
1461
- getPoint(event, altitude);
1462
-
1463
- const state = this.props.state;
1464
-
1465
- this.lastMousePosition.x = mouse.x;
1466
- this.lastMousePosition.y = mouse.y;
1467
-
1468
- const layer = state.scene.getIn(['layers', state.scene.selectedLayer]);
1469
- const sCount =
1470
- layer.selected.areas.size +
1471
- layer.selected.holes.size +
1472
- layer.selected.items.size +
1473
- layer.selected.lines.size;
1474
-
1475
- if (sCount <= 0) {
1476
- isSelected = false;
1477
- } else if (sCount >= 0 && selectedObject && 'holeID' in selectedObject) {
1478
- isSelected = true;
1479
- }
1480
-
1481
- prevX = Point.x;
1482
- prevY = Point.y;
1483
-
1484
- /**
1485
- * 0 - rotate
1486
- * 1 - move up/down
1487
- * 2 - move x/y
1488
- * 3 - camera rotate
1489
- */
1490
- let transflag = 3;
1491
- raycaster.setFromCamera(mouse, camera);
1492
- const meshes = [];
1493
- toIntersect.forEach(object => {
1494
- if (!object) return;
1495
- object.traverse(o => {
1496
- if (o.isMesh) meshes.push(o);
1497
- });
1498
- });
1499
- let intersects = raycaster.intersectObjects(meshes, true);
1500
-
1501
- let toolIntersects = raycaster.intersectObjects([toolObj], true);
1502
-
1503
- if (toolIntersects.length > 0) {
1504
- let distance = Math.sqrt(
1505
- Math.pow((toolIntersects[0].uv.x - 0.5) * 50, 2) +
1506
- Math.pow((toolIntersects[0].uv.y - 0.25) * 100, 2)
1507
- );
1508
- if (distance <= 20) {
1509
- transflag = 2;
1510
- } else {
1511
- distance = Math.sqrt(
1512
- Math.pow((toolIntersects[0].uv.x - 0.5) * 50, 2) +
1513
- Math.pow((toolIntersects[0].uv.y - 0.75) * 100, 2)
1514
- );
1515
- if (distance <= 20) {
1516
- transflag = 0;
1517
- }
1518
- }
1519
- }
1520
-
1521
- if (intersects.length > 0) {
1522
- let i = 0,
1523
- length = intersects.length;
1524
- for (i = 0; i < length; i++) {
1525
- if (
1526
- intersects[i].object.type !== 'BoxHelper' &&
1527
- // intersects[i].object.type === OBJTYPE_MESH &&
1528
- intersects[i].object.name !== 'lineText' &&
1529
- intersects[i].object.name !== 'soul' &&
1530
- !intersects[i].object.name.includes('WarningBox')
1531
- )
1532
- break;
1533
- }
1534
-
1535
- if (intersects[i] !== undefined) {
1536
- if (intersects[i].object.name.indexOf('transUp') != -1) transflag = 1;
1537
- if (intersects[i].object.name.indexOf('transHole') != -1)
1538
- transflag = 2;
1539
- } else {
1540
- console.log('intersects[i] is undefined in viewer3d/viewer3d.js');
1541
- }
1542
- }
1543
-
1544
- if (this.props.state.mode == MODE_DRAWING_ITEM_3D) return;
1545
-
1546
- if (isSelected) {
1547
- if (intersects.length > 0 && !isNaN(intersects[0].distance)) {
1548
- let i;
1549
- for (i = 0; i < intersects.length; i++) {
1550
- if (
1551
- intersects[i].object instanceof Three.Mesh &&
1552
- intersects[i].object.name != 'TransformBox' &&
1553
- intersects[i].object.type != 'Line' &&
1554
- intersects[i].object.name != 'lineText' &&
1555
- intersects[i].object.name != 'countertops' &&
1556
- intersects[i].object.type != 'BoxHelper' &&
1557
- intersects[i].object.name != 'floor' &&
1558
- intersects[i].object.name != 'backFace' &&
1559
- intersects[i].object.name != 'soul' &&
1560
- !intersects[i].object.name.includes('backsplash') &&
1561
- !intersects[i].object.name.includes('WarningBox')
1562
- )
1563
- break;
1564
- }
1565
- if (intersects[i] === undefined) {
1566
- if (transflag !== 0 && transflag !== 2) {
1567
- isSelected = false;
1568
- this.context.projectActions.unselectAll();
1569
- scene3D.remove(toolObj);
1570
- this.context.itemsActions.removeReplacingSupport();
1571
- return;
1572
- }
1573
- }
1574
- if (selectedObject !== undefined) {
1575
- sPoint.set(Point.x, Point.y);
1576
- if (transflag == 0) {
1577
- scene3D.remove(toolObj);
1578
- let alti = 0;
1579
- if (
1580
- allItemRect &&
1581
- allItemRect.cur &&
1582
- allItemRect.cur.itemInfo !== undefined
1583
- ) {
1584
- let properties = allItemRect.cur.itemInfo.properties;
1585
- alti = properties.getIn(['altitude', '_length']);
1586
- let unit = properties.getIn(['altitude', '_unit']) || 'in';
1587
- alti = convert(alti).from(unit).to(this.props.state.scene.unit);
1588
- }
1589
- getPoint(
1590
- { offsetX: event.offsetX - 50, offsetY: event.offsetY },
1591
- alti
1592
- );
1593
- let selectedItem =
1594
- planData.sceneGraph.layers[selectedObject.layerID].items[
1595
- selectedObject.itemID
1596
- ];
1597
- if (isUndefined(selectedItem)) return;
1598
- const selItem = this.props.state.scene.layers
1599
- .get(selectedObject.layerID)
1600
- .items.get(selectedObject.itemID);
1601
-
1602
- lastAngle = 0;
1603
-
1604
- angleObj.position.set(
1605
- planData.plan.position.x + Point.x,
1606
- selItem.category === 'lighting'
1607
- ? -planData.plan.position.y -
1608
- selItem.properties.get('height').get('length')
1609
- : selItem.properties.get('altitude').get('length') +
1610
- planData.plan.position.y,
1611
- planData.plan.position.z - Point.y
1612
- );
1613
-
1614
- angleTexture.image = createAngleObject(0);
1615
- angleTexture.needsUpdate = true;
1616
-
1617
- scene3D.add(angleObj);
1618
- this.setState({ angleObj: angleObj });
1619
- let centerPos = Point;
1620
- getPoint(event, alti);
1621
-
1622
- this.context.itemsActions.beginRotatingItem3D(
1623
- selectedObject.layerID,
1624
- selectedObject.itemID,
1625
- Point.x,
1626
- Point.y,
1627
- centerPos.x,
1628
- centerPos.y
1629
- );
1630
- bRotate = true;
1631
- } else if (transflag == 1) {
1632
- bMoveUP = true;
1633
- } else if (transflag == 2) {
1634
- switch (true) {
1635
- case 'holeID' in selectedObject:
1636
- this.context.holesActions.beginDraggingHole3D(
1637
- selectedObject.layerID,
1638
- selectedObject.holeID,
1639
- Point.x,
1640
- Point.y
1641
- );
1642
- break;
1643
- default:
1644
- this.context.itemsActions.beginDraggingItem3D(
1645
- selectedObject.layerID,
1646
- selectedObject.itemID,
1647
- Point.x,
1648
- Point.y
1649
- );
1650
- break;
1651
- }
1652
- bMove = true;
1653
- scene3D.remove(toolObj);
1654
- }
1655
- if (!ARRAY_ELEVATION_VIEW_MODES.includes(mode))
1656
- cameraControls.mouseButtons.left = CameraControls.ACTION.NONE;
1657
- }
1658
- } else {
1659
- isSelected = false;
1660
- this.context.projectActions.unselectAll();
1661
- scene3D.remove(toolObj);
1662
- this.context.itemsActions.removeReplacingSupport();
1663
- return;
1664
- }
1665
- }
1666
- };
1667
-
1668
- this.renderer.setClearColor(new Three.Color(SharedStyle.COLORS.white)); // 3D background color
1669
- this.renderer.setSize(this.width, this.height);
1670
-
1671
- // Add the output of the renderer to the html element
1672
- const canvasWrapper = ReactDOM.findDOMNode(this.refs.canvasWrapper);
1673
- canvasWrapper.appendChild(this.renderer.domElement);
1674
-
1675
- //
1676
-
1677
- if (
1678
- scene.getIn(['layers', scene.selectedLayer, 'selected', 'items']).size !=
1679
- 0
1680
- ) {
1681
- // if selected Object
1682
- isSelected = true;
1683
- selectedObject.layerID = scene.selectedLayer;
1684
- selectedObject.itemID = scene
1685
- .getIn(['layers', scene.selectedLayer, 'selected', 'items'])
1686
- .toJS()[0];
1687
- setTimeout(() => {
1688
- try {
1689
- currentObject =
1690
- planData.sceneGraph.layers[selectedObject.layerID].items[
1691
- selectedObject.itemID
1692
- ];
1693
- if (isUndefined(currentObject)) return;
1694
- const selItem = this.props.state.scene.layers
1695
- .get(selectedObject.layerID)
1696
- .items.get(selectedObject.itemID);
1697
- let itemPos = currentObject.position.clone();
1698
- toolObj.position.set(
1699
- planData.plan.position.x + itemPos.x,
1700
- selItem.category === 'lighting'
1701
- ? -planData.plan.position.y -
1702
- selItem.properties.get('height').get('length')
1703
- : planData.plan.position.y + currentObject.children[0].position.y,
1704
- planData.plan.position.z + itemPos.z
1705
- );
1706
-
1707
- scene3D.add(toolObj);
1708
- this.setState({ toolObj: toolObj });
1709
- } catch (err) {
1710
- console.log(
1711
- 'selectedObject : ' +
1712
- JSON.stringify(selectedObject) +
1713
- '\nError: ' +
1714
- err
1715
- );
1716
- }
1717
- }, 2000);
1718
- }
1719
-
1720
- // Scene functions
1721
-
1722
- function init() {
1723
- clock = new Three.Clock();
1724
- scene3D = new Three.Scene();
1725
- scene3D.background = new Three.Color(0xc3cadc); // change color about v1: 0x8791AB, v2: 0xC2C2C2, v3: 0xC3CADC
1726
- // scene3D.fog = new Three.Fog(0xC3CADC, 2000, 3500);
1727
- window.scene3D = scene3D;
1728
- // Camera
1729
- if (ARRAY_ELEVATION_VIEW_MODES.includes(state.mode)) {
1730
- let { layers } = scene;
1731
- let selectedLayer = layers.get(scene.selectedLayer);
1732
- let ceilHeight = convert(selectedLayer.ceilHeight)
1733
- .from(selectedLayer.unit)
1734
- .to(scene.unit);
1735
- let vertices = selectedLayer.vertices.toJS();
1736
- let maxX = 0,
1737
- maxY = 0,
1738
- minX = 0,
1739
- minY = 0;
1740
- let lines = [];
1741
- selectedLayer.lines.toArray().forEach(line => {
1742
- let vertex0 = selectedLayer.vertices.get(line.vertices.get(0));
1743
- let vertex1 = selectedLayer.vertices.get(line.vertices.get(1));
1744
- let { x: x1, y: y1 } = vertex0;
1745
- let { x: x2, y: y2 } = vertex1;
1746
- let data = line.toJS();
1747
- data = { ...data, l0: { x: x1, y: y1 }, l1: { x: x2, y: y2 } };
1748
- switch (mode) {
1749
- case MODE_FRONT_ELEVATION_VIEW:
1750
- if (almostEqual(y1, y2) && x1 < x2) {
1751
- lines.push(data);
1752
- }
1753
- break;
1754
- case MODE_BACK_ELEVATION_VIEW:
1755
- if (almostEqual(y1, y2) && x1 > x2) {
1756
- lines.push(data);
1757
- }
1758
- break;
1759
- case MODE_LEFT_ELEVATION_VIEW:
1760
- if (almostEqual(x1, x2) && y1 < y2) {
1761
- lines.push(data);
1762
- }
1763
- break;
1764
- case MODE_RIGHT_ELEVATION_VIEW:
1765
- if (almostEqual(x1, x2) && y1 > y2) {
1766
- lines.push(data);
1767
- }
1768
- break;
1769
- default:
1770
- break;
1771
- }
1772
- });
1773
- for (let vertex in vertices) {
1774
- maxX = Math.max(vertices[vertex].x, maxX);
1775
- maxY = Math.max(vertices[vertex].y, maxY);
1776
- if (minX === 0) minX = vertices[vertex].x;
1777
- if (minY === 0) minY = vertices[vertex].y;
1778
- minX = Math.min(vertices[vertex].x, minX);
1779
- minY = Math.min(vertices[vertex].y, minY);
1780
- }
1781
- let line_length, angle, posX, posY;
1782
- switch (state.mode) {
1783
- case MODE_FRONT_ELEVATION_VIEW:
1784
- line_length = maxX - minX;
1785
- posY = -(minY - 100);
1786
- posX = (minX + maxX) / 2;
1787
- angle = 0;
1788
- break;
1789
- case MODE_RIGHT_ELEVATION_VIEW:
1790
- line_length = maxY - minY;
1791
- posX = -(minX - 100);
1792
- posY = (minY + maxY) / 2;
1793
- angle = -Math.PI / 2;
1794
- break;
1795
- case MODE_LEFT_ELEVATION_VIEW:
1796
- line_length = maxY - minY;
1797
- posX = maxX + 100;
1798
- posY = (minY + maxY) / 2;
1799
- angle = Math.PI / 2;
1800
- break;
1801
- case MODE_BACK_ELEVATION_VIEW:
1802
- line_length = maxX - minX;
1803
- posY = maxY + 100;
1804
- posX = (minX + maxX) / 2;
1805
- angle = Math.PI;
1806
- break;
1807
- }
1808
- let scale = Math.min(
1809
- (self.width * 0.85) / line_length,
1810
- (self.height * 0.85) / ceilHeight
1811
- );
1812
- // let frontRect = {width: line_length * scale, height: ceilHeight * scale};
1813
- let cameraRect = {
1814
- width: self.width / scale,
1815
- height: self.height / scale
1816
- };
1817
- camera = new Three.OrthographicCamera(
1818
- -cameraRect.width / 2,
1819
- cameraRect.width / 2,
1820
- cameraRect.height / 2,
1821
- -cameraRect.height / 2,
1822
- 1,
1823
- 10000
1824
- );
1825
- camera.position.set(posX, ceilHeight / 2, -posY);
1826
- camera.rotation.set(0, angle, 0);
1827
- } else {
1828
- const aspectRatio = self.width / self.height;
1829
- camera = new Three.PerspectiveCamera(45, aspectRatio, 1, 300000);
1830
- camera.position.set(0, 0, 1);
1831
- }
1832
- camera.layers.enable(1);
1833
-
1834
- function loadENV() {
1835
- new RGBELoader().load(
1836
- '/assets/brown_photostudio_02_1k.hdr',
1837
- function (texture) {
1838
- texture.mapping = Three.EquirectangularReflectionMapping;
1839
- scene3D.environment = texture;
1840
- texture.dispose();
1841
- }
1842
- );
1843
- }
1844
-
1845
- // Camera Controls
1846
- if (!ARRAY_ELEVATION_VIEW_MODES.includes(state.mode)) {
1847
- cameraControls = new CameraControls(camera, self.renderer.domElement);
1848
- cameraControls.dollyToCursor = true;
1849
- cameraControls.infinityDolly = true;
1850
- cameraControls.minDistance = 50;
1851
- cameraControls.maxDistance = Infinity;
1852
- cameraControls.zoomSpeed = 1;
1853
-
1854
- loadENV();
1855
- }
1856
-
1857
- scene3D.add(planData.plan);
1858
- scene3D.add(planData.grid);
1859
- scene3D.add(camera);
1860
- if (ARRAY_ELEVATION_VIEW_MODES.includes(state.mode)) {
1861
- planData.cam.add(camera);
1862
- scene3D.add(planData.cam);
1863
- } else {
1864
- pivot = new Three.Object3D();
1865
- pivot.add(camera);
1866
- scene3D.add(pivot);
1867
- }
1868
-
1869
- // LIGHT
1870
-
1871
- let light = new Three.AmbientLight(0xbfbfbf, 0.9); // soft white light
1872
- }
1873
-
1874
- function render() {
1875
- const delta = clock.getDelta(); // Get time delta for smooth updates
1876
- if (!ARRAY_ELEVATION_VIEW_MODES.includes(state.mode))
1877
- cameraControls.update(delta);
1878
- for (let i = 0; i < lights.length; i++) {
1879
- lights[i].light.position.set(
1880
- planData.plan.position.x + lights[i].x,
1881
- planData.plan.position.y + lights[i].height - 10,
1882
- planData.plan.position.z - lights[i].y
1883
- );
1884
- lights[i].target.position.set(
1885
- planData.plan.position.x + lights[i].x,
1886
- planData.plan.position.y,
1887
- planData.plan.position.z - lights[i].y
1888
- );
1889
- }
1890
-
1891
- camera.updateMatrix();
1892
- camera.updateMatrixWorld();
1893
-
1894
- for (let elemID in planData.sceneGraph.LODs) {
1895
- planData.sceneGraph.LODs[elemID].update(camera);
1896
- }
1897
- if (snapBox !== null) {
1898
- if (snapAnimI >= 15) {
1899
- if ('x' in targetPoint)
1900
- snapBox.position.set(
1901
- targetPoint.x,
1902
- snapBox.position.y,
1903
- targetPoint.z
1904
- );
1905
- snapFlag = false;
1906
- t_i++;
1907
- } else {
1908
- if (snapAnimI == 0) {
1909
- targetCRotation =
1910
- ((((targetRot / 180) * Math.PI - snapBox.rotation.y + Math.PI) *
1911
- 180) /
1912
- Math.PI) %
1913
- 360;
1914
- if (targetCRotation > 180) targetCRotation -= 360;
1915
- if (targetCRotation < -180) targetCRotation += 360;
1916
- targetCRotation = (targetCRotation / 180) * Math.PI;
1917
- }
1918
- if (snapAnimI < 10) {
1919
- snapBox.rotateY(targetCRotation / 10);
1920
- } else {
1921
- snapBox.position.set(
1922
- snapBox.position.clone().x - targetUVec.x / 10,
1923
- snapBox.position.clone().y - targetUVec.y / 10,
1924
- snapBox.position.clone().z - targetUVec.z / 10
1925
- );
1926
- }
1927
- snapAnimI++;
1928
- }
1929
- }
1930
-
1931
- if (t_i === 20) {
1932
- //stop snap after 5s
1933
- removeSnapBox();
1934
- }
1935
-
1936
- // hide hole if wall is not visible
1937
- let layerID = self.props.state.scene.selectedLayer;
1938
- let layer = self.props.state.scene.layers.get(layerID);
1939
- layer.holes.forEach(data => {
1940
- let line = planData.sceneGraph.layers[layerID].lines[data.line];
1941
- let hole = planData.sceneGraph.layers[layerID].holes[data.id];
1942
- if (line instanceof Three.Object3D && !line.isMesh) {
1943
- line = line.children[0].children[0];
1944
- // index(faces) of the line
1945
- const indexAttribute = line.geometry.getIndex();
1946
- const firstFaceIndices = [
1947
- indexAttribute.getX(0),
1948
- indexAttribute.getX(1),
1949
- indexAttribute.getX(2)
1950
- ];
1951
-
1952
- if (firstFaceIndices == undefined) return;
1953
- // normal vector of the line
1954
- const normalAttribute = line.geometry.attributes.normal;
1955
- let normal = new Three.Vector3()
1956
- .fromBufferAttribute(normalAttribute, 0)
1957
- .clone();
1958
- normal = normal
1959
- .applyMatrix4(line.matrixWorld)
1960
- .sub(new Three.Vector3(0, 0, 0).applyMatrix4(line.matrixWorld))
1961
- .normalize();
1962
- let vertices = layer.lines.get(data.line).vertices.toJS();
1963
- let vertex1 = layer.vertices.get(vertices[0]);
1964
- let vertex2 = layer.vertices.get(vertices[1]);
1965
- let cX = (vertex1.x + vertex2.x) / 2;
1966
- let cY = (vertex1.y + vertex2.y) / 2;
1967
- let posVec = new Three.Vector3(cX, 150, -cY);
1968
- posVec = posVec.add(planData.plan.position.clone());
1969
- let cameraLine = camera.position.clone().sub(posVec);
1970
- if (hole) {
1971
- hole.traverse(child => {
1972
- if (child.isMesh) {
1973
- child.material.opacity = cameraLine.dot(normal) > 0 ? 1 : 0;
1974
- child.material.transparent =
1975
- cameraLine.dot(normal) > 0 ? false : true;
1976
- child.material.needsUpdate = true;
1977
- }
1978
- });
1979
- }
1980
- }
1981
- // /////////////////////////////////////
1982
- });
1983
-
1984
- if (scene3D && camera) {
1985
- self.renderer.render(scene3D, camera);
1986
- }
1987
- self.renderingID = requestAnimationFrame(render);
1988
-
1989
- if (self.state.waitForRender > 0) {
1990
- self.state.waitForRender++;
1991
- if (self.state.waitForRender > 2) {
1992
- self.setState({ isLoading: false, waitForRender: 0 });
1993
-
1994
- switch (self.props.state.mode) {
1995
- case MODE_FRONT_ELEVATION_VIEW:
1996
- setTimeout(() => {
1997
- self.props.setIsLoadingElevation('front', false);
1998
- }, 100);
1999
- break;
2000
- case MODE_BACK_ELEVATION_VIEW:
2001
- setTimeout(() => {
2002
- self.props.setIsLoadingElevation('back', false);
2003
- }, self);
2004
- break;
2005
- case MODE_LEFT_ELEVATION_VIEW:
2006
- setTimeout(() => {
2007
- self.props.setIsLoadingElevation('left', false);
2008
- }, 100);
2009
- break;
2010
- case MODE_RIGHT_ELEVATION_VIEW:
2011
- setTimeout(() => {
2012
- self.props.setIsLoadingElevation('right', false);
2013
- }, 100);
2014
- break;
2015
- case MODE_3D_VIEW:
2016
- setTimeout(() => self.props.setIsLoading3D(false), 100);
2017
- break;
2018
- }
2019
- self.renderer.domElement.style.display = 'block';
2020
- }
2021
- }
2022
- }
2023
-
2024
- //
2025
-
2026
- window.planData = planData;
2027
- this.planData = planData;
2028
- this.camera = camera;
2029
- this.cameraControls = cameraControls;
2030
- this.scene3D = scene3D;
2031
-
2032
- prepareSnap(layer);
2033
- }
2034
-
2035
- componentWillUnmount() {
2036
- cancelAnimationFrame(this.renderingID);
2037
-
2038
- if (!ARRAY_ELEVATION_VIEW_MODES.includes(this.props.state.mode)) {
2039
- if (this.cameraControls !== undefined) this.cameraControls.dispose();
2040
- }
2041
-
2042
- disposeScene(this.scene3D);
2043
- this.scene3D.remove(this.planData.plan);
2044
- this.scene3D.remove(this.planData.grid);
2045
-
2046
- this.scene3D = null;
2047
- this.planData = null;
2048
- this.camera = null;
2049
- this.cameraControls = null;
2050
- this.renderer.renderLists.dispose();
2051
- }
2052
-
2053
- componentWillReceiveProps(nextProps) {
2054
- if (diff(this.props.state, nextProps.state).toJS().length == 0) return;
2055
-
2056
- let { width, height } = nextProps;
2057
- let actions = {
2058
- areaActions: this.context.areaActions,
2059
- holesActions: this.context.holesActions,
2060
- itemsActions: this.context.itemsActions,
2061
- sceneActions: this.context.sceneActions,
2062
- linesActions: this.context.linesActions,
2063
- projectActions: this.context.projectActions,
2064
- catalog: this.context.catalog
2065
- };
2066
-
2067
- this.width = width;
2068
- this.height = height;
2069
-
2070
- this.renderer.setSize(width, height);
2071
-
2072
- let allLines;
2073
- let allLineRects;
2074
- let allItemRect;
2075
-
2076
- this.camera.aspect = width / height;
2077
- this.camera.updateProjectionMatrix();
2078
-
2079
- let data = nextProps.state.scene;
2080
- let layer = data.getIn(['layers', data.selectedLayer]);
2081
- const self = this;
2082
-
2083
- function implementBacksplash() {
2084
- let allItems = GeometryUtils.getAllItemSpecified(
2085
- nextProps.state.scene,
2086
- actions.catalog,
2087
- BASE_CABINET_LAYOUTPOS
2088
- );
2089
- let i,
2090
- items = [];
2091
- for (i = 0; i < allItems.others.length; i++)
2092
- items.push(allItems.others[i]);
2093
- if (allItems.cur) items.push(allItems.cur);
2094
-
2095
- for (i = 0; i < items.length; i++) {
2096
- let calcRect = GeometryUtils.getCalcRectFromItem3D(items[i]);
2097
- let visible = GeometryUtils.isSnappedLine(calcRect, allLineRects);
2098
- actions.itemsActions.setBacksplashVisible(
2099
- items[i].itemInfo.id,
2100
- visible
2101
- );
2102
-
2103
- createBacksplash(
2104
- items[i],
2105
- nextProps.state.scene.getIn([
2106
- 'layers',
2107
- nextProps.state.scene.selectedLayer
2108
- ]),
2109
- planData,
2110
- nextProps.state.scene
2111
- );
2112
- }
2113
- }
2114
- function implementWarningBox() {
2115
- let holeItems = GeometryUtils.getHoleItems(layer);
2116
- let i,
2117
- items = [];
2118
- for (i = 0; i < allItemRect.others.length; i++)
2119
- items.push(allItemRect.others[i]);
2120
- if (allItemRect.cur) items.push(allItemRect.cur);
2121
-
2122
- for (i = 0; i < items.length; i++)
2123
- checkCabinetOverlap(
2124
- { x: items[i].pos.x, y: items[i].pos.y },
2125
- items[i],
2126
- holeItems,
2127
- planData
2128
- );
2129
- }
2130
-
2131
- let prepareSnapSpec = layer => {
2132
- allLines = GeometryUtils.getAllLines(layer);
2133
- allLineRects = GeometryUtils.buildRectFromLines(layer, allLines);
2134
- allItemRect = GeometryUtils.getAllItemSpecified(
2135
- this.props.state.scene,
2136
- actions.catalog,
2137
- [WALL_CABINET_LAYOUTPOS, TALL_CABINET_LAYOUTPOS]
2138
- );
2139
- };
2140
-
2141
- let layer1 = this.props.state.scene.getIn(['layers', data.selectedLayer]);
2142
-
2143
- if (this.state.showflag) {
2144
- prepareSnapSpec(layer);
2145
- implementBacksplash();
2146
- implementWarningBox();
2147
- this.setState({ showflag: false });
2148
- }
2149
- if (
2150
- nextProps.state.scene !== this.props.state.scene ||
2151
- (nextProps.state.doorStyle &&
2152
- nextProps.state.doorStyle.get('name') !==
2153
- this.props.state.doorStyle.get('name'))
2154
- ) {
2155
- let changedValues = diff(this.props.state.scene, nextProps.state.scene);
2156
- prepareSnapSpec(layer);
2157
- if (
2158
- nextProps.state.doorStyle &&
2159
- nextProps.state.doorStyle.get('name') ===
2160
- this.props.state.doorStyle.get('name')
2161
- ) {
2162
- self.setState({ isLoading: true, waitForRender: 0 });
2163
-
2164
- switch (self.props.state.mode) {
2165
- case MODE_FRONT_ELEVATION_VIEW:
2166
- self.props.setIsLoadingElevation('front', true);
2167
- break;
2168
- case MODE_BACK_ELEVATION_VIEW:
2169
- self.props.setIsLoadingElevation('back', true);
2170
- break;
2171
- case MODE_LEFT_ELEVATION_VIEW:
2172
- self.props.setIsLoadingElevation('left', true);
2173
- break;
2174
- case MODE_RIGHT_ELEVATION_VIEW:
2175
- self.props.setIsLoadingElevation('right', true);
2176
- break;
2177
- case MODE_3D_VIEW:
2178
- self.props.setIsLoading3D(true);
2179
- break;
2180
- }
2181
- self.renderer.domElement.style.display = 'none';
2182
- }
2183
- if (nextProps.state.scene.showfg == true) {
2184
- implementBacksplash();
2185
- implementWarningBox();
2186
- } else {
2187
- deleteSpecifiedMeshObjects('TransformBox');
2188
- }
2189
- let { toolObj, angleObj } = this.state;
2190
- var { promise } = updateScene(
2191
- this.planData,
2192
- nextProps.state.scene,
2193
- this.props.state.scene,
2194
- changedValues.toJS(),
2195
- actions,
2196
- this.context.catalog,
2197
- nextProps.state.mode,
2198
- toolObj,
2199
- angleObj
2200
- );
2201
- promise.then(p1Value => {
2202
- self.setState({ waitForRender: 1 });
2203
- });
2204
- }
2205
- }
2206
-
2207
- render() {
2208
- const { isLoading } = this.state;
2209
- if (isLoading) {
2210
- // document.getElementById('elevation') && (document.getElementById('elevation').style.display = 'none');
2211
- this.renderer.domElement.style.display = 'none';
2212
- return (
2213
- <div
2214
- style={{
2215
- alignItems: ' center',
2216
- width: this.props.width,
2217
- height: this.props.height,
2218
- display: 'inline-flex',
2219
- justifyContent: 'center'
2220
- }}
2221
- >
2222
- <img
2223
- style={{
2224
- width: '70px',
2225
- height: '70px',
2226
- animation: 'spin 2s linear infinite'
2227
- }}
2228
- src={'/assets/img/loading_large.gif'}
2229
- alt="img"
2230
- />
2231
- </div>
2232
- );
2233
- } else {
2234
- this.renderer.domElement.style.pointerEvents = 'auto';
2235
- this.renderer.domElement.style.opacity = '1';
2236
- // document.getElementById('elevation') && (document.getElementById('elevation').style.display = 'block');
2237
- return React.createElement('div', { ref: 'canvasWrapper' });
2238
- }
2239
- }
2240
- }
2241
-
2242
- Viewer3DDownLoad.propTypes = {
2243
- state: PropTypes.object.isRequired,
2244
- width: PropTypes.number.isRequired,
2245
- height: PropTypes.number.isRequired,
2246
- replaceCabinet: PropTypes.func.isRequired
2247
- };
2248
-
2249
- Viewer3DDownLoad.contextTypes = {
2250
- areaActions: PropTypes.object.isRequired,
2251
- holesActions: PropTypes.object.isRequired,
2252
- itemsActions: PropTypes.object.isRequired,
2253
- linesActions: PropTypes.object.isRequired,
2254
- sceneActions: PropTypes.object.isRequired,
2255
- projectActions: PropTypes.object.isRequired,
2256
- catalog: PropTypes.object
2257
- };