kitchen-simulator 1.1.1-test.48 → 1.1.1-test.49

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 (359) hide show
  1. package/lib/KitchenConfiguratorApp.js +3 -0
  2. package/package.json +1 -1
  3. package/es/@history.js +0 -2
  4. package/es/AppContext.js +0 -3
  5. package/es/KitchenConfigurator.js +0 -645
  6. package/es/KitchenConfiguratorApp.js +0 -478
  7. package/es/actions/area-actions.js +0 -14
  8. package/es/actions/export.js +0 -23
  9. package/es/actions/groups-actions.js +0 -89
  10. package/es/actions/holes-actions.js +0 -119
  11. package/es/actions/items-actions.js +0 -313
  12. package/es/actions/lines-actions.js +0 -81
  13. package/es/actions/project-actions.js +0 -281
  14. package/es/actions/scene-actions.js +0 -33
  15. package/es/actions/vertices-actions.js +0 -27
  16. package/es/actions/viewer2d-actions.js +0 -58
  17. package/es/actions/viewer3d-actions.js +0 -23
  18. package/es/catalog/areas/area/planner-element.js +0 -40
  19. package/es/catalog/areas/area/textures/ceramic-tile.jpg +0 -0
  20. package/es/catalog/areas/area/textures/grass.jpg +0 -0
  21. package/es/catalog/areas/area/textures/parquet.jpg +0 -0
  22. package/es/catalog/areas/area/textures/strand-porcelain.jpg +0 -0
  23. package/es/catalog/areas/area/textures/tile1.jpg +0 -0
  24. package/es/catalog/catalog.js +0 -277
  25. package/es/catalog/envMap/nx.hdr +0 -0
  26. package/es/catalog/envMap/ny.hdr +0 -0
  27. package/es/catalog/envMap/nz.hdr +0 -0
  28. package/es/catalog/envMap/px.hdr +0 -0
  29. package/es/catalog/envMap/py.hdr +0 -0
  30. package/es/catalog/envMap/pz.hdr +0 -0
  31. package/es/catalog/factories/area-factory-3d.js +0 -181
  32. package/es/catalog/factories/area-factory.js +0 -81
  33. package/es/catalog/factories/export.js +0 -7
  34. package/es/catalog/factories/wall-factory-3d.js +0 -202
  35. package/es/catalog/factories/wall-factory.js +0 -268
  36. package/es/catalog/holes/door-closet/planner-element.js +0 -222
  37. package/es/catalog/holes/door-double/door_double.png +0 -0
  38. package/es/catalog/holes/door-double/planner-element.js +0 -315
  39. package/es/catalog/holes/door-exterior/planner-element.js +0 -215
  40. package/es/catalog/holes/door-interior/planner-element.js +0 -227
  41. package/es/catalog/holes/door-panic/panicDoor.png +0 -0
  42. package/es/catalog/holes/door-panic/planner-element.js +0 -503
  43. package/es/catalog/holes/door-panic-double/panicDoorDouble.png +0 -0
  44. package/es/catalog/holes/door-panic-double/planner-element.js +0 -463
  45. package/es/catalog/holes/door-sliding/planner-element.js +0 -225
  46. package/es/catalog/holes/doorway-framed/planner-element.js +0 -145
  47. package/es/catalog/holes/doorway-frameless/planner-element.js +0 -104
  48. package/es/catalog/holes/export.js +0 -13
  49. package/es/catalog/holes/gate/gate.jpg +0 -0
  50. package/es/catalog/holes/window-clear/planner-element.js +0 -166
  51. package/es/catalog/holes/window-clear/texture.png +0 -0
  52. package/es/catalog/holes/window-cross/planner-element.js +0 -165
  53. package/es/catalog/holes/window-cross/texture.png +0 -0
  54. package/es/catalog/holes/window-double-hung/planner-element.js +0 -303
  55. package/es/catalog/holes/window-double-hung/texture.png +0 -0
  56. package/es/catalog/holes/window-vertical/planner-element.js +0 -276
  57. package/es/catalog/holes/window-vertical/texture.png +0 -0
  58. package/es/catalog/lines/wall/planner-element.js +0 -70
  59. package/es/catalog/lines/wall/textures/bricks-normal.jpg +0 -0
  60. package/es/catalog/lines/wall/textures/bricks-normal2.jpg +0 -0
  61. package/es/catalog/lines/wall/textures/bricks.jpg +0 -0
  62. package/es/catalog/lines/wall/textures/bricks2.jpg +0 -0
  63. package/es/catalog/lines/wall/textures/bricks3.jpg +0 -0
  64. package/es/catalog/lines/wall/textures/morden-normal.jpg +0 -0
  65. package/es/catalog/lines/wall/textures/morden.jpg +0 -0
  66. package/es/catalog/lines/wall/textures/painted-normal.jpg +0 -0
  67. package/es/catalog/lines/wall/textures/painted.jpg +0 -0
  68. package/es/catalog/lines/wall/textures/plaster-normal.jpg +0 -0
  69. package/es/catalog/lines/wall/textures/plaster.jpg +0 -0
  70. package/es/catalog/lines/wall/wall.png +0 -0
  71. package/es/catalog/molding/molding-dcm/planner-element.js +0 -28
  72. package/es/catalog/molding/molding-dcm/texture.png +0 -0
  73. package/es/catalog/molding/molding-fbm/planner-element.js +0 -28
  74. package/es/catalog/molding/molding-fbm/texture.png +0 -0
  75. package/es/catalog/molding/molding-lrm/planner-element.js +0 -28
  76. package/es/catalog/molding/molding-lrm/texture.png +0 -0
  77. package/es/catalog/properties/export.js +0 -21
  78. package/es/catalog/properties/property-checkbox.js +0 -116
  79. package/es/catalog/properties/property-color.js +0 -39
  80. package/es/catalog/properties/property-enum.js +0 -97
  81. package/es/catalog/properties/property-hidden.js +0 -19
  82. package/es/catalog/properties/property-lenght-measure.js +0 -101
  83. package/es/catalog/properties/property-length-measure.js +0 -134
  84. package/es/catalog/properties/property-length-measure_hole.js +0 -101
  85. package/es/catalog/properties/property-number.js +0 -48
  86. package/es/catalog/properties/property-read-only.js +0 -26
  87. package/es/catalog/properties/property-string.js +0 -48
  88. package/es/catalog/properties/property-toggle.js +0 -39
  89. package/es/catalog/properties/shared-property-style.js +0 -14
  90. package/es/catalog/utils/FuseUtils.js +0 -82
  91. package/es/catalog/utils/exporter.js +0 -148
  92. package/es/catalog/utils/geom-utils.js +0 -189
  93. package/es/catalog/utils/item-loader.js +0 -1521
  94. package/es/catalog/utils/load-obj.js +0 -91
  95. package/es/catalog/utils/mtl-loader.js +0 -358
  96. package/es/catalog/utils/obj-loader.js +0 -477
  97. package/es/class/FuseUtils.js +0 -82
  98. package/es/class/area.js +0 -145
  99. package/es/class/export.js +0 -24
  100. package/es/class/group.js +0 -440
  101. package/es/class/guide.js +0 -62
  102. package/es/class/hole.js +0 -929
  103. package/es/class/item.js +0 -1883
  104. package/es/class/layer.js +0 -667
  105. package/es/class/line.js +0 -1180
  106. package/es/class/project.js +0 -793
  107. package/es/class/vertex.js +0 -202
  108. package/es/components/content.js +0 -107
  109. package/es/components/disclaimer/disclaimer.js +0 -97
  110. package/es/components/export.js +0 -9
  111. package/es/components/style/button.js +0 -113
  112. package/es/components/style/cancel-button.js +0 -22
  113. package/es/components/style/content-container.js +0 -33
  114. package/es/components/style/content-title.js +0 -29
  115. package/es/components/style/delete-button.js +0 -25
  116. package/es/components/style/export.js +0 -31
  117. package/es/components/style/form-block.js +0 -24
  118. package/es/components/style/form-color-input.js +0 -27
  119. package/es/components/style/form-label.js +0 -26
  120. package/es/components/style/form-number-input.js +0 -213
  121. package/es/components/style/form-number-input_2.js +0 -206
  122. package/es/components/style/form-select.js +0 -68
  123. package/es/components/style/form-slider.js +0 -61
  124. package/es/components/style/form-submit-button.js +0 -26
  125. package/es/components/style/form-text-input.js +0 -95
  126. package/es/components/viewer2d/area.js +0 -81
  127. package/es/components/viewer2d/export.js +0 -31
  128. package/es/components/viewer2d/grids/grid-horizontal-streak.js +0 -37
  129. package/es/components/viewer2d/grids/grid-streak.js +0 -37
  130. package/es/components/viewer2d/grids/grid-vertical-streak.js +0 -37
  131. package/es/components/viewer2d/grids/grids.js +0 -35
  132. package/es/components/viewer2d/group.js +0 -53
  133. package/es/components/viewer2d/item.js +0 -513
  134. package/es/components/viewer2d/layer.js +0 -164
  135. package/es/components/viewer2d/line.js +0 -882
  136. package/es/components/viewer2d/ruler.js +0 -100
  137. package/es/components/viewer2d/rulerDist.js +0 -146
  138. package/es/components/viewer2d/rulerX.js +0 -151
  139. package/es/components/viewer2d/rulerY.js +0 -153
  140. package/es/components/viewer2d/scene.js +0 -140
  141. package/es/components/viewer2d/snap.js +0 -74
  142. package/es/components/viewer2d/state.js +0 -78
  143. package/es/components/viewer2d/utils.js +0 -198
  144. package/es/components/viewer2d/vertex.js +0 -65
  145. package/es/components/viewer2d/viewer2d.js +0 -1398
  146. package/es/components/viewer3d/camera-controls-module/camera-controls.module.js +0 -2592
  147. package/es/components/viewer3d/dcm.js +0 -401
  148. package/es/components/viewer3d/fbm.js +0 -414
  149. package/es/components/viewer3d/front3D.js +0 -66
  150. package/es/components/viewer3d/grid-creator.js +0 -25
  151. package/es/components/viewer3d/grids/grid-horizontal-streak.js +0 -36
  152. package/es/components/viewer3d/grids/grid-streak.js +0 -27
  153. package/es/components/viewer3d/grids/grid-vertical-streak.js +0 -36
  154. package/es/components/viewer3d/libs/first-person-controls.js +0 -67
  155. package/es/components/viewer3d/libs/helvetiker_regular.typeface.js +0 -1281
  156. package/es/components/viewer3d/libs/mtl-loader.js +0 -357
  157. package/es/components/viewer3d/libs/obj-loader.js +0 -462
  158. package/es/components/viewer3d/libs/orbit-controls.js +0 -699
  159. package/es/components/viewer3d/libs/pointer-lock-controls.js +0 -46
  160. package/es/components/viewer3d/lrm.js +0 -305
  161. package/es/components/viewer3d/model.js +0 -708
  162. package/es/components/viewer3d/pointer-lock-navigation.js +0 -115
  163. package/es/components/viewer3d/ruler-utils/itemRect.js +0 -61
  164. package/es/components/viewer3d/ruler-utils/layer3D.js +0 -495
  165. package/es/components/viewer3d/ruler-utils/ruler3D.js +0 -227
  166. package/es/components/viewer3d/ruler-utils/scene3D.js +0 -60
  167. package/es/components/viewer3d/ruler-utils/state3D.js +0 -18
  168. package/es/components/viewer3d/scene-creator.js +0 -3608
  169. package/es/components/viewer3d/three-memory-cleaner.js +0 -51
  170. package/es/components/viewer3d/viewer3d-first-person.js +0 -315
  171. package/es/components/viewer3d/viewer3d.js +0 -2527
  172. package/es/constants.js +0 -636
  173. package/es/index.js +0 -16
  174. package/es/models.js +0 -510
  175. package/es/plugins/SVGLoader.js +0 -1412
  176. package/es/plugins/autosave.js +0 -33
  177. package/es/plugins/console-debugger.js +0 -37
  178. package/es/plugins/export.js +0 -9
  179. package/es/plugins/keyboard.js +0 -101
  180. package/es/reducers/areas-reducer.js +0 -12
  181. package/es/reducers/export.js +0 -25
  182. package/es/reducers/groups-reducer.js +0 -38
  183. package/es/reducers/holes-reducer.js +0 -62
  184. package/es/reducers/items-reducer.js +0 -140
  185. package/es/reducers/lines-reducer.js +0 -45
  186. package/es/reducers/project-reducer.js +0 -129
  187. package/es/reducers/reducer.js +0 -19
  188. package/es/reducers/scene-reducer.js +0 -28
  189. package/es/reducers/user-reducer.js +0 -40
  190. package/es/reducers/vertices-reducer.js +0 -19
  191. package/es/reducers/viewer2d-reducer.js +0 -75
  192. package/es/reducers/viewer3d-reducer.js +0 -56
  193. package/es/shared-style.js +0 -66
  194. package/es/styles/export.js +0 -5
  195. package/es/styles/tabs.css +0 -40
  196. package/es/translator/en.js +0 -104
  197. package/es/translator/it.js +0 -79
  198. package/es/translator/ru.js +0 -79
  199. package/es/translator/translator.js +0 -84
  200. package/es/utils/browser.js +0 -33
  201. package/es/utils/email-validator.js +0 -4
  202. package/es/utils/export.js +0 -25
  203. package/es/utils/geometry.js +0 -2420
  204. package/es/utils/get-edges-of-subgraphs.js +0 -27
  205. package/es/utils/graph-cycles.js +0 -237
  206. package/es/utils/graph-inner-cycles.js +0 -46
  207. package/es/utils/graph.js +0 -150
  208. package/es/utils/helper.js +0 -268
  209. package/es/utils/history.js +0 -29
  210. package/es/utils/id-broker.js +0 -19
  211. package/es/utils/logger.js +0 -8
  212. package/es/utils/math.js +0 -50
  213. package/es/utils/molding.js +0 -871
  214. package/es/utils/name-generator.js +0 -18
  215. package/es/utils/objects-utils.js +0 -50
  216. package/es/utils/phone-validator.js +0 -4
  217. package/es/utils/process-black-list.js +0 -18
  218. package/es/utils/react-if.js +0 -18
  219. package/es/utils/snap-scene.js +0 -99
  220. package/es/utils/snap.js +0 -237
  221. package/es/utils/summarizeCart.js +0 -24
  222. package/es/utils/threeCSG.es6.js +0 -498
  223. package/es/version.js +0 -2
  224. package/lib/catalog/properties/property-string.js +0 -55
  225. package/lib/catalog/properties/property-toggle.js +0 -46
  226. package/lib/catalog/properties/shared-property-style.js +0 -20
  227. package/lib/catalog/utils/FuseUtils.js +0 -88
  228. package/lib/catalog/utils/exporter.js +0 -155
  229. package/lib/catalog/utils/geom-utils.js +0 -205
  230. package/lib/catalog/utils/item-loader.js +0 -1533
  231. package/lib/catalog/utils/load-obj.js +0 -99
  232. package/lib/catalog/utils/mtl-loader.js +0 -363
  233. package/lib/catalog/utils/obj-loader.js +0 -482
  234. package/lib/class/FuseUtils.js +0 -88
  235. package/lib/class/area.js +0 -150
  236. package/lib/class/export.js +0 -96
  237. package/lib/class/group.js +0 -445
  238. package/lib/class/guide.js +0 -67
  239. package/lib/class/hole.js +0 -934
  240. package/lib/class/item.js +0 -1889
  241. package/lib/class/layer.js +0 -672
  242. package/lib/class/line.js +0 -1186
  243. package/lib/class/project.js +0 -799
  244. package/lib/class/vertex.js +0 -207
  245. package/lib/components/content.js +0 -116
  246. package/lib/components/disclaimer/disclaimer.js +0 -105
  247. package/lib/components/export.js +0 -33
  248. package/lib/components/style/button.js +0 -120
  249. package/lib/components/style/cancel-button.js +0 -29
  250. package/lib/components/style/content-container.js +0 -40
  251. package/lib/components/style/content-title.js +0 -37
  252. package/lib/components/style/delete-button.js +0 -34
  253. package/lib/components/style/export.js +0 -121
  254. package/lib/components/style/form-block.js +0 -31
  255. package/lib/components/style/form-color-input.js +0 -34
  256. package/lib/components/style/form-label.js +0 -33
  257. package/lib/components/style/form-number-input.js +0 -220
  258. package/lib/components/style/form-number-input_2.js +0 -213
  259. package/lib/components/style/form-select.js +0 -75
  260. package/lib/components/style/form-slider.js +0 -68
  261. package/lib/components/style/form-submit-button.js +0 -35
  262. package/lib/components/style/form-text-input.js +0 -101
  263. package/lib/components/viewer2d/area.js +0 -88
  264. package/lib/components/viewer2d/export.js +0 -121
  265. package/lib/components/viewer2d/grids/grid-horizontal-streak.js +0 -44
  266. package/lib/components/viewer2d/grids/grid-streak.js +0 -44
  267. package/lib/components/viewer2d/grids/grid-vertical-streak.js +0 -44
  268. package/lib/components/viewer2d/grids/grids.js +0 -44
  269. package/lib/components/viewer2d/group.js +0 -62
  270. package/lib/components/viewer2d/item.js +0 -521
  271. package/lib/components/viewer2d/layer.js +0 -171
  272. package/lib/components/viewer2d/line.js +0 -892
  273. package/lib/components/viewer2d/ruler.js +0 -107
  274. package/lib/components/viewer2d/rulerDist.js +0 -153
  275. package/lib/components/viewer2d/rulerX.js +0 -158
  276. package/lib/components/viewer2d/rulerY.js +0 -160
  277. package/lib/components/viewer2d/scene.js +0 -147
  278. package/lib/components/viewer2d/snap.js +0 -83
  279. package/lib/components/viewer2d/state.js +0 -87
  280. package/lib/components/viewer2d/utils.js +0 -210
  281. package/lib/components/viewer2d/vertex.js +0 -74
  282. package/lib/components/viewer2d/viewer2d.js +0 -1405
  283. package/lib/components/viewer3d/camera-controls-module/camera-controls.module.js +0 -2597
  284. package/lib/components/viewer3d/dcm.js +0 -407
  285. package/lib/components/viewer3d/fbm.js +0 -420
  286. package/lib/components/viewer3d/front3D.js +0 -75
  287. package/lib/components/viewer3d/grid-creator.js +0 -34
  288. package/lib/components/viewer3d/grids/grid-horizontal-streak.js +0 -44
  289. package/lib/components/viewer3d/grids/grid-streak.js +0 -35
  290. package/lib/components/viewer3d/grids/grid-vertical-streak.js +0 -44
  291. package/lib/components/viewer3d/libs/first-person-controls.js +0 -74
  292. package/lib/components/viewer3d/libs/helvetiker_regular.typeface.js +0 -1287
  293. package/lib/components/viewer3d/libs/mtl-loader.js +0 -363
  294. package/lib/components/viewer3d/libs/obj-loader.js +0 -468
  295. package/lib/components/viewer3d/libs/orbit-controls.js +0 -705
  296. package/lib/components/viewer3d/libs/pointer-lock-controls.js +0 -52
  297. package/lib/components/viewer3d/lrm.js +0 -311
  298. package/lib/components/viewer3d/model.js +0 -714
  299. package/lib/components/viewer3d/pointer-lock-navigation.js +0 -122
  300. package/lib/components/viewer3d/ruler-utils/itemRect.js +0 -68
  301. package/lib/components/viewer3d/ruler-utils/layer3D.js +0 -502
  302. package/lib/components/viewer3d/ruler-utils/ruler3D.js +0 -234
  303. package/lib/components/viewer3d/ruler-utils/scene3D.js +0 -68
  304. package/lib/components/viewer3d/ruler-utils/state3D.js +0 -25
  305. package/lib/components/viewer3d/scene-creator.js +0 -3642
  306. package/lib/components/viewer3d/three-memory-cleaner.js +0 -60
  307. package/lib/components/viewer3d/viewer3d-first-person.js +0 -320
  308. package/lib/components/viewer3d/viewer3d.js +0 -2532
  309. package/lib/constants.js +0 -645
  310. package/lib/index.js +0 -96
  311. package/lib/models.js +0 -517
  312. package/lib/plugins/SVGLoader.js +0 -1417
  313. package/lib/plugins/autosave.js +0 -39
  314. package/lib/plugins/console-debugger.js +0 -44
  315. package/lib/plugins/export.js +0 -33
  316. package/lib/plugins/keyboard.js +0 -107
  317. package/lib/reducers/areas-reducer.js +0 -18
  318. package/lib/reducers/export.js +0 -97
  319. package/lib/reducers/groups-reducer.js +0 -44
  320. package/lib/reducers/holes-reducer.js +0 -68
  321. package/lib/reducers/items-reducer.js +0 -146
  322. package/lib/reducers/lines-reducer.js +0 -51
  323. package/lib/reducers/project-reducer.js +0 -135
  324. package/lib/reducers/reducer.js +0 -26
  325. package/lib/reducers/scene-reducer.js +0 -34
  326. package/lib/reducers/user-reducer.js +0 -46
  327. package/lib/reducers/vertices-reducer.js +0 -25
  328. package/lib/reducers/viewer2d-reducer.js +0 -82
  329. package/lib/reducers/viewer3d-reducer.js +0 -63
  330. package/lib/shared-style.js +0 -72
  331. package/lib/styles/export.js +0 -13
  332. package/lib/translator/en.js +0 -110
  333. package/lib/translator/it.js +0 -85
  334. package/lib/translator/ru.js +0 -85
  335. package/lib/translator/translator.js +0 -90
  336. package/lib/utils/browser.js +0 -40
  337. package/lib/utils/email-validator.js +0 -10
  338. package/lib/utils/export.js +0 -56
  339. package/lib/utils/geometry.js +0 -2516
  340. package/lib/utils/get-edges-of-subgraphs.js +0 -34
  341. package/lib/utils/graph-cycles.js +0 -240
  342. package/lib/utils/graph-inner-cycles.js +0 -54
  343. package/lib/utils/graph.js +0 -157
  344. package/lib/utils/helper.js +0 -291
  345. package/lib/utils/history.js +0 -36
  346. package/lib/utils/id-broker.js +0 -25
  347. package/lib/utils/logger.js +0 -14
  348. package/lib/utils/math.js +0 -57
  349. package/lib/utils/molding.js +0 -895
  350. package/lib/utils/name-generator.js +0 -23
  351. package/lib/utils/objects-utils.js +0 -60
  352. package/lib/utils/phone-validator.js +0 -10
  353. package/lib/utils/process-black-list.js +0 -24
  354. package/lib/utils/react-if.js +0 -24
  355. package/lib/utils/snap-scene.js +0 -105
  356. package/lib/utils/snap.js +0 -249
  357. package/lib/utils/summarizeCart.js +0 -30
  358. package/lib/utils/threeCSG.es6.js +0 -503
  359. package/lib/version.js +0 -8
@@ -1,3608 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
3
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
6
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
7
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
- function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
9
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
- function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
12
- function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
13
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
14
- import * as Three from 'three';
15
- import { Color, Group } from 'three';
16
- import createGrid from "./grid-creator";
17
- import { disposeObject } from "./three-memory-cleaner";
18
- import { ANIMATE_STEP_MAX, ANIMATE_STEP_MIN, ARRAY_3D_MODES, ARROW_TEXT_BACKCOLOR, ARROW_TEXT_FONTFACE, ARROW_TEXT_FORECOLOR, BASE_CABINET_LAYOUTPOS, BOTTOM_MOLDING_LOCATION, DECIMAL_PLACES_2, DIFFERENT_VALUES_PATH_LENGTH, DISTANCE_EPSILON, EPSILON, MIDDLE_MOLDING_LOCATION, MODE_DRAGGING_ITEM_3D, MODE_DRAWING_ITEM_3D, MODE_IDLE, MODE_IDLE_3D, MODE_ROTATING_ITEM_3D, OBJTYPE_MESH, SHADE_DARK_PURPLE_COLOR, TOP_MOLDING_LOCATION, UNIT_CENTIMETER, WALL_CABINET_LAYOUTPOS } from "../../constants";
19
- import { GeometryUtils, IDBroker, MoldingUtils } from "../../utils/export";
20
- import convert from 'convert-units';
21
- import { verticesDistance } from "../../utils/geometry";
22
- import * as GeomUtils from "../../catalog/utils/geom-utils";
23
- import { loadTexture } from "../../catalog/utils/item-loader";
24
- import { returnReplaceableDeepSearchType } from "../viewer2d/utils";
25
- import { animateDoor, isElevationView, isEmpty, replaceMeshesWithLineSegments, translateDrawer } from "../../utils/helper";
26
- import { formatNumber } from "../../utils/math";
27
- var transformBox;
28
- export var fVLine = [];
29
- var scene_mode = null;
30
- export function parseData(sceneData, actions, catalog, camera, renderer, mode) {
31
- var planData = {
32
- catalog: catalog,
33
- sceneData: sceneData
34
- };
35
- window.planData = planData;
36
- planData.sceneGraph = {
37
- unit: sceneData.unit,
38
- layers: {},
39
- busyResources: {
40
- layers: {}
41
- },
42
- width: sceneData.width,
43
- height: sceneData.height,
44
- LODs: {}
45
- };
46
- planData.plan = new Three.Object3D();
47
- planData.plan.name = 'plan';
48
- planData.cam = new Three.Object3D();
49
- planData.cam.name = 'cam';
50
-
51
- // Add a grid to the plan
52
- planData.grid = createGrid(sceneData);
53
- planData.grid.name = 'grid';
54
- planData.boundingBox = new Three.Box3().setFromObject(planData.grid);
55
- planData.boundingBox.name = 'boundingBox';
56
- var promises = [];
57
- sceneData.layers.forEach(function (layer) {
58
- if (layer.id === sceneData.selectedLayer || layer.visible) {
59
- promises = promises.concat(createLayerObjects(layer, planData, sceneData, actions, catalog, mode, camera, renderer));
60
- }
61
- });
62
- var p1 = new Promise(function (resolve) {
63
- Promise.all(promises).then(function (value) {
64
- if (planData.plan.parent !== null && planData.plan.children.length !== 0) {
65
- updateBoundingBox(planData, false, mode);
66
-
67
- // if mode is elevation, build elevation scene
68
- if (isElevationView(mode)) buildElevationScene(planData, mode);
69
- }
70
- resolve('success');
71
- });
72
- });
73
- return {
74
- promise: p1,
75
- planData: planData
76
- };
77
-
78
- // return planData;
79
- }
80
- export function visibleTransformBox(flag) {
81
- // if (transformBox instanceof Three.Mesh)
82
- // transformBox.visible = flag;
83
- }
84
- var buildElevationScene = function buildElevationScene(planData, mode) {
85
- var scene = planData.plan.parent;
86
- scene.updateMatrixWorld();
87
- var ELEV_GRP = 'ELEV_GRP';
88
- var oldElevationGroup = scene.getObjectByName(ELEV_GRP);
89
- if (oldElevationGroup) oldElevationGroup.parent.remove(oldElevationGroup);
90
- var elevationGroup = new Three.Group();
91
- scene.traverse(function (obj) {
92
- if (obj.name == 'MainObject') {
93
- var clone = obj.clone();
94
- clone.name = '';
95
- clone.visible = obj.parent.visible;
96
- clone.applyMatrix4(obj.parent.matrixWorld);
97
- elevationGroup.add(clone);
98
- }
99
- });
100
- elevationGroup.name = ELEV_GRP;
101
- elevationGroup.visible = false;
102
- planData.elevationGroup = elevationGroup;
103
- scene.traverse(function (obj) {
104
- if (obj.name == 'MainObject') {
105
- replaceMeshesWithLineSegments(obj);
106
- }
107
- });
108
- scene.add(elevationGroup);
109
- };
110
- function createLayerObjects(layer, planData, sceneData, actions, catalog, mode, camera, renderer) {
111
- var promises = [];
112
- var moldingGroups = MoldingUtils.getAllMoldingGroups(layer);
113
- planData.sceneGraph.layers[layer.id] = {
114
- id: layer.id,
115
- lines: {},
116
- holes: {},
117
- areas: {},
118
- items: {},
119
- countertops: [],
120
- moldingGroups: moldingGroups,
121
- backsplashes: [],
122
- visible: layer.visible,
123
- altitude: layer.altitude
124
- };
125
- planData.sceneGraph.busyResources.layers[layer.id] = {
126
- id: layer.id,
127
- lines: {},
128
- holes: {},
129
- areas: {},
130
- items: {},
131
- moldingGroups: {}
132
- };
133
- // Import lines
134
- layer.lines.forEach(function (line) {
135
- promises.push(addLine(sceneData, planData, layer, line.id, catalog, actions.linesActions, mode));
136
- line.holes.forEach(function (holeID) {
137
- promises.push(addHole(sceneData, planData, layer, holeID, catalog, actions.holesActions, mode));
138
- });
139
- });
140
-
141
- // Import areas
142
- layer.areas.forEach(function (area) {
143
- promises.push(addArea(sceneData, planData, layer, area.id, catalog, actions.areaActions, mode));
144
- });
145
- // Import items
146
- layer.items.forEach(function (item) {
147
- promises.push(addItem(sceneData, planData, layer, item.id, catalog, actions.itemsActions, mode, null, null
148
- // false
149
- ));
150
- });
151
- return promises;
152
- }
153
- var canvas = document.createElement('canvas');
154
- canvas.width = 50;
155
- canvas.height = 100;
156
- canvas.style.width = 50 + 'px';
157
- canvas.style.height = 100 + 'px';
158
- var ctx = canvas.getContext('2d');
159
- ctx.fillStyle = '#FFFFFF';
160
- ctx.strokeStyle = '#ff7400';
161
- ctx.beginPath();
162
- ctx.arc(25, 25, 20, 0, 2 * Math.PI);
163
- ctx.fill();
164
- ctx.stroke();
165
- var img1 = new Image();
166
- img1.crossOrigin = 'anonymous';
167
- img1.src = '/assets/img/svg/3d_item_warning_info.svg';
168
- img1.onload = function () {
169
- ctx.drawImage(img1, 0, 0, 50, 50);
170
- };
171
- ctx.lineWidth = 4;
172
- ctx.beginPath();
173
- ctx.arc(25, 75, 20, 0, 2 * Math.PI);
174
- ctx.fill();
175
- ctx.stroke();
176
- var img2 = new Image();
177
- img2.crossOrigin = 'anonymous';
178
- img2.src = '/assets/img/svg/3d_item_warning_edit.svg';
179
- img2.onload = function () {
180
- ctx.drawImage(img2, 8, 58, 34, 34);
181
- };
182
- export function createWarningObject() {
183
- var warningTexture = new Three.Texture(canvas);
184
- warningTexture.needsUpdate = true;
185
- var warningObj = new Three.Sprite(new Three.SpriteMaterial({
186
- map: warningTexture,
187
- sizeAttenuation: true
188
- }));
189
- warningObj.material.transparent = true;
190
- warningObj.material.depthTest = false;
191
- warningObj.scale.set(20, 40, 20);
192
- warningObj.renderOrder = 3;
193
- warningObj.name = 'warningObj';
194
- return warningObj;
195
- }
196
- export function updateScene(planData, sceneData, oldSceneData, diffArray, actions, catalog) {
197
- var _draggingItem$toJS, _filteredDiffs, _filteredDiffs2;
198
- var mode = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
199
- var toolObj = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
200
- var angleObj = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : null;
201
- var draggingItem = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : null;
202
- var result = [];
203
- if (mode != null) {
204
- scene_mode = mode;
205
- }
206
- var splitted = diffArray.map(function (el) {
207
- return {
208
- op: el.op,
209
- path: el.path.split('/'),
210
- value: el.value
211
- };
212
- });
213
- var filteredDiffs = filterDiffs(splitted, sceneData, oldSceneData);
214
- //***testing additional filter***
215
- filteredDiffs = filteredDiffs.filter(function (_ref) {
216
- var path = _ref.path;
217
- return path[3] !== 'selected';
218
- });
219
- filteredDiffs = filteredDiffs.filter(function (_ref2) {
220
- var path = _ref2.path;
221
- return path[1] !== 'groups';
222
- });
223
- //*******************************
224
- //This is executed when dragging item is end and performs the updateing filteredDiffs.
225
- if ((sceneData === null || sceneData === void 0 ? void 0 : sceneData.isEndDragging) === true && draggingItem && !isEmpty((_draggingItem$toJS = draggingItem.toJS) === null || _draggingItem$toJS === void 0 ? void 0 : _draggingItem$toJS.call(draggingItem)) && ((_filteredDiffs = filteredDiffs) === null || _filteredDiffs === void 0 || (_filteredDiffs = _filteredDiffs[0]) === null || _filteredDiffs === void 0 || (_filteredDiffs = _filteredDiffs.path) === null || _filteredDiffs === void 0 ? void 0 : _filteredDiffs.length) < DIFFERENT_VALUES_PATH_LENGTH && (_filteredDiffs2 = filteredDiffs) !== null && _filteredDiffs2 !== void 0 && (_filteredDiffs2 = _filteredDiffs2[0]) !== null && _filteredDiffs2 !== void 0 && (_filteredDiffs2 = _filteredDiffs2.path) !== null && _filteredDiffs2 !== void 0 && _filteredDiffs2.includes('showfg')) {
226
- var _draggingItem$getIn, _draggingItem$getIn2;
227
- var layerID = (_draggingItem$getIn = draggingItem.getIn) === null || _draggingItem$getIn === void 0 ? void 0 : _draggingItem$getIn.call(draggingItem, ['layerID']);
228
- var itemID = (_draggingItem$getIn2 = draggingItem.getIn) === null || _draggingItem$getIn2 === void 0 ? void 0 : _draggingItem$getIn2.call(draggingItem, ['itemID']);
229
- if (layerID && itemID) {
230
- var _sceneData$getIn, _sceneData$getIn$toJS, _selLayer$items;
231
- filteredDiffs[0].path = ['', 'layers', layerID, 'items', itemID, 'distArray'];
232
- var selLayer = (_sceneData$getIn = sceneData.getIn) === null || _sceneData$getIn === void 0 || (_sceneData$getIn = _sceneData$getIn.call(sceneData, ['layers', layerID])) === null || _sceneData$getIn === void 0 || (_sceneData$getIn$toJS = _sceneData$getIn.toJS) === null || _sceneData$getIn$toJS === void 0 ? void 0 : _sceneData$getIn$toJS.call(_sceneData$getIn);
233
- var distArray = selLayer === null || selLayer === void 0 || (_selLayer$items = selLayer.items) === null || _selLayer$items === void 0 || (_selLayer$items = _selLayer$items[itemID]) === null || _selLayer$items === void 0 ? void 0 : _selLayer$items.distArray;
234
- filteredDiffs[0].value = distArray;
235
- }
236
- }
237
-
238
- // Check to see if diffs includes changes associated with doorStyle and global molding simultaneously.
239
- var isSettingDoorStyle = false; // If it includes any doorStyle change
240
- var isUpdateMolding = false; // If it includes any global molding change
241
- filteredDiffs.forEach(function (_ref3) {
242
- var path = _ref3.path;
243
- /**
244
- * Every 'doorStyle' change has a 'door_style_id' change.
245
- * So, if door_style_id changes, it indicates 'doorStyle' change.
246
- */
247
- if (['id'].includes(path[path.length - 1])) isSettingDoorStyle = true;
248
-
249
- // If there are any molding change of layer
250
- if (path[1] === 'layers' && path[3] === 'molding') isUpdateMolding = true;
251
- });
252
- if (isSettingDoorStyle && isUpdateMolding)
253
- /**
254
- * If so, any other changes could be ignored.
255
- * Because the molding change of layer invokes 'createLayerObject()'
256
- * and that function re-renders an whole layer.
257
- */
258
- filteredDiffs = filteredDiffs.filter(function (_ref4) {
259
- var path = _ref4.path;
260
- return path[1] === 'layers' && path[3] === 'molding';
261
- });
262
- filteredDiffs.forEach(function (_ref5) {
263
- var op = _ref5.op,
264
- path = _ref5.path,
265
- value = _ref5.value;
266
- /* First of all I need to find the object I need to update */
267
- if (path[1] === 'layers') {
268
- var layer = sceneData.getIn(['layers', path[2]]);
269
- if (path.length === 3 && op === 'remove') {
270
- removeLayer(path[2], planData);
271
- } else if (path.length > 3) {
272
- if (path.length > 5) if (path[5] === 'submodule' || path[5] === 'doorStyle' || path[5] === 'properties') op = 'replace';
273
- switch (op) {
274
- case 'replace':
275
- var promiseValue = replaceObject(path, layer, planData, actions, sceneData, oldSceneData, catalog, mode, value);
276
- if (promiseValue !== undefined) {
277
- result.push(promiseValue.promise);
278
- }
279
- break;
280
- case 'add':
281
- addObject(path, layer, planData, actions, sceneData, oldSceneData, catalog, mode, toolObj);
282
- break;
283
- case 'remove':
284
- if (angleObj) planData.plan.parent.remove(angleObj);
285
- if (toolObj) planData.plan.parent.remove(toolObj);
286
- deleteSpecifiedMeshObjects('WarningBox' + path[4]);
287
- deleteSpecifiedMeshObjects('backsplash' + path[4]);
288
- var item = oldSceneData.getIn(['layers', path[2]]).getIn(['items', path[4]]);
289
- deleteCountertop(planData.sceneGraph.layers[layer.id].countertops, item, planData, layer);
290
- removeObject(path, layer, planData, actions, sceneData, oldSceneData, catalog);
291
- break;
292
- }
293
- }
294
- } else if (path[1] === 'selectedLayer') {
295
- var layerSelectedID = value;
296
- var layerSelected = sceneData.getIn(['layers', layerSelectedID]);
297
- // First of all I check if the new selected layer is not visible
298
- if (!layerSelected.visible) {
299
- // I need to create the objects for this layer
300
- var promises = createLayerObjects(layerSelected, planData, sceneData, actions, catalog, mode);
301
- Promise.all(promises).then(function () {
302
- return updateBoundingBox(planData, false, mode);
303
- });
304
- }
305
- var layerGraph = planData.sceneGraph.layers[oldSceneData.selectedLayer];
306
- if (layerGraph) {
307
- if (!layerGraph.visible) {
308
- // I need to remove the objects for this layer
309
- for (var lineID in layerGraph.lines) removeLine(planData, layerGraph.id, lineID);
310
- for (var areaID in layerGraph.areas) removeArea(planData, layerGraph.id, areaID);
311
- for (var _itemID in layerGraph.items) removeItem(planData, layerGraph.id, _itemID);
312
- for (var holeID in layerGraph.holes) removeHole(planData, layerGraph.id, holeID);
313
- }
314
- }
315
- }
316
- });
317
- var p1 = new Promise(function (resolve) {
318
- Promise.all(result).then(function (replaceValue) {
319
- // if mode is elevation, build elevation scene
320
- // When scene is updated, replaceValue is not empty.
321
- if (isElevationView(mode) && !isEmpty(replaceValue)) buildElevationScene(planData, mode);
322
- resolve('successPromise');
323
- });
324
- });
325
- return {
326
- promise: p1,
327
- planData: planData
328
- };
329
- }
330
- var animate_objects = {};
331
- function myAnimRotate(obj, open_doors, item, isCorner) {
332
- var animateStep = animate_objects[obj.name].animateStep;
333
-
334
- // if open the door, animateStep increases to ANIMATE_STEP_MAX and if close the door, animateStep decreases to ANIMATE_STEP_MIN
335
- animateStep = open_doors ? animateStep + 1 : animateStep - 1;
336
-
337
- // clear interval when the opening or closing door is ended.
338
- if (animateStep > ANIMATE_STEP_MAX || animateStep < ANIMATE_STEP_MIN) {
339
- clearInterval(animate_objects[obj.name].animate_intervalID);
340
- return;
341
- }
342
- animate_objects[obj.name].animateStep = animateStep;
343
- animateDoor(animate_objects[obj.name].offset, obj, open_doors, item, isCorner, 'Opened3D');
344
- }
345
- function myAnimTranslate(obj, open_doors, item) {
346
- var animateStep = animate_objects[obj.name].animateStep;
347
- animateStep = open_doors ? animateStep + 1 : animateStep - 1;
348
- if (animateStep > ANIMATE_STEP_MAX || animateStep < ANIMATE_STEP_MIN) {
349
- clearInterval(animate_objects[obj.name].animate_intervalID);
350
- return;
351
- }
352
- animate_objects[obj.name].animateStep = animateStep;
353
- translateDrawer(item, obj, open_doors, 'Opened3D');
354
- }
355
- function replaceObject(modifiedPath, layer, planData, actions, sceneData, oldSceneData, catalog) {
356
- var mode = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
357
- var value = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : null;
358
- var promises = [];
359
- var matchStr = /\d_(door[^LR1-9]*)(_[LR])?(_[1-9])?$/;
360
- switch (modifiedPath[3]) {
361
- case 'vertices':
362
- if (modifiedPath[5] !== 'selected') {
363
- var vertex = layer.getIn(['vertices', modifiedPath[4]]);
364
- if (modifiedPath[5] === 'x' || modifiedPath[5] === 'y') {
365
- vertex.lines.forEach(function (lineID) {
366
- var lineHoles = oldSceneData.getIn(['layers', layer.id, 'lines', lineID, 'holes']);
367
- if (lineHoles) lineHoles.forEach(function (holeID) {
368
- replaceObject([0, 0, 0, 'holes', holeID, 'selected'], layer, planData, actions, sceneData, oldSceneData, catalog, mode);
369
- });
370
- return replaceObject([0, 0, 0, 'lines', lineID], layer, planData, actions, sceneData, oldSceneData, catalog, mode);
371
- });
372
- vertex.areas.forEach(function (areaID) {
373
- return replaceObject([0, 0, 0, 'areas', areaID], layer, planData, actions, sceneData, oldSceneData, catalog, mode);
374
- });
375
- }
376
- if (modifiedPath[5] === 'areas') {
377
- var areaID = vertex.getIn(['areas', ~~modifiedPath[6]]);
378
- replaceObject([0, 0, 0, 'areas', areaID], layer, planData, actions, sceneData, oldSceneData, catalog, mode);
379
- }
380
- }
381
- break;
382
- case 'holes':
383
- var newHoleData = layer.getIn(['holes', modifiedPath[4]]);
384
- if (catalog.getElement(newHoleData.type).updateRender3D) {
385
- promises.push(updateHole(sceneData, oldSceneData, planData, layer, modifiedPath[4], modifiedPath.slice(5), catalog, actions.holesActions, function () {
386
- return removeHole(planData, layer.id, newHoleData.id);
387
- }, function () {
388
- return addHole(sceneData, planData, layer, newHoleData.id, catalog, actions.holesActions, mode);
389
- }));
390
- } else {
391
- var lineID = newHoleData.line;
392
- if (modifiedPath[5] === 'selected' || scene_mode === 'MODE_DRAWING_HOLE_3D' || scene_mode === 'MODE_DRAGGING_HOLE_3D') {
393
- // I remove only the hole without removing the wall
394
- removeHole(planData, layer.id, newHoleData.id);
395
- promises.push(addHole(sceneData, planData, layer, newHoleData.id, catalog, actions.holesActions, mode));
396
- } else {
397
- layer.getIn(['lines', lineID, 'holes']).forEach(function (holeID) {
398
- removeHole(planData, layer.id, holeID);
399
- });
400
- removeLine(planData, layer.id, lineID);
401
- promises.push(addLine(sceneData, planData, layer, lineID, catalog, actions.linesActions));
402
- layer.getIn(['lines', lineID, 'holes']).forEach(function (holeID) {
403
- promises.push(addHole(sceneData, planData, layer, holeID, catalog, actions.holesActions, mode));
404
- });
405
- }
406
- }
407
- break;
408
- case 'lines':
409
- var line = layer.getIn(['lines', modifiedPath[4]]);
410
- if (catalog.getElement(line.type).updateRender3D) {
411
- promises.push(updateLine(sceneData, oldSceneData, planData, layer, modifiedPath[4], modifiedPath.slice(5), catalog, actions.linesActions, function () {
412
- return removeLine(planData, layer.id, modifiedPath[4]);
413
- }, function () {
414
- return addLine(sceneData, planData, layer, modifiedPath[4], catalog, actions.linesActions);
415
- }));
416
- } else {
417
- removeLine(planData, layer.id, modifiedPath[4]);
418
- promises.push(addLine(sceneData, planData, layer, modifiedPath[4], catalog, actions.linesActions));
419
- }
420
- break;
421
- case 'areas':
422
- var area = layer.getIn(['areas', modifiedPath[4]]);
423
- if (catalog.getElement(area.type).updateRender3D) {
424
- promises.push(updateArea(sceneData, oldSceneData, planData, layer, modifiedPath[4], modifiedPath.slice(5), catalog, actions.areaActions, function () {
425
- return removeArea(planData, layer.id, modifiedPath[4]);
426
- }, function () {
427
- return addArea(sceneData, planData, layer, modifiedPath[4], catalog, actions.areaActions);
428
- }));
429
- } else {
430
- if (planData.sceneGraph.layers[layer.id].areas[modifiedPath[4]]) {
431
- removeArea(planData, layer.id, modifiedPath[4]);
432
- }
433
- promises.push(addArea(sceneData, planData, layer, modifiedPath[4], catalog, actions.areaActions));
434
- }
435
- break;
436
- case 'items':
437
- var item = layer.getIn(['items', modifiedPath[4]]);
438
- deleteCountertop(planData.sceneGraph.layers[layer.id].countertops, item, planData, layer);
439
- var tmpMoldings = _toConsumableArray(planData.sceneGraph.layers[layer.id].moldingGroups);
440
- if (catalog.getElement(item.type).updateRender3D) {
441
- promises.push(updateItem(sceneData, oldSceneData, planData, layer, modifiedPath[4], modifiedPath.slice(5), catalog, actions.itemsActions, function () {
442
- return removeItem(planData, layer.id, modifiedPath[4], oldSceneData.getIn(['layers', layer.id]), layer);
443
- }, function () {
444
- return addItem(sceneData, planData, layer, modifiedPath[4], catalog, actions.itemsActions, mode);
445
- }));
446
- } else {
447
- var item3D = null;
448
- try {
449
- item3D = planData.sceneGraph.layers[layer.id].items[modifiedPath[4]];
450
- } catch (err) {
451
- console.log('modifiedPath: ', modifiedPath, '\nError: ', err);
452
- return;
453
- }
454
- if (!item3D) return;
455
- var keyIndex = modifiedPath.length - 1;
456
- if (modifiedPath[keyIndex] == 'rotation') {
457
- item3D.rotation.set(0, value * Math.PI / 180 + Math.PI, 0);
458
- setTimeout(function () {
459
- getDistances(layer);
460
- }, 50);
461
- removeSelItemMesh(tmpMoldings, item, planData, mode);
462
- } else if (modifiedPath[keyIndex] == 'x') {
463
- item3D.position.x = value;
464
- setTimeout(function () {
465
- getDistances(layer);
466
- }, 50);
467
- removeSelItemMesh(tmpMoldings, item, planData, mode);
468
- } else if (modifiedPath[keyIndex] == 'y') {
469
- item3D.position.z = -value;
470
- setTimeout(function () {
471
- getDistances(layer);
472
- }, 50);
473
- removeSelItemMesh(tmpMoldings, item, planData, mode);
474
- } else if (modifiedPath[keyIndex] == 'selected') {
475
- var itemType = !!catalog.elements[item.type] ? catalog.elements[item.type].type : catalog.elements[returnReplaceableDeepSearchType(item.type)].type;
476
- if (value == false) {
477
- item3D.children[0].children = item3D.children[0].children.filter(function (item3DElement) {
478
- return item3DElement.name !== 'TransformBox' && item3DElement.name !== 'TransformGizmo';
479
- });
480
- if (item3D) {
481
- if (item3D.children.length > 1) {
482
- item3D.children.pop();
483
- }
484
- var mBoxColor = 0x99c3fb;
485
- var _item = item.toJS();
486
- if (_item.doorStyle.doorStyles !== undefined && _item.doorStyle.doorStyles.cds) {
487
- if (showYelloBox(_item)) {
488
- mBoxColor = 'rgba(232,187,47,1)';
489
- var mBox = GeomUtils.makeMBoxfromObject(item3D, mBoxColor);
490
- var warningObj = createWarningObject();
491
- warningObj.position.set(0, item.properties.get('height').get('length') / 3, 0);
492
- if (mBox) {
493
- mBox.add(warningObj);
494
- item3D.add(mBox);
495
- }
496
- }
497
- }
498
- }
499
- var temp_MGArray = planData.sceneGraph.layers[layer.id].moldingGroups;
500
- } else {
501
- if (item3D.name !== 'pivot' && item3D.children[0].children[item3D.children[0].children.length - 1].name == 'TransformGizmo') return;
502
- if (item3D.children[0].children[item3D.children[0].children.length - 1].name == 'TransformGizmo') {
503
- item3D.children[0].children.pop();
504
- }
505
- var object = item3D.children[0].clone();
506
- if (item3D.children.length > 1) {
507
- item3D.children.pop();
508
- }
509
- item3D.children.pop();
510
- var altitude = item.properties.get('altitude').get('length');
511
- var scalevec = new Three.Vector3(object.scale.x, object.scale.y, object.scale.z);
512
- var posVec = new Three.Vector3(object.position.x, object.position.y, object.position.z);
513
- var newAltitude = item.properties.get('altitude').get('_length');
514
- var newUnit = item.properties.get('altitude').get('_unit') || 'in';
515
- newAltitude = convert(newAltitude).from(newUnit).to(sceneData.unit);
516
- var newWidth = item.properties.get('width').get('_length');
517
- var newWidthUnit = item.properties.get('width').get('_unit') || 'in';
518
- newWidth = convert(newWidth).from(newWidthUnit).to('in');
519
- var newHeight = item.properties.get('height').get('_length');
520
- var newHeightUnit = item.properties.get('height').get('_unit') || 'in';
521
- newHeight = convert(newHeight).from(newHeightUnit).to('in');
522
- var newDepth = item.properties.get('depth').get('_length');
523
- var newDepthUnit = item.properties.get('depth').get('_unit') || 'in';
524
- newDepth = convert(newDepth).from(newDepthUnit).to('in');
525
- var sizeinfo = !!catalog.elements[item.type] ? catalog.elements[item.type].info.sizeinfo : catalog.elements[returnReplaceableDeepSearchType(item.type)].info.sizeinfo;
526
- object.scale.set(1 * newWidth / sizeinfo.width, 1 * newHeight / sizeinfo.height, 1 * newDepth / sizeinfo.depth);
527
- object.position.set(0, 0, 0);
528
- object.rotation.set(0, 0, 0);
529
- var box = GeomUtils.baseBoxHelper(object, 0xffffff);
530
- box.material.lineWidth = 0.01;
531
- var boundingBox = GeomUtils.baseBox3FromObject(object);
532
- var max = boundingBox.max;
533
- var min = boundingBox.min;
534
- var radius = Math.sqrt((boundingBox.max.x - boundingBox.min.x) * (boundingBox.max.x - boundingBox.min.x) + (boundingBox.max.z - boundingBox.min.z) * (boundingBox.max.z - boundingBox.min.z)) / 2;
535
- var moveBox = new Three.BoxGeometry(max.x - min.x, max.y - min.y, max.z - min.z);
536
-
537
- // translate Object
538
- var controlGeom = GeomUtils.controlGeom();
539
-
540
- // rotate Object //////////
541
- var rotGeom = GeomUtils.rotGeoms(radius + 0.05);
542
- // //////////////////////////////////
543
- // upwards Geometry///////////
544
- var upwardsGeom = GeomUtils.upwardsGeom();
545
- var vLineGeom = new Three.BufferGeometry();
546
- var vertices = [(max.x - min.x) / 2 + min.x, 0, max.z, (max.x - min.x) / 2 + min.x, 0, max.z + 1.3];
547
- vLineGeom.setAttribute('position', new Three.BufferAttribute(new Float32Array(vertices), 3));
548
- vLineGeom.attributes.position.needsUpdate = true;
549
- var vLineGeom1 = new Three.BufferGeometry();
550
- var vertices1 = [(max.x - min.x) / 2 + min.x, 0, min.z, (max.x - min.x) / 2 + min.x, 0, min.z - 1.3];
551
- vLineGeom1.setAttribute('position', new Three.BufferAttribute(new Float32Array(vertices1), 3));
552
- vLineGeom1.attributes.position.needsUpdate = true;
553
- var vLineGeom2 = new Three.BufferGeometry();
554
- var vertices2 = [max.x, 0, max.z - (max.z - min.z) / 2, max.x + 1.3, 0, max.z - (max.z - min.z) / 2];
555
- vLineGeom2.setAttribute('position', new Three.BufferAttribute(new Float32Array(vertices2), 3));
556
- var vLineGeom3 = new Three.BufferGeometry();
557
- var vertices3 = [min.x, 0, max.z - (max.z - min.z) / 2, min.x - 1.3, 0, max.z - (max.z - min.z) / 2];
558
- vLineGeom3.setAttribute('position', new Three.BufferAttribute(new Float32Array(vertices3), 3));
559
- // ///////////////////////////////////////
560
-
561
- // set names of transform object
562
- var rotFillObj = new Three.Mesh(rotGeom.rotFill, new Three.MeshPhongMaterial({
563
- color: 0x000000,
564
- side: Three.DoubleSide,
565
- colorWrite: true
566
- }));
567
- var rotStrokeObj = new Three.Line(rotGeom.rotStroke, new Three.LineBasicMaterial({
568
- color: 0xffffff,
569
- colorWrite: true
570
- }));
571
- rotFillObj.name = 'rotate';
572
- var upObj = new Three.Mesh(upwardsGeom, new Three.MeshBasicMaterial({
573
- color: 0x000000,
574
- side: Three.DoubleSide
575
- }));
576
- // let upLine = new Three.Line(upwardsGeom, new Three.LineBasicMaterial({ color: 0x000000 }));
577
- // upLine.name = "transUp";
578
- // upObj.add(upLine);
579
- upObj.name = 'transUp';
580
- var upwardbox = new Three.BoxHelper(upObj, 0x326780);
581
- upwardbox.material.lineWidth = 0.01;
582
- fVLine = [];
583
- // let obj = new Three.Mesh(controlGeom, new Three.MeshPhongMaterial({ color: 0xffffff, side: Three.DoubleSide, colorWrite: true }));
584
- // obj.name = "translateX";
585
- var color = SHADE_DARK_PURPLE_COLOR;
586
- var _mBox = new Three.Mesh(moveBox, new Three.MeshBasicMaterial({
587
- color: 0xdd6699,
588
- side: Three.DoubleSide,
589
- transparent: true,
590
- opacity: 0.4
591
- }));
592
- var vLine = new Three.Line(vLineGeom, new Three.LineBasicMaterial({
593
- color: color
594
- }));
595
- var vLine1 = new Three.Line(vLineGeom1, new Three.LineBasicMaterial({
596
- color: color
597
- }));
598
- var vLine2 = new Three.Line(vLineGeom2, new Three.LineBasicMaterial({
599
- color: color
600
- }));
601
- var vLine3 = new Three.Line(vLineGeom3, new Three.LineBasicMaterial({
602
- color: color
603
- }));
604
- fVLine.push(vLine);
605
- fVLine.push(vLine1);
606
- fVLine.push(vLine2);
607
- fVLine.push(vLine3);
608
- vLine.renderOrder = 1;
609
- vLine1.renderOrder = 1;
610
- vLine2.renderOrder = 1;
611
- vLine3.renderOrder = 1;
612
- vLine.material.transparent = true;
613
- vLine1.material.transparent = true;
614
- vLine2.material.transparent = true;
615
- vLine3.material.transparent = true;
616
- vLine.material.depthTest = false;
617
- vLine1.material.depthTest = false;
618
- vLine2.material.depthTest = false;
619
- vLine3.material.depthTest = false;
620
- var uVec = new Three.Vector3(-posVec.x / scalevec.x, -posVec.y / scalevec.y, -posVec.z / scalevec.z);
621
- var blLighting = item.type.includes('Light');
622
- vLine.translateY(blLighting ? 1.6 : 0.1);
623
- vLine1.translateY(blLighting ? 1.6 : 0.1);
624
- vLine2.translateY(blLighting ? 1.6 : 0.1);
625
- vLine3.translateY(blLighting ? 1.6 : 0.1);
626
- upObj.translateOnAxis(uVec, 1);
627
- upObj.translateY(max.y - min.y);
628
- _mBox.name = 'TransformBox';
629
- _mBox.translateOnAxis(new Three.Vector3(uVec.x, uVec.y + (max.y - min.y) / 2, uVec.z), 1);
630
- _mBox.scale.set(1.01, 1.01, 1.01);
631
- var rotFillObj1 = rotFillObj.clone();
632
- var rotStrokeObj1 = rotStrokeObj.clone();
633
- rotFillObj1.rotateY(Math.PI);
634
- rotStrokeObj1.rotateY(Math.PI);
635
- var asrtObj = new Three.Group();
636
- // let asrtObj1 = new Three.Group();
637
- // asrtObj.add(obj);
638
- // asrtObj.add(obj1);
639
- rotFillObj.translateY(blLighting ? 1.6 : 0.1);
640
- rotFillObj1.translateY(blLighting ? 1.6 : 0.1);
641
- rotStrokeObj.translateY(blLighting ? 1.6 : 0.1);
642
- rotStrokeObj1.translateY(blLighting ? 1.6 : 0.1);
643
- upObj.translateY(posVec.y / scalevec.y);
644
- upObj.add(upwardbox);
645
- //asrtObj.add(upObj);
646
- // vLine.translateY(posVec.y / scalevec.y);
647
- // vLine1.translateY(posVec.y / scalevec.y);
648
- // vLine2.translateY(posVec.y / scalevec.y);
649
- // vLine3.translateY(posVec.y / scalevec.y);
650
-
651
- _mBox.translateY(posVec.y / scalevec.y);
652
- // asrtObj.add(rotFillObj);
653
- // asrtObj.add(rotFillObj1);
654
- // asrtObj.add(rotStrokeObj);
655
- // asrtObj.add(rotStrokeObj1);
656
- asrtObj.add(vLine);
657
- asrtObj.add(vLine1);
658
- asrtObj.add(vLine2);
659
- asrtObj.add(vLine3);
660
- asrtObj.add(box);
661
- asrtObj.scale.set(1 / object.scale.x, object.scale.y, 1 / object.scale.z);
662
- _mBox.visible = false;
663
- // transformBox = mBox;
664
- // asrtObj.add(mBox);
665
- asrtObj.name = 'TransformGizmo';
666
- object.add(asrtObj);
667
- object.position.x = posVec.x;
668
- object.position.y = posVec.y;
669
- object.position.z = posVec.z;
670
- // object.rotation.y = Math.PI;
671
- object.scale.set(scalevec.x, scalevec.y, scalevec.z);
672
- item3D.add(object);
673
- if (item3D) {
674
- var _mBoxColor = 0x99c3fb;
675
- var _item2 = item.toJS();
676
- if (_item2.doorStyle.doorStyles !== undefined && _item2.doorStyle.doorStyles.cds) {
677
- if (showYelloBox(_item2)) {
678
- _mBoxColor = 'rgba(232,187,47,1)';
679
- var _mBox2 = GeomUtils.makeMBoxfromObject(item3D, _mBoxColor);
680
- var _warningObj = createWarningObject();
681
- _warningObj.position.set(0, item.properties.get('height').get('length') / 3, 0);
682
- if (_mBox2) {
683
- _mBox2.add(_warningObj);
684
- item3D.add(_mBox2);
685
- }
686
- }
687
- }
688
- }
689
- applyInteract(item3D, function () {
690
- // closes the setting dialog
691
- // document.getElementById('setting_dialog').style.display = 'none';
692
- return actions.itemsActions.selectItem(layer.id, modifiedPath[4]);
693
- });
694
- setTimeout(function () {
695
- getDistances(layer);
696
- }, 100);
697
- }
698
- } else if (modifiedPath[keyIndex] == 'length') {
699
- var _object = item3D.children[0];
700
- var prevPos = _object.position;
701
- _object.position.set(prevPos.x, value, prevPos.z);
702
- } else if (modifiedPath[keyIndex] == 'flip_doorhandle') {
703
- updateDoorHandleMesh(item, item3D, value);
704
- var _object2 = item3D.children[0];
705
- var door_animate_offset = _object2.userData.door_animate_offset;
706
- var _loop = function _loop(it) {
707
- if (_object2.children.filter(function (elem) {
708
- return elem.name === it;
709
- }).length) {
710
- var door_match = it.match(matchStr);
711
- var rotate_match_text = item.properties.toJS().flip_doorhandle ? 'rotate_L' : 'rotate_R';
712
- if (door_match[2] === '_L') {
713
- rotate_match_text = item.properties.toJS().flip_doorhandle ? 'rotate_R' : 'rotate_L';
714
- }
715
- _object2.children.filter(function (elem) {
716
- return elem.name === it;
717
- })[0].children[0].children.forEach(function (child) {
718
- if (child.name.endsWith(rotate_match_text)) {
719
- door_animate_offset[it] = {
720
- x: child.position.x,
721
- y: child.position.y,
722
- z: child.position.z
723
- };
724
- }
725
- });
726
- }
727
- };
728
- for (var it in door_animate_offset) {
729
- _loop(it);
730
- }
731
- _object2.userData.door_animate_offset = door_animate_offset;
732
- } else if (modifiedPath[keyIndex] == 'animValue') {
733
- return;
734
- } else if (modifiedPath[keyIndex] == 'open_doors') {
735
- var _object3 = item3D.children[0];
736
- var userData = item3D.children[0].userData;
737
- var moveObjectChildrens = [];
738
- var selectedItem = layer.getIn(['items', layer.selected.toJS().items[0]]).toJS();
739
- _object3.children.forEach(function (child, idx) {
740
- var object_match = child.name.match(/\d_(interior_drawer[^LR1-9]*)(_[LR1-9])?$/) || child.name.match(matchStr);
741
- if (object_match && object_match.length > 2) {
742
- moveObjectChildrens.push({
743
- type: object_match[1],
744
- obj: child
745
- });
746
- animate_objects[child.name] = animate_objects[child.name] || {};
747
- }
748
- });
749
- var temp = moveObjectChildrens.filter(function (item) {
750
- var _object3$userData$doo;
751
- return (_object3$userData$doo = _object3.userData.door_animate_offset[item.obj.name]) === null || _object3$userData$doo === void 0 ? void 0 : _object3$userData$doo.isCorner;
752
- });
753
- var isCorner = temp.length > 0;
754
- moveObjectChildrens.forEach(function (element) {
755
- var _animate_objects$elem, _animate_objects$elem2;
756
- if (((_animate_objects$elem = animate_objects[element.obj.name]) === null || _animate_objects$elem === void 0 ? void 0 : _animate_objects$elem.animateStep) === undefined) {
757
- animate_objects[element.obj.name].animateStep = selectedItem.properties.open_doors ? ANIMATE_STEP_MIN : ANIMATE_STEP_MAX;
758
- }
759
-
760
- // clear origin Interval.
761
- if ((_animate_objects$elem2 = animate_objects[element.obj.name]) !== null && _animate_objects$elem2 !== void 0 && _animate_objects$elem2.animate_intervalID) {
762
- var _animate_objects$elem3;
763
- clearInterval((_animate_objects$elem3 = animate_objects[element.obj.name]) === null || _animate_objects$elem3 === void 0 ? void 0 : _animate_objects$elem3.animate_intervalID);
764
- }
765
- if (element.type === 'door') {
766
- var _userData$door_animat, _element$obj;
767
- // This is excuted when item has door.
768
- var offset = userData === null || userData === void 0 || (_userData$door_animat = userData.door_animate_offset) === null || _userData$door_animat === void 0 ? void 0 : _userData$door_animat[element === null || element === void 0 || (_element$obj = element.obj) === null || _element$obj === void 0 ? void 0 : _element$obj.name];
769
- if (offset) {
770
- var _offset$x, _offset$y, _offset$z;
771
- animate_objects[element.obj.name].offset = {
772
- x: (_offset$x = offset.x) !== null && _offset$x !== void 0 ? _offset$x : 0,
773
- y: (_offset$y = offset.y) !== null && _offset$y !== void 0 ? _offset$y : 0,
774
- z: (_offset$z = offset.z) !== null && _offset$z !== void 0 ? _offset$z : 0
775
- };
776
- } else {
777
- var _element$obj2;
778
- console.warn('⚠ Missing door_animate_offset for', element === null || element === void 0 || (_element$obj2 = element.obj) === null || _element$obj2 === void 0 ? void 0 : _element$obj2.name);
779
- animate_objects[element.obj.name].offset = {
780
- x: 0,
781
- y: 0,
782
- z: 0
783
- };
784
- }
785
-
786
- // Set the interval ID to new interval ID
787
- animate_objects[element.obj.name].animate_intervalID = setInterval(function () {
788
- myAnimRotate(element.obj, selectedItem.properties.open_doors, selectedItem, isCorner);
789
- }, 30);
790
- } else {
791
- // This is excuted when item has drawer box
792
- // Set the interval ID to new interval ID
793
- animate_objects[element.obj.name].animate_intervalID = setInterval(function () {
794
- myAnimTranslate(element.obj, selectedItem.properties.open_doors, selectedItem);
795
- }, 30);
796
- }
797
- });
798
- } else if (['_length', 'doorStyle', 'cabinet_door_style_id', 'counterTop', 'texture', 'drawer_door_handle_1_gltf'].includes(modifiedPath[keyIndex])) {
799
- var rItem = planData.sceneGraph.layers[layer.id].items[modifiedPath[4]];
800
- if (rItem) {
801
- if (rItem.children.length > 1) {
802
- rItem.children.pop();
803
- }
804
- var _mBoxColor2 = 0x99c3fb;
805
- var _item3 = item.toJS();
806
- if (_item3.doorStyle.doorStyles !== undefined && _item3.doorStyle.doorStyles.cds) {
807
- if (showYelloBox(_item3)) {
808
- _mBoxColor2 = 'rgba(232,187,47,1)';
809
- }
810
- }
811
- rItem.children[0].children.forEach(function (rItemElement) {
812
- rItemElement.visible = false;
813
- });
814
- var _mBox3 = GeomUtils.makeMBoxfromObject(rItem, _mBoxColor2);
815
- if (_mBox3) {
816
- //rItem.add (mBox);
817
- }
818
- }
819
- if (rItem != null) {
820
- removeItemWithoutItem(planData, layer.id, modifiedPath[4]);
821
- promises.push(addItem(sceneData, planData, layer, modifiedPath[4], catalog, actions.itemsActions, mode, null, rItem));
822
- setTimeout(function () {
823
- getDistances(layer);
824
- }, 100);
825
- }
826
- break;
827
- }
828
- }
829
- item = layer.getIn(['items', modifiedPath[4]]);
830
- addCountertop(planData.sceneGraph.layers[layer.id].countertops, item, planData, layer);
831
- // Toggle selection should not update molding
832
- if (item.category === 'cabinet' && modifiedPath[modifiedPath.length - 1] !== 'selected') {
833
- planData.sceneGraph.layers[layer.id].moldingGroups = addMolding(tmpMoldings, item, planData, layer, actions.itemsActions, mode) || _toConsumableArray(tmpMoldings);
834
- }
835
- break;
836
- case 'visible':
837
- if (!layer.visible) {
838
- var _layerGraph = planData.sceneGraph.layers[layer.id];
839
- for (var _lineID in _layerGraph.lines) removeLine(planData, layer.id, _lineID);
840
- for (var _areaID in _layerGraph.areas) removeArea(planData, layer.id, _areaID);
841
- for (var itemID in _layerGraph.items) removeItem(planData, layer.id, itemID);
842
- for (var holeID in _layerGraph.holes) removeHole(planData, layer.id, holeID);
843
- } else {
844
- promises = promises.concat(createLayerObjects(layer, planData, sceneData, actions, catalog, mode));
845
- }
846
- break;
847
- case 'unit':
848
- case 'ceilHeight':
849
- case 'opacity':
850
- case 'altitude':
851
- case 'molding':
852
- var layerGraph = planData.sceneGraph.layers[layer.id];
853
- for (var _lineID2 in layerGraph.lines) removeLine(planData, layer.id, _lineID2);
854
- for (var _areaID2 in layerGraph.areas) removeArea(planData, layer.id, _areaID2);
855
- for (var _itemID2 in layerGraph.items) removeItem(planData, layer.id, _itemID2);
856
- for (var _holeID in layerGraph.holes) removeHole(planData, layer.id, _holeID);
857
- promises = promises.concat(createLayerObjects(layer, planData, sceneData, actions, catalog, mode));
858
- }
859
- var p1 = new Promise(function (resolve) {
860
- Promise.all(promises).then(function (values) {
861
- updateBoundingBox(planData, true, mode);
862
- resolve('replaceObject');
863
- });
864
- });
865
- return {
866
- promise: p1
867
- };
868
- }
869
- export function getDistances(layer, isCalcWall) {
870
- fVLine.forEach(function (line, index) {
871
- getLineDistance(line, layer, isCalcWall === undefined ? false : isCalcWall, index);
872
- });
873
- }
874
- function getLineDistance(obj, layer, isCalcWall, index) {
875
- if (obj === undefined) return;
876
- var positionAttribute = obj.geometry.attributes.position;
877
- if (positionAttribute === undefined) return;
878
- var wPoint0 = new Three.Vector3().fromBufferAttribute(positionAttribute, 0).applyMatrix4(obj.matrixWorld);
879
- var wPoint1 = new Three.Vector3().fromBufferAttribute(positionAttribute, 1).applyMatrix4(obj.matrixWorld);
880
- var raycaster = new Three.Raycaster(wPoint0, new Three.Vector3(wPoint1.x - wPoint0.x, wPoint1.y - wPoint0.y, wPoint1.z - wPoint0.z));
881
- var rayDirection = raycaster.ray.direction;
882
- raycaster.camera = new Three.Camera();
883
- rayDirection.normalize();
884
- var meshes = [];
885
- planData.plan.traverse(function (child) {
886
- if (child.isMesh && child.geometry) {
887
- meshes.push(child);
888
- }
889
- });
890
- var intersects = raycaster.intersectObjects(meshes, true);
891
- var lx = wPoint0.x - wPoint1.x;
892
- var ly = wPoint0.y - wPoint1.y;
893
- var lz = wPoint0.z - wPoint1.z;
894
- var length = Math.sqrt(lx * lx + ly * ly + lz * lz);
895
- var scale = 1;
896
- var extrudeSettings = {
897
- steps: 2,
898
- depth: 0.01,
899
- bevelEnabled: false
900
- };
901
- var w = 0.2;
902
- var h = w * (Math.sqrt(3) / 2);
903
- var shape = new Three.Shape();
904
- shape.moveTo(0, 0);
905
- shape.lineTo(-w / 4, h / 2);
906
- shape.lineTo(w / 4, h / 2);
907
- var geom = new Three.ExtrudeGeometry(shape, extrudeSettings);
908
- geom.center();
909
- if (!isCalcWall) {
910
- for (var i = 0; i < intersects.length; i++) {
911
- if (intersects[i].object.name != 'TransformBox' && !intersects[i].object.name.includes('WarningBox') && intersects[i].object.type != 'Line' && intersects[i].object.name != 'rotate' && intersects[i].object.name != 'lineText' && intersects[i].object.type != 'BoxHelper' && !intersects[i].object.name.includes('molding') && intersects[i].object.name != 'soul') {
912
- scale = intersects[i].distance / length;
913
- if (intersects[i].distance <= 0.1) {
914
- scale = 0.1 / length;
915
- }
916
- obj.userData.distance = intersects[i].distance;
917
- obj.userData.target = intersects[i].object;
918
- var originPoint = obj.geometry.attributes.position.array.slice(0, 3);
919
- var _lx = obj.geometry.attributes.position.array[3] - obj.geometry.attributes.position.array[0];
920
- var _ly = obj.geometry.attributes.position.array[4] - obj.geometry.attributes.position.array[1];
921
- var _lz = obj.geometry.attributes.position.array[5] - obj.geometry.attributes.position.array[2];
922
- var newVec = new Three.Vector3(originPoint[0] + _lx * scale, originPoint[1] + _ly * scale, originPoint[2] + _lz * scale);
923
- obj.geometry.attributes.position.array[3] = newVec.x;
924
- obj.geometry.attributes.position.array[4] = newVec.y;
925
- obj.geometry.attributes.position.array[5] = newVec.z;
926
- obj.geometry.attributes.position.needsUpdate = true;
927
- obj.geometry.computeBoundingSphere();
928
- obj.geometry.computeBoundingBox();
929
- var dist = formatNumber(convert(intersects[i].distance).from('cm').to('in'), DECIMAL_PLACES_2);
930
- if (dist > 3) {
931
- var _canvas = getTextCanvas(dist);
932
- var wid = _canvas.width / window.innerWidth * 30;
933
- var hei = _canvas.height / window.innerHeight * 30;
934
- var texture = new Three.Texture(_canvas);
935
- texture.minFilter = Three.LinearFilter;
936
- texture.needsUpdate = true;
937
- var geometry = new Three.PlaneGeometry(wid / 5, hei / 5);
938
- geometry.computeBoundingBox();
939
- var material = new Three.MeshBasicMaterial({
940
- map: texture,
941
- side: Three.DoubleSide
942
- });
943
- var textMesh = new Three.Mesh(geometry, material);
944
- for (; obj.children.length != 0;) {
945
- var temp = obj.children.pop();
946
- disposeObject(temp);
947
- }
948
- textMesh.rotation.set(Math.PI / 2, Math.PI, 0);
949
- // obj.add(textMesh);
950
- textMesh.position.set((obj.geometry.attributes.position.array[0] + obj.geometry.attributes.position.array[3]) / 2, 0.01, (obj.geometry.attributes.position.array[2] + obj.geometry.attributes.position.array[5]) / 2);
951
- textMesh.name = 'lineText';
952
- textMesh.renderOrder = 2;
953
- textMesh.material.depthTest = false;
954
- textMesh.material.transparent = true;
955
- var sprite1 = new Three.Sprite(new Three.SpriteMaterial({
956
- map: texture
957
- }));
958
- sprite1.position.set((obj.geometry.attributes.position.array[0] + obj.geometry.attributes.position.array[3]) / 2, 0.01, (obj.geometry.attributes.position.array[2] + obj.geometry.attributes.position.array[5]) / 2);
959
- sprite1.name = 'lineText';
960
- sprite1.renderOrder = 2;
961
- sprite1.scale.set(0.2, 0.1, 0.2);
962
- sprite1.layers.set(1);
963
- obj.add(sprite1);
964
- if (obj.parent != null) {
965
- // is not lighting
966
- var item3D = obj.parent.parent.parent;
967
- var max = item3D.children[0].userData.max;
968
- var min = item3D.children[0].userData.min;
969
- var objW = (max.x - min.x) / 100,
970
- objL = (max.z - min.z) / 100;
971
- var triangle = new Three.Mesh(geom, new Three.MeshBasicMaterial({
972
- color: SHADE_DARK_PURPLE_COLOR
973
- }));
974
- var triangle1 = new Three.Mesh(geom, new Three.MeshBasicMaterial({
975
- color: SHADE_DARK_PURPLE_COLOR
976
- }));
977
- triangle.position.set((index < 2 ? 0 : Math.sin((index === 2 ? 1 : -1) * Math.PI / 2)) * (obj.geometry.attributes.position.array[0] + h / 4 + (index % 2 === 0 ? 0 : objW)), newVec.y, (index < 2 ? Math.cos(index * Math.PI) : 0) * (obj.geometry.attributes.position.array[2] + h / 4 + (index % 2 === 0 ? 0 : objL)));
978
- triangle1.position.set(newVec.x - (index < 2 ? 0 : Math.sin((index === 2 ? 1 : -1) * Math.PI / 2)) * h / 4, newVec.y, newVec.z - (index < 2 ? Math.cos(index * Math.PI) : 0) * h / 4);
979
- if (index < 2) {
980
- triangle.rotation.x = Math.cos(index * Math.PI) * Math.PI / 2;
981
- triangle1.rotation.x = -Math.cos(index * Math.PI) * Math.PI / 2;
982
- } else {
983
- triangle.rotation.x = -Math.PI / 2;
984
- triangle.rotation.z = -(index === 2 ? 1 : -1) * Math.PI / 2;
985
- triangle1.rotation.x = Math.PI / 2;
986
- triangle1.rotation.z = (index === 2 ? 1 : -1) * Math.PI / 2;
987
- }
988
- triangle.name = 'lineText';
989
- triangle1.name = 'lineText';
990
- triangle.renderOrder = 2;
991
- triangle1.renderOrder = 2;
992
- triangle.material.transparent = true;
993
- triangle1.material.transparent = true;
994
- triangle.material.depthTest = false;
995
- triangle1.material.depthTest = false;
996
- obj.add(triangle);
997
- obj.add(triangle1);
998
- }
999
- }
1000
-
1001
- // if (obj.userData.distance <= 50 && obj.userData.distance >= 0.5) {
1002
- var real_target = obj.userData.target;
1003
- for (; real_target.name != 'pivot';) {
1004
- if (real_target.parent == null) break;
1005
- real_target = real_target.parent;
1006
- }
1007
- // let item3D = obj.parent.parent.parent;
1008
- // let origin = obj.geometry.vertices[0].clone().applyMatrix4(obj.matrixWorld);
1009
- // let target = obj.geometry.vertices[1].clone().applyMatrix4(obj.matrixWorld);
1010
- // let uVec = new Three.Vector3(target.x - origin.x - 0.2, target.y - origin.y - 0.2, target.z - origin.z - 0.2);
1011
- obj.visible = true;
1012
- if (dist < 3) obj.visible = false;
1013
- return obj;
1014
- }
1015
- }
1016
- }
1017
- var tX = wPoint0.x - planData.plan.position.x;
1018
- var tZ = wPoint0.z - planData.plan.position.z;
1019
- tZ = -tZ;
1020
- var tX1 = wPoint1.x - planData.plan.position.x;
1021
- var tZ1 = wPoint1.z - planData.plan.position.z;
1022
- tZ1 = -tZ1;
1023
- if (!layer) return;
1024
- layer.lines.forEach(function (data) {
1025
- var px = [];
1026
- var py = [];
1027
- var opX = [tX, tX1];
1028
- var opY = [tZ, tZ1];
1029
- data.vertices.forEach(function (vec) {
1030
- var vertices = layer.vertices.get(vec);
1031
- px.push(vertices.x);
1032
- py.push(vertices.y);
1033
- });
1034
- var distance = getIntersectPoint(opX, opY, px, py);
1035
- if (distance != null) {
1036
- obj.userData.distance = distance;
1037
- obj.userData.target = planData.sceneGraph.layers[layer.id].lines[data.get('id')];
1038
- scale = distance / length;
1039
- if (distance <= 0.1) {
1040
- scale = 0.1 / length;
1041
- }
1042
- var _originPoint = obj.geometry.attributes.position.array.slice(0, 3);
1043
- lx = obj.geometry.attributes.position.array[3] - obj.geometry.attributes.position.array[0];
1044
- ly = obj.geometry.attributes.position.array[4] - obj.geometry.attributes.position.array[1];
1045
- lz = obj.geometry.attributes.position.array[5] - obj.geometry.attributes.position.array[2];
1046
- var _newVec = new Three.Vector3(_originPoint.x + lx * scale, _originPoint.y + ly * scale, _originPoint.z + lz * scale);
1047
- obj.geometry.attributes.position.array[3] = _newVec.x;
1048
- obj.geometry.attributes.position.array[4] = _newVec.y;
1049
- obj.geometry.attributes.position.array[5] = _newVec.z;
1050
- obj.geometry.attributes.position.needsUpdate = true;
1051
- var _dist = formatNumber(distance, DECIMAL_PLACES_2);
1052
- if (_dist > 3) {
1053
- var _canvas2 = getTextCanvas(_dist);
1054
- var _wid = _canvas2.width / window.innerWidth * 30;
1055
- var _hei = _canvas2.height / window.innerHeight * 30;
1056
- var _texture = new Three.Texture(_canvas2);
1057
- _texture.needsUpdate = true;
1058
- var _geometry = new Three.PlaneGeometry(_wid / 2, _hei / 2);
1059
- _geometry.computeBoundingBox();
1060
- var _material = new Three.MeshBasicMaterial({
1061
- map: _texture,
1062
- side: Three.DoubleSide
1063
- });
1064
- var _textMesh = new Three.Mesh(_geometry, _material);
1065
- for (; obj.children.length != 0;) {
1066
- var _temp = obj.children.pop();
1067
- disposeObject(_temp);
1068
- }
1069
- _textMesh.rotation.set(Math.PI / 2, Math.PI, 0);
1070
- // obj.add(textMesh);
1071
- _textMesh.position.set((obj.geometry.attributes.position.array[0] + obj.geometry.attributes.position.array[3]) / 2, 0.01, (obj.geometry.attributes.position.array[2] + obj.geometry.attributes.position.array[5]) / 2);
1072
- _textMesh.name = 'lineText';
1073
- _textMesh.renderOrder = 2;
1074
- _textMesh.material.depthTest = false;
1075
- _textMesh.material.transparent = true;
1076
- var _sprite = new Three.Sprite(new Three.SpriteMaterial({
1077
- map: _texture
1078
- }));
1079
- _sprite.position.set((obj.geometry.attributes.position.array[0] + obj.geometry.attributes.position.array[3]) / 2, 0.01, (obj.geometry.attributes.position.array[2] + obj.geometry.attributes.position.array[5]) / 2);
1080
- _sprite.name = 'lineText';
1081
- _sprite.scale.set(0.2, 0.1, 0.2);
1082
- _sprite.layers.set(1);
1083
- obj.add(_sprite);
1084
- var _item3D = obj.parent.parent.parent;
1085
- var _max = _item3D.children[0].userData.max;
1086
- var _min = _item3D.children[0].userData.min;
1087
- var _objW = (_max.x - _min.x) / 100,
1088
- _objL = (_max.z - _min.z) / 100;
1089
- var triangle = new Three.Mesh(geom, new Three.MeshBasicMaterial({
1090
- color: SHADE_DARK_PURPLE_COLOR
1091
- }));
1092
- var triangle1 = new Three.Mesh(geom, new Three.MeshBasicMaterial({
1093
- color: SHADE_DARK_PURPLE_COLOR
1094
- }));
1095
- triangle.position.set((index < 2 ? 0 : Math.sin((index === 2 ? 1 : -1) * Math.PI / 2)) * (obj.geometry.attributes.position.array[0] + h / 4 + (index % 2 === 0 ? 0 : _objW)), _newVec.y, (index < 2 ? Math.cos(index * Math.PI) : 0) * (obj.geometry.attributes.position.array[2] + h / 4 + (index % 2 === 0 ? 0 : _objL)) - 0.02);
1096
- triangle1.position.set(_newVec.x - (index < 2 ? 0 : Math.sin((index === 2 ? 1 : -1) * Math.PI / 2)) * h / 4, _newVec.y, _newVec.z - (index < 2 ? Math.cos(index * Math.PI) : 0) * h / 4);
1097
- if (index < 2) {
1098
- triangle.rotation.x = Math.cos(index * Math.PI) * Math.PI / 2;
1099
- triangle1.rotation.x = -Math.cos(index * Math.PI) * Math.PI / 2;
1100
- } else {
1101
- triangle.rotation.x = -Math.PI / 2;
1102
- triangle.rotation.z = -(index === 2 ? 1 : -1) * Math.PI / 2;
1103
- triangle1.rotation.x = Math.PI / 2;
1104
- triangle1.rotation.z = (index === 2 ? 1 : -1) * Math.PI / 2;
1105
- }
1106
- triangle.name = 'lineText';
1107
- triangle1.name = 'lineText';
1108
- triangle.renderOrder = 2;
1109
- triangle1.renderOrder = 2;
1110
- triangle.material.transparent = true;
1111
- triangle1.material.transparent = true;
1112
- triangle.material.depthTest = false;
1113
- triangle1.material.depthTest = false;
1114
- obj.add(triangle);
1115
- obj.add(triangle1);
1116
- }
1117
- // if (obj.userData.distance <= 50 && obj.userData.distance >= 0.5) {
1118
- // let item3D = obj.parent.parent.parent;
1119
- // let pos = item3D.position.clone();
1120
- // let origin = obj.geometry.vertices[0].clone().applyMatrix4(obj.matrixWorld);
1121
- // let target = obj.geometry.vertices[1].clone().applyMatrix4(obj.matrixWorld);
1122
- // let uVec = new Three.Vector3(target.x - origin.x - 0.2, target.y - origin.y - 0.2, target.z - origin.z - 0.2);
1123
- obj.visible = true;
1124
- if (_dist > 3) obj.visible = false;
1125
- return obj;
1126
- // itemsActions.updateDraggingItemChanged(pos.x - uVec.x, -pos.z + uVec.z);
1127
- // }
1128
- }
1129
- });
1130
- obj.visible = false;
1131
- return obj;
1132
- }
1133
- export function getIntersectPoint(opX, opY, pX, pY) {
1134
- var oA;
1135
- if (opX[1] == opX[0]) oA = null;else oA = (opY[1] - opY[0]) / (opX[1] - opX[0]);
1136
- var A;
1137
- if (pX[1] == pX[0]) A = null;else A = (pY[1] - pY[0]) / (pX[1] - pX[0]);
1138
- if (oA == A) return null;
1139
- if (oA != null && A != null) {
1140
- var oB = opY[0] - oA * opX[0];
1141
- var B = pY[0] - A * pX[0];
1142
- var iX = (B - oB) / (oA - A);
1143
- if (pX[0] <= iX && iX <= pX[1] || pX[0] >= iX && iX >= pX[1]) {
1144
- if (opX[0] <= opX[1] && opX[0] <= iX || opX[0] >= opX[1] && opX[0] >= iX) {
1145
- var iY = pY[0] + A * (iX - pX[0]);
1146
- var distance = Math.sqrt((opX[0] - iX) * (opX[0] - iX) + (opY[0] - iY) * (opY[0] - iY));
1147
- return distance;
1148
- }
1149
- return null;
1150
- }
1151
- }
1152
- if (oA == null) {
1153
- var _iX = opX[0];
1154
- if (A != null) {
1155
- if (pX[0] <= _iX && _iX <= pX[1] || pX[0] >= _iX && _iX >= pX[1]) {
1156
- var _iY = pY[0] + A * (_iX - pX[0]);
1157
- if (opY[0] <= _iY && opY[0] <= opY[1] || opY[0] >= _iY && opY[0] >= opY[1]) {
1158
- var _distance = Math.sqrt((opX[0] - _iX) * (opX[0] - _iX) + (opY[0] - _iY) * (opY[0] - _iY));
1159
- return _distance;
1160
- }
1161
- }
1162
- }
1163
- }
1164
- if (A == null) {
1165
- var _iX2 = pX[0];
1166
- if (oA != null) {
1167
- var _iY2 = _iX2 * oA + opY[0] - oA * opX[0];
1168
- if (pY[0] <= _iY2 && _iY2 <= pY[1] || pY[0] >= _iY2 && _iY2 >= pY[1]) {
1169
- if (opY[0] <= _iY2 && opY[0] <= opY[1] || opY[0] >= _iY2 && opY[0] >= opY[1]) {
1170
- var _distance2 = Math.sqrt((opX[0] - _iX2) * (opX[0] - _iX2) + (opY[0] - _iY2) * (opY[0] - _iY2));
1171
- return _distance2;
1172
- }
1173
- }
1174
- }
1175
- }
1176
- return null;
1177
- }
1178
- function gcd(a, b) {
1179
- return a % b ? gcd(b, a % b) : b;
1180
- }
1181
- function getTextCanvas(text) {
1182
- var parameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1183
- var canvas = document.createElement('canvas');
1184
- var ctx = canvas.getContext('2d');
1185
- var fontSize = 16;
1186
- var integral = String(text) + "''";
1187
- parameters.fontName = parameters.fontName || ARROW_TEXT_FONTFACE;
1188
-
1189
- // Prepare the font to be able to measure
1190
- ctx.font = "".concat(fontSize, "px ") + parameters.fontName;
1191
- if (parameters.italic) {
1192
- ctx.font = "italic ".concat(fontSize, "px ") + parameters.fontName;
1193
- }
1194
- if (parameters.bold) {
1195
- ctx.font = "bold ".concat(fontSize, "px ") + parameters.fontName;
1196
- }
1197
- if (parameters.bold && parameters.italic) {
1198
- ctx.font = "italic bold ".concat(fontSize, "px ") + parameters.fontName;
1199
- }
1200
- var textMetrics = ctx.measureText(integral);
1201
- var width = 70;
1202
- var height = fontSize + 20;
1203
-
1204
- // Resize canvas to match text size
1205
- canvas.width = width;
1206
- canvas.height = height;
1207
- canvas.style.width = width + 'px';
1208
- canvas.style.height = height + 'px';
1209
-
1210
- // Re-apply font since canvas is resized.
1211
- ctx.font = "".concat(fontSize, "px ") + parameters.fontName;
1212
- if (parameters.italic) {
1213
- ctx.font = "italic ".concat(fontSize, "px ") + parameters.fontName;
1214
- }
1215
- if (parameters.bold) {
1216
- ctx.font = "bold ".concat(fontSize, "px ") + parameters.fontName;
1217
- }
1218
- if (parameters.bold && parameters.italic) {
1219
- ctx.font = "italic bold ".concat(fontSize, "px ") + parameters.fontName;
1220
- }
1221
- //ctx.textAlign = parameters.align || "center";
1222
- ctx.textBaseline = parameters.baseline || 'middle';
1223
- var r = 10;
1224
- // Make the canvas transparent for simplicity
1225
- ctx.fillStyle = ARROW_TEXT_BACKCOLOR;
1226
- // ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
1227
- var w = ctx.canvas.width;
1228
- var h = ctx.canvas.height;
1229
- ctx.beginPath();
1230
- ctx.moveTo(r, 0);
1231
- ctx.lineTo(w - r, 0);
1232
- ctx.arcTo(w, 0, w, r, r);
1233
- ctx.lineTo(w, h - r);
1234
- ctx.arcTo(w, h, w - r, h, r);
1235
- ctx.lineTo(r, h);
1236
- ctx.arcTo(0, h, 0, h - r, r);
1237
- ctx.lineTo(0, r);
1238
- ctx.arcTo(0, 0, r, 0, r);
1239
- // ctx.arcTo(w+r, h+2*r, w+r, 0, r);
1240
- ctx.fill();
1241
- ctx.fillStyle = parameters.fillColor || ARROW_TEXT_FORECOLOR;
1242
- ctx.fillText(integral, (width - textMetrics.width) / 2, height / 2);
1243
- ctx.strokeStyle = parameters.strokeColor || ARROW_TEXT_FORECOLOR;
1244
- ctx.strokeText(integral, (width - textMetrics.width) / 2, height / 2);
1245
-
1246
- // ctx.font = `${fontSize - 5}px ` + parameters.fontName;
1247
- // const denoMetrics = ctx.measureText(deno);
1248
- // const numoMetrics = ctx.measureText(numo);
1249
- // ctx.fillStyle = ARROW_TEXT_FORECOLOR;
1250
- // ctx.fillRect(
1251
- // ctx.canvas.width / 2 + 3,
1252
- // ctx.canvas.height / 2 - 2,
1253
- // denoMetrics.width,
1254
- // 1
1255
- // );
1256
-
1257
- // const denoMetrics = ctx.measureText(deno);
1258
- // ctx.fillStyle = ARROW_TEXT_FORECOLOR;
1259
- // ctx.fillRect(
1260
- // ctx.canvas.width / 2 + 3,
1261
- // ctx.canvas.height / 2 - 2,
1262
- // denoMetrics.width,
1263
- // 1
1264
- // );
1265
-
1266
- // ctx.fillStyle = parameters.fillColor || ARROW_TEXT_FORECOLOR;
1267
- // ctx.fillText(
1268
- // numo,
1269
- // ctx.canvas.width / 2 + 3 + (denoMetrics.width - numoMetrics.width) / 2,
1270
- // height / 2 - 8
1271
- // );
1272
- // ctx.font = `${fontSize}px ` + parameters.fontName;
1273
- // ctx.fillText(
1274
- // "''",
1275
- // ctx.canvas.width / 2 + 4 + denoMetrics.width,
1276
- // height / 2 - 7
1277
- // );
1278
- // ctx.font = `${fontSize - 5}px ` + parameters.fontName;
1279
-
1280
- // ctx.strokeStyle = parameters.strokeColor || ARROW_TEXT_FORECOLOR;
1281
- // ctx.strokeText(
1282
- // numo,
1283
- // ctx.canvas.width / 2 + 3 + (denoMetrics.width - numoMetrics.width) / 2,
1284
- // height / 2 - 8
1285
- // );
1286
-
1287
- // ctx.fillStyle = parameters.fillColor || ARROW_TEXT_FORECOLOR;
1288
- // ctx.fillText(deno, ctx.canvas.width / 2 + 3, height / 2 + 8);
1289
- // ctx.strokeStyle = parameters.strokeColor || ARROW_TEXT_FORECOLOR;
1290
- // ctx.strokeText(deno, ctx.canvas.width / 2 + 3, height / 2 + 8);
1291
- return canvas;
1292
- }
1293
- function removeObject(modifiedPath, layer, planData, actions, sceneData, oldSceneData, catalog) {
1294
- var promises = [];
1295
- switch (modifiedPath[3]) {
1296
- case 'lines':
1297
- // Here I remove the line with all its holes
1298
- var lineID = modifiedPath[4];
1299
- oldSceneData.getIn(['layers', layer.id, 'lines', lineID, 'holes']).forEach(function (holeID) {
1300
- removeHole(planData, layer.id, holeID);
1301
- });
1302
- removeLine(planData, layer.id, lineID);
1303
- var mode = oldSceneData.mode;
1304
- if (ARRAY_3D_MODES.includes(mode)) mode = MODE_IDLE_3D;else mode = MODE_IDLE;
1305
- if (modifiedPath.length > 5) {
1306
- // I removed an hole, so I should add the new line
1307
- promises.push(addLine(sceneData, planData, layer, lineID, catalog, actions.linesActions));
1308
- layer.getIn(['lines', lineID, 'holes']).forEach(function (holeID) {
1309
- promises.push(addHole(sceneData, planData, layer, holeID, catalog, actions.holesActions, mode));
1310
- });
1311
- }
1312
- break;
1313
- case 'areas':
1314
- if (modifiedPath.length === 5) {
1315
- // I am removing an entire area
1316
- removeArea(planData, layer.id, modifiedPath[4]);
1317
- }
1318
- break;
1319
- case 'items':
1320
- if (modifiedPath.length === 5) {
1321
- // I am removing an item
1322
- removeItem(planData, layer.id, modifiedPath[4], oldSceneData.getIn(['layers', layer.id]), layer);
1323
- }
1324
- break;
1325
- }
1326
- Promise.all(promises).then(function (values) {
1327
- return updateBoundingBox(planData);
1328
- });
1329
- }
1330
- function removeLayer(layerId, planData) {
1331
- var layerGraph = planData.sceneGraph.layers[layerId];
1332
- for (var lineID in layerGraph.lines) removeLine(planData, layerId, lineID);
1333
- for (var areaID in layerGraph.areas) removeArea(planData, layerId, areaID);
1334
- for (var itemID in layerGraph.items) removeItem(planData, layerId, itemID);
1335
- for (var holeID in layerGraph.holes) removeHole(planData, layerId, holeID);
1336
- delete planData.sceneGraph.layers[layerId];
1337
- }
1338
- function removeHole(planData, layerId, holeID) {
1339
- if (planData.sceneGraph.busyResources.layers[layerId].holes[holeID]) {
1340
- setTimeout(function () {
1341
- return removeHole(planData, layerId, holeID);
1342
- }, 100);
1343
- return;
1344
- }
1345
- planData.sceneGraph.busyResources.layers[layerId].holes[holeID] = true;
1346
- var hole3D = planData.sceneGraph.layers[layerId].holes[holeID];
1347
- if (hole3D) {
1348
- planData.plan.remove(hole3D);
1349
- disposeObject(hole3D);
1350
- delete planData.sceneGraph.layers[layerId].holes[holeID];
1351
- delete planData.sceneGraph.LODs[holeID];
1352
- hole3D = null;
1353
- updateBoundingBox(planData, true);
1354
- }
1355
- planData.sceneGraph.busyResources.layers[layerId].holes[holeID] = false;
1356
- }
1357
- function removeLine(planData, layerId, lineID) {
1358
- if (planData.sceneGraph.busyResources.layers[layerId].lines[lineID]) {
1359
- setTimeout(function () {
1360
- return removeLine(planData, layerId, lineID);
1361
- }, 100);
1362
- return;
1363
- }
1364
- planData.sceneGraph.busyResources.layers[layerId].lines[lineID] = true;
1365
- var line3D = planData.sceneGraph.layers[layerId].lines[lineID];
1366
- if (line3D) {
1367
- planData.plan.remove(line3D);
1368
- disposeObject(line3D);
1369
- delete planData.sceneGraph.layers[layerId].lines[lineID];
1370
- delete planData.sceneGraph.LODs[lineID];
1371
- line3D = null;
1372
- updateBoundingBox(planData, true);
1373
- }
1374
- planData.sceneGraph.busyResources.layers[layerId].lines[lineID] = false;
1375
- }
1376
- function removeArea(planData, layerId, areaID) {
1377
- if (planData.sceneGraph.busyResources.layers[layerId].areas[areaID]) {
1378
- setTimeout(function () {
1379
- return removeArea(planData, layerId, areaID);
1380
- }, 100);
1381
- return;
1382
- }
1383
- planData.sceneGraph.busyResources.layers[layerId].areas[areaID] = true;
1384
- var area3D = planData.sceneGraph.layers[layerId].areas[areaID];
1385
- if (area3D) {
1386
- planData.plan.remove(area3D);
1387
- disposeObject(area3D);
1388
- delete planData.sceneGraph.layers[layerId].areas[areaID];
1389
- delete planData.sceneGraph.LODs[areaID];
1390
- area3D = null;
1391
- updateBoundingBox(planData, true);
1392
- }
1393
- planData.sceneGraph.busyResources.layers[layerId].areas[areaID] = false;
1394
- }
1395
- export function removeItem(planData, layerId, itemID) {
1396
- var oldSceneLayer = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
1397
- var newSceneLayer = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
1398
- if (planData.sceneGraph.busyResources.layers[layerId].items[itemID]) {
1399
- setTimeout(function () {
1400
- return removeItem(planData, layerId, itemID, oldSceneLayer, newSceneLayer);
1401
- }, 100);
1402
- return;
1403
- }
1404
- planData.sceneGraph.busyResources.layers[layerId].items[itemID] = true;
1405
-
1406
- // The layer variable is layer that contains the deleted item.
1407
- var layer = oldSceneLayer ? oldSceneLayer : planData.sceneData.getIn(['layers', layerId]);
1408
- var item = layer.getIn(['items', itemID]); // deleted item.
1409
- deleteCountertop(planData.sceneGraph.layers[layerId].countertops, item, planData, layer);
1410
- planData.sceneGraph.layers[layerId].moldingGroups = deleteAllMolding(planData.sceneGraph.layers[layerId].moldingGroups, item, planData, layer, newSceneLayer);
1411
- var item3D = planData.sceneGraph.layers[layerId].items[itemID];
1412
- if (item3D) {
1413
- planData.plan.remove(item3D);
1414
- disposeObject(item3D);
1415
- delete planData.sceneGraph.layers[layerId].items[itemID];
1416
- delete planData.sceneGraph.LODs[itemID];
1417
- item3D = null;
1418
- updateBoundingBox(planData, true);
1419
- }
1420
- planData.sceneGraph.busyResources.layers[layerId].items[itemID] = false;
1421
- }
1422
- function removeItemWithoutItem(planData, layerId, itemID) {
1423
- if (planData.sceneGraph.busyResources.layers[layerId].items[itemID]) {
1424
- setTimeout(function () {
1425
- return removeItemWithoutItem(planData, layerId, itemID);
1426
- }, 100);
1427
- return;
1428
- }
1429
- planData.sceneGraph.busyResources.layers[layerId].items[itemID] = true;
1430
- var layer = planData.sceneData.getIn(['layers', layerId]);
1431
- var item = layer.getIn(['items', itemID]);
1432
- deleteCountertop(planData.sceneGraph.layers[layerId].countertops, item, planData, layer);
1433
- var item3D = planData.sceneGraph.layers[layerId].items[itemID];
1434
- if (item3D) {
1435
- planData.plan.remove(item3D);
1436
- disposeObject(item3D);
1437
- item3D = null;
1438
- updateBoundingBox(planData);
1439
- delete planData.sceneGraph.layers[layerId].items[itemID];
1440
- delete planData.sceneGraph.LODs[itemID];
1441
- }
1442
- planData.sceneGraph.busyResources.layers[layerId].items[itemID] = false;
1443
- }
1444
-
1445
- //TODO generate an area's replace if vertex has been changed
1446
- function addObject(modifiedPath, layer, planData, actions, sceneData, oldSceneData, catalog, mode, toolObj) {
1447
- if (modifiedPath.length >= 5) {
1448
- var addPromise = null,
1449
- addAction = null;
1450
- switch (modifiedPath[3]) {
1451
- case 'lines':
1452
- if (modifiedPath[5] === 'holes' && scene_mode !== 'MODE_DRAWING_HOLE_3D' && scene_mode !== 'MODE_DRAGGING_HOLE_3D') {
1453
- removeLine(planData, layer.id, modifiedPath[4]);
1454
- }
1455
- if (scene_mode !== 'MODE_DRAWING_HOLE_3D' && scene_mode !== 'MODE_DRAGGING_HOLE_3D') {
1456
- addPromise = addLine;
1457
- }
1458
- addAction = actions.linesActions;
1459
- break;
1460
- case 'areas':
1461
- addPromise = addArea;
1462
- addAction = actions.areaActions;
1463
- break;
1464
- case 'items':
1465
- addPromise = addItem;
1466
- addAction = actions.itemsActions;
1467
- break;
1468
- case 'holes':
1469
- addPromise = addHole;
1470
- addAction = actions.holesActions;
1471
- break;
1472
- }
1473
- if (addPromise) {
1474
- // if( addPromise(sceneData, planData, layer, modifiedPath[4], catalog, addAction) === undefined ) {
1475
- // return;
1476
- // }
1477
- addPromise(sceneData, planData, layer, modifiedPath[4], catalog, addAction, mode, toolObj).then(function () {
1478
- return updateBoundingBox(planData);
1479
- });
1480
- }
1481
- }
1482
- }
1483
- function addHole(sceneData, planData, layer, holeID, catalog, holesActions, mode) {
1484
- var toolObj = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
1485
- var holeData = layer.getIn(['holes', holeID]);
1486
-
1487
- // Create the hole object
1488
- return holeData === undefined ? '' : catalog.getElement(holeData.type).render3D(holeData, layer, sceneData).then(function (object) {
1489
- if (object instanceof Three.LOD) {
1490
- planData.sceneGraph.LODs[holeID] = object;
1491
- }
1492
- object.children.forEach(function (item) {
1493
- var name = item.name;
1494
- item.castShadow = true;
1495
- var texture;
1496
- if (name.includes('_wood')) {
1497
- texture = loadTexture('/assets/img/texture/white1px.jpg');
1498
- } else if (name.includes('_glass')) {
1499
- var material = new Three.MeshPhysicalMaterial({
1500
- roughness: 0.5,
1501
- transmission: 1,
1502
- thickness: 0.5,
1503
- // Add refraction!
1504
- transparency: 0.6
1505
- });
1506
- item.material = material;
1507
- return item;
1508
- } else if (name.includes('_steel')) {
1509
- texture = loadTexture('/assets/img/texture/steel.jpg');
1510
- } else if (name.includes('_glass')) {
1511
- var _material2 = new Three.MeshPhysicalMaterial({
1512
- roughness: 0.5,
1513
- transmission: 1,
1514
- thickness: 0.5,
1515
- // Add refraction!
1516
- transparency: 0.6
1517
- });
1518
- item.material = _material2;
1519
- return item;
1520
- }
1521
- });
1522
- if (holeData.selected) {
1523
- // if object is drawing in 3d mode and selected
1524
- if (holeData.type === 'FrameLess Doorway') {
1525
- var x, y, z;
1526
- x = holeData.getIn(['properties', 'width', 'length']) || 0;
1527
- y = holeData.getIn(['properties', 'height', 'length']) || 0;
1528
- z = holeData.getIn(['properties', 'thickness', 'length']) || 0;
1529
- var moveBox = new Three.BoxGeometry(x, y, z);
1530
- var mBox = new Three.Mesh(moveBox, new Three.MeshBasicMaterial({
1531
- color: 0x99c3fb,
1532
- side: Three.DoubleSide,
1533
- transparent: true,
1534
- opacity: 0.4
1535
- }));
1536
- mBox.name = 'FrameLessDoormBox';
1537
- mBox.renderOrder = 1;
1538
- if (mBox !== undefined) {
1539
- object.add(mBox);
1540
- }
1541
- } else {
1542
- var _boundingBox = GeomUtils.baseBox3FromObject(object);
1543
- if (_boundingBox === undefined) return;
1544
- var max = _boundingBox.max;
1545
- if (!Number.isFinite(max.x)) return;
1546
- var transGroup = new Three.Group();
1547
- var extrudeSettings = {
1548
- depth: 1,
1549
- bevelEnabled: true,
1550
- bevelSegments: 2,
1551
- steps: 2,
1552
- bevelSize: 1,
1553
- bevelThickness: 1
1554
- };
1555
- var triangleShape = new Three.Shape().moveTo(max.x, 15) // A
1556
- .lineTo(max.x + 6, 15) // B
1557
- .lineTo(max.x + 6, 30) // C
1558
- .lineTo(max.x + 16, 0) // D
1559
- .lineTo(max.x + 6, -29) // E
1560
- .lineTo(max.x + 6, -15) // F
1561
- .lineTo(max.x, -15) // G
1562
- .lineTo(max.x, 15); // close path
1563
- var transHole_Right = GeomUtils.addShape(triangleShape, extrudeSettings, scene_mode !== 'MODE_DRAGGING_HOLE_3D' ? 0x000000 : 0x99c3fb, 0, 0, 0, 0, 0, 0, 1);
1564
- transHole_Right.name = 'transHole_Right';
1565
- transGroup.add(transHole_Right);
1566
- triangleShape = new Three.Shape().moveTo(-max.x, 15) // A
1567
- .lineTo(-(max.x + 6), 15) // B
1568
- .lineTo(-(max.x + 6), 30) // C
1569
- .lineTo(-(max.x + 16), 0) // D
1570
- .lineTo(-(max.x + 6), -29) // E
1571
- .lineTo(-(max.x + 6), -15) // F
1572
- .lineTo(-max.x, -15) // G
1573
- .lineTo(-max.x, 15); // close path
1574
- var transHole_Left = GeomUtils.addShape(triangleShape, extrudeSettings, scene_mode !== 'MODE_DRAGGING_HOLE_3D' ? 0x000000 : 0x99c3fb, 0, 0, 0, 0, 0, 0, 1);
1575
- transHole_Left.name = 'transHole_Left';
1576
- transGroup.add(transHole_Left);
1577
- transGroup.scale.set(1 / object.scale.x, 1 / object.scale.y, 1 / object.scale.z);
1578
- object.add(transGroup);
1579
- }
1580
- }
1581
- var pivot = new Three.Object3D();
1582
- pivot.name = 'pivot';
1583
- if (isElevationView(mode)) {
1584
- var lineID = holeData.getIn(['line']);
1585
- if (planData.sceneGraph.layers['layer-1'].lines[lineID].visible) {
1586
- pivot.visible = true;
1587
- } else {
1588
- pivot.visible = false;
1589
- }
1590
- object.traverse(function (obj) {
1591
- replaceMeshesWithLineSegments(obj);
1592
- });
1593
- }
1594
- pivot.add(object);
1595
- var line = layer.getIn(['lines', holeData.line]);
1596
-
1597
- // First of all I need to find the vertices of this line
1598
- var vertex0 = layer.vertices.get(line.vertices.get(0));
1599
- var vertex1 = layer.vertices.get(line.vertices.get(1));
1600
- var offset = holeData.offset;
1601
- if (vertex0.x > vertex1.x) {
1602
- var tmp = vertex0;
1603
- vertex0 = vertex1;
1604
- vertex1 = tmp;
1605
- offset = 1 - offset;
1606
- }
1607
- var distance = Math.sqrt(Math.pow(vertex0.x - vertex1.x, 2) + Math.pow(vertex0.y - vertex1.y, 2));
1608
- var alpha = Math.asin((vertex1.y - vertex0.y) / distance);
1609
- var boundingBox = new Three.Box3().setFromObject(pivot);
1610
- var center = [(boundingBox.max.x - boundingBox.min.x) / 2 + boundingBox.min.x, (boundingBox.max.y - boundingBox.min.y) / 2 + boundingBox.min.y, (boundingBox.max.z - boundingBox.min.z) / 2 + boundingBox.min.z];
1611
- var holeAltitude = holeData.properties.getIn(['altitude', 'length']);
1612
- var holeHeight = holeData.properties.getIn(['height', 'length']);
1613
- pivot.rotation.y = alpha;
1614
- pivot.position.x = vertex0.x + distance * offset * Math.cos(alpha) - center[0] * Math.cos(alpha) - center[2] * Math.sin(alpha);
1615
- pivot.position.y = holeAltitude + holeHeight / 2 - center[1] + layer.altitude;
1616
- pivot.position.z = -vertex0.y - distance * offset * Math.sin(alpha) - center[2] * Math.cos(alpha) + center[0] * Math.sin(alpha);
1617
- pivot.userData.type = 'hole';
1618
- pivot.userData.layerId = layer.id;
1619
- pivot.userData.holeId = holeData.id;
1620
-
1621
- // if holeId is existing, remove it first
1622
- var childLen = planData.plan.children.length;
1623
- var children = [];
1624
- for (var i = 0; i < childLen; i++) {
1625
- if (planData.plan.children[i].userData.holeId != holeData.id) children.push(planData.plan.children[i]);
1626
- }
1627
- planData.plan.children = children;
1628
- planData.plan.add(pivot);
1629
- planData.sceneGraph.layers[layer.id].holes[holeData.id] = pivot;
1630
- applyInteract(pivot, function () {
1631
- // document.getElementById('setting_dialog').style.display = 'none';
1632
- return holesActions.selectHole(layer.id, holeData.id);
1633
- });
1634
- var opacity = layer.opacity;
1635
- if (holeData.selected) {
1636
- opacity = 1;
1637
- }
1638
- applyOpacity(pivot, opacity);
1639
- });
1640
- }
1641
- function updateHole(sceneData, oldSceneData, planData, layer, holeID, differences, catalog, holesActions, selfDestroy, selfBuild) {
1642
- var hole = layer.getIn(['holes', holeID]);
1643
- var oldHole = oldSceneData.getIn(['layers', layer.id, 'holes', holeID]);
1644
- var mesh = planData.sceneGraph.layers[layer.id].holes[holeID];
1645
- if (!mesh) return null;
1646
- return catalog.getElement(hole.type).updateRender3D(hole, layer, sceneData, mesh, oldHole, differences, selfDestroy, selfBuild);
1647
- }
1648
- function addLine(sceneData, planData, layer, lineID, catalog, linesActions) {
1649
- var mode = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
1650
- var toolObj = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
1651
- if (planData.sceneGraph.busyResources.layers[layer.id].lines[lineID]) {
1652
- setTimeout(function () {
1653
- return addLine(sceneData, planData, layer, lineID, catalog, linesActions, mode);
1654
- }, 100);
1655
- return;
1656
- }
1657
- planData.sceneGraph.busyResources.layers[layer.id].lines[lineID] = true;
1658
- var line = layer.getIn(['lines', lineID]);
1659
- line.userData.stateMode = scene_mode;
1660
-
1661
- // First of all I need to find the vertices of this line
1662
- var vertex0 = layer.vertices.get(line.vertices.get(0));
1663
- var vertex1 = layer.vertices.get(line.vertices.get(1));
1664
- if (vertex0.x > vertex1.x) {
1665
- var tmp = vertex0;
1666
- vertex0 = vertex1;
1667
- vertex1 = tmp;
1668
- }
1669
- return catalog.getElement(line.type).render3D(line, layer, sceneData, mode).then(function (line3D) {
1670
- if (line3D === null) {
1671
- return;
1672
- }
1673
- if (line3D instanceof Three.LOD) {
1674
- planData.sceneGraph.LODs[line.id] = line3D;
1675
- }
1676
- var pivot = new Three.Object3D();
1677
- pivot.name = 'pivot';
1678
- pivot.add(line3D);
1679
- pivot.position.x = (vertex0.x + vertex1.x) / 2;
1680
- pivot.position.y = layer.altitude;
1681
- pivot.position.z = -(vertex0.y + vertex1.y) / 2;
1682
- pivot.userData.type = 'line';
1683
-
1684
- // In elevation view, show(visible = true) just selected wall pivot. If not, hidden(visible = false)
1685
- if (isElevationView(mode)) {
1686
- var lineVisible;
1687
- if (line.selected) {
1688
- pivot.traverse(function (obj) {
1689
- replaceMeshesWithLineSegments(obj);
1690
- });
1691
- lineVisible = true;
1692
- } else {
1693
- lineVisible = false;
1694
- }
1695
- pivot.visible = lineVisible;
1696
- }
1697
- pivot.userData.layerId = layer.id;
1698
- pivot.userData.lineId = lineID;
1699
- planData.plan.add(pivot);
1700
- planData.sceneGraph.layers[layer.id].lines[lineID] = pivot;
1701
- applyInteract(pivot, function () {
1702
- // document.getElementById('setting_dialog').style.display = 'none';
1703
- return linesActions.selectLine(layer.id, line.id);
1704
- });
1705
- var opacity = layer.opacity;
1706
- if (line.selected) {
1707
- opacity = 1;
1708
- }
1709
- applyOpacity(pivot, opacity);
1710
- planData.sceneGraph.busyResources.layers[layer.id].lines[lineID] = false;
1711
- });
1712
- }
1713
- function updateLine(sceneData, oldSceneData, planData, layer, lineID, differences, catalog, linesActions, selfDestroy, selfBuild) {
1714
- var line = layer.getIn(['lines', lineID]);
1715
- var oldLine = oldSceneData.getIn(['layers', layer.id, 'lines', lineID]);
1716
- var mesh = planData.sceneGraph.layers[layer.id].lines[lineID];
1717
- if (!mesh) return null;
1718
- return catalog.getElement(line.type).updateRender3D(line, layer, sceneData, mesh, oldLine, differences, selfDestroy, selfBuild);
1719
- }
1720
- function addArea(sceneData, planData, layer, areaID, catalog, areaActions, mode) {
1721
- var toolObj = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
1722
- if (planData.sceneGraph.busyResources.layers[layer.id].areas[areaID]) {
1723
- setTimeout(function () {
1724
- return addArea(sceneData, planData, layer, areaID, catalog, areaActions, mode);
1725
- }, 100);
1726
- return;
1727
- }
1728
- planData.sceneGraph.busyResources.layers[layer.id].areas[areaID] = true;
1729
- var area = layer.getIn(['areas', areaID]);
1730
- var interactFunction = function interactFunction() {
1731
- return areaActions.selectArea(layer.id, areaID);
1732
- };
1733
- return catalog.getElement(area.type).render3D(area, layer, sceneData).then(function (area3D) {
1734
- if (area3D instanceof Three.LOD) {
1735
- planData.sceneGraph.LODs[areaID] = area3D;
1736
- }
1737
- var pivot = new Three.Object3D();
1738
- var floorSupport = area3D.userData.floorSupport;
1739
- floorSupport.onBeforeRender = function (renderer, scene, camera, geometry, material, group) {
1740
- var floorMesh = this.parent.getObjectByName('floor');
1741
- if (geometry.attributes.normal === undefined) return floorMesh.visible = false;
1742
- geometry.computeVertexNormals();
1743
- var normals = geometry.attributes.normal.array;
1744
- var pos = new Three.Vector4(0, 0, 0, 1);
1745
- pos = pos.applyMatrix4(this.matrixWorld);
1746
- pos = pos.applyMatrix4(camera.matrixWorldInverse);
1747
- var normal = new Three.Vector4(normals[0], normals[1], normals[2], 0);
1748
- normal = normal.applyMatrix4(this.matrixWorld);
1749
- normal = normal.applyMatrix4(camera.matrixWorldInverse);
1750
- if (floorMesh) {
1751
- if (normal.dot(pos) <= 0) {
1752
- floorMesh.visible = true;
1753
- } else {
1754
- floorMesh.visible = false;
1755
- }
1756
- }
1757
- };
1758
- var ceil = area3D.userData.floorSupport.clone();
1759
- var ceilMaterial = new Three.MeshStandardMaterial({
1760
- color: 0xdfdfdf,
1761
- side: Three.BackSide,
1762
- roughness: 0.3,
1763
- metalness: 0.4
1764
- });
1765
- ceil.name = 'ceil';
1766
- ceil.material = ceilMaterial;
1767
- var vertices = [];
1768
- var lines = [];
1769
- var height = 100;
1770
- area.vertices.forEach(function (data) {
1771
- vertices.push(data);
1772
- });
1773
- layer.lines.forEach(function (data) {
1774
- lines.push(data);
1775
- });
1776
- var _loop2 = function _loop2() {
1777
- var data = lines[i];
1778
- var realVec = [];
1779
- data.vertices.forEach(function (vec) {
1780
- realVec.push(vec);
1781
- });
1782
- if (vertices.includes(realVec[0]) && vertices.includes(realVec[1])) {
1783
- height = convert(layer.ceilHeight).from(layer.unit).to(UNIT_CENTIMETER);
1784
- // height = data.properties.getIn(["height", "length"]);
1785
- return 1; // break
1786
- }
1787
- };
1788
- for (var i = 0; i < lines.length; i++) {
1789
- if (_loop2()) break;
1790
- }
1791
- ceil.translateZ(convert(layer.ceilHeight).from(layer.unit).to(UNIT_CENTIMETER));
1792
- pivot.name = 'pivot';
1793
- pivot.add(area3D);
1794
- pivot.add(area3D.userData.floorSupport);
1795
- pivot.add(ceil);
1796
- pivot.position.y = layer.altitude;
1797
-
1798
- // if elevation view, show just wall - not show floor and ceil
1799
- if (isElevationView(mode)) pivot.visible = false;
1800
- planData.plan.add(pivot);
1801
- planData.sceneGraph.layers[layer.id].areas[areaID] = pivot;
1802
- // document.getElementById('setting_dialog').style.display = 'none';
1803
- applyInteract(pivot, interactFunction);
1804
- var opacity = layer.opacity;
1805
- if (area.selected) {
1806
- opacity = 1;
1807
- }
1808
- applyOpacity(pivot, opacity);
1809
- planData.sceneGraph.busyResources.layers[layer.id].areas[areaID] = false;
1810
- });
1811
- }
1812
- function updateArea(sceneData, oldSceneData, planData, layer, areaID, differences, catalog, areaActions, selfDestroy, selfBuild) {
1813
- var area = layer.getIn(['areas', areaID]);
1814
- var oldArea = oldSceneData.getIn(['layers', layer.id, 'areas', areaID]);
1815
- var mesh = planData.sceneGraph.layers[layer.id].areas[areaID];
1816
- if (!mesh) return null;
1817
- return catalog.getElement(area.type).updateRender3D(area, layer, sceneData, mesh, oldArea, differences, selfDestroy, selfBuild);
1818
- }
1819
- function addItem(sceneData, planData, layer, itemID, catalog, itemsActions) {
1820
- var mode = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
1821
- var toolObj = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
1822
- var rItem = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : null;
1823
- var bAddMolding = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : true;
1824
- if (planData.sceneGraph.busyResources.layers[layer.id].items[itemID]) {
1825
- setTimeout(function () {
1826
- return addItem(sceneData, planData, layer, itemID, catalog, itemsActions, mode, toolObj, rItem, bAddMolding);
1827
- }, 100);
1828
- return;
1829
- }
1830
- var item = layer.getIn(['items', itemID]);
1831
- if (item.doorStyle === null) {
1832
- console.log(item.name + 's doorStyle is null!');
1833
- return;
1834
- }
1835
- if (!sceneData.loadFlag && scene_mode == MODE_DRAWING_ITEM_3D) {
1836
- itemsActions.toggleLoadingCabinet();
1837
- }
1838
- var catalogElement = catalog.getElement(item.type);
1839
- if (!catalogElement) catalogElement = catalog.getElement(returnReplaceableDeepSearchType(item.type));
1840
- if (!catalogElement) return false;
1841
- return catalogElement.render3D(item, layer, sceneData, mode).then(function (item3D) {
1842
- if (item3D instanceof Three.LOD) {
1843
- planData.sceneGraph.LODs[itemID] = item3D;
1844
- }
1845
- if (rItem !== null) {
1846
- planData.plan.remove(rItem);
1847
- disposeObject(rItem);
1848
- rItem = null;
1849
- }
1850
- var pivot = new Three.Object3D();
1851
- pivot.name = 'pivot';
1852
- pivot.add(item3D);
1853
- if (pivot) {
1854
- var mBoxColor = 0x99c3fb;
1855
- var _item = item.toJS();
1856
- if (_item.doorStyle.doorStyles !== undefined && _item.doorStyle.doorStyles.cds) {
1857
- if (showYelloBox(_item)) {
1858
- mBoxColor = 'rgba(232,187,47,1)';
1859
- } else {
1860
- pivot.children[0].children.forEach(function (pivotElement) {
1861
- pivotElement.visible = false;
1862
- });
1863
- }
1864
- var mBox = GeomUtils.makeMBoxfromObject(pivot, mBoxColor);
1865
- var warningObj = createWarningObject();
1866
- warningObj.position.set(0, item.properties.get('height').get('length') / 3, 0);
1867
- if (mBox) {
1868
- mBox.add(warningObj);
1869
- pivot.add(mBox);
1870
- }
1871
- }
1872
- }
1873
- if (item.selected) {
1874
- var tranformControl = item3D.children[item3D.children.length - 1];
1875
- transformBox = tranformControl.children[tranformControl.children.length - 1];
1876
- }
1877
- pivot.rotation.y = item.rotation * Math.PI / 180 + Math.PI;
1878
- // pivot.rotation.y = item.rotation;
1879
- pivot.position.x = item.x;
1880
- pivot.position.y = layer.altitude;
1881
- pivot.position.z = -item.y;
1882
- applyInteract(item3D, function () {
1883
- // closes the setting dialog
1884
- // document.getElementById('setting_dialog').style.display = 'none';
1885
- return itemsActions.selectItem(layer.id, item.id);
1886
- });
1887
- var opacity = layer.opacity;
1888
- if (item.selected) {
1889
- opacity = 1;
1890
- fVLine = [];
1891
- var TransformGizmo = item3D.children[item3D.children.length - 1];
1892
- TransformGizmo.children.forEach(function (child) {
1893
- if (child.type === 'Line' && child.geometry.attributes !== undefined) fVLine.push(child);
1894
- });
1895
- setTimeout(function () {
1896
- getDistances();
1897
- }, 50);
1898
- }
1899
- applyOpacity(pivot, opacity);
1900
- pivot.userData.type = 'item';
1901
- pivot.userData.layerId = layer.id;
1902
- pivot.userData.itemId = item.id;
1903
-
1904
- /**
1905
- *
1906
- * @param {array} itemRect Array of item's 4 side lines
1907
- * @returns {boolean} true (if item is snapped into wall) or false (if item is not snapped into wall)
1908
- */
1909
- //////////////////
1910
- ///// wall ///////
1911
- // 3 ***** 2
1912
- // * *
1913
- // * item *
1914
- // * *
1915
- // 0 ***** 1
1916
-
1917
- var getItemVisible = function getItemVisible(itemRect) {
1918
- var selectedLine = layer.lines.get(layer.selected.lines.toJS()[0]);
1919
- var itemVisible = false;
1920
- var vertex0 = layer.vertices.get(selectedLine.vertices.get(0));
1921
- var vertex1 = layer.vertices.get(selectedLine.vertices.get(1));
1922
- var l0 = {
1923
- x: vertex0.x,
1924
- y: vertex0.y
1925
- };
1926
- var l1 = {
1927
- x: vertex1.x,
1928
- y: vertex1.y
1929
- };
1930
- var r0 = itemRect.rect[0];
1931
- var r1 = itemRect.rect[1];
1932
- var r2 = itemRect.rect[2];
1933
- var r3 = itemRect.rect[3];
1934
-
1935
- // it doesn't need consider distance between item's line01 (frontside - it has door) and wall
1936
- var delta12 = GeometryUtils.distancePointFromLineSegment(l0, l1, (r1.x + r2.x) / 2, (r1.y + r2.y) / 2); // distance between item's line12 and wall
1937
- var delta23 = GeometryUtils.distancePointFromLineSegment(l0, l1, (r2.x + r3.x) / 2, (r2.y + r3.y) / 2); // distance between item's line23 and wall
1938
- var delta30 = GeometryUtils.distancePointFromLineSegment(l0, l1, (r3.x + r0.x) / 2, (r3.y + r0.y) / 2); // distance between item's line30 and wall
1939
-
1940
- if (delta12 < DISTANCE_EPSILON || delta23 < DISTANCE_EPSILON || delta30 < DISTANCE_EPSILON) {
1941
- itemVisible = true;
1942
- }
1943
- return itemVisible;
1944
- };
1945
- var val = {
1946
- pos: {
1947
- x: item.x,
1948
- y: item.y
1949
- },
1950
- rotRad: item.rotation / 180 * Math.PI
1951
- };
1952
- var catid = item.type;
1953
- var cat = catalog.elements[catid];
1954
- if (!cat) cat = catalog.elements[returnReplaceableDeepSearchType(catid)];
1955
- var width = convert(item.properties.getIn(['width', '_length'])).from('in').to(sceneData.unit);
1956
- var height = convert(item.properties.getIn(['height', '_length'])).from('in').to(sceneData.unit);
1957
- var depth = convert(item.properties.getIn(['depth', '_length'])).from('in').to(sceneData.unit);
1958
- val.size = {
1959
- width: width,
1960
- height: height,
1961
- depth: depth
1962
- };
1963
- val.layoutpos = cat.info.layoutpos;
1964
- val.is_corner = cat.info.is_corner;
1965
- val.item = item;
1966
- var calcrect = GeometryUtils.getCalcRectFromItem3D(val);
1967
-
1968
- // In elevation view, determin if item show or not
1969
- if (isElevationView(mode)) pivot.visible = getItemVisible(calcrect);
1970
- planData.plan.add(pivot);
1971
- planData.sceneGraph.layers[layer.id].items[item.id] = pivot;
1972
- //In a 3D view, merge each couterTop of equal height into a single conuterTop.
1973
- if (!isElevationView(mode)) {
1974
- addCountertop(planData.sceneGraph.layers[layer.id].countertops, item, planData, layer);
1975
- }
1976
- if (bAddMolding && item.category === 'cabinet' && (isElevationView(mode) && getItemVisible(calcrect) || !isElevationView(mode))) {
1977
- planData.sceneGraph.layers[layer.id].moldingGroups = addMolding(planData.sceneGraph.layers[layer.id].moldingGroups, item, planData, layer, itemsActions, mode) || planData.sceneGraph.layers[layer.id].moldingGroups;
1978
- }
1979
- if (pivot) {
1980
- // update the tool object's position to selected object's position
1981
- var selectedItem = planData.sceneGraph.layers[sceneData.selectedLayer].items[itemID];
1982
- var itemPos = selectedItem.position.clone();
1983
- if (!isEmpty(toolObj)) {
1984
- toolObj.position.set(planData.plan.position.x + itemPos.x, selectedItem.category === 'lighting' ? -planData.plan.position.y - selectedItem.properties.get('height').get('length') : planData.plan.position.y + selectedItem.children[0].position.y, planData.plan.position.z + itemPos.z);
1985
- }
1986
- pivot.children[0].children.forEach(function (pivotElement) {
1987
- pivotElement.visible = true;
1988
- });
1989
- if (pivot.children.length > 1) {
1990
- var _item4 = item.toJS();
1991
- if (_item4.doorStyle.doorStyles !== undefined) {
1992
- if (_item4.category === 'cabinet') {
1993
- if (_item4.doorStyle.doorStyles.cds.some(function (element) {
1994
- return element.itemID === item.itemID;
1995
- })) {
1996
- pivot.children.pop();
1997
- }
1998
- } else {
1999
- pivot.children.pop();
2000
- }
2001
- }
2002
- }
2003
- }
2004
- applyInteract(pivot, function () {
2005
- // document.getElementById('setting_dialog').style.display = 'none';
2006
- return itemsActions.selectItem(layer.id, item.id);
2007
- });
2008
- setTimeout(function () {
2009
- return getDistances(layer);
2010
- }, 100);
2011
- if (!sceneData.loadFlag && scene_mode == MODE_DRAWING_ITEM_3D) {
2012
- itemsActions.endLoading();
2013
- itemsActions.toggleLoadingCabinet();
2014
- }
2015
- });
2016
- }
2017
- function updateItem(sceneData, oldSceneData, planData, layer, itemID, differences, catalog, itemsActions, selfDestroy, selfBuild) {
2018
- var item = layer.getIn(['items', itemID]);
2019
- var oldItem = oldSceneData.getIn(['layers', layer.id, 'items', itemID]);
2020
- var mesh = planData.sceneGraph.layers[layer.id].items[itemID];
2021
- if (!mesh) return null;
2022
- return catalog.getElement(item.type).updateRender3D(item, layer, sceneData, mesh, oldItem, differences, selfDestroy, selfBuild);
2023
- }
2024
-
2025
- // Apply interact function to children of an Object3D
2026
- function applyInteract(object, interactFunction) {
2027
- // document.getElementById('setting_dialog').style.display = 'none';
2028
- object.traverse(function (child) {
2029
- if (child instanceof Three.Mesh) {
2030
- child.interact = interactFunction;
2031
- }
2032
- });
2033
- }
2034
-
2035
- // Apply opacity to children of an Object3D
2036
- function applyOpacity(object, opacity) {
2037
- object.traverse(function (child) {
2038
- if (child instanceof Three.Mesh) {
2039
- if (child.material && !Array.isArray(child.material)) {
2040
- // child.material.materials.forEach(materialChild => {
2041
- // materialChild.transparent = true;
2042
- // if (materialChild.maxOpacity) {
2043
- // materialChild.opacity = Math.min(materialChild.maxOpacity, opacity);
2044
- // } else if (materialChild.opacity && materialChild.opacity > opacity) {
2045
- // materialChild.maxOpacity = materialChild.opacity;
2046
- // materialChild.opacity = opacity;
2047
- // }
2048
- // });
2049
- } else if (child.material instanceof Array) {
2050
- child.material.forEach(function (material) {
2051
- material.transparent = true;
2052
- if (material.maxOpacity) {
2053
- material.opacity = Math.min(material.maxOpacity, opacity);
2054
- } else if (material.opacity && material.opacity > opacity) {
2055
- material.maxOpacity = material.opacity;
2056
- material.opacity = opacity;
2057
- }
2058
- });
2059
- } else {
2060
- child.material.transparent = true;
2061
- if (child.material.maxOpacity) {
2062
- child.material.opacity = Math.min(child.material.maxOpacity, opacity);
2063
- } else if (child.material.opacity && child.material.opacity > opacity) {
2064
- child.material.maxOpacity = child.material.opacity;
2065
- child.material.opacity = opacity;
2066
- }
2067
- }
2068
- }
2069
- });
2070
- }
2071
- function updateBoundingBox(planData) {
2072
- var flag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2073
- var mode = arguments.length > 2 ? arguments[2] : undefined;
2074
- if (scene_mode == MODE_DRAWING_ITEM_3D) return;
2075
- var newBoundingBox = new Three.Box3().setFromObject(planData.plan);
2076
- if (isFinite(newBoundingBox.max.x) && isFinite(newBoundingBox.min.x) && isFinite(newBoundingBox.max.y) && isFinite(newBoundingBox.min.y) && isFinite(newBoundingBox.max.z) && isFinite(newBoundingBox.min.z)) {
2077
- var newCenter = new Three.Vector3((newBoundingBox.max.x - newBoundingBox.min.x) / 2 + newBoundingBox.min.x, (newBoundingBox.max.y - newBoundingBox.min.y) / 2 + newBoundingBox.min.y, (newBoundingBox.max.z - newBoundingBox.min.z) / 2 + newBoundingBox.min.z);
2078
- if (!flag) {
2079
- planData.plan.position.sub(newCenter);
2080
- planData.grid.position.sub(newCenter);
2081
- if (isElevationView(mode)) {
2082
- planData.cam.position.sub(newCenter);
2083
- }
2084
- }
2085
- newBoundingBox.min.sub(newCenter);
2086
- newBoundingBox.max.sub(newCenter);
2087
- planData.boundingBox = newBoundingBox;
2088
- }
2089
- }
2090
-
2091
- /**
2092
- * Filter the array of diffs
2093
- * @param diffArray
2094
- * @param sceneData
2095
- * @param oldSceneData
2096
- * @returns {Array}
2097
- */
2098
- function filterDiffs(diffArray, sceneData, oldSceneData) {
2099
- return minimizeRemoveDiffsWhenSwitchingLayers(minimizeChangePropertiesAfterSelectionsDiffs(minimizeChangePropertiesDiffs(diffArray, sceneData, oldSceneData), sceneData, oldSceneData), sceneData, oldSceneData);
2100
- }
2101
-
2102
- /**
2103
- * Reduces the number of remove diffs when switching an hidden layer
2104
- * @param diffArray the array of the diffs
2105
- * @param sceneData
2106
- * @param oldSceneData
2107
- * @returns {Array}
2108
- */
2109
- function minimizeRemoveDiffsWhenSwitchingLayers(diffArray, sceneData, oldSceneData) {
2110
- var foundDiff;
2111
- var i;
2112
- for (i = 0; i < diffArray.length && !foundDiff; i++) {
2113
- if (diffArray[i].path[1] === 'selectedLayer') {
2114
- foundDiff = diffArray[i];
2115
- }
2116
- }
2117
- if (foundDiff) {
2118
- if (!sceneData.getIn(['layers', oldSceneData.selectedLayer, 'visible'])) {
2119
- return diffArray.filter(function (_ref6) {
2120
- var op = _ref6.op,
2121
- path = _ref6.path;
2122
- return !(path[path.length - 1] === 'selected' && path[1] === 'layers' && path[2] === oldSceneData.selectedLayer) && !(op === 'remove' && path.indexOf(oldSceneData.selectedLayer) !== -1);
2123
- });
2124
- }
2125
- }
2126
- return diffArray;
2127
- }
2128
-
2129
- /**
2130
- * Reduces the number of change properties diffs for selected elements
2131
- * @param diffArray the array of the diffs
2132
- * @param sceneData
2133
- * @param oldSceneData
2134
- * @returns {Array}
2135
- */
2136
- function minimizeChangePropertiesAfterSelectionsDiffs(diffArray, sceneData, oldSceneData) {
2137
- var idsFound = {};
2138
- diffArray.forEach(function (_ref7) {
2139
- var path = _ref7.path;
2140
- if (path[5] === 'selected') {
2141
- idsFound[path[4]] = path[4];
2142
- }
2143
- });
2144
- return diffArray.filter(function (_ref8) {
2145
- var path = _ref8.path;
2146
- if (path[5] === 'properties') {
2147
- return idsFound[path[4]] ? false : true;
2148
- }
2149
- return true;
2150
- });
2151
- }
2152
-
2153
- /**
2154
- * Reduces the number of change properties diffs
2155
- * @param diffArray the array of the diffs
2156
- * @param sceneData
2157
- * @param oldSceneData
2158
- * @returns {Array}
2159
- */
2160
- function minimizeChangePropertiesDiffs(diffArray, sceneData, oldSceneData) {
2161
- var idsFound = {};
2162
- return diffArray.filter(function (_ref9) {
2163
- var path = _ref9.path;
2164
- if (path[5] === 'properties') {
2165
- return idsFound[path[4]] ? false : idsFound[path[4]] = true;
2166
- } else if (path[5] === 'misc') {
2167
- // Remove misc changes
2168
- return false;
2169
- }
2170
- return true;
2171
- });
2172
- }
2173
-
2174
- // countertops:
2175
- // o id:
2176
- // o items: [itemid]
2177
- // o ct3d: 3d object
2178
- // o catid
2179
- // o pos
2180
- // o rotRad
2181
- // o size
2182
- function createCTFromItem(item, unit, catalog) {
2183
- return createCTFromItems([item], unit, catalog);
2184
- }
2185
- function createCTFromItems(items, unit, catalog) {
2186
- var item0 = items[0];
2187
- var item1 = items[items.length - 1];
2188
- var CTId = IDBroker.acquireID();
2189
- var ct3d = null;
2190
- var catid = item0.type;
2191
- var pos = {
2192
- x: (item0.x + item1.x) / 2,
2193
- y: (item0.y + item1.y) / 2
2194
- };
2195
- var rotRad = item0.rotation / 180 * Math.PI;
2196
- var cat = catalog.elements[catid];
2197
- // let width = convert(item0.properties.getIn(['width', '_length'])).from('in').to('cm');
2198
- // let depth = convert(item0.properties.getIn(['depth', '_length'])).from('in').to('cm');
2199
- // let height = convert(item0.properties.getIn(['height', '_length'])).from('in').to('cm');
2200
- var width = item0.properties.get('width').get('_length');
2201
- var widthUnit = item0.properties.get('width').get('_unit') || 'cm';
2202
- width = convert(width).from(widthUnit).to('cm');
2203
- var depth = item0.properties.get('depth').get('_length');
2204
- var depthUnit = item0.properties.get('depth').get('_unit') || 'cm';
2205
- depth = convert(depth).from(depthUnit).to('cm');
2206
- var height = item0.properties.get('height').get('_length');
2207
- var heightUnit = item0.properties.get('height').get('_unit') || 'cm';
2208
- height = convert(height).from(heightUnit).to('cm');
2209
- var size = {
2210
- width: width * items.length,
2211
- depth: depth,
2212
- height: height
2213
- };
2214
- return {
2215
- id: CTId,
2216
- items: items,
2217
- ct3d: ct3d,
2218
- catid: catid,
2219
- pos: pos,
2220
- rotRad: rotRad,
2221
- size: size
2222
- };
2223
- }
2224
- export function createMDFromItem(item, lines, molding) {
2225
- var MDId = IDBroker.acquireID();
2226
- var z = item.properties.get('altitude').get('_length');
2227
- var zUnit = item.properties.get('altitude').get('_unit') || 'cm';
2228
- z = convert(z).from(zUnit).to('cm');
2229
- var height = item.properties.get('height').get('_length');
2230
- var heightUnit = item.properties.get('height').get('_unit') || 'cm';
2231
- height = convert(height).from(heightUnit).to('cm');
2232
- switch (molding.location_type) {
2233
- case TOP_MOLDING_LOCATION:
2234
- z += height;
2235
- break;
2236
- case MIDDLE_MOLDING_LOCATION:
2237
- z += height / 2;
2238
- break;
2239
- case BOTTOM_MOLDING_LOCATION:
2240
- z += 0;
2241
- break;
2242
- default:
2243
- break;
2244
- }
2245
- return {
2246
- id: MDId,
2247
- items: [item],
2248
- meshes: [],
2249
- pos: {
2250
- x: 0,
2251
- y: 0,
2252
- z: z
2253
- },
2254
- size: {
2255
- width: 0,
2256
- depth: 0,
2257
- height: 0
2258
- },
2259
- lines: lines,
2260
- molding: molding,
2261
- pointGroups: []
2262
- };
2263
- }
2264
- function tryAdjacent(ct1, ct2) {
2265
- if (ct1.catid.includes('Dishwasher') && ct1.catid.includes('BF')) {
2266
- var temp = ct1;
2267
- ct1 = ct2;
2268
- ct2 = temp;
2269
- }
2270
- log('----tryAdjacent', ct1.id, ct2.id);
2271
- if (!ct2.catid.includes('Dishwasher') && !ct2.catid.includes('BF') && ct1.catid != ct2.catid) return false;
2272
- if (ct1.rotRad != ct2.rotRad) return false;
2273
- log('ct1', ct1.pos.x, ct1.pos.y, ct1.size.width);
2274
- log('ct2', ct2.pos.x, ct2.pos.y, ct2.size.width);
2275
- var dist = GeometryUtils.verticesDistance(ct1.pos, ct2.pos);
2276
- var totalwidth = ct1.size.width + ct2.size.width;
2277
- log('epsilon', dist, totalwidth, Math.abs(2 * dist - totalwidth));
2278
- if (Math.abs(2 * dist - totalwidth) / totalwidth > 1e-3) return false;
2279
- log('----success');
2280
- var newpos = {
2281
- x: (ct1.pos.x * ct1.size.width + ct2.pos.x * ct2.size.width) / totalwidth,
2282
- y: (ct1.pos.y * ct1.size.width + ct2.pos.y * ct2.size.width) / totalwidth
2283
- };
2284
- var newsize = {
2285
- width: totalwidth,
2286
- depth: ct1.size.depth,
2287
- height: ct1.size.height
2288
- };
2289
- var CTId = IDBroker.acquireID();
2290
- var items = GeometryUtils.compareVertices(ct1.pos, ct2.pos) > 0 ? [].concat(_toConsumableArray(ct1.items), _toConsumableArray(ct2.items)) : [].concat(_toConsumableArray(ct2.items), _toConsumableArray(ct1.items));
2291
- var ct3d = null;
2292
- var catid = ct1.catid;
2293
- return {
2294
- id: CTId,
2295
- items: items,
2296
- ct3d: ct3d,
2297
- catid: catid,
2298
- pos: newpos,
2299
- rotRad: ct1.rotRad,
2300
- size: newsize
2301
- };
2302
- }
2303
- function isParallelLines(line1, line2) {
2304
- var isParallel = false;
2305
- if (Math.abs(line1[0].y - line1[1].y) <= EPSILON && Math.abs(line2[0].y - line2[1].y) <= EPSILON) isParallel = true;
2306
- if (Math.abs(line1[0].x - line1[1].x) <= EPSILON && Math.abs(line2[0].x - line2[1].x) <= EPSILON) isParallel = true;
2307
- if (Math.abs((line1[0].x - line1[1].x) / (line1[0].y - line1[1].y) - (line2[0].x - line2[1].x) / (line2[0].y - line2[1].y)) <= EPSILON) isParallel = true;
2308
- if (isParallel) {
2309
- return true;
2310
- }
2311
- return false;
2312
- }
2313
- export function tryAdjacentMD(md1, md2, molding) {
2314
- log('----tryAdjacent', md1.id, md2.id);
2315
- if (Math.abs(md1.pos.z - md2.pos.z) > EPSILON) return false;
2316
- var id1 = md1.items[0].doorStyle.hasOwnProperty('id') ? md1.items[0].doorStyle.id : md1.items[0].doorStyle.toJS().id,
2317
- id2 = md2.items[0].doorStyle.hasOwnProperty('id') ? md2.items[0].doorStyle.id : md2.items[0].doorStyle.toJS().id;
2318
- if (id1 !== id2) return false;
2319
- var newLines = md1.lines.concat(md2.lines);
2320
- var isMerge = false;
2321
- md1.lines.forEach(function (line1) {
2322
- md2.lines.map(function (line2) {
2323
- // filter removed lines
2324
- if (newLines.findIndex(function (a) {
2325
- return a[2] === line1[2];
2326
- }) === -1 || newLines.findIndex(function (a) {
2327
- return a[2] === line2[2];
2328
- }) === -1) return false;
2329
- // is parallel two lines
2330
- if (isParallelLines(line1, line2)) {
2331
- var disLine1 = GeometryUtils.verticesDistance(line1[0], line1[1]);
2332
- var disLine2 = GeometryUtils.verticesDistance(line2[0], line2[1]);
2333
- if (GeometryUtils.sameMDistances(GeometryUtils.verticesDistance(line2[0], line1[0]) + GeometryUtils.verticesDistance(line1[1], line2[1]), Math.abs(disLine2 - disLine1))) {
2334
- newLines = newLines.filter(function (a) {
2335
- return !(a[2] === line1[2] || a[2] === line2[2]);
2336
- });
2337
- if (!GeometryUtils.sameMPoints(line1[0], line2[0])) newLines.push([line1[0], line2[0], IDBroker.acquireID()]);
2338
- if (!GeometryUtils.sameMPoints(line1[1], line2[1])) newLines.push([line1[1], line2[1], IDBroker.acquireID()]);
2339
- isMerge = true;
2340
- return false;
2341
- }
2342
- if (GeometryUtils.sameMDistances(GeometryUtils.verticesDistance(line2[0], line1[1]) + GeometryUtils.verticesDistance(line1[0], line2[1]), Math.abs(disLine2 - disLine1))) {
2343
- newLines = newLines.filter(function (a) {
2344
- return !(a[2] === line1[2] || a[2] === line2[2]);
2345
- });
2346
- if (!GeometryUtils.sameMPoints(line1[1], line2[0])) newLines.push([line1[1], line2[0], IDBroker.acquireID()]);
2347
- if (!GeometryUtils.sameMPoints(line1[0], line2[1])) newLines.push([line1[0], line2[1], IDBroker.acquireID()]);
2348
- isMerge = true;
2349
- return false;
2350
- }
2351
- var samePointNum = -1,
2352
- i = 0;
2353
- while (i < 4 && samePointNum === -1) {
2354
- if (GeometryUtils.sameMPoints(line1[Math.floor(i / 2)], line2[i % 2]) && GeometryUtils.sameMDistances(disLine1 + disLine2, GeometryUtils.verticesDistance(line1[Math.floor((3 - i) / 2)], line2[(3 - i) % 2]))) {
2355
- samePointNum = 3 - i;
2356
- } else {
2357
- i++;
2358
- }
2359
- }
2360
- if (samePointNum > -1) {
2361
- newLines = newLines.filter(function (a) {
2362
- return !(a[2] === line1[2] || a[2] === line2[2]);
2363
- });
2364
- newLines.push([_objectSpread({}, line1[Math.floor(samePointNum / 2)]), _objectSpread({}, line2[samePointNum % 2]), IDBroker.acquireID()]);
2365
- isMerge = true;
2366
- return false;
2367
- }
2368
- var pointNum = -1,
2369
- k = 0;
2370
- while (k < 4 && pointNum === -1) {
2371
- if (GeometryUtils.sameMDistances(GeometryUtils.verticesDistance(line1[Math.floor(k / 2)], line2[k % 2]) + GeometryUtils.verticesDistance(line1[1 - Math.floor(k / 2)], line2[k % 2]), disLine1) && GeometryUtils.sameMDistances(GeometryUtils.verticesDistance(line1[1 - Math.floor(k / 2)], line2[k % 2]) + GeometryUtils.verticesDistance(line1[1 - Math.floor(k / 2)], line2[1 - k % 2]), disLine2)) {
2372
- pointNum = k;
2373
- } else {
2374
- k++;
2375
- }
2376
- }
2377
- }
2378
- return false;
2379
- });
2380
- });
2381
- if (!newLines.length) return _objectSpread({}, md2);
2382
- if (!isMerge) return false;
2383
- return {
2384
- id: IDBroker.acquireID(),
2385
- items: [].concat(_toConsumableArray(md2.items.filter(function (item) {
2386
- return md1.items.findIndex(function (it) {
2387
- return it.id === item.id;
2388
- }) === -1;
2389
- })), _toConsumableArray(md1.items)),
2390
- meshes: [],
2391
- pos: md1.pos,
2392
- size: md1.size,
2393
- lines: newLines,
2394
- molding: molding
2395
- };
2396
- }
2397
- function showItemCT(item, CT, visible, planData, layer) {
2398
- var item3D = planData.sceneGraph.layers[layer.id].items[item.id];
2399
- if (item3D === undefined) return undefined;
2400
- item3D.traverse(function (child) {
2401
- if (child.name.includes('countertop')) {
2402
- child.visible = visible;
2403
- if (child.material.map === null) {
2404
- var normalMap = item.counterTop.uri;
2405
- var interiortexture = loadTexture(normalMap);
2406
- applyTexture(child.material, interiortexture, 100, 100);
2407
- child.material.color = new Color(1, 1, 1);
2408
- return;
2409
- }
2410
- child.material.map.repeat.x = 1;
2411
- }
2412
- });
2413
- }
2414
- function getCountertopMesh(item, visible, planData, layer) {
2415
- if (item.type.includes('Dishwasher')) return undefined;
2416
- if (item.type.includes('BF')) return undefined;
2417
- var item3D = planData.sceneGraph.layers[layer.id].items[item.id];
2418
- var countertop = null;
2419
- if (item3D === undefined) return undefined;
2420
- item3D.traverse(function (child) {
2421
- if (child.name.includes('countertop')) {
2422
- countertop = child;
2423
- }
2424
- });
2425
- return countertop;
2426
- }
2427
- function getDoorStyleMaterial(items, planData, layer, name) {
2428
- var item3D = null;
2429
- // find Item with visible = true, in elevation mode
2430
- items.forEach(function (item) {
2431
- var tempItem = null;
2432
- tempItem = planData.sceneGraph.layers[layer.id].items[item.id];
2433
- if (tempItem && tempItem.visible) {
2434
- item3D = tempItem;
2435
- }
2436
- });
2437
- var door_mesh = null;
2438
- if (!item3D) return undefined;
2439
- item3D.traverse(function (child) {
2440
- if (!door_mesh && !child.name.includes('countertop') && !child.name.includes('_interior_') && !child.name.includes('handle') && child.type === OBJTYPE_MESH) {
2441
- door_mesh = child;
2442
- }
2443
- });
2444
- return door_mesh && door_mesh.material;
2445
- }
2446
- function addCTMesh(countertop, planData, layer) {
2447
- if (countertop.items.length == 1) {
2448
- showItemCT(countertop.items[0], countertop, true, planData, layer);
2449
- } else {
2450
- var ctMesh = null;
2451
- countertop.items.some(function (item) {
2452
- ctMesh = getCountertopMesh(item, true, planData, layer);
2453
- return ctMesh != null;
2454
- });
2455
- if (!ctMesh) return;
2456
- if (0) {
2457
- var material = ctMesh.material;
2458
- var thickness = 3.81;
2459
- var geometry = new Three.BoxGeometry(countertop.size.width, thickness, countertop.size.depth);
2460
- var ct3d = new Three.Mesh(geometry, material);
2461
- countertop.ct3d = ct3d;
2462
- planData.plan.add(ct3d);
2463
- ct3d.position.x = countertop.pos.x;
2464
- ct3d.position.z = -countertop.pos.y;
2465
- ct3d.position.y = countertop.size.height + thickness / 2;
2466
- ct3d.quaternion.setFromAxisAngle(new Three.Vector3(0, 1, 0), countertop.rotRad);
2467
- ct3d.name = 'countertops';
2468
- } else {
2469
- var _ct3d = ctMesh.clone();
2470
- countertop.ct3d = _ct3d;
2471
- _ct3d.visible = true;
2472
- _ct3d.material = ctMesh.material.clone();
2473
- if (_ct3d.material.map !== null) {
2474
- _ct3d.material.map.copy(ctMesh.material.map);
2475
- _ct3d.material.map.repeat.x = countertop.items.length;
2476
- }
2477
- ctMesh.updateMatrix();
2478
- ctMesh.parent.updateMatrix();
2479
- ctMesh.parent.parent.updateMatrix();
2480
- var ctmeshMat = ctMesh.matrix;
2481
- var objMat = ctMesh.parent.matrix;
2482
- var pivotMat = ctMesh.parent.parent.matrix;
2483
- pivotMat.setPosition(new Three.Vector3(countertop.pos.x, 0, -countertop.pos.y));
2484
- var width = countertop.items.find(function (ct) {
2485
- return !ct.type.includes('Dishwasher') && !ct.type.includes('BF');
2486
- }).properties.get('width').get('_length');
2487
- var unit_width = countertop.items.find(function (ct) {
2488
- return !ct.type.includes('Dishwasher') && !ct.type.includes('BF');
2489
- }).properties.get('width').get('_unit') || 'cm';
2490
- width = convert(width).from(unit_width).to('cm');
2491
- pivotMat.scale(new Three.Vector3(countertop.size.width / width, 1, 1));
2492
- var finalMat = objMat.premultiply(pivotMat);
2493
- _ct3d.applyMatrix4(finalMat);
2494
- planData.plan.add(_ct3d);
2495
- _ct3d.name = 'countertops';
2496
- }
2497
- }
2498
- }
2499
- function getArea(a, b, c) {
2500
- return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);
2501
- }
2502
- function isSingleQuadrilateral(groupCount, pointGroup) {
2503
- return groupCount === 1 && pointGroup.length === 4;
2504
- }
2505
-
2506
- /**
2507
- * @param MDV - molding points
2508
- * @param width - cabinet width
2509
- * @param depth - cabinet depth ( z axis )
2510
- * @param model - molding info that appear in real 3D
2511
- */
2512
- function moldingVertices(mPointGroup, mdGeo, MDV, model, svg_width, svg_height, groupCount) {
2513
- var pointGroup = mPointGroup;
2514
- var length = pointGroup.length;
2515
- var isSnap = true;
2516
-
2517
- // Point O
2518
- var o = new Three.Vector2(0, 0);
2519
- if (GeometryUtils.samePoints(pointGroup[0], pointGroup[length - 1])) {
2520
- pointGroup = pointGroup.slice(0, length - 1);
2521
- length--;
2522
- isSnap = false;
2523
- }
2524
- var verticesArray = [];
2525
- var t = [[-1, -1], [1, -1], [1, 1], [-1, 1]];
2526
- if (!isSnap && isSingleQuadrilateral(groupCount, pointGroup)) {
2527
- var tmp_pos = [];
2528
- t.forEach(function (tmp) {
2529
- pointGroup.forEach(function (point) {
2530
- if (point.x * tmp[0] > 0 && point.y * tmp[1] > 0) {
2531
- tmp_pos.push(point);
2532
- }
2533
- });
2534
- });
2535
- pointGroup = tmp_pos;
2536
- }
2537
- pointGroup.forEach(function (cur, i) {
2538
- var prev = isSnap && i === 0 ? cur : pointGroup[(i + length - 1) % length];
2539
- var next = isSnap && i === length - 1 ? cur : pointGroup[(i + 1) % length];
2540
- var vecPC = cur.clone().sub(prev); // vector from point `prev` to point `cur`
2541
- var vecNC = cur.clone().sub(next); // vector from point `next` to point `cur`
2542
-
2543
- // Calculate normal vector to `vecPC`
2544
- var vecNorm = new Three.Vector2(0, 1);
2545
- if (vecPC.x) {
2546
- if (vecPC.x > 0) {
2547
- vecNorm = new Three.Vector2(-vecPC.y / vecPC.x, 1);
2548
- } else {
2549
- vecNorm = new Three.Vector2(vecPC.y / vecPC.x, -1);
2550
- }
2551
- } else {
2552
- if (vecPC.y === 0) {
2553
- if (vecNC.x) {
2554
- if (vecNC.x > 0) {
2555
- vecNorm = new Three.Vector2(vecNC.y / vecNC.x, -1);
2556
- } else {
2557
- vecNorm = new Three.Vector2(-vecNC.y / vecNC.x, 1);
2558
- }
2559
- } else {
2560
- if (vecNC.y > 0) {
2561
- vecNorm = new Three.Vector2(1, 0);
2562
- } else {
2563
- vecNorm = new Three.Vector2(-1, 0);
2564
- }
2565
- }
2566
- } else {
2567
- if (vecPC.y > 0) {
2568
- vecNorm = new Three.Vector2(-1, 0);
2569
- } else {
2570
- vecNorm = new Three.Vector2(1, 0);
2571
- }
2572
- }
2573
- }
2574
- var p1 = cur.clone().add(vecNorm); // the point that's away from `cur` by `vecNorm`
2575
- if (getArea(prev, p1, cur) > 0) {
2576
- vecNorm.multiplyScalar(-1);
2577
- }
2578
- var area = 0.5 * getArea(prev, cur, next);
2579
- var lenPN = next.clone().sub(prev).length();
2580
- var lenNC = vecNC.length();
2581
- var lenPC = vecPC.length();
2582
- var alpha = Math.acos((lenNC * lenNC + lenPC * lenPC - lenPN * lenPN) / (2 * lenNC * lenPC));
2583
- if (area < 0) alpha = 2 * Math.PI - alpha; // Exterior Angle
2584
- alpha /= 2;
2585
- if (isNaN(alpha)) {
2586
- alpha = Math.PI / 2;
2587
- }
2588
- vecNorm.rotateAround(o, Math.PI / 2 - alpha);
2589
- vecNorm.normalize();
2590
- vecNorm.multiplyScalar(1 / Math.sin(alpha));
2591
-
2592
- // Make 3D Points
2593
- MDV.forEach(function (p) {
2594
- var x = cur.x - vecNorm.x * ((p.x / svg_width - 0.5) * model.length);
2595
- var y = (0.5 - p.y / svg_height) * model.width;
2596
- var z = -cur.y + vecNorm.y * ((p.x / svg_width - 0.5) * model.length);
2597
- if (mdGeo.attributes.hasOwnProperty('position')) verticesArray = mdGeo.attributes.position.array;
2598
- verticesArray.push(x, y, z);
2599
- });
2600
- });
2601
- var mdGeo1 = mdGeo.setAttribute('position', new Three.BufferAttribute(new Float32Array(verticesArray), 3));
2602
- mdGeo1.needsUpdate = true;
2603
- return mdGeo1;
2604
- }
2605
- var dcmFace = function dcmFace(a, leng, MDV) {
2606
- for (var i = a; i < a + 2; i++) {
2607
- var f_a1 = i;
2608
- var f_b1 = i + leng;
2609
- var f_c1 = i + leng + 1;
2610
- var f_a2 = i;
2611
- var f_b2 = i + 1;
2612
- var f_c2 = f_c1;
2613
- var _indices = Array.from(MDV.index.array);
2614
- _indices.push(f_a1, f_b1, f_c1, f_c2, f_b2, f_a2);
2615
- MDV.setIndex(_indices);
2616
- }
2617
- var indices = Array.from(MDV.index.array);
2618
- indices.push(a + 2, a + leng + 2, a + leng + 4, a + leng + 4, a + 4, a + 2);
2619
- MDV.setIndex(indices);
2620
- for (var _i = a + 4; _i < a + 74; _i++) {
2621
- var _f_a = _i;
2622
- var _f_b = _i + leng;
2623
- var _f_c = _i + leng + 1;
2624
- var _f_a2 = _i;
2625
- var _f_b2 = _i + 1;
2626
- var _f_c2 = _f_c;
2627
- var _indices2 = Array.from(MDV.index.array);
2628
- _indices2.push(_f_a, _f_b, _f_c, _f_c2, _f_b2, _f_a2);
2629
- MDV.setIndex(_indices2);
2630
- }
2631
- var faces = Array.from(MDV.index.array);
2632
- faces.push(a + 50, a + 3, a + 103, a + 103, a + 150, a + 50);
2633
- MDV.setIndex(faces);
2634
- };
2635
- var fbmFace = function fbmFace(a, leng, MDV) {
2636
- var total_leng = leng * 4;
2637
- for (var i = a; i < a + leng - 1; i++) {
2638
- var f_a1 = i;
2639
- var f_b1 = (i + leng) % total_leng;
2640
- var f_c1 = (i + leng + 1) % total_leng;
2641
- var f_a2 = i;
2642
- var f_b2 = i + 1;
2643
- var f_c2 = f_c1;
2644
- var indices = [];
2645
- if (MDV.index !== null) {
2646
- indices = Array.from(MDV.index.array);
2647
- }
2648
- indices.push(f_a1, f_b1, f_c1, f_c2, f_b2, f_a2);
2649
- MDV.setIndex(indices);
2650
- }
2651
- };
2652
- var assignUVs = function assignUVs(geometry) {
2653
- geometry.computeBoundingBox();
2654
- var h = 400;
2655
- var _geometry$boundingBox = geometry.boundingBox,
2656
- min = _geometry$boundingBox.min,
2657
- max = _geometry$boundingBox.max;
2658
- var offset = new Three.Vector2(0 - min.x, 0 - min.z);
2659
- var range = new Three.Vector2(max.x - min.x, max.z - min.z);
2660
- geometry.faceVertexUvs[0] = geometry.faces.map(function (face) {
2661
- var v1 = geometry.vertices[face.a];
2662
- var v2 = geometry.vertices[face.b];
2663
- var v3 = geometry.vertices[face.c];
2664
- return [new Three.Vector2((v1.x + offset.x) / range.x, (v1.z + offset.y) / (range.y + h)), new Three.Vector2((v2.x + offset.x) / range.x, (v2.z + offset.y) / (range.y + h)), new Three.Vector2((v3.x + offset.x) / range.x, (v3.z + offset.y) / (range.y + h))];
2665
- });
2666
- geometry.uvsNeedUpdate = true;
2667
- };
2668
- var assignUVsA = function assignUVsA(geometry) {
2669
- geometry.computeBoundingBox();
2670
- var h = 200;
2671
- var _geometry$boundingBox2 = geometry.boundingBox,
2672
- min = _geometry$boundingBox2.min,
2673
- max = _geometry$boundingBox2.max;
2674
- var offset = new Three.Vector2(0 - min.x, 0 - min.y);
2675
- var range = new Three.Vector2(max.x - min.x, max.y - min.y);
2676
- geometry.faceVertexUvs[0] = geometry.faces.map(function (face) {
2677
- var v1 = geometry.vertices[face.a];
2678
- var v2 = geometry.vertices[face.b];
2679
- var v3 = geometry.vertices[face.c];
2680
- return [new Three.Vector2((v1.x + offset.x) / (range.x + h), (v1.y + offset.y) / (range.y + h)), new Three.Vector2((v2.x + offset.x) / (range.x + h), (v2.y + offset.y) / (range.y + h)), new Three.Vector2((v3.x + offset.x) / (range.x + h), (v3.y + offset.y) / (range.y + h))];
2681
- });
2682
- geometry.uvsNeedUpdate = true;
2683
- };
2684
-
2685
- /*
2686
- Remove specified type of 3d object easily
2687
- */
2688
- export function deleteSpecifiedMeshObjects(type) {
2689
- var childLen = planData.plan.children.length;
2690
- var children = [];
2691
- for (var i = 0; i < childLen; i++) {
2692
- if (planData.plan.children[i].name != type) children.push(planData.plan.children[i]);
2693
- }
2694
- planData.plan.children = children;
2695
- }
2696
- export function getMeshesFromScene() {
2697
- var childLen = planData.plan.children.length;
2698
- var children = [];
2699
- for (var i = 0; i < childLen; i++) {
2700
- if (planData.plan.children[i].type == OBJTYPE_MESH) children.push(planData.plan.children[i]);
2701
- }
2702
- return children;
2703
- }
2704
- export function threedfabs(a) {
2705
- return a > 0 ? a : -a;
2706
- }
2707
- export function getDistanceBetweenLineSegment(pos1, pos2, pos3, pos4) {
2708
- if (pos1.x == pos2.x && pos3.x == pos4.x) return pos3.x - pos1.x;else if (pos1.y == pos2.y && pos3.y == pos4.y) return pos3.y - pos1.y;else return -1;
2709
- }
2710
-
2711
- /**
2712
- * check to see if an item is suitable for the given doorStyle.
2713
- * @param _item
2714
- * @returns true if it's not suitable.
2715
- */
2716
- export function showYelloBox(_item) {
2717
- var _doorStyle;
2718
- var doorStyle = _item === null || _item === void 0 ? void 0 : _item.doorStyle;
2719
-
2720
- // If doorStyle is an Immutable Map, convert to plain JS
2721
- if (doorStyle && typeof doorStyle.toJS === 'function') {
2722
- doorStyle = doorStyle.toJS();
2723
- }
2724
- var isItemCabinet = (_item === null || _item === void 0 ? void 0 : _item.category) === 'cabinet';
2725
- var cds = (_doorStyle = doorStyle) === null || _doorStyle === void 0 || (_doorStyle = _doorStyle.doorStyles) === null || _doorStyle === void 0 ? void 0 : _doorStyle.cds;
2726
-
2727
- // hasItemCDS: item is suitable if its itemID exists in cds
2728
- var hasItemCDS = isItemCabinet && Array.isArray(cds) ? cds.some(function (element) {
2729
- return element.itemID === _item.itemID;
2730
- }) : false;
2731
-
2732
- // return true if it's a cabinet but not suitable for the current doorStyle
2733
- return isItemCabinet && !hasItemCDS;
2734
- }
2735
- function isSimilar(a, b) {
2736
- if (threedfabs(a - b) <= 0.01) return 1;
2737
- return 0;
2738
- }
2739
- export function sameSign(pos1, pos2, pos3) {
2740
- var ch1 = 0.0;
2741
- var ch2 = 1.0;
2742
- if (isSimilar(pos1.x, pos2.x) && isSimilar(pos1.x, pos3.x)) {
2743
- ch1 = (pos2.y - pos1.y) * (pos3.y - pos1.y);
2744
- } else if (isSimilar(pos1.y, pos2.y) && isSimilar(pos1.y, pos3.y)) {
2745
- ch1 = (pos2.x - pos1.x) * (pos3.x - pos1.x);
2746
- } else {
2747
- ch1 = (pos2.y - pos1.y) * 1.0 / (pos2.x - pos1.x);
2748
- ch2 = (pos3.y - pos1.y) * 1.0 / (pos3.x - pos1.x);
2749
- }
2750
- if (ch1 * ch2 >= 0) return 1;
2751
- return 0;
2752
- }
2753
- export function getTotalDistance(pos, rect) {
2754
- var sum = 0;
2755
- for (var i = 0; i < rect.length; i++) {
2756
- sum += verticesDistance(pos, rect[i]);
2757
- }
2758
- return sum;
2759
- }
2760
- var applyTexture = function applyTexture(material, texture, length, height) {
2761
- if (texture) {
2762
- material.map = texture;
2763
- material.needsUpdate = true;
2764
- material.map.wrapS = Three.RepeatWrapping;
2765
- material.map.wrapT = Three.RepeatWrapping;
2766
- material.map.repeat.set(length * 0.01, height * 0.01);
2767
- if (texture.normal) {
2768
- material.normalMap = loadTexture(texture.normal.uri);
2769
- material.normalScale = new Vector2(texture.normal.normalScaleX, texture.normal.normalScaleY);
2770
- material.normalMap.wrapS = Three.RepeatWrapping;
2771
- material.normalMap.wrapT = Three.RepeatWrapping;
2772
- material.normalMap.repeat.set(length * texture.normal.lengthRepeatScale, height * texture.normal.heightRepeatScale);
2773
- }
2774
- }
2775
- };
2776
-
2777
- /**
2778
- *
2779
- * @param {{is_corner:number,itemInfo:Item,layoutpos:string,pos:{x:number,y:number},rect:[{x:number,y:number}],
2780
- * rotRad:number,size:{depth:number,width:number,height:number}}} item
2781
- * @param {Layer} layer
2782
- * @param {{boundingBox:Box3,catalog:Catalog,grid: Object3D,plan: Object3D,sceneData: Scene,sceneGraph}} planData
2783
- * @param {Scene} scene
2784
- */
2785
- export function createBacksplash(item, layer, planData, scene) {
2786
- var sceneGraph = planData.sceneGraph;
2787
- var selectedLayer = planData.sceneData.selectedLayer;
2788
- /**
2789
- * @type {[{backsplash,info:{rotY:number,posX:number,posY:number,posZ:number,splashWidth:number,splashHeight:number,splashDepth:number,id:string}}]}
2790
- */
2791
- var backsplashes = sceneGraph.layers[selectedLayer].backsplashes;
2792
- var backsplashApplied = layer.get('backsplashApplied');
2793
- var name = 'backsplash' + item.itemInfo.id;
2794
- var index = backsplashes.findIndex(function (item) {
2795
- return item.backsplash.name === name;
2796
- });
2797
- var itemToSave = {
2798
- backsplash: null,
2799
- info: {}
2800
- };
2801
- if (!item.itemInfo.backsplashVisible) {
2802
- // If backsplash is not visible
2803
- if (index >= 0) {
2804
- backsplashes.splice(index, 1); // Remove from backsplashes array
2805
- }
2806
- return;
2807
- }
2808
-
2809
- // Get wall items
2810
-
2811
- var i,
2812
- wallItems = [];
2813
- var allWallItems = GeometryUtils.getAllItemSpecified(scene, planData.catalog, WALL_CABINET_LAYOUTPOS);
2814
- for (i = 0; i < allWallItems.others.length; i++) wallItems.push(allWallItems.others[i]);
2815
- if (allWallItems.cur) wallItems.push(allWallItems.cur);
2816
-
2817
- // Get information of item itself
2818
-
2819
- var altitude = item.itemInfo.properties.get('altitude').get('_length');
2820
- var altitudeUnit = item.itemInfo.properties.get('altitude').get('_unit') || 'cm';
2821
- altitude = convert(altitude).from(altitudeUnit).to('cm');
2822
- var thickness = 1,
2823
- /** Height --- altitude */depth;
2824
-
2825
- // Calc wall & hole items info
2826
-
2827
- /**
2828
- * Wall & Hole items info
2829
- * @type {[{x:number,width:number,altitude:number}]}
2830
- */
2831
- var altItems = [],
2832
- flag = false;
2833
- wallItems.map(function (wallItem) {
2834
- var altitude = wallItem.itemInfo.properties.get('altitude').get('_length');
2835
- var altitudeUnit = wallItem.itemInfo.properties.get('altitude').get('_unit') || 'cm';
2836
- altitude = convert(altitude).from(altitudeUnit).to('cm');
2837
- altItems.push({
2838
- x: wallItem.pos.x,
2839
- width: wallItem.size.width,
2840
- altitude: altitude
2841
- });
2842
- });
2843
- layer.holes.map(function (hole) {
2844
- var width = hole.properties.getIn(['width', 'length']);
2845
- var altitude = hole.properties.getIn(['altitude', 'length']);
2846
- altItems.push({
2847
- x: hole.x,
2848
- width: width,
2849
- altitude: altitude
2850
- });
2851
- });
2852
- if (altItems.length > 0) {
2853
- depth = altItems[0].altitude;
2854
- altItems.map(function (altItem) {
2855
- if (item.pos.x + item.size.width / 2 >= altItem.x - altItem.width / 2 && item.pos.x - item.size.width / 2 <= altItem.x + altItem.width / 2) {
2856
- if (depth >= altItem.altitude) {
2857
- depth = altItem.altitude;
2858
- flag = true;
2859
- }
2860
- }
2861
- });
2862
- }
2863
- if (!flag) depth = 52 * 2.54;
2864
-
2865
- // Get backsplash info
2866
-
2867
- var posX = item.pos.x - Math.sin(item.rotRad) * (item.size.depth / 2 - thickness);
2868
- var posY = altitude + depth / 2;
2869
- var posZ = -item.pos.y - Math.cos(item.rotRad) * (item.size.depth / 2 - thickness);
2870
- // TODO If you want apply backsplash to walls that's not vertical or horizontal ( slope )
2871
- // You must update this calcuating rotY
2872
- var rotY = item.rotRad;
2873
- var posX1 = item.pos.x + Math.cos(item.rotRad) * (item.size.width / 2 - thickness);
2874
- var posY1 = altitude + depth / 2;
2875
- var posZ1 = -item.pos.y - Math.sin(item.rotRad) * (item.size.width / 2 - thickness);
2876
- // TODO If you want apply backsplash to walls that's not vertical or horizontal ( slope )
2877
- // You must update this calcuating rotY
2878
- var rotY1 = item.rotRad + Math.PI / 2;
2879
- var splashWidth = item.size.width;
2880
- var splashHeight = depth;
2881
- var splashDepth = thickness;
2882
-
2883
- // Find mergeable other backsplashes
2884
-
2885
- var info, wholeWidth, /** Width factor */factor, distance, halfWidth, /** To get new center */centerFactor;
2886
- var _iterator = _createForOfIteratorHelper(backsplashes),
2887
- _step;
2888
- try {
2889
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
2890
- var back = _step.value;
2891
- info = back.info;
2892
- if (info.height === splashHeight && info.rotY === rotY) {
2893
- factor = Math.cos(rotY) || 1;
2894
- distance = Math.hypot(posX - info.posX, posZ - info.posZ) / factor;
2895
- halfWidth = (info.width + splashWidth) / 2;
2896
- if (Math.abs(distance - halfWidth) < 1e-2) {
2897
- // dispose `back`
2898
- if (info.id) {
2899
- deleteSpecifiedMeshObjects('backsplash' + info.id);
2900
- }
2901
-
2902
- // Get center position
2903
- wholeWidth = info.width + splashWidth;
2904
- centerFactor = info.width / wholeWidth;
2905
- posX = posX + centerFactor * (info.posX - posX);
2906
- posZ = posZ + centerFactor * (info.posZ - posZ);
2907
- splashWidth = wholeWidth;
2908
- }
2909
- }
2910
- }
2911
- } catch (err) {
2912
- _iterator.e(err);
2913
- } finally {
2914
- _iterator.f();
2915
- }
2916
- itemToSave.info.posX = posX;
2917
- itemToSave.info.posY = posY;
2918
- itemToSave.info.posZ = posZ;
2919
- itemToSave.info.rotY = rotY;
2920
- itemToSave.info.width = splashWidth;
2921
- itemToSave.info.height = splashHeight;
2922
- itemToSave.info.depth = splashDepth;
2923
-
2924
- // Make material
2925
-
2926
- var texture = layer.get('backsplash');
2927
- var areaMaterial = new Three.MeshStandardMaterial({
2928
- side: Three.DoubleSide,
2929
- metalness: texture.metalness,
2930
- roughness: texture.roughness
2931
- });
2932
- var interiortexture = loadTexture(texture.uri);
2933
- applyTexture(areaMaterial, interiortexture, splashWidth * 1.5, splashHeight * 1.5);
2934
-
2935
- // Make geometry
2936
- var geometry = new Three.BoxGeometry(splashWidth, splashHeight, splashDepth);
2937
-
2938
- // Make backsplash mesh
2939
-
2940
- var backsplash = itemToSave.backsplash = new Three.Mesh(geometry, areaMaterial);
2941
- backsplash.position.x = itemToSave.info.posX;
2942
- backsplash.position.y = itemToSave.info.posY;
2943
- backsplash.position.z = itemToSave.info.posZ;
2944
- backsplash.rotation.y = itemToSave.info.rotY;
2945
- var allLines = GeometryUtils.getAllLines(layer);
2946
- var allLineRects = GeometryUtils.buildRectFromLines(layer, allLines);
2947
- if (item.is_corner && GeometryUtils.isSnappedSideLine(item, allLineRects)) {
2948
- // corner cabinet item.itemInfo.getIn(["cabinet_category"]) === "Corner Base Cabinets"
2949
- var geometry1 = new Three.BoxGeometry(splashWidth, splashHeight, splashDepth);
2950
- // Make backsplash mesh
2951
- //console.log(sceneGraph.layers["layer-1"].lines);
2952
- var backsplash1 = itemToSave.backsplash = new Three.Mesh(geometry1, areaMaterial);
2953
- backsplash1.position.x = posX1;
2954
- backsplash1.position.y = posY1;
2955
- backsplash1.position.z = posZ1;
2956
- backsplash1.rotation.y = rotY1;
2957
- var newBacksplash = new Group();
2958
- newBacksplash.add(backsplash);
2959
- newBacksplash.add(backsplash1);
2960
- backsplash = newBacksplash;
2961
- }
2962
- itemToSave.info.id = item.itemInfo.id;
2963
- deleteSpecifiedMeshObjects('backsplash' + item.itemInfo.id);
2964
- if (item.rotRad % (Math.PI / 2) === 0) planData.plan.add(backsplash);
2965
- backsplash.name = name;
2966
- backsplash.visible = item.itemInfo.get('backsplashVisible') && backsplashApplied && item.rotRad % (Math.PI / 2) === 0;
2967
-
2968
- // Save to scene graph
2969
-
2970
- if (index < 0) {
2971
- backsplashes.push(itemToSave);
2972
- } else {
2973
- disposeObject(backsplashes[index].backsplash);
2974
- backsplashes.splice(index, 1, itemToSave);
2975
- }
2976
- }
2977
-
2978
- /**
2979
- * @param {Map} item - Selected Item
2980
- */
2981
- function addMGMesh(molding, planData, layer) {
2982
- var _molding$molding;
2983
- var flag = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
2984
- var point = [];
2985
- var data = molding === null || molding === void 0 || (_molding$molding = molding.molding) === null || _molding$molding === void 0 ? void 0 : _molding$molding.data;
2986
- if (isEmpty(data)) return;
2987
- var paths = data.paths,
2988
- svg_width = data.svg_width,
2989
- svg_height = data.svg_height;
2990
- for (var i = 0; i < paths.length; i++) {
2991
- var path = paths[i];
2992
- for (var j = 0, jl = path.subPaths.length; j < jl; j++) {
2993
- var subPath = new Three.Path();
2994
- if (path.subPaths[j].hasOwnProperty('metadata')) {
2995
- subPath.fromJSON(path.subPaths[j]);
2996
- } else {
2997
- subPath = path.subPaths[j];
2998
- }
2999
- point = subPath.getPoints();
3000
- }
3001
- }
3002
- _addMGMesh(molding, planData, layer, point, svg_width, svg_height, flag);
3003
- }
3004
- var isBaseCabinet = function isBaseCabinet(item) {
3005
- return item.layoutpos === BASE_CABINET_LAYOUTPOS;
3006
- };
3007
-
3008
- /**
3009
- * @param data - Molding SVG Points
3010
- */
3011
-
3012
- // function assignUVs
3013
- function _addMGMesh(molding, planData, layer, data, svg_width, svg_height, flag) {
3014
- var child = molding.molding;
3015
- var material = getDoorStyleMaterial(molding.items, planData, layer, child.name);
3016
- if (!material) return;
3017
- material = new Three.MeshStandardMaterial(material);
3018
- // let texture = loadTexture(material.map.image.src);
3019
- // var material1 = new Three.MeshLambertMaterial( { map:texture } );
3020
- material.side = parseInt(Three.DoubleSide);
3021
- // let layoutType = molding.items[0].layoutpos;
3022
- // let visible = molding.items[0];
3023
- molding.pointGroups.forEach(function (pointGroup) {
3024
- var geometry = new Three.BufferGeometry();
3025
- var length = data.length; //point array
3026
- var temp_unit = child.height_unit;
3027
- if (temp_unit === 'inch') {
3028
- child.height = convert(child.height).from('in').to('cm');
3029
- child.height_unit = 'cm';
3030
- }
3031
- temp_unit = child.width_unit;
3032
- if (temp_unit === 'inch') {
3033
- child.width = convert(child.width).from('in').to('cm');
3034
- child.width_unit = 'cm';
3035
- }
3036
- temp_unit = child.length_unit;
3037
- if (temp_unit === 'inch') {
3038
- child.length = convert(child.length).from('in').to('cm');
3039
- child.length_unit = 'cm';
3040
- }
3041
- geometry.needsUpdate = true;
3042
- geometry = moldingVertices(pointGroup, geometry, data, child, svg_width, svg_height, molding.pointGroups.length);
3043
- var total = geometry.attributes.position.count;
3044
- var len = geometry.attributes.position.count / length;
3045
- if (!GeometryUtils.samePoints(pointGroup[0], pointGroup[pointGroup.length - 1])) {
3046
- len--;
3047
- }
3048
- for (var i = 0; i < len; i++) {
3049
- for (var j = i * length; j < (i + 1) * length - 1; j++) {
3050
- var f_a1 = j;
3051
- var f_b1 = (j + length) % total;
3052
- var f_c1 = (j + length + 1) % total;
3053
- var f_a2 = j;
3054
- var f_b2 = j + 1;
3055
- var f_c2 = f_c1;
3056
- var indices = [];
3057
- if (geometry.index !== null) {
3058
- indices = Array.from(geometry.index.array);
3059
- }
3060
- indices.push(f_a1, f_b1, f_c1, f_c2, f_b2, f_a2);
3061
- geometry.setIndex(indices);
3062
- }
3063
- }
3064
-
3065
- // handle molding texture
3066
- // (0, e[i]) ------------- (1, e[i])
3067
- // ----------- --- -----------
3068
- // ----------- --- -----------
3069
- // ----------- --- -----------
3070
- // ----------- --- -----------
3071
- // (0, e[i+1]) ------------- (1, e[i+1])
3072
- geometry = geometry.toNonIndexed();
3073
- var sumDistance = 0;
3074
- var sumDistanceArray = [0];
3075
- var finalDistance = 0;
3076
- var uvs_element_array = [];
3077
- for (var _i2 = 0; _i2 < data.length - 1; _i2++) {
3078
- var v1 = {
3079
- x: data[_i2].x,
3080
- y: data[_i2].y
3081
- };
3082
- var v2 = {
3083
- x: data[_i2 + 1].x,
3084
- y: data[_i2 + 1].y
3085
- };
3086
- var posDistance = verticesDistance(v1, v2);
3087
- sumDistance += posDistance;
3088
- if (_i2 === data.length - 2) finalDistance = sumDistance;
3089
- sumDistanceArray.push(sumDistance);
3090
- }
3091
- for (var _i3 = 0; _i3 < sumDistanceArray.length; _i3++) {
3092
- uvs_element_array.push(sumDistanceArray[_i3] / finalDistance);
3093
- }
3094
- var uvs = [];
3095
- var uvs_item = [];
3096
- for (var _i4 = 0; _i4 < uvs_element_array.length - 1; _i4++) {
3097
- uvs_item = [0, uvs_element_array[_i4], 1, uvs_element_array[_i4], 1, uvs_element_array[_i4 + 1], 1, uvs_element_array[_i4 + 1], 0, uvs_element_array[_i4 + 1], 0, uvs_element_array[_i4]];
3098
- uvs.push.apply(uvs, _toConsumableArray(uvs_item));
3099
- }
3100
- var all_uvs = [];
3101
- for (var _i5 = 0; _i5 < pointGroup.length; _i5++) {
3102
- all_uvs.push.apply(all_uvs, uvs);
3103
- }
3104
- geometry.setAttribute('uv', new Three.BufferAttribute(new Float32Array(all_uvs), 2));
3105
- geometry.computeVertexNormals();
3106
- var fbm3d = new Three.Mesh(geometry, material);
3107
- fbm3d.position.x = molding.pos.x;
3108
- fbm3d.position.z = -molding.pos.y;
3109
- fbm3d.position.y = molding.pos.z;
3110
- planData.plan.add(fbm3d);
3111
- fbm3d.name = child.name + molding.id + 'molding';
3112
- molding.meshes.push(fbm3d);
3113
- fbm3d.visible = true;
3114
- fbm3d.castShadow = true;
3115
- });
3116
- }
3117
- function deleteCTMesh(countertop, planData, layer) {
3118
- log('--deleteCTMesh', countertop);
3119
- if (countertop.items.length == 1) {
3120
- showItemCT(countertop.items[0], countertop, false, planData, layer);
3121
- } else {
3122
- var ct3d = countertop.ct3d;
3123
- if (ct3d) {
3124
- planData.plan.remove(ct3d);
3125
- disposeObject(ct3d);
3126
- }
3127
- }
3128
- }
3129
- export function deleteMGMesh(molding, planData) {
3130
- var mode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
3131
- // mode is 3D or elevation
3132
- molding.meshes.forEach(function (mesh) {
3133
- if (isElevationView(mode)) {
3134
- var _planData$plan$childr;
3135
- // when elevation mode, remove obj same as selected global molding_name in platnData.plan
3136
- (_planData$plan$childr = planData.plan.children) === null || _planData$plan$childr === void 0 || _planData$plan$childr.forEach(function (obj) {
3137
- var parent = obj.parent;
3138
- if (obj.name.match(mesh.name)) parent.remove(obj);
3139
- });
3140
- } else {
3141
- // when 3D mode
3142
- planData.plan.remove(mesh);
3143
- disposeObject(mesh);
3144
- }
3145
- });
3146
- molding.meshes = [];
3147
- }
3148
- function log() {
3149
- // console.log(...arguments);
3150
- }
3151
- function addCountertop(CTArray, addItem, planData, layer) {
3152
- log('addCountertop', _toConsumableArray(CTArray), addItem.id);
3153
- var tmp = planData;
3154
- tmp = tmp && tmp.catalog.getElement(addItem.type);
3155
- if (!tmp) tmp = planData.catalog.getElement(returnReplaceableDeepSearchType(addItem.type));
3156
- var long_name = tmp && tmp.long_name;
3157
- if (long_name.includes('Sink ')) return;
3158
- var newCT = createCTFromItem(addItem, planData.sceneGraph.unit, planData.catalog);
3159
- var oldCT = null;
3160
- var extCT = false;
3161
- var extCTIndex = -1;
3162
- var tryMergeCT = function tryMergeCT() {
3163
- extCTIndex = CTArray.findIndex(function (el) {
3164
- extCT = tryAdjacent(newCT, el);
3165
- return extCT != false;
3166
- });
3167
- return extCTIndex >= 0;
3168
- };
3169
- while (tryMergeCT()) {
3170
- oldCT = CTArray.splice(extCTIndex, 1)[0];
3171
- deleteCTMesh(newCT, planData, layer);
3172
- deleteCTMesh(oldCT, planData, layer);
3173
- newCT = extCT;
3174
- }
3175
- addCTMesh(newCT, planData, layer);
3176
- CTArray.push(newCT);
3177
- }
3178
- export function deleteCountertop(CTArray, delItem, planData, layer) {
3179
- if (delItem == undefined) {
3180
- return;
3181
- }
3182
- log('deleteCountertop', _toConsumableArray(CTArray), delItem.id);
3183
- var delCT = null;
3184
- var delItemIndex = -1;
3185
- var delCTIndex = CTArray.findIndex(function (el) {
3186
- delItemIndex = el.items.findIndex(function (el) {
3187
- return el.id == delItem.id;
3188
- });
3189
- return delItemIndex >= 0;
3190
- });
3191
- if (delCTIndex < 0) return;
3192
- delCT = CTArray.splice(delCTIndex, 1)[0];
3193
- if (delCT.items.length > 1) {
3194
- deleteCTMesh(delCT, planData, layer);
3195
- var ct1 = delCT.items.slice(0, delItemIndex);
3196
- var ct2 = delCT.items.slice(delItemIndex + 1);
3197
- [ct1, ct2].forEach(function (cts) {
3198
- if (cts.length == 0) return;
3199
- var newCT = createCTFromItems(cts, planData.sceneGraph.unit, planData.catalog);
3200
- CTArray.push(newCT);
3201
- addCTMesh(newCT, planData, layer);
3202
- });
3203
- }
3204
- }
3205
- export function deleteAllMolding(MGArray, delItem, planData, oldSceneLayer, newSceneLayer) {
3206
- var tempMGArray = _toConsumableArray(MGArray);
3207
- if (isEmpty(delItem)) {
3208
- return tempMGArray;
3209
- }
3210
-
3211
- // remove the MGs which includes delItem
3212
- tempMGArray = tempMGArray.filter(function (mg) {
3213
- if (mg.items.some(function (it) {
3214
- return it.id === delItem.id;
3215
- })) {
3216
- deleteMGMesh(mg, planData, null);
3217
- return false;
3218
- } else return true;
3219
- });
3220
- if (newSceneLayer !== null) {
3221
- // find the snapped items with delItem
3222
- var snappedItems = [];
3223
- oldSceneLayer.items.toArray().forEach(function (oItem) {
3224
- if (oItem.category === 'cabinet' && oItem.id !== delItem.id && MoldingUtils.isItemSnappedItem(delItem, oItem)) {
3225
- snappedItems.push(oItem);
3226
- }
3227
- });
3228
-
3229
- // update molding group array with snapped items in the new scene layer
3230
- for (var i = 0; i < snappedItems.length; i++) {
3231
- tempMGArray = updateMoldingGroupArray(tempMGArray, snappedItems[i], planData, newSceneLayer, null, null, 0);
3232
- }
3233
- }
3234
- return tempMGArray;
3235
- }
3236
- export function addMolding(MGArray, addItem, planData, layer, itemActions, mode) {
3237
- if (addItem.selected && [MODE_DRAGGING_ITEM_3D, MODE_ROTATING_ITEM_3D].includes(mode)) return false;
3238
-
3239
- // If the item is not available for current doorStyle
3240
- if (showYelloBox(addItem))
3241
- // Do not add molding to that item
3242
- return MGArray;
3243
-
3244
- // if (
3245
- // !(
3246
- // (addItem.layoutpos === BASE_CABINET_LAYOUTPOS &&
3247
- // !GeometryUtils.isSnappedLine(
3248
- // MoldingUtils.getItemRect(addItem),
3249
- // GeometryUtils.buildRectFromLines(
3250
- // layer,
3251
- // GeometryUtils.getAllLines(layer)
3252
- // )
3253
- // )) ||
3254
- // ((addItem.layoutpos === WALL_CABINET_LAYOUTPOS ||
3255
- // addItem.layoutpos === TALL_CABINET_LAYOUTPOS) &&
3256
- // GeometryUtils.isSnappedLine(
3257
- // MoldingUtils.getItemRect(addItem),
3258
- // GeometryUtils.buildRectFromLines(
3259
- // layer,
3260
- // GeometryUtils.getAllLines(layer)
3261
- // )
3262
- // ))
3263
- // )
3264
- // )
3265
- // return false;
3266
-
3267
- // update the molding group array.
3268
- var temp_MGArray = updateMoldingGroupArray(MGArray, addItem, planData, layer, itemActions, mode, 0);
3269
- temp_MGArray.forEach(function (mg) {
3270
- var moldingMesh = mg.meshes[0];
3271
- if (isElevationView(mode)) {
3272
- if (!isEmpty(moldingMesh)) {
3273
- replaceMeshesWithLineSegments(moldingMesh);
3274
- }
3275
- }
3276
- });
3277
- return temp_MGArray;
3278
- }
3279
- export function updateMoldingGroupArray(MGArray, selItem, planData, layer) {
3280
- var itemActions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
3281
- var mode = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
3282
- var cnt = arguments.length > 6 ? arguments[6] : undefined;
3283
- try {
3284
- cnt++;
3285
- if (cnt > 500) {
3286
- console.log('updateMoldingGroupArray has limited!');
3287
- return MGArray;
3288
- }
3289
- var temp_MGArray = _toConsumableArray(MGArray);
3290
- if (isEmpty(selItem)) return temp_MGArray;
3291
- var isEnableMolding = MoldingUtils.isEnableItemForMolding(layer, selItem);
3292
- // Make a items group with selItem to create the new MG(molding group) array of selItem
3293
- var itemsForGroup = [selItem];
3294
- var i = 0;
3295
- while (i < itemsForGroup.length) {
3296
- layer.items.toArray().forEach(function (curItem) {
3297
- if (!itemsForGroup.some(function (it) {
3298
- return it.id === curItem.id;
3299
- }) && curItem.category === 'cabinet' && MoldingUtils.isSameMoldingLayoutpos(curItem, itemsForGroup[i]) && MoldingUtils.isItemSnappedItem(itemsForGroup[i], curItem)) {
3300
- itemsForGroup.push(curItem);
3301
- }
3302
- });
3303
- i++;
3304
- }
3305
-
3306
- // Create the new MG(molding group) array of selItem
3307
- var new_MGArray = MoldingUtils.getAllMoldingGroups(layer, itemsForGroup);
3308
-
3309
- // get molding settings of update molding from adjoined item's molding
3310
- var changeMoldings = [];
3311
- new_MGArray.forEach(function (mg) {
3312
- if (mg.items.some(function (it) {
3313
- return it.id === selItem.id;
3314
- }) && mg.items.length > 1) {
3315
- var destItem = mg.items.find(function (it) {
3316
- return it.id !== selItem.id;
3317
- });
3318
- var destMolding = destItem.molding.find(function (md) {
3319
- return md.location_type === mg.location_type;
3320
- });
3321
-
3322
- // if current item has not destination molding then set it to the current molding
3323
- if (!isEmpty(destMolding) && !selItem.molding.some(function (md) {
3324
- return md.location_type === destMolding.location_type;
3325
- })) {
3326
- // only update with the same height cabinet or update the bottom molding setting
3327
- // itemActions.setMolding(destMoldings[i], false);
3328
- changeMoldings.push(destMolding);
3329
- } else if (isEmpty(destMolding) && selItem.molding.some(function (md) {
3330
- return md.location_type === mg.location_type;
3331
- })) {
3332
- // if current item has more molding than adjoined then remove theses moldings
3333
- // itemActions.setMolding(selItem.molding[i], false);
3334
- changeMoldings.push(selItem.molding.find(function (md) {
3335
- return md.location_type === mg.location_type;
3336
- }));
3337
- }
3338
- }
3339
- });
3340
- var regenMGItemList = [];
3341
- // An old MG and a new MG include a same item && The location_type of Two MGs are same
3342
- // Then replace the old MG with the new MG
3343
- temp_MGArray = temp_MGArray.filter(function (oldMG) {
3344
- var filteredNewMGList = new_MGArray.filter(function (mg) {
3345
- return mg.location_type === oldMG.location_type;
3346
- });
3347
- if (isEmpty(filteredNewMGList)) {
3348
- return true;
3349
- }
3350
- var _loop3 = function _loop3() {
3351
- var newMG = filteredNewMGList[k];
3352
- if (oldMG.items.some(function (it) {
3353
- return it.id === selItem.id;
3354
- })) {
3355
- // if current action is a seprating item from group, then have to regenerate the MGs of old snapped items
3356
- if (oldMG.items.filter(function (oIt) {
3357
- return !newMG.items.some(function (nIt) {
3358
- return nIt.id === oIt.id;
3359
- });
3360
- }).length > 0) {
3361
- oldMG.items.forEach(function (oIt) {
3362
- if (oIt.id !== selItem.id && !regenMGItemList.some(function (rIt) {
3363
- return rIt.id === oIt.id;
3364
- })) regenMGItemList.push(oIt);
3365
- });
3366
- }
3367
- }
3368
- // remove the old MG meshes
3369
- for (var _i6 = 0; _i6 < oldMG.items.length; _i6++) {
3370
- var oItem = oldMG.items[_i6];
3371
- for (var j = 0; j < newMG.items.length; j++) {
3372
- var nItem = newMG.items[j];
3373
- if (oItem.id === nItem.id) {
3374
- deleteMGMesh(oldMG, planData, mode);
3375
- // if (oldMG.items.length > 1) {
3376
- // // separating item from group
3377
- // oldMG.items.splice(i, 1);
3378
- // // update the old molding group info
3379
- // const mIdx = oldMG.items[0].molding.findIndex(
3380
- // m => m.location_type == oldMG.location_type
3381
- // );
3382
- // if (mIdx >= 0) {
3383
- // let molding = oldMG.items[0].molding[mIdx];
3384
- // oldMG = MoldingUtils.createMonldingGroup(
3385
- // oldMG,
3386
- // layer,
3387
- // molding,
3388
- // planData.catalog
3389
- // );
3390
- // addMGMesh(oldMG, planData, layer);
3391
- // }
3392
- // return true;
3393
- // }
3394
- return {
3395
- v: false
3396
- };
3397
- }
3398
- }
3399
- }
3400
- },
3401
- _ret;
3402
- for (var k = 0; k < filteredNewMGList.length; k++) {
3403
- _ret = _loop3();
3404
- if (_ret) return _ret.v;
3405
- }
3406
- return true;
3407
- });
3408
- if (changeMoldings.length === 0 && isEnableMolding) {
3409
- // refresh mesh of the updating molding groups
3410
- new_MGArray.forEach(function (mg, index) {
3411
- if (mg.items[0].molding.some(function (mol) {
3412
- return mol.location_type === mg.location_type;
3413
- })) {
3414
- var molding = mg.items[0].molding.filter(function (mol) {
3415
- return mol.location_type === mg.location_type;
3416
- })[0];
3417
- if (mg.molding === null || mg.molding.itemID !== mol.itemID || mg.lines === null || mg.points === null) {
3418
- if (mg.molding !== null && mg.molding.itemID !== molding.itemID) {
3419
- deleteMGMesh(mg, planData, mode);
3420
- }
3421
- mg = MoldingUtils.createMonldingGroup(mg, layer, molding, planData.catalog);
3422
- }
3423
- if (!mg.meshes.length) {
3424
- addMGMesh(mg, planData, layer);
3425
- }
3426
- } else {
3427
- deleteMGMesh(mg, planData, mode);
3428
- }
3429
- });
3430
- }
3431
- new_MGArray.forEach(function (mg) {
3432
- return temp_MGArray.push(mg);
3433
- });
3434
- regenMGItemList.forEach(function (it) {
3435
- temp_MGArray = updateMoldingGroupArray(temp_MGArray, it, planData, layer, itemActions, mode, cnt);
3436
- });
3437
- if (changeMoldings.length > 0 && itemActions !== null) {
3438
- setTimeout(function () {
3439
- changeMoldings.forEach(function (chMolding) {
3440
- itemActions.setMolding(chMolding, false);
3441
- });
3442
- }, 200);
3443
- }
3444
- return temp_MGArray;
3445
- } catch (e) {
3446
- console.log('updateMoldingGroupArray catched :', e);
3447
- return MGArray;
3448
- }
3449
- }
3450
- export function removeSelItemMesh(MGArray, selItem, planData, mode) {
3451
- if (selItem) {
3452
- if (!selItem.selected) {
3453
- return;
3454
- }
3455
- MGArray.forEach(function (mg) {
3456
- if (mg.items.some(function (it) {
3457
- return it.id === selItem.id;
3458
- })) deleteMGMesh(mg, planData, mode);
3459
- });
3460
- }
3461
- }
3462
-
3463
- /**
3464
- * Flip door handle
3465
- * @param item Scene state item ( redux )
3466
- * @param item3D Mesh
3467
- * @param {Boolean} flip Determines handle position.
3468
- * @note When `flip` is set
3469
- *
3470
- * `true`
3471
- * * Left side door - use left handle (LL)
3472
- * * Right side door - use right handle (RR)
3473
- *
3474
- * `false`
3475
- * * Left side door - use right handle (LR)
3476
- * * Right side door - use left handle (RL)
3477
- *
3478
- * And one-door-cabinet is the same case with the left door of two-door-cabinet
3479
- */
3480
- export function updateDoorHandleMesh(_, item3D, flip) {
3481
- if (!item3D) {
3482
- console.error('Item mesh is undefined.');
3483
- return;
3484
- }
3485
-
3486
- /**
3487
- * Mesh whose name pass this regexp is a place holder for a door
3488
- * which is the parent or grand parent of a door mesh and its handles
3489
- */
3490
- var doorReg = /ph_.*[^(drawer)]_door(?:_(L|R))?(?:_[1-9])?$/;
3491
- var doorHandleReg = /ph_.*_door_.*_handle_(L|R)?(_[1-9])?/;
3492
- item3D.traverse(function (child) {
3493
- /**
3494
- * Hold the name of the place holder for door and its position
3495
- * @type {[string,"L"|"R"|undefined]}
3496
- */
3497
- var doorRegResult = doorReg.exec(child.name);
3498
- if (doorRegResult) {
3499
- // `child` is place holder for door mesh, and also grand parent of on[0]e
3500
- var phDoor = child.children[0];
3501
- if (!phDoor) {
3502
- return console.error('Group is no valid.');
3503
- }
3504
- var doorHandle = null;
3505
- var phRight = null;
3506
- var phLeft = null;
3507
-
3508
- // Find door_handle, ph_left, ph_right 3D item
3509
- phDoor.traverse(function (childOfDoor) {
3510
- /**
3511
- * @type {[string, "L"|"R"]}
3512
- */
3513
- var result = doorHandleReg.exec(childOfDoor.name);
3514
- if (result !== null) {
3515
- // `childOfDoor` is place holder for door handle
3516
-
3517
- switch (result[1]) {
3518
- case 'L':
3519
- phLeft = childOfDoor;
3520
- break;
3521
- case 'R':
3522
- phRight = childOfDoor;
3523
- break;
3524
- default:
3525
- console.error('Place holder type should be L or R.');
3526
- return;
3527
- }
3528
- if (childOfDoor.children.length !== 0) {
3529
- // It has a door handle
3530
- doorHandle = childOfDoor.children[0];
3531
- }
3532
- }
3533
- });
3534
-
3535
- // Change door handle position
3536
- if (doorHandle && phLeft && phRight) {
3537
- // Remove handles for re-addition
3538
- if (phLeft.children.length) {
3539
- phLeft.remove(doorHandle);
3540
- }
3541
- if (phRight.children.length) {
3542
- phRight.remove(doorHandle);
3543
- }
3544
- switch (doorRegResult[1]) {
3545
- case undefined: // Single door cabinet
3546
- case 'R':
3547
- // Right side door
3548
- (flip ? phRight : phLeft).add(doorHandle);
3549
- break;
3550
- case 'L':
3551
- // Left side door
3552
- (flip ? phLeft : phRight).add(doorHandle);
3553
- break;
3554
- }
3555
- } else {
3556
- console.error('door_handle or ph_left or ph_right is null.');
3557
- }
3558
- }
3559
- });
3560
- }
3561
- export function addWarningBox(itemId, altitude, planData) {
3562
- deleteSpecifiedMeshObjects('WarningBox' + itemId);
3563
- var item3D = planData.sceneGraph.layers[planData.sceneData.selectedLayer].items[itemId];
3564
- if (item3D == undefined) return;
3565
- var altitudeLength = convert(altitude).from('in').to('cm');
3566
- var sBounding = item3D.children[0].userData;
3567
- var width = sBounding.max.x - sBounding.min.x;
3568
- var height = sBounding.max.y - sBounding.min.y;
3569
- var depth = sBounding.max.z - sBounding.min.z;
3570
- var warnBoxGeom = new Three.BoxGeometry(width, height, depth);
3571
- var warnBoxObj = new Three.Mesh(warnBoxGeom, new Three.MeshBasicMaterial({
3572
- color: 0xff2200,
3573
- opacity: 0.8,
3574
- transparent: true,
3575
- blending: Three.MultiplyBlending
3576
- }));
3577
- var box = new Three.BoxHelper(warnBoxObj, 0x000000);
3578
- box.material.linewidth = 2;
3579
- box.material.depthTest = false;
3580
- box.renderOrder = 200;
3581
- warnBoxObj.add(box);
3582
- warnBoxObj.position.set(item3D.position.x, altitudeLength + item3D.position.y + height / 2, item3D.position.z);
3583
- warnBoxObj.rotation.set(item3D.rotation.x, item3D.rotation.y, item3D.rotation.z);
3584
- warnBoxObj.name = 'WarningBox' + itemId;
3585
- // planData.plan.add(warnBoxObj);
3586
- }
3587
- export function checkCabinetOverlap(itemPos, itemRect, holeItems, planData) {
3588
- if (holeItems.length) {
3589
- var depth = itemRect.size.depth;
3590
- var i;
3591
- for (i = 0; i < holeItems.length; i++) {
3592
- var hole = holeItems[i];
3593
- var holeAlti = hole.altitude;
3594
- if (holeAlti >= depth) continue;
3595
- if (Math.abs(Math.sin(itemRect.rotRad)) === 1) {
3596
- if (itemPos.y + itemRect.size.width / 2 >= hole.y - hole.width / 2 && itemPos.y - itemRect.size.width / 2 <= hole.y + hole.width / 2 && (itemRect.rotRad == 0 || itemRect.rotRad == -Math.PI / 2 ? itemPos.x <= hole.x && itemPos.x + itemRect.size.height >= hole.x : itemPos.x >= hole.x && itemPos.x - itemRect.size.height <= hole.x)) break;
3597
- } else {
3598
- if (itemPos.x + itemRect.size.width / 2 >= hole.x - hole.width / 2 && itemPos.x - itemRect.size.width / 2 <= hole.x + hole.width / 2 && (itemRect.rotRad == 0 || itemRect.rotRad == -Math.PI / 2 ? itemPos.y <= hole.y && itemPos.y + itemRect.size.height >= hole.y : itemPos.y >= hole.y && itemPos.y - itemRect.size.height <= hole.y)) break;
3599
- }
3600
- }
3601
- if (i != holeItems.length) {
3602
- var altitude = itemRect.itemInfo.properties.get('altitude').get('_length');
3603
- var altitudeUnit = itemRect.itemInfo.properties.get('altitude').get('_unit') || 'cm';
3604
- altitude = convert(altitude).from(altitudeUnit).to('cm');
3605
- addWarningBox(itemRect.itemInfo.id, altitude, planData);
3606
- }
3607
- }
3608
- }