w-threejs-vue 1.0.0

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 (151) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +55 -0
  4. package/.jsdoc +25 -0
  5. package/LICENSE +21 -0
  6. package/README.md +39 -0
  7. package/SECURITY.md +5 -0
  8. package/babel.config.js +15 -0
  9. package/dist/w-threejs-vue.umd.js +26 -0
  10. package/dist/w-threejs-vue.umd.js.map +1 -0
  11. package/docs/examples/app.html +66 -0
  12. package/docs/examples/app.umd.js +31 -0
  13. package/docs/examples/app.umd.js.map +1 -0
  14. package/docs/examples/ex-AppBasicAutoRotateDeg.html +190 -0
  15. package/docs/examples/ex-AppBasicBackgroundColor.html +189 -0
  16. package/docs/examples/ex-AppBasicSize.html +170 -0
  17. package/docs/examples/ex-AppBasicUploadStl.html +237 -0
  18. package/docs/examples/ex-AppBasicUseAutoRotate.html +189 -0
  19. package/docs/examples/ex-AppCmCameraFar.html +191 -0
  20. package/docs/examples/ex-AppCmCameraFov.html +191 -0
  21. package/docs/examples/ex-AppCmCameraNear.html +191 -0
  22. package/docs/examples/ex-AppCmCameraOrthographicRatio.html +191 -0
  23. package/docs/examples/ex-AppCmCameraType.html +190 -0
  24. package/docs/examples/ex-AppCmGetCameraViewAngle.html +218 -0
  25. package/docs/examples/ex-AppCmSetCameraAzimuthAngle.html +190 -0
  26. package/docs/examples/ex-AppCmSetCameraPolarAngle.html +190 -0
  27. package/docs/examples/ex-AppCmSetCameraViewAngle.html +194 -0
  28. package/docs/examples/ex-AppHpHelperAxesLengthRatio.html +189 -0
  29. package/docs/examples/ex-AppHpHelperGridDensity.html +189 -0
  30. package/docs/examples/ex-AppHpHelperGridLengthRatio.html +189 -0
  31. package/docs/examples/ex-AppHpHelperGridPositionRatioZ.html +189 -0
  32. package/docs/examples/ex-AppHpUseHelperAxes.html +189 -0
  33. package/docs/examples/ex-AppHpUseHelperGrid.html +189 -0
  34. package/docs/examples/ex-AppLgLegnedBackgroundColor.html +189 -0
  35. package/docs/examples/ex-AppLgLegnedHeight.html +189 -0
  36. package/docs/examples/ex-AppLgLegnedHeightMax.html +189 -0
  37. package/docs/examples/ex-AppLtLightAmbientColor.html +189 -0
  38. package/docs/examples/ex-AppLtLightDirectionColor.html +191 -0
  39. package/docs/examples/ex-AppLtLightDirectionIntensity.html +191 -0
  40. package/docs/examples/ex-AppLtLightDirectionPos.html +191 -0
  41. package/docs/examples/ex-AppLtLightPointColor.html +192 -0
  42. package/docs/examples/ex-AppLtLightPointDecay.html +192 -0
  43. package/docs/examples/ex-AppLtLightPointDistance.html +192 -0
  44. package/docs/examples/ex-AppLtLightPointIntensity.html +192 -0
  45. package/docs/examples/ex-AppLtLightPointPoss.html +192 -0
  46. package/docs/examples/ex-AppLtUseLightAmbient.html +191 -0
  47. package/docs/examples/ex-AppLtUseLightDirection.html +191 -0
  48. package/docs/examples/ex-AppLtUseLightPoint.html +191 -0
  49. package/docs/examples/ex-AppMhGetMeshsInfor.html +198 -0
  50. package/docs/examples/ex-AppMhSetMeshColor.html +190 -0
  51. package/docs/examples/ex-AppMhSetMeshLabelText.html +190 -0
  52. package/docs/examples/ex-AppMhSetMeshLabelTextColor.html +190 -0
  53. package/docs/examples/ex-AppMhSetMeshLabelTextFontFamily.html +190 -0
  54. package/docs/examples/ex-AppMhSetMeshLabelTextFontSize.html +190 -0
  55. package/docs/examples/ex-AppMhSetMeshLabelVisible.html +198 -0
  56. package/docs/examples/ex-AppMhSetMeshVisible.html +198 -0
  57. package/docs/examples/ex-AppMuMenuIcons.html +217 -0
  58. package/docs/examples/ex-AppMuMenuTooltips.html +218 -0
  59. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  60. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  61. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  62. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  63. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  64. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  65. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  66. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  67. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  68. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  69. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  70. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  71. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  72. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  73. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  74. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  75. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  76. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  77. package/docs/index.html +84 -0
  78. package/docs/module-WThreejsVue.html +216 -0
  79. package/docs/scripts/collapse.js +39 -0
  80. package/docs/scripts/commonNav.js +28 -0
  81. package/docs/scripts/linenumber.js +25 -0
  82. package/docs/scripts/nav.js +12 -0
  83. package/docs/scripts/polyfill.js +4 -0
  84. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  85. package/docs/scripts/prettify/lang-css.js +2 -0
  86. package/docs/scripts/prettify/prettify.js +28 -0
  87. package/docs/scripts/search.js +99 -0
  88. package/docs/styles/jsdoc.css +776 -0
  89. package/docs/styles/prettify.css +80 -0
  90. package/package.json +74 -0
  91. package/public/index.html +42 -0
  92. package/src/App.vue +574 -0
  93. package/src/AppBasicAutoRotateDeg.vue +102 -0
  94. package/src/AppBasicBackgroundColor.vue +101 -0
  95. package/src/AppBasicSize.vue +90 -0
  96. package/src/AppBasicUploadStl.vue +159 -0
  97. package/src/AppBasicUseAutoRotate.vue +101 -0
  98. package/src/AppCmCameraFar.vue +103 -0
  99. package/src/AppCmCameraFov.vue +103 -0
  100. package/src/AppCmCameraNear.vue +103 -0
  101. package/src/AppCmCameraOrthographicRatio.vue +103 -0
  102. package/src/AppCmCameraType.vue +102 -0
  103. package/src/AppCmGetCameraViewAngle.vue +135 -0
  104. package/src/AppCmSetCameraAzimuthAngle.vue +104 -0
  105. package/src/AppCmSetCameraPolarAngle.vue +104 -0
  106. package/src/AppCmSetCameraViewAngle.vue +105 -0
  107. package/src/AppHpHelperAxesLengthRatio.vue +101 -0
  108. package/src/AppHpHelperGridDensity.vue +101 -0
  109. package/src/AppHpHelperGridLengthRatio.vue +101 -0
  110. package/src/AppHpHelperGridPositionRatioZ.vue +101 -0
  111. package/src/AppHpUseHelperAxes.vue +101 -0
  112. package/src/AppHpUseHelperGrid.vue +101 -0
  113. package/src/AppLgLegnedBackgroundColor.vue +101 -0
  114. package/src/AppLgLegnedHeight.vue +101 -0
  115. package/src/AppLgLegnedHeightMax.vue +101 -0
  116. package/src/AppLtLightAmbientColor.vue +101 -0
  117. package/src/AppLtLightDirectionColor.vue +103 -0
  118. package/src/AppLtLightDirectionIntensity.vue +103 -0
  119. package/src/AppLtLightDirectionPos.vue +103 -0
  120. package/src/AppLtLightPointColor.vue +104 -0
  121. package/src/AppLtLightPointDecay.vue +104 -0
  122. package/src/AppLtLightPointDistance.vue +104 -0
  123. package/src/AppLtLightPointIntensity.vue +104 -0
  124. package/src/AppLtLightPointPoss.vue +104 -0
  125. package/src/AppLtUseLightAmbient.vue +103 -0
  126. package/src/AppLtUseLightDirection.vue +103 -0
  127. package/src/AppLtUseLightPoint.vue +103 -0
  128. package/src/AppMhGetMeshsInfor.vue +112 -0
  129. package/src/AppMhSetMeshColor.vue +104 -0
  130. package/src/AppMhSetMeshLabelText.vue +104 -0
  131. package/src/AppMhSetMeshLabelTextColor.vue +104 -0
  132. package/src/AppMhSetMeshLabelTextFontFamily.vue +104 -0
  133. package/src/AppMhSetMeshLabelTextFontSize.vue +104 -0
  134. package/src/AppMhSetMeshLabelVisible.vue +106 -0
  135. package/src/AppMhSetMeshVisible.vue +106 -0
  136. package/src/AppMuMenuIcons.vue +130 -0
  137. package/src/AppMuMenuTooltips.vue +131 -0
  138. package/src/components/WThreejsVue.vue +955 -0
  139. package/src/js/addStl.mjs +83 -0
  140. package/src/js/getCsrdFromMeshs.mjs +85 -0
  141. package/src/js/plot3d.mjs +1407 -0
  142. package/src/main.js +8 -0
  143. package/test/all.test.mjs +10 -0
  144. package/toolg/addVersion.mjs +4 -0
  145. package/toolg/cleanFolder.mjs +4 -0
  146. package/toolg/gDistApp.mjs +38 -0
  147. package/toolg/gDistRollupComps.mjs +22 -0
  148. package/toolg/gDocExams.mjs +47 -0
  149. package/toolg/gExtractHtml.mjs +159 -0
  150. package/toolg/modifyReadme.mjs +4 -0
  151. package/vue.config.js +21 -0
@@ -0,0 +1,955 @@
1
+ <template>
2
+ <div :style="`display:inline-block; width:${widthInp}px; min-width:${widthInp}px; height:${heightInp}px; overflow-y:hidden;`">
3
+
4
+ <div style="position:relative; width:0px; height:0px;" v-if="loading">
5
+ <div style="position:absolute; top:0px; left:0px;">
6
+ <WIconLoading></WIconLoading>
7
+ </div>
8
+ </div>
9
+
10
+ <div style="position:relative;">
11
+
12
+ <div
13
+ ref="panel"
14
+ :style="`position:relative; width:${widthInp}px; height:${heightInp}px; opacity:${loading?0:1};`"
15
+ v-domresize
16
+ @domresize="resizePanel"
17
+ ></div>
18
+
19
+ <div
20
+ :style="`position:absolute; top:0px; left:0px;`"
21
+ v-if="!loading"
22
+ >
23
+
24
+ <div style="padding:10px; display:flex; align-items:flex-start;">
25
+
26
+ <!-- 設定區 -->
27
+ <WGroupIconCheck
28
+ :items="useItems"
29
+ :dir="'vertical'"
30
+ :iconColor="'#aaa'"
31
+ :iconColorHover="'#ccc'"
32
+ :iconColorFocus="'#ccc'"
33
+ :iconColorActive="'#fff'"
34
+ :backgroundColor="'#000'"
35
+ :backgroundColorHover="'#111'"
36
+ :backgroundColorFocus="'#111'"
37
+ :backgroundColorActive="'#444'"
38
+ :seplineColor="'#333'"
39
+ :tooltipTextFontSize="'0.7rem'"
40
+ :value="itemsSelects"
41
+ _input="updateItem"
42
+ @click="ckItem"
43
+ ></WGroupIconCheck>
44
+
45
+ <template v-if="useLegend">
46
+
47
+ <div :style="`padding-left:10px;`"></div>
48
+
49
+ <!-- 圖例區 -->
50
+ <div :style="`padding:5px; border-radius:4px; background:${useLegnedBackgroundColor};`">
51
+ <div :style="`${useLegnedHeight}`">
52
+
53
+ <div
54
+ :style="``"
55
+ :key="'km-'+km"
56
+ v-for="(m,km) in meshs"
57
+ >
58
+
59
+ <div style="display:flex; align-items:center; padding:3px;">
60
+
61
+ <WIcon
62
+ style="cursor:pointer;"
63
+ :icon="m.visible?mdiEyeOutline:mdiEyeOffOutline"
64
+ :color="'#ccc'"
65
+ :colorHover="'#ddd'"
66
+ :size="20"
67
+ @click="toggleMeshVisible(m,km)"
68
+ ></WIcon>
69
+
70
+ <div style="padding-left:5px;"></div>
71
+
72
+ <WColorSelect
73
+ :colorBlockBorderColor="'#888'"
74
+ :showColorText="false"
75
+ _colorTextColor="'#ddd'"
76
+ :panelBackgroundColor="'#111'"
77
+ :toolBackgroundColor="'#222'"
78
+ :menuIconColor="'#666'"
79
+ :menuIconColorHover="'#777'"
80
+ :menuIconColorActive="'#ddd'"
81
+ :borderColor="'#333'"
82
+ :borderColorHover="'#333'"
83
+ :borderColorActive="'#444'"
84
+ :backgroundColor="'#111'"
85
+ :menuBackgroundColor="'#111'"
86
+ :menuBackgroundColorHover="'#222'"
87
+ :menuBackgroundColorActive="'#333'"
88
+ :menuTextColor="'#b2b2b2'"
89
+ :menuTextColorHover="'#ccc'"
90
+ :menuTextColorActive="'#ddd'"
91
+ :menuTextFontSize="'0.75rem'"
92
+ :inputBorderColor="'#444'"
93
+ :inputBorderColorHover="'#555'"
94
+ :inputBorderColorActive="'#666'"
95
+ :inputBackgroundColor="'#000'"
96
+ :inputBackgroundColorHover="'#111'"
97
+ :inputBackgroundColorActive="'#222'"
98
+ :inputTextColor="'#999'"
99
+ :inputLabelColor="'#888'"
100
+ :barProgColor="'#888'"
101
+ :barProgBackgroundColor="'#222'"
102
+ :barSliderBackgroundColor="'#ccc'"
103
+ :barSliderBackgroundColorHover="'#ddd'"
104
+ :btnTextColor="'#eee'"
105
+ :btnTextColorHover="'#fff'"
106
+ :btnTextColorActive="'#fff'"
107
+ :btnBackgroundColor="'#444'"
108
+ :btnBackgroundColorHover="'#555'"
109
+ :btnBackgroundColorActive="'#555'"
110
+ :value="getMeshColor(m)"
111
+ @input="(c)=>{setMeshColor(m,km,c)}"
112
+ ></WColorSelect>
113
+
114
+ <div style="padding-left:5px;"></div>
115
+
116
+ <div :style="`color:${m.labelTextColor}; font-size:${m.labelTextFontSize}; font-family:${m.labelTextFontFamily};`">
117
+ {{m.labelText}}
118
+ </div>
119
+
120
+ </div>
121
+
122
+ </div>
123
+
124
+ </div>
125
+ </div>
126
+
127
+ </template>
128
+
129
+ </div>
130
+
131
+ </div>
132
+
133
+ </div>
134
+
135
+ </div>
136
+ </template>
137
+
138
+ <script>
139
+ import { mdiCogOutline, mdiAxis, mdiAxisZRotateCounterclockwise, mdiGrid, mdiProjectorScreenOutline, mdiListBoxOutline, mdiEyeOutline, mdiEyeOffOutline } from '@mdi/js/mdi.js'
140
+ import get from 'lodash-es/get'
141
+ import each from 'lodash-es/each'
142
+ import map from 'lodash-es/map'
143
+ import find from 'lodash-es/find'
144
+ import toUpper from 'lodash-es/toUpper'
145
+ import keys from 'lodash-es/keys'
146
+ import pull from 'lodash-es/pull'
147
+ import isEqual from 'lodash-es/isEqual'
148
+ import cloneDeep from 'lodash-es/cloneDeep'
149
+ import waitFun from 'wsemi/src/waitFun.mjs'
150
+ import haskey from 'wsemi/src/haskey.mjs'
151
+ import isnum from 'wsemi/src/isnum.mjs'
152
+ import isestr from 'wsemi/src/isestr.mjs'
153
+ import iseobj from 'wsemi/src/iseobj.mjs'
154
+ import isEle from 'wsemi/src/isEle.mjs'
155
+ import isfun from 'wsemi/src/isfun.mjs'
156
+ import cdbl from 'wsemi/src/cdbl.mjs'
157
+ import delay from 'wsemi/src/delay.mjs'
158
+ import strleft from 'wsemi/src/strleft.mjs'
159
+ import strdelleft from 'wsemi/src/strdelleft.mjs'
160
+ import oc from 'wsemi/src/color.mjs'
161
+ import domResize from 'w-component-vue/src/js/domResize.mjs'
162
+ import WIconLoading from 'w-component-vue/src/components/WIconLoading.vue'
163
+ import WGroupIconCheck from 'w-component-vue/src/components/WGroupIconCheck.vue'
164
+ import WIcon from 'w-component-vue/src/components/WIcon.vue'
165
+ import WColorSelect from 'w-component-vue/src/components/WColorSelect.vue'
166
+ import plot3d from '../js/plot3d.mjs'
167
+
168
+
169
+ /**
170
+ * @vue-prop {Object} [options={}] 輸入設定物件,預設{}
171
+ */
172
+ export default {
173
+ directives: {
174
+ domresize: domResize(),
175
+ },
176
+ components: {
177
+ WIconLoading,
178
+ WGroupIconCheck,
179
+ WIcon,
180
+ WColorSelect,
181
+ },
182
+ props: {
183
+ opt: {
184
+ type: Object,
185
+ default: () => {},
186
+ },
187
+ },
188
+ data: function() {
189
+ return {
190
+ mdiEyeOutline,
191
+ mdiEyeOffOutline,
192
+
193
+ loading: true,
194
+
195
+ timer: null,
196
+
197
+ // items,
198
+ itemsSelectIds: [],
199
+ itemsSelects: [],
200
+
201
+ useSetting: true,
202
+ useAutoRotate: false,
203
+ useHelperAxes: true,
204
+ useHelperGrid: true,
205
+ usePerspective: true,
206
+ useLegend: true,
207
+
208
+ optTemp: null,
209
+
210
+ meshs: [],
211
+
212
+ ev: null,
213
+
214
+ menuSettingIcon: '',
215
+ menuSettingTooltip: '',
216
+ menuAutoRotateIcon: '',
217
+ menuAutoRotateTooltip: '',
218
+ menuAxesIcon: '',
219
+ menuAxesTooltip: '',
220
+ menuGridIcon: '',
221
+ menuGridTooltip: '',
222
+ menuPerspectiveIcon: '',
223
+ menuPerspectiveTooltip: '',
224
+ menuLegendIcon: '',
225
+ menuLegendTooltip: '',
226
+
227
+ useLegnedBackgroundColor: '',
228
+ useLegnedHeight: '',
229
+
230
+ }
231
+ },
232
+ mounted: function() {
233
+ let vo = this
234
+ let t
235
+ vo.timer = setInterval(() => {
236
+
237
+ // vo.useSetting
238
+
239
+ t = vo.getParam('useHelperAxes')
240
+ if (vo.useHelperAxes !== t) {
241
+ vo.useHelperAxes = t
242
+ }
243
+
244
+ t = vo.getParam('useAutoRotate')
245
+ if (vo.useAutoRotate !== t) {
246
+ vo.useAutoRotate = t
247
+ }
248
+
249
+ t = vo.getParam('useHelperGrid')
250
+ if (vo.useHelperGrid !== t) {
251
+ vo.useHelperGrid = t
252
+ }
253
+
254
+ t = vo.getParam('cameraType') === 'perspective'
255
+ if (vo.usePerspective !== t) {
256
+ vo.usePerspective = t
257
+ }
258
+
259
+ // vo.useLegend
260
+
261
+ t = vo.getMeshs()
262
+ if (!isEqual(vo.meshs, t)) {
263
+ vo.meshs = t
264
+ // console.log('meshs', vo.meshs)
265
+ }
266
+
267
+ vo.syncItemsSelectIds()
268
+
269
+ vo.updateItemsSelects(false)
270
+
271
+ }, 50)
272
+ },
273
+ beforeDestroy: function() {
274
+ let vo = this
275
+ clearInterval(vo.timer)
276
+ vo.dispose()
277
+ },
278
+ watch: {
279
+ 'opt': {
280
+ handler(value) {
281
+ // console.log('watch opt handler', cloneDeep(value))
282
+
283
+ let vo = this
284
+
285
+ if (vo.loading) {
286
+ // console.log('init')
287
+
288
+ //init
289
+ vo.init()
290
+ .finally(() => {
291
+
292
+ //save
293
+ vo.optTemp = cloneDeep(vo.opt)
294
+
295
+ })
296
+
297
+ }
298
+ else {
299
+ // console.log('modify')
300
+
301
+ //modify, vue監聽obj需要原本有鍵而值有變化才能偵測, 若需要用modify得須於設定opt時預先給予初始值
302
+ vo.modify()
303
+ .finally(() => {
304
+
305
+ //save
306
+ vo.optTemp = cloneDeep(vo.opt)
307
+
308
+ })
309
+
310
+ }
311
+
312
+
313
+ },
314
+ immediate: true,
315
+ deep: true,
316
+ }
317
+ },
318
+ computed: {
319
+
320
+ widthInp: function() {
321
+ //console.log('computed widthInp')
322
+
323
+ let vo = this
324
+
325
+ //w
326
+ let w = 0
327
+ let wOpt = get(vo, 'opt.width', '')
328
+ if (isnum(wOpt)) {
329
+ w = cdbl(wOpt)
330
+ }
331
+
332
+ return w
333
+ },
334
+
335
+ heightInp: function() {
336
+ //console.log('computed heightInp')
337
+
338
+ let vo = this
339
+
340
+ //h
341
+ let h = 0
342
+ let hOpt = get(vo, 'opt.height', '')
343
+ if (isnum(hOpt)) {
344
+ h = cdbl(hOpt)
345
+ }
346
+
347
+ return h
348
+ },
349
+
350
+ items: function() {
351
+ let vo = this
352
+ let rs = [
353
+ {
354
+ id: 'setting',
355
+ icon: vo.menuSettingIcon,
356
+ tooltip: vo.menuSettingTooltip,
357
+ },
358
+ {
359
+ id: 'auto_rotate',
360
+ icon: vo.menuAutoRotateIcon,
361
+ tooltip: vo.menuAutoRotateTooltip,
362
+ },
363
+ {
364
+ id: 'axes',
365
+ icon: vo.menuAxesIcon,
366
+ tooltip: vo.menuAxesTooltip,
367
+ },
368
+ {
369
+ id: 'grid',
370
+ icon: vo.menuGridIcon,
371
+ tooltip: vo.menuGridTooltip,
372
+ },
373
+ {
374
+ id: 'perspective',
375
+ icon: vo.menuPerspectiveIcon,
376
+ tooltip: vo.menuPerspectiveTooltip,
377
+ },
378
+ {
379
+ id: 'legend',
380
+ icon: vo.menuLegendIcon,
381
+ tooltip: vo.menuLegendTooltip,
382
+ },
383
+ ]
384
+ // console.log('computed gen items', rs)
385
+ return rs
386
+ },
387
+
388
+ useItems: function() {
389
+ let vo = this
390
+ let rs = []
391
+ if (vo.useSetting) {
392
+ rs = cloneDeep(vo.items)
393
+ }
394
+ else {
395
+ rs = [cloneDeep(vo.items[0])]
396
+ }
397
+ // console.log('computed gen useItems', rs)
398
+ return rs
399
+ },
400
+
401
+ },
402
+ methods: {
403
+
404
+ resizePanel: function(msg) {
405
+ // console.log('methods resizePanel', msg)
406
+
407
+ let vo = this
408
+
409
+ //check
410
+ if (vo.ev === null) {
411
+ return
412
+ }
413
+
414
+ //resize
415
+ let fun = get(vo, 'ev.resize')
416
+ if (isfun(fun)) {
417
+
418
+ //resize
419
+ fun()
420
+
421
+ //emit
422
+ vo.$emit('resize', msg)
423
+
424
+ }
425
+
426
+
427
+ },
428
+
429
+ syncItemsSelectIds: function() {
430
+ let vo = this
431
+
432
+ let ids = []
433
+ if (vo.useSetting) {
434
+ ids.push('setting')
435
+ }
436
+ if (vo.useAutoRotate) {
437
+ ids.push('auto_rotate')
438
+ }
439
+ if (vo.useHelperAxes) {
440
+ ids.push('axes')
441
+ }
442
+ if (vo.useHelperGrid) {
443
+ ids.push('grid')
444
+ }
445
+ if (vo.usePerspective) {
446
+ ids.push('perspective')
447
+ }
448
+ if (vo.useLegend) {
449
+ ids.push('legend')
450
+ }
451
+
452
+ //check
453
+ if (isEqual(vo.itemsSelectIds, ids)) {
454
+ return
455
+ }
456
+
457
+ //save
458
+ vo.itemsSelectIds = ids
459
+ // console.log('syncItemsSelectIds itemsSelectIds', cloneDeep(vo.itemsSelectIds))
460
+
461
+ },
462
+
463
+ updateItemsSelects: function(force = false) {
464
+ let vo = this
465
+
466
+ //check
467
+ let ids = map(vo.itemsSelects, 'id')
468
+ if (!force && isEqual(vo.itemsSelectIds, ids)) {
469
+ return
470
+ }
471
+
472
+ let rs = []
473
+ each(vo.itemsSelectIds, (id) => {
474
+ let r = find(vo.items, { id })
475
+ if (!iseobj(r)) {
476
+ console.log(`invalid id[${id}]`)
477
+ }
478
+ else {
479
+ rs.push(r)
480
+ }
481
+ })
482
+
483
+ //save
484
+ vo.itemsSelects = rs
485
+ // console.log('updateItemsSelects itemsSelects', cloneDeep(vo.itemsSelects))
486
+
487
+ },
488
+
489
+ updateMenus: function() {
490
+ let vo = this
491
+
492
+ let menuSettingIcon = get(vo, 'opt.menuSettingIcon', '')
493
+ if (!isestr(menuSettingIcon)) {
494
+ menuSettingIcon = mdiCogOutline
495
+ }
496
+
497
+ let menuSettingTooltip = get(vo, 'opt.menuSettingTooltip', '')
498
+ if (!isestr(menuSettingTooltip)) {
499
+ menuSettingTooltip = 'Settings'
500
+ }
501
+
502
+ let menuAutoRotateIcon = get(vo, 'opt.menuAutoRotateIcon', '')
503
+ if (!isestr(menuAutoRotateIcon)) {
504
+ menuAutoRotateIcon = mdiAxisZRotateCounterclockwise
505
+ }
506
+
507
+ let menuAutoRotateTooltip = get(vo, 'opt.menuAutoRotateTooltip', '')
508
+ if (!isestr(menuAutoRotateTooltip)) {
509
+ menuAutoRotateTooltip = 'Auto rotate'
510
+ }
511
+
512
+ let menuAxesIcon = get(vo, 'opt.menuAxesIcon', '')
513
+ if (!isestr(menuAxesIcon)) {
514
+ menuAxesIcon = mdiAxis
515
+ }
516
+
517
+ let menuAxesTooltip = get(vo, 'opt.menuAxesTooltip', '')
518
+ if (!isestr(menuAxesTooltip)) {
519
+ menuAxesTooltip = 'Axes'
520
+ }
521
+
522
+ let menuGridIcon = get(vo, 'opt.menuGridIcon', '')
523
+ if (!isestr(menuGridIcon)) {
524
+ menuGridIcon = mdiGrid
525
+ }
526
+
527
+ let menuGridTooltip = get(vo, 'opt.menuGridTooltip', '')
528
+ if (!isestr(menuGridTooltip)) {
529
+ menuGridTooltip = 'Grid'
530
+ }
531
+
532
+ let menuPerspectiveIcon = get(vo, 'opt.menuPerspectiveIcon', '')
533
+ if (!isestr(menuPerspectiveIcon)) {
534
+ menuPerspectiveIcon = mdiProjectorScreenOutline
535
+ }
536
+
537
+ let menuPerspectiveTooltip = get(vo, 'opt.menuPerspectiveTooltip', '')
538
+ if (!isestr(menuPerspectiveTooltip)) {
539
+ menuPerspectiveTooltip = 'Perspective'
540
+ }
541
+
542
+ let menuLegendIcon = get(vo, 'opt.menuLegendIcon', '')
543
+ if (!isestr(menuLegendIcon)) {
544
+ menuLegendIcon = mdiListBoxOutline
545
+ }
546
+
547
+ let menuLegendTooltip = get(vo, 'opt.menuLegendTooltip', '')
548
+ if (!isestr(menuLegendTooltip)) {
549
+ menuLegendTooltip = 'Legend'
550
+ }
551
+
552
+ //save
553
+ vo.menuSettingIcon = menuSettingIcon
554
+ vo.menuSettingTooltip = menuSettingTooltip
555
+ vo.menuAutoRotateIcon = menuAutoRotateIcon
556
+ vo.menuAutoRotateTooltip = menuAutoRotateTooltip
557
+ vo.menuAxesIcon = menuAxesIcon
558
+ vo.menuAxesTooltip = menuAxesTooltip
559
+ vo.menuGridIcon = menuGridIcon
560
+ vo.menuGridTooltip = menuGridTooltip
561
+ vo.menuPerspectiveIcon = menuPerspectiveIcon
562
+ vo.menuPerspectiveTooltip = menuPerspectiveTooltip
563
+ vo.menuLegendIcon = menuLegendIcon
564
+ vo.menuLegendTooltip = menuLegendTooltip
565
+
566
+ //vo.items會因為computed自動變更, 故不須另外處理
567
+
568
+ //updateItemsSelects, vo.itemsSelects只通過timer偵測id來變更, 若有更新icon或tooltip因id不變而不須變更, 故此處須使用強制變更
569
+ vo.updateItemsSelects(true)
570
+
571
+ },
572
+
573
+ refreshLegend: function() {
574
+ let vo = this
575
+
576
+ //legnedBackgroundColor
577
+ let legnedBackgroundColor = get(vo, 'opt.legnedBackgroundColor', '')
578
+ if (!isestr(legnedBackgroundColor)) {
579
+ legnedBackgroundColor = 'rgba(90,90,90,0.5)'
580
+ }
581
+
582
+ vo.useLegnedBackgroundColor = oc.toRgbaString(legnedBackgroundColor)
583
+ // console.log('useLegnedBackgroundColor', vo.useLegnedBackgroundColor)
584
+
585
+ //legnedHeight
586
+ let legnedHeight = get(vo, 'opt.legnedHeight', null)
587
+
588
+ //legnedHeightMax
589
+ let legnedHeightMax = get(vo, 'opt.legnedHeightMax', null)
590
+
591
+ let useLegnedHeight = ''
592
+ if (isnum(legnedHeight)) {
593
+ legnedHeight = cdbl(legnedHeight)
594
+ useLegnedHeight += `height:${legnedHeight}px;`
595
+ }
596
+ if (isnum(legnedHeightMax)) {
597
+ legnedHeightMax = cdbl(legnedHeightMax)
598
+ useLegnedHeight += `max-height:${legnedHeightMax}px;`
599
+ }
600
+ if (isnum(legnedHeight) || isnum(legnedHeightMax)) {
601
+ useLegnedHeight += `overflow-y:auto;`
602
+ }
603
+ vo.useLegnedHeight = useLegnedHeight
604
+ // console.log('useLegnedHeight', vo.useLegnedHeight)
605
+
606
+ },
607
+
608
+ init: async function() {
609
+ let vo = this
610
+
611
+ async function core() {
612
+
613
+ //dispose
614
+ vo.dispose()
615
+
616
+ //waitFun
617
+ await waitFun(() => {
618
+ return isEle(vo.$refs.panel)
619
+ })
620
+ // console.log('vo.$refs.panel', vo.$refs.panel)
621
+
622
+ //show loading
623
+ vo.loading = true
624
+
625
+ //optPlot3d
626
+ let optPlot3d = cloneDeep(vo.opt)
627
+ optPlot3d.domPanel = vo.$refs.panel
628
+
629
+ //items
630
+ let items = get(optPlot3d, 'items', [])
631
+ // console.log('items', items)
632
+
633
+ //plot3d
634
+ let ev = await plot3d(items, optPlot3d)
635
+
636
+ //on
637
+ ev.on('init', () => {
638
+ // console.log('init')
639
+ vo.$emit('init')
640
+
641
+ //updateMenus
642
+ vo.updateMenus()
643
+
644
+ //refreshLegend
645
+ vo.refreshLegend()
646
+
647
+ //hide loading
648
+ vo.loading = false
649
+
650
+ })
651
+ ev.on('loading', (msg) => {
652
+ // console.log('loading', msg)
653
+ vo.$emit('loading', msg)
654
+ })
655
+ ev.on('dispose', () => {
656
+ // console.log('dispose')
657
+ vo.$emit('dispose')
658
+ })
659
+ ev.on('change-view-angle', (msg) => {
660
+ // console.log('change-view-angle')
661
+ vo.$emit('change-view-angle', msg)
662
+ })
663
+
664
+ //save
665
+ vo.ev = ev
666
+
667
+ }
668
+
669
+ //core
670
+ await core()
671
+ .catch((err) => {
672
+ console.log(err)
673
+ })
674
+
675
+ },
676
+
677
+ modify: async function () {
678
+ let vo = this
679
+
680
+ async function core() {
681
+
682
+ //check
683
+ if (vo.ev === null) {
684
+ return
685
+ }
686
+
687
+ //delay
688
+ await delay(300)
689
+
690
+ //ks, ksTemp
691
+ let ks = keys(vo.opt)
692
+ let ksTemp = keys(vo.optTemp)
693
+ // console.log('ks', ks)
694
+ // console.log('ksTemp', ksTemp)
695
+
696
+ //rs
697
+ let rs = []
698
+ each(ks, (k) => {
699
+
700
+ //vNew, vOld
701
+ let vNew = get(vo, `opt.${k}`, null)
702
+ let vOld = get(vo, `optTemp.${k}`, null)
703
+
704
+ //check
705
+ if (!isEqual(vNew, vOld)) {
706
+ rs.push({
707
+ type: 'mod',
708
+ k,
709
+ vOld,
710
+ vNew,
711
+ })
712
+ }
713
+
714
+ //pull
715
+ pull(ksTemp, k)
716
+
717
+ })
718
+ each(ksTemp, (k) => {
719
+ let vOld = get(vo, `optTemp.${k}`, null)
720
+ rs.push({
721
+ type: 'del',
722
+ k,
723
+ vOld,
724
+ vNew: null,
725
+ })
726
+ })
727
+ // console.log('rs', rs)
728
+
729
+ //kpSet
730
+ let kpSet = {
731
+
732
+ backgroundColor: 'ev.setBackgroundColor',
733
+ useAutoRotate: 'ev.setUseAutoRotate',
734
+ autoRotateDeg: 'ev.setAutoRotateDeg',
735
+ useHelperAxes: 'ev.setUseHelperAxes',
736
+ helperAxesLengthRatio: 'ev.setHelperAxesLengthRatio',
737
+ useHelperGrid: 'ev.setUseHelperGrid',
738
+ helperGridLengthRatio: 'ev.setHelperGridLengthRatio',
739
+ helperGridDensity: 'ev.setHelperGridDensity',
740
+ helperGridPositionRatioZ: 'ev.setHelperGridPositionRatioZ',
741
+ useLightAmbient: 'ev.setUseLightAmbient',
742
+ lightAmbientColor: 'ev.setLightAmbientColor',
743
+ useLightPoint: 'ev.setUseLightPoint',
744
+ lightPointPoss: 'ev.setLightPointPoss',
745
+ lightPointColor: 'ev.setLightPointColor',
746
+ lightPointIntensity: 'ev.setLightPointIntensity',
747
+ lightPointDistance: 'ev.setLightPointDistance',
748
+ lightPointDecay: 'ev.setLightPointDecay',
749
+ useLightDirection: 'ev.setUseLightDirection',
750
+ lightDirectionColor: 'ev.setLightDirectionColor',
751
+ lightDirectionIntensity: 'ev.setLightDirectionIntensity',
752
+ lightDirectionPos: 'ev.setLightDirectionPos',
753
+ cameraType: 'ev.setCameraType',
754
+ // cameraPos: 'ev.setCameraPos', //因cameraPos跟cameraPolarAngle與cameraAzimuthAngle衝突, 故僅提供設定cameraPolarAngle與cameraAzimuthAngle
755
+ cameraFov: 'ev.setCameraFov',
756
+ cameraNear: 'ev.setCameraNear',
757
+ cameraFar: 'ev.setCameraFar',
758
+ cameraOrthographicRatio: 'ev.setCameraOrthographicRatio',
759
+ cameraAzimuthAngle: 'ev.setCameraAzimuthAngle', //因可通過ui改變導致vue無法監聽變數有變而觸發computed, 故建議直接使用setCameraAzimuthAngle變更
760
+ cameraPolarAngle: 'ev.setCameraPolarAngle', //因可通過ui改變導致vue無法監聽變數有變而觸發computed, 故建議直接使用setCameraPolarAngle變更
761
+
762
+ menuSettingIcon: 'updateMenus',
763
+ menuSettingTooltip: 'updateMenus',
764
+ menuAutoRotateIcon: 'updateMenus',
765
+ menuAutoRotateTooltip: 'updateMenus',
766
+ menuAxesIcon: 'updateMenus',
767
+ menuAxesTooltip: 'updateMenus',
768
+ menuGridIcon: 'updateMenus',
769
+ menuGridTooltip: 'updateMenus',
770
+ menuPerspectiveIcon: 'updateMenus',
771
+ menuPerspectiveTooltip: 'updateMenus',
772
+ menuLegendIcon: 'updateMenus',
773
+ menuLegendTooltip: 'updateMenus',
774
+
775
+ legnedBackgroundColor: 'refreshLegend',
776
+ legnedHeight: 'refreshLegend',
777
+ legnedHeightMax: 'refreshLegend',
778
+
779
+ }
780
+
781
+ //call
782
+ each(rs, (v) => {
783
+ let k = v.k
784
+ if (haskey(kpSet, k)) {
785
+ let cf = kpSet[k]
786
+ // console.log('call', k, cf)
787
+ let fun = get(vo, cf)
788
+ try {
789
+ fun(v.vNew)
790
+ }
791
+ catch (err) {
792
+ console.log(err)
793
+ }
794
+ }
795
+ else {
796
+ console.log(`尚未建置 ${k} 之 set 函數`)
797
+ }
798
+ })
799
+
800
+ }
801
+
802
+ //core
803
+ await core()
804
+ .catch((err) => {
805
+ console.log(err)
806
+ })
807
+
808
+ },
809
+
810
+ dispose: function() {
811
+ let vo = this
812
+
813
+ //使用setTimeout讓記憶體脫勾, 避免被computed視為連動
814
+ setTimeout(() => {
815
+
816
+ //check
817
+ if (vo.ev === null) {
818
+ return
819
+ }
820
+
821
+ //dispose
822
+ let fun = get(vo, 'ev.dispose')
823
+ if (isfun(fun)) {
824
+ vo.ev.dispose()
825
+ vo.ev = null
826
+ // console.log('dispose')
827
+ }
828
+
829
+ }, 1)
830
+
831
+ },
832
+
833
+ getInst: function() {
834
+ let vo = this
835
+ return get(vo, 'ev')
836
+ },
837
+
838
+ getMeshs: function() {
839
+ let vo = this
840
+ let fun = get(vo, 'ev.getMeshsInfor')
841
+ let meshs = []
842
+ if (isfun(fun)) {
843
+ meshs = fun()
844
+ // console.log('meshs', meshs)
845
+ }
846
+ return meshs
847
+ },
848
+
849
+ getMeshColor: function(m) {
850
+ // let vo = this
851
+ let c = get(m, 'color', '')
852
+ c = oc.toRgbaString(c)
853
+ return c
854
+ },
855
+
856
+ setMeshColor: function(m, km, c) {
857
+ let vo = this
858
+ vo.ev.setMeshColor(km, c)
859
+ },
860
+
861
+ toggleMeshVisible: function(m, km) {
862
+ let vo = this
863
+ vo.ev.setMeshVisible(km, !m.visible)
864
+ },
865
+
866
+ strUpperHead: function(c) {
867
+ // let vo = this
868
+ let c0 = strleft(c, 1)
869
+ c0 = toUpper(c0)
870
+ let c1 = strdelleft(c, 1)
871
+ return `${c0}${c1}`
872
+ },
873
+
874
+ getParam: function(key) {
875
+ let vo = this
876
+ let r = null
877
+ key = vo.strUpperHead(key)
878
+ let fun = get(vo, `ev.get${key}`)
879
+ if (isfun(fun)) {
880
+ r = fun()
881
+ }
882
+ return r
883
+ },
884
+
885
+ setParam: function(key, v) {
886
+ let vo = this
887
+ key = vo.strUpperHead(key)
888
+ let fun = get(vo, `ev.set${key}`)
889
+ if (isfun(fun)) {
890
+ fun(v)
891
+ }
892
+ },
893
+
894
+ toggleParam: function(key) {
895
+ let vo = this
896
+ let b = vo.getParam(key)
897
+ b = !b
898
+ vo.setParam(key, b)
899
+ },
900
+
901
+ ckItem: function(item) {
902
+ let vo = this
903
+
904
+ //kp
905
+ let kp = {
906
+ setting: () => {
907
+ vo.useSetting = !vo.useSetting
908
+ },
909
+ axes: () => {
910
+ vo.toggleParam('useHelperAxes')
911
+ },
912
+ auto_rotate: () => {
913
+ vo.toggleParam('useAutoRotate')
914
+ },
915
+ grid: () => {
916
+ vo.toggleParam('useHelperGrid')
917
+ },
918
+ perspective: () => {
919
+ if (vo.usePerspective) {
920
+ vo.setParam('cameraType', 'orthographic')
921
+ }
922
+ else {
923
+ vo.setParam('cameraType', 'perspective')
924
+ }
925
+ },
926
+ legend: () => {
927
+ vo.useLegend = !vo.useLegend
928
+ },
929
+ }
930
+
931
+ //id
932
+ let id = get(item, 'id', '')
933
+ // console.log('id', id)
934
+
935
+ //fun
936
+ let fun = get(kp, id)
937
+
938
+ //call
939
+ if (isfun(fun)) {
940
+ fun()
941
+ }
942
+ else {
943
+ console.log('item', item)
944
+ console.log('kp', kp)
945
+ console.log(`invalid id[${id}]`)
946
+ }
947
+
948
+ },
949
+
950
+ },
951
+ }
952
+ </script>
953
+
954
+ <style scoped>
955
+ </style>