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.
- package/.editorconfig +9 -0
- package/.eslintignore +3 -0
- package/.eslintrc.js +55 -0
- package/.jsdoc +25 -0
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/SECURITY.md +5 -0
- package/babel.config.js +15 -0
- package/dist/w-threejs-vue.umd.js +26 -0
- package/dist/w-threejs-vue.umd.js.map +1 -0
- package/docs/examples/app.html +66 -0
- package/docs/examples/app.umd.js +31 -0
- package/docs/examples/app.umd.js.map +1 -0
- package/docs/examples/ex-AppBasicAutoRotateDeg.html +190 -0
- package/docs/examples/ex-AppBasicBackgroundColor.html +189 -0
- package/docs/examples/ex-AppBasicSize.html +170 -0
- package/docs/examples/ex-AppBasicUploadStl.html +237 -0
- package/docs/examples/ex-AppBasicUseAutoRotate.html +189 -0
- package/docs/examples/ex-AppCmCameraFar.html +191 -0
- package/docs/examples/ex-AppCmCameraFov.html +191 -0
- package/docs/examples/ex-AppCmCameraNear.html +191 -0
- package/docs/examples/ex-AppCmCameraOrthographicRatio.html +191 -0
- package/docs/examples/ex-AppCmCameraType.html +190 -0
- package/docs/examples/ex-AppCmGetCameraViewAngle.html +218 -0
- package/docs/examples/ex-AppCmSetCameraAzimuthAngle.html +190 -0
- package/docs/examples/ex-AppCmSetCameraPolarAngle.html +190 -0
- package/docs/examples/ex-AppCmSetCameraViewAngle.html +194 -0
- package/docs/examples/ex-AppHpHelperAxesLengthRatio.html +189 -0
- package/docs/examples/ex-AppHpHelperGridDensity.html +189 -0
- package/docs/examples/ex-AppHpHelperGridLengthRatio.html +189 -0
- package/docs/examples/ex-AppHpHelperGridPositionRatioZ.html +189 -0
- package/docs/examples/ex-AppHpUseHelperAxes.html +189 -0
- package/docs/examples/ex-AppHpUseHelperGrid.html +189 -0
- package/docs/examples/ex-AppLgLegnedBackgroundColor.html +189 -0
- package/docs/examples/ex-AppLgLegnedHeight.html +189 -0
- package/docs/examples/ex-AppLgLegnedHeightMax.html +189 -0
- package/docs/examples/ex-AppLtLightAmbientColor.html +189 -0
- package/docs/examples/ex-AppLtLightDirectionColor.html +191 -0
- package/docs/examples/ex-AppLtLightDirectionIntensity.html +191 -0
- package/docs/examples/ex-AppLtLightDirectionPos.html +191 -0
- package/docs/examples/ex-AppLtLightPointColor.html +192 -0
- package/docs/examples/ex-AppLtLightPointDecay.html +192 -0
- package/docs/examples/ex-AppLtLightPointDistance.html +192 -0
- package/docs/examples/ex-AppLtLightPointIntensity.html +192 -0
- package/docs/examples/ex-AppLtLightPointPoss.html +192 -0
- package/docs/examples/ex-AppLtUseLightAmbient.html +191 -0
- package/docs/examples/ex-AppLtUseLightDirection.html +191 -0
- package/docs/examples/ex-AppLtUseLightPoint.html +191 -0
- package/docs/examples/ex-AppMhGetMeshsInfor.html +198 -0
- package/docs/examples/ex-AppMhSetMeshColor.html +190 -0
- package/docs/examples/ex-AppMhSetMeshLabelText.html +190 -0
- package/docs/examples/ex-AppMhSetMeshLabelTextColor.html +190 -0
- package/docs/examples/ex-AppMhSetMeshLabelTextFontFamily.html +190 -0
- package/docs/examples/ex-AppMhSetMeshLabelTextFontSize.html +190 -0
- package/docs/examples/ex-AppMhSetMeshLabelVisible.html +198 -0
- package/docs/examples/ex-AppMhSetMeshVisible.html +198 -0
- package/docs/examples/ex-AppMuMenuIcons.html +217 -0
- package/docs/examples/ex-AppMuMenuTooltips.html +218 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/index.html +84 -0
- package/docs/module-WThreejsVue.html +216 -0
- package/docs/scripts/collapse.js +39 -0
- package/docs/scripts/commonNav.js +28 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/nav.js +12 -0
- package/docs/scripts/polyfill.js +4 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/scripts/search.js +99 -0
- package/docs/styles/jsdoc.css +776 -0
- package/docs/styles/prettify.css +80 -0
- package/package.json +74 -0
- package/public/index.html +42 -0
- package/src/App.vue +574 -0
- package/src/AppBasicAutoRotateDeg.vue +102 -0
- package/src/AppBasicBackgroundColor.vue +101 -0
- package/src/AppBasicSize.vue +90 -0
- package/src/AppBasicUploadStl.vue +159 -0
- package/src/AppBasicUseAutoRotate.vue +101 -0
- package/src/AppCmCameraFar.vue +103 -0
- package/src/AppCmCameraFov.vue +103 -0
- package/src/AppCmCameraNear.vue +103 -0
- package/src/AppCmCameraOrthographicRatio.vue +103 -0
- package/src/AppCmCameraType.vue +102 -0
- package/src/AppCmGetCameraViewAngle.vue +135 -0
- package/src/AppCmSetCameraAzimuthAngle.vue +104 -0
- package/src/AppCmSetCameraPolarAngle.vue +104 -0
- package/src/AppCmSetCameraViewAngle.vue +105 -0
- package/src/AppHpHelperAxesLengthRatio.vue +101 -0
- package/src/AppHpHelperGridDensity.vue +101 -0
- package/src/AppHpHelperGridLengthRatio.vue +101 -0
- package/src/AppHpHelperGridPositionRatioZ.vue +101 -0
- package/src/AppHpUseHelperAxes.vue +101 -0
- package/src/AppHpUseHelperGrid.vue +101 -0
- package/src/AppLgLegnedBackgroundColor.vue +101 -0
- package/src/AppLgLegnedHeight.vue +101 -0
- package/src/AppLgLegnedHeightMax.vue +101 -0
- package/src/AppLtLightAmbientColor.vue +101 -0
- package/src/AppLtLightDirectionColor.vue +103 -0
- package/src/AppLtLightDirectionIntensity.vue +103 -0
- package/src/AppLtLightDirectionPos.vue +103 -0
- package/src/AppLtLightPointColor.vue +104 -0
- package/src/AppLtLightPointDecay.vue +104 -0
- package/src/AppLtLightPointDistance.vue +104 -0
- package/src/AppLtLightPointIntensity.vue +104 -0
- package/src/AppLtLightPointPoss.vue +104 -0
- package/src/AppLtUseLightAmbient.vue +103 -0
- package/src/AppLtUseLightDirection.vue +103 -0
- package/src/AppLtUseLightPoint.vue +103 -0
- package/src/AppMhGetMeshsInfor.vue +112 -0
- package/src/AppMhSetMeshColor.vue +104 -0
- package/src/AppMhSetMeshLabelText.vue +104 -0
- package/src/AppMhSetMeshLabelTextColor.vue +104 -0
- package/src/AppMhSetMeshLabelTextFontFamily.vue +104 -0
- package/src/AppMhSetMeshLabelTextFontSize.vue +104 -0
- package/src/AppMhSetMeshLabelVisible.vue +106 -0
- package/src/AppMhSetMeshVisible.vue +106 -0
- package/src/AppMuMenuIcons.vue +130 -0
- package/src/AppMuMenuTooltips.vue +131 -0
- package/src/components/WThreejsVue.vue +955 -0
- package/src/js/addStl.mjs +83 -0
- package/src/js/getCsrdFromMeshs.mjs +85 -0
- package/src/js/plot3d.mjs +1407 -0
- package/src/main.js +8 -0
- package/test/all.test.mjs +10 -0
- package/toolg/addVersion.mjs +4 -0
- package/toolg/cleanFolder.mjs +4 -0
- package/toolg/gDistApp.mjs +38 -0
- package/toolg/gDistRollupComps.mjs +22 -0
- package/toolg/gDocExams.mjs +47 -0
- package/toolg/gExtractHtml.mjs +159 -0
- package/toolg/modifyReadme.mjs +4 -0
- package/vue.config.js +21 -0
|
@@ -0,0 +1,1407 @@
|
|
|
1
|
+
import get from 'lodash-es/get'
|
|
2
|
+
import set from 'lodash-es/set'
|
|
3
|
+
import each from 'lodash-es/each'
|
|
4
|
+
import map from 'lodash-es/map'
|
|
5
|
+
import isEqual from 'lodash-es/isEqual'
|
|
6
|
+
import isNumber from 'lodash-es/isNumber'
|
|
7
|
+
import evem from 'wsemi/src/evem.mjs'
|
|
8
|
+
import isnum from 'wsemi/src/isnum.mjs'
|
|
9
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
10
|
+
import isbol from 'wsemi/src/isbol.mjs'
|
|
11
|
+
import isearr from 'wsemi/src/isearr.mjs'
|
|
12
|
+
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
13
|
+
import isEle from 'wsemi/src/isEle.mjs'
|
|
14
|
+
import delay from 'wsemi/src/delay.mjs'
|
|
15
|
+
import pmSeries from 'wsemi/src/pmSeries.mjs'
|
|
16
|
+
import cdbl from 'wsemi/src/cdbl.mjs'
|
|
17
|
+
import oc from 'wsemi/src/color.mjs'
|
|
18
|
+
import domRemove from 'wsemi/src/domRemove.mjs'
|
|
19
|
+
import getFileNameExt from 'wsemi/src/getFileNameExt.mjs'
|
|
20
|
+
import * as THREE from 'three'
|
|
21
|
+
// import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
|
|
22
|
+
import { CSS2DRenderer, CSS2DObject } from 'three/addons/renderers/CSS2DRenderer.js'
|
|
23
|
+
import CameraControls from 'camera-controls'
|
|
24
|
+
import addStl from './addStl.mjs'
|
|
25
|
+
import getCsrdFromMeshs from './getCsrdFromMeshs.mjs'
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
let toRad = Math.PI / 180
|
|
29
|
+
let toDeg = 180 / Math.PI
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
let nc = (c) => {
|
|
33
|
+
c = oc.toRgbString(c)
|
|
34
|
+
return c
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
async function plot3d(items, opt = {}) {
|
|
39
|
+
|
|
40
|
+
//如果是多个网格模型组成一个模型对象,分别去平移每个网格模型对应的几何体可能比较麻烦,对于这种情况也可以给该模型对象嵌套一个父对象,然后把该模型对象相对于父对象平移一定距离,然后旋转该模型的父对象,不旋转模型本身,可以看到该模型的旋转效果,视觉效果上旋转轴改变了。
|
|
41
|
+
//http://www.yanhuangxueyuan.com/doc/Three.js/translateAxis.html
|
|
42
|
+
|
|
43
|
+
//有使用labels時OrbitControls得使用rendererLabels.domElement掛載, 否則會失去監聽無法操作
|
|
44
|
+
//https://blog.csdn.net/weixin_41111068/article/details/83650977
|
|
45
|
+
|
|
46
|
+
//How to completely clean up a Three.js scene
|
|
47
|
+
//https://discourse.threejs.org/t/when-to-dispose-how-to-completely-clean-up-a-three-js-scene/1549/10
|
|
48
|
+
|
|
49
|
+
//In general, attributes are freed if you call dispose() on the respective geometry object. However, if attributes needs to be replaced, it could be indeed a source of a memory leak because there it’s not possible so far to selectively free a single buffer attribute.
|
|
50
|
+
//https://discourse.threejs.org/t/disposal-of-buffers-colors-vectors-etc/13094
|
|
51
|
+
|
|
52
|
+
//MeshPhysicalMaterial清漆层
|
|
53
|
+
//https://www.mvrlink.com/threejs-meshphysicalmaterial-clearcoat-layer/
|
|
54
|
+
|
|
55
|
+
//check
|
|
56
|
+
if (!isearr(items)) {
|
|
57
|
+
items = []
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//domPanel
|
|
61
|
+
let domPanel = get(opt, 'domPanel')
|
|
62
|
+
if (!isEle(domPanel)) {
|
|
63
|
+
domPanel = document.body
|
|
64
|
+
// console.log('domPanel use document.body')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let gs = (ele) => {
|
|
68
|
+
let w = 0
|
|
69
|
+
if (isNumber(ele.innerWidth)) {
|
|
70
|
+
w = ele.innerWidth
|
|
71
|
+
}
|
|
72
|
+
else if (isNumber(ele.clientWidth)) {
|
|
73
|
+
w = ele.clientWidth
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
console.log('ele', ele)
|
|
77
|
+
throw new Error(`can not get width from ele`)
|
|
78
|
+
}
|
|
79
|
+
let h = 0
|
|
80
|
+
if (isNumber(ele.innerWidth)) {
|
|
81
|
+
h = ele.innerHeight
|
|
82
|
+
}
|
|
83
|
+
else if (isNumber(ele.clientWidth)) {
|
|
84
|
+
h = ele.clientHeight
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
console.log('ele', ele)
|
|
88
|
+
throw new Error(`can not get height from ele`)
|
|
89
|
+
}
|
|
90
|
+
return { w, h }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//rendererWidth, rendererHeight
|
|
94
|
+
let rwh = gs(domPanel)
|
|
95
|
+
let rendererWidth = rwh.w
|
|
96
|
+
let rendererHeight = rwh.h
|
|
97
|
+
|
|
98
|
+
//backgroundColor
|
|
99
|
+
let backgroundColor = get(opt, 'backgroundColor')
|
|
100
|
+
if (!isestr(backgroundColor)) {
|
|
101
|
+
backgroundColor = '#222'
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//useHelperAxes
|
|
105
|
+
let useHelperAxes = get(opt, 'useHelperAxes')
|
|
106
|
+
if (!isbol(useHelperAxes)) {
|
|
107
|
+
useHelperAxes = true
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//helperAxesLengthRatio
|
|
111
|
+
let helperAxesLengthRatio = get(opt, 'helperAxesLengthRatio')
|
|
112
|
+
if (!isnum(helperAxesLengthRatio)) {
|
|
113
|
+
helperAxesLengthRatio = 1
|
|
114
|
+
}
|
|
115
|
+
helperAxesLengthRatio = cdbl(helperAxesLengthRatio)
|
|
116
|
+
|
|
117
|
+
//useHelperGrid
|
|
118
|
+
let useHelperGrid = get(opt, 'useHelperGrid')
|
|
119
|
+
if (!isbol(useHelperGrid)) {
|
|
120
|
+
useHelperGrid = true
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//helperGridLengthRatio
|
|
124
|
+
let helperGridLengthRatio = get(opt, 'helperGridLengthRatio')
|
|
125
|
+
if (!isnum(helperGridLengthRatio)) {
|
|
126
|
+
helperGridLengthRatio = 5
|
|
127
|
+
}
|
|
128
|
+
helperGridLengthRatio = cdbl(helperGridLengthRatio)
|
|
129
|
+
|
|
130
|
+
//helperGridDensity
|
|
131
|
+
let helperGridDensity = get(opt, 'helperGridDensity')
|
|
132
|
+
if (!isnum(helperGridDensity)) {
|
|
133
|
+
helperGridDensity = 50
|
|
134
|
+
}
|
|
135
|
+
helperGridDensity = cdbl(helperGridDensity)
|
|
136
|
+
|
|
137
|
+
//helperGridPositionRatioZ
|
|
138
|
+
let helperGridPositionRatioZ = get(opt, 'helperGridPositionRatioZ')
|
|
139
|
+
if (!isnum(helperGridPositionRatioZ)) {
|
|
140
|
+
helperGridPositionRatioZ = -1
|
|
141
|
+
}
|
|
142
|
+
helperGridPositionRatioZ = cdbl(helperGridPositionRatioZ)
|
|
143
|
+
|
|
144
|
+
//useLightAmbient
|
|
145
|
+
let useLightAmbient = get(opt, 'useLightAmbient')
|
|
146
|
+
if (!isbol(useLightAmbient)) {
|
|
147
|
+
useLightAmbient = true
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//lightAmbientColor
|
|
151
|
+
let lightAmbientColor = get(opt, 'lightAmbientColor')
|
|
152
|
+
if (!isestr(lightAmbientColor)) {
|
|
153
|
+
lightAmbientColor = '#999'
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//useLightPoint
|
|
157
|
+
let useLightPoint = get(opt, 'useLightPoint')
|
|
158
|
+
if (!isbol(useLightPoint)) {
|
|
159
|
+
useLightPoint = false
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//lightPointPoss
|
|
163
|
+
let lightPointPoss = get(opt, 'lightPointPoss')
|
|
164
|
+
if (!isearr(lightPointPoss)) {
|
|
165
|
+
lightPointPoss = [
|
|
166
|
+
[5, 5, 5],
|
|
167
|
+
[-5, 5, 5],
|
|
168
|
+
[5, -5, 5],
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//lightPointColor
|
|
173
|
+
let lightPointColor = get(opt, 'lightPointColor')
|
|
174
|
+
if (!isestr(lightPointColor)) {
|
|
175
|
+
lightPointColor = '#fff'
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
//lightPointIntensity
|
|
179
|
+
let lightPointIntensity = get(opt, 'lightPointIntensity')
|
|
180
|
+
if (!isnum(lightPointIntensity)) {
|
|
181
|
+
lightPointIntensity = 100
|
|
182
|
+
}
|
|
183
|
+
lightPointIntensity = cdbl(lightPointIntensity)
|
|
184
|
+
|
|
185
|
+
//lightPointDistance
|
|
186
|
+
let lightPointDistance = get(opt, 'lightPointDistance')
|
|
187
|
+
if (!isnum(lightPointDistance)) {
|
|
188
|
+
lightPointDistance = 0 //無限遠
|
|
189
|
+
}
|
|
190
|
+
lightPointDistance = cdbl(lightPointDistance)
|
|
191
|
+
|
|
192
|
+
//lightPointDecay
|
|
193
|
+
let lightPointDecay = get(opt, 'lightPointDecay')
|
|
194
|
+
if (!isnum(lightPointDecay)) {
|
|
195
|
+
lightPointDecay = 2
|
|
196
|
+
}
|
|
197
|
+
lightPointDecay = cdbl(lightPointDecay)
|
|
198
|
+
|
|
199
|
+
//useLightDirection
|
|
200
|
+
let useLightDirection = get(opt, 'useLightDirection')
|
|
201
|
+
if (!isbol(useLightDirection)) {
|
|
202
|
+
useLightDirection = true
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
//lightDirectionColor
|
|
206
|
+
let lightDirectionColor = get(opt, 'lightDirectionColor')
|
|
207
|
+
if (!isestr(lightDirectionColor)) {
|
|
208
|
+
lightDirectionColor = '#fff'
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
//lightDirectionIntensity
|
|
212
|
+
let lightDirectionIntensity = get(opt, 'lightDirectionIntensity')
|
|
213
|
+
if (!isnum(lightDirectionIntensity)) {
|
|
214
|
+
lightDirectionIntensity = 3
|
|
215
|
+
}
|
|
216
|
+
lightDirectionIntensity = cdbl(lightDirectionIntensity)
|
|
217
|
+
|
|
218
|
+
//lightDirectionPos
|
|
219
|
+
let lightDirectionPos = get(opt, 'lightDirectionPos')
|
|
220
|
+
if (!isearr(lightDirectionPos)) {
|
|
221
|
+
lightDirectionPos = [10, 10, 10]
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
//cameraType
|
|
225
|
+
let cameraType = get(opt, 'cameraType')
|
|
226
|
+
if (cameraType !== 'perspective' && cameraType !== 'orthographic') {
|
|
227
|
+
cameraType = 'perspective'
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
//cameraFov
|
|
231
|
+
let cameraFov = get(opt, 'cameraFov')
|
|
232
|
+
if (!isnum(cameraFov)) {
|
|
233
|
+
cameraFov = 35
|
|
234
|
+
}
|
|
235
|
+
cameraFov = cdbl(cameraFov)
|
|
236
|
+
|
|
237
|
+
//cameraNear
|
|
238
|
+
let cameraNear = get(opt, 'cameraNear')
|
|
239
|
+
if (!isnum(cameraNear)) {
|
|
240
|
+
cameraNear = 0.1
|
|
241
|
+
}
|
|
242
|
+
cameraNear = cdbl(cameraNear)
|
|
243
|
+
|
|
244
|
+
//cameraFar
|
|
245
|
+
let cameraFar = get(opt, 'cameraFar')
|
|
246
|
+
if (!isnum(cameraFar)) {
|
|
247
|
+
cameraFar = 1000
|
|
248
|
+
}
|
|
249
|
+
cameraFar = cdbl(cameraFar)
|
|
250
|
+
|
|
251
|
+
//cameraOrthographicRatio
|
|
252
|
+
let cameraOrthographicRatio = get(opt, 'cameraOrthographicRatio')
|
|
253
|
+
if (!isnum(cameraOrthographicRatio)) {
|
|
254
|
+
cameraOrthographicRatio = 0.5
|
|
255
|
+
}
|
|
256
|
+
cameraOrthographicRatio = cdbl(cameraOrthographicRatio)
|
|
257
|
+
|
|
258
|
+
//cameraPos
|
|
259
|
+
let cameraPos = get(opt, 'cameraPos')
|
|
260
|
+
if (!isearr(cameraPos)) {
|
|
261
|
+
cameraPos = [1, 1, 1]
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
//cameraAzimuthAngle
|
|
265
|
+
let cameraAzimuthAngle = get(opt, 'cameraAzimuthAngle')
|
|
266
|
+
if (!isnum(cameraAzimuthAngle)) {
|
|
267
|
+
cameraAzimuthAngle = 130
|
|
268
|
+
}
|
|
269
|
+
cameraAzimuthAngle = cdbl(cameraAzimuthAngle)
|
|
270
|
+
|
|
271
|
+
//cameraPolarAngle
|
|
272
|
+
let cameraPolarAngle = get(opt, 'cameraPolarAngle')
|
|
273
|
+
if (!isnum(cameraPolarAngle)) {
|
|
274
|
+
cameraPolarAngle = 50
|
|
275
|
+
}
|
|
276
|
+
cameraPolarAngle = cdbl(cameraPolarAngle)
|
|
277
|
+
|
|
278
|
+
//labelTextColor
|
|
279
|
+
let labelTextColor = get(opt, 'labelTextColor')
|
|
280
|
+
if (!isestr(labelTextColor)) {
|
|
281
|
+
labelTextColor = '#fff'
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
//labelTextFontFamily
|
|
285
|
+
let labelTextFontFamily = get(opt, 'labelTextFontFamily')
|
|
286
|
+
if (!isestr(labelTextFontFamily)) {
|
|
287
|
+
labelTextFontFamily = 'Microsoft JhengHei'
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
//labelTextFontSize
|
|
291
|
+
let labelTextFontSize = get(opt, 'labelTextFontSize')
|
|
292
|
+
if (!isestr(labelTextFontSize)) {
|
|
293
|
+
labelTextFontSize = '0.8rem'
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
//useAutoRotate
|
|
297
|
+
let useAutoRotate = get(opt, 'useAutoRotate')
|
|
298
|
+
if (!isbol(useAutoRotate)) {
|
|
299
|
+
useAutoRotate = false
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
let getUseAutoRotate = () => {
|
|
303
|
+
return useAutoRotate
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
let setUseAutoRotate = (b) => {
|
|
307
|
+
useAutoRotate = b
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
//autoRotateDeg
|
|
311
|
+
let autoRotateDeg = get(opt, 'autoRotateDeg')
|
|
312
|
+
if (!isnum(autoRotateDeg)) {
|
|
313
|
+
autoRotateDeg = 20
|
|
314
|
+
}
|
|
315
|
+
autoRotateDeg = cdbl(autoRotateDeg)
|
|
316
|
+
|
|
317
|
+
let setAutoRotateDeg = (r) => {
|
|
318
|
+
autoRotateDeg = r
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
//ev
|
|
322
|
+
let ev = evem()
|
|
323
|
+
|
|
324
|
+
//clock
|
|
325
|
+
let clock = new THREE.Clock()
|
|
326
|
+
// console.log('clock',clock)
|
|
327
|
+
|
|
328
|
+
//scene
|
|
329
|
+
let scene = new THREE.Scene()
|
|
330
|
+
let disposeScene = () => {
|
|
331
|
+
let cleanMaterial = (material) => { //已預先執行多種dispose, 此函數暫時用不到
|
|
332
|
+
// console.log('dispose material')
|
|
333
|
+
material.dispose()
|
|
334
|
+
// dispose textures
|
|
335
|
+
for (let key of Object.keys(material)) {
|
|
336
|
+
let value = material[key]
|
|
337
|
+
if (value && typeof value === 'object' && 'minFilter' in value) {
|
|
338
|
+
// console.log('dispose texture')
|
|
339
|
+
value.dispose()
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
scene.traverse(object => {
|
|
344
|
+
// console.log('object', object)
|
|
345
|
+
if (object.isLight) {
|
|
346
|
+
// console.log('dispose light')
|
|
347
|
+
object.dispose()
|
|
348
|
+
}
|
|
349
|
+
if (object.isMesh) {
|
|
350
|
+
// console.log('dispose geometry')
|
|
351
|
+
object.geometry.dispose()
|
|
352
|
+
if (object.material.isMaterial) {
|
|
353
|
+
cleanMaterial(object.material)
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
// an array of materials
|
|
357
|
+
for (let material of object.material) cleanMaterial(material)
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
})
|
|
361
|
+
scene = null
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
//backgroundColor
|
|
365
|
+
scene.background = new THREE.Color(nc(backgroundColor))
|
|
366
|
+
|
|
367
|
+
let setBackgroundColor = (c) => {
|
|
368
|
+
backgroundColor = c
|
|
369
|
+
scene.background = new THREE.Color(nc(c))
|
|
370
|
+
render()
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
//helperAxes
|
|
374
|
+
let helperAxes = null
|
|
375
|
+
let createHelperAxes = () => {
|
|
376
|
+
helperAxes = new THREE.AxesHelper(helperAxesLengthRatio)
|
|
377
|
+
helperAxes.visible = useHelperAxes
|
|
378
|
+
scene.add(helperAxes)
|
|
379
|
+
}
|
|
380
|
+
let disposeHelperAxes = () => {
|
|
381
|
+
scene.remove(helperAxes)
|
|
382
|
+
helperAxes.dispose()
|
|
383
|
+
helperAxes = null
|
|
384
|
+
}
|
|
385
|
+
createHelperAxes()
|
|
386
|
+
|
|
387
|
+
let getUseHelperAxes = () => {
|
|
388
|
+
return useHelperAxes
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
let setUseHelperAxes = (b) => {
|
|
392
|
+
//可直接變更visible
|
|
393
|
+
useHelperAxes = b
|
|
394
|
+
helperAxes.visible = b
|
|
395
|
+
render()
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
let setHelperAxesLengthRatio = (r) => {
|
|
399
|
+
//因無直接設定AxesHelper size函數, 故使用重產給予
|
|
400
|
+
helperAxesLengthRatio = r
|
|
401
|
+
disposeHelperAxes()
|
|
402
|
+
createHelperAxes()
|
|
403
|
+
render()
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
//helperGrid
|
|
407
|
+
let helperGrid = null
|
|
408
|
+
let createHelperGrid = () => {
|
|
409
|
+
helperGrid = new THREE.GridHelper(helperGridLengthRatio, helperGridDensity)
|
|
410
|
+
helperGrid.visible = useHelperGrid
|
|
411
|
+
helperGrid.geometry.rotateX(Math.PI * 0.5)
|
|
412
|
+
helperGrid.geometry.translate(0, 0, helperGridPositionRatioZ)
|
|
413
|
+
scene.add(helperGrid)
|
|
414
|
+
}
|
|
415
|
+
let disposeHelperGrid = () => {
|
|
416
|
+
scene.remove(helperGrid)
|
|
417
|
+
helperGrid.dispose()
|
|
418
|
+
helperGrid = null
|
|
419
|
+
}
|
|
420
|
+
createHelperGrid()
|
|
421
|
+
|
|
422
|
+
let getUseHelperGrid = () => {
|
|
423
|
+
return useHelperGrid
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
let setUseHelperGrid = (b) => {
|
|
427
|
+
useHelperGrid = b
|
|
428
|
+
helperGrid.visible = b
|
|
429
|
+
render()
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
let setHelperGridLengthRatio = (r) => {
|
|
433
|
+
helperGridLengthRatio = r
|
|
434
|
+
disposeHelperGrid()
|
|
435
|
+
createHelperGrid()
|
|
436
|
+
render()
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
let setHelperGridDensity = (r) => {
|
|
440
|
+
helperGridDensity = r
|
|
441
|
+
disposeHelperGrid()
|
|
442
|
+
createHelperGrid()
|
|
443
|
+
render()
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
let setHelperGridPositionRatioZ = (r) => {
|
|
447
|
+
helperGridPositionRatioZ = r
|
|
448
|
+
disposeHelperGrid()
|
|
449
|
+
createHelperGrid()
|
|
450
|
+
render()
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// //fog
|
|
454
|
+
// let fogColor='#aaa'
|
|
455
|
+
// let fog = new THREE.Fog( nc(fogColor) , 0, 3 )
|
|
456
|
+
// scene.fog = fog
|
|
457
|
+
|
|
458
|
+
//lightAmbient
|
|
459
|
+
let lightAmbient = null
|
|
460
|
+
let createLightAmbient = () => {
|
|
461
|
+
lightAmbient = new THREE.AmbientLight(nc(lightAmbientColor))
|
|
462
|
+
lightAmbient.visible = useLightAmbient
|
|
463
|
+
scene.add(lightAmbient)
|
|
464
|
+
}
|
|
465
|
+
let disposeLightAmbient = () => {
|
|
466
|
+
scene.remove(lightAmbient)
|
|
467
|
+
lightAmbient.dispose()
|
|
468
|
+
lightAmbient = null
|
|
469
|
+
}
|
|
470
|
+
createLightAmbient()
|
|
471
|
+
|
|
472
|
+
let setUseLightAmbient = (b) => {
|
|
473
|
+
useLightAmbient = b
|
|
474
|
+
lightAmbient.visible = b
|
|
475
|
+
render()
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
let setLightAmbientColor = (c) => {
|
|
479
|
+
lightAmbientColor = c
|
|
480
|
+
lightAmbient.color = new THREE.Color(nc(c))
|
|
481
|
+
render()
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
//lightPoint
|
|
485
|
+
let lightPoints = null
|
|
486
|
+
let createLightPoints = () => {
|
|
487
|
+
lightPoints = []
|
|
488
|
+
each(lightPointPoss, (lp) => {
|
|
489
|
+
let lightPoint = new THREE.PointLight(nc(lightPointColor), lightPointIntensity, lightPointDistance, lightPointDecay)
|
|
490
|
+
lightPoint.visible = useLightPoint
|
|
491
|
+
let x = get(lp, 0, 0)
|
|
492
|
+
let y = get(lp, 1, 0)
|
|
493
|
+
let z = get(lp, 2, 0)
|
|
494
|
+
lightPoint.position.set(x, y, z)
|
|
495
|
+
scene.add(lightPoint)
|
|
496
|
+
lightPoints.push(lightPoint)
|
|
497
|
+
})
|
|
498
|
+
}
|
|
499
|
+
let disposeLightPoints = () => {
|
|
500
|
+
each(lightPoints, (lightPoint) => {
|
|
501
|
+
scene.remove(lightPoint)
|
|
502
|
+
lightPoint.dispose()
|
|
503
|
+
lightPoint = null
|
|
504
|
+
})
|
|
505
|
+
lightPoints = null
|
|
506
|
+
}
|
|
507
|
+
createLightPoints()
|
|
508
|
+
|
|
509
|
+
let setUseLightPoint = (b) => {
|
|
510
|
+
useLightPoint = b
|
|
511
|
+
each(lightPoints, (lightPoint) => {
|
|
512
|
+
lightPoint.visible = b
|
|
513
|
+
})
|
|
514
|
+
render()
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
let setLightPointPoss = (poss) => {
|
|
518
|
+
lightPointPoss = poss
|
|
519
|
+
disposeLightPoints()
|
|
520
|
+
createLightPoints()
|
|
521
|
+
render()
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
let setLightPointColor = (c) => {
|
|
525
|
+
lightPointColor = c
|
|
526
|
+
disposeLightPoints()
|
|
527
|
+
createLightPoints()
|
|
528
|
+
render()
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
let setLightPointIntensity = (r) => {
|
|
532
|
+
lightPointIntensity = r
|
|
533
|
+
disposeLightPoints()
|
|
534
|
+
createLightPoints()
|
|
535
|
+
render()
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
let setLightPointDistance = (r) => {
|
|
539
|
+
lightPointDistance = r
|
|
540
|
+
disposeLightPoints()
|
|
541
|
+
createLightPoints()
|
|
542
|
+
render()
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
let setLightPointDecay = (r) => {
|
|
546
|
+
lightPointDecay = r
|
|
547
|
+
disposeLightPoints()
|
|
548
|
+
createLightPoints()
|
|
549
|
+
render()
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
//lightDirection
|
|
553
|
+
let lightDirection = null
|
|
554
|
+
let createLightDirection = () => {
|
|
555
|
+
lightDirection = new THREE.DirectionalLight(nc(lightDirectionColor), lightDirectionIntensity)
|
|
556
|
+
lightDirection.visible = useLightDirection
|
|
557
|
+
let x = get(lightDirectionPos, 0, 0)
|
|
558
|
+
let y = get(lightDirectionPos, 1, 0)
|
|
559
|
+
let z = get(lightDirectionPos, 2, 0)
|
|
560
|
+
lightDirection.position.set(x, y, z)
|
|
561
|
+
// lightDirection.castShadow = true
|
|
562
|
+
scene.add(lightDirection)
|
|
563
|
+
}
|
|
564
|
+
let disposeLightDirection = () => {
|
|
565
|
+
scene.remove(lightDirection)
|
|
566
|
+
lightDirection.dispose()
|
|
567
|
+
lightDirection = null
|
|
568
|
+
|
|
569
|
+
}
|
|
570
|
+
createLightDirection()
|
|
571
|
+
|
|
572
|
+
let setUseLightDirection = (b) => {
|
|
573
|
+
useLightDirection = b
|
|
574
|
+
lightDirection.visible = b
|
|
575
|
+
render()
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
let setLightDirectionColor = (c) => {
|
|
579
|
+
lightDirectionColor = c
|
|
580
|
+
lightDirection.color = new THREE.Color(nc(c))
|
|
581
|
+
render()
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
let setLightDirectionIntensity = (r) => {
|
|
585
|
+
lightDirectionIntensity = r
|
|
586
|
+
disposeLightDirection()
|
|
587
|
+
createLightDirection()
|
|
588
|
+
render()
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
let setLightDirectionPos = (pos) => {
|
|
592
|
+
lightDirectionPos = pos
|
|
593
|
+
disposeLightDirection()
|
|
594
|
+
createLightDirection()
|
|
595
|
+
render()
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
let gasp = (w, h) => {
|
|
599
|
+
let r = 1
|
|
600
|
+
if (h > 0) {
|
|
601
|
+
r = w / h
|
|
602
|
+
}
|
|
603
|
+
return r
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
//cameraAspect
|
|
607
|
+
let cameraAspect = gasp(rendererWidth, rendererHeight)
|
|
608
|
+
|
|
609
|
+
//camera
|
|
610
|
+
let camera = null
|
|
611
|
+
let createPerspectiveCamera = () => {
|
|
612
|
+
camera = new THREE.PerspectiveCamera(
|
|
613
|
+
cameraFov, //攝像機視錐體垂直視野角度
|
|
614
|
+
cameraAspect, //攝像機視錐體長寬比
|
|
615
|
+
cameraNear, //攝像機視錐體近端面
|
|
616
|
+
cameraFar, //攝像機視錐體遠端面
|
|
617
|
+
)
|
|
618
|
+
}
|
|
619
|
+
let createOrthographicCamera = () => {
|
|
620
|
+
let s = cameraOrthographicRatio
|
|
621
|
+
camera = new THREE.OrthographicCamera(
|
|
622
|
+
-s * cameraAspect, // left: 攝像機視錐體左側面
|
|
623
|
+
s * cameraAspect, // right: 攝像機視錐體右側面
|
|
624
|
+
s, // top: 攝像機視錐體上側面
|
|
625
|
+
-s, // bottom : 攝像機視錐體下側面
|
|
626
|
+
cameraNear, //攝像機視錐體近端面
|
|
627
|
+
cameraFar, //攝像機視錐體遠端面
|
|
628
|
+
)
|
|
629
|
+
}
|
|
630
|
+
let viewCenter = () => {
|
|
631
|
+
|
|
632
|
+
let setViewYShiftRatio = (yShiftRatio) => {
|
|
633
|
+
let yDiff = yShiftRatio * rendererHeight
|
|
634
|
+
let fullWidth = rendererWidth
|
|
635
|
+
let fullHeight = rendererHeight - yDiff
|
|
636
|
+
let widthOffset = 0
|
|
637
|
+
let heightOffset = -yDiff
|
|
638
|
+
let viewWidth = rendererWidth
|
|
639
|
+
let viewHeight = rendererHeight
|
|
640
|
+
camera.setViewOffset(fullWidth, fullHeight, widthOffset, heightOffset, viewWidth, viewHeight)
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// setViewYShiftRatio(-1, 0, 0, 0) //平移模型中心(旋轉中心)至panel頂部
|
|
644
|
+
setViewYShiftRatio(-0.08, 0, 0, 0) //視區中心稍微往上
|
|
645
|
+
|
|
646
|
+
}
|
|
647
|
+
let setCameraPosCore = (pos) => {
|
|
648
|
+
let x = get(pos, 0, 0)
|
|
649
|
+
let y = get(pos, 1, 0)
|
|
650
|
+
let z = get(pos, 2, 0)
|
|
651
|
+
camera.position.set(x, y, z) //旋轉物件面向世界空間中的一個點
|
|
652
|
+
}
|
|
653
|
+
let createCamera = () => {
|
|
654
|
+
|
|
655
|
+
//create
|
|
656
|
+
if (cameraType === 'perspective') {
|
|
657
|
+
createPerspectiveCamera()
|
|
658
|
+
}
|
|
659
|
+
else if (cameraType === 'orthographic') {
|
|
660
|
+
createOrthographicCamera()
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
//setCameraPosCore
|
|
664
|
+
setCameraPosCore(cameraPos)
|
|
665
|
+
|
|
666
|
+
//camera的z軸朝上
|
|
667
|
+
camera.up.x = 0
|
|
668
|
+
camera.up.y = 0
|
|
669
|
+
camera.up.z = 1
|
|
670
|
+
|
|
671
|
+
//viewCenter
|
|
672
|
+
viewCenter()
|
|
673
|
+
|
|
674
|
+
}
|
|
675
|
+
let disposeCamera = () => {
|
|
676
|
+
camera = null
|
|
677
|
+
}
|
|
678
|
+
createCamera()
|
|
679
|
+
|
|
680
|
+
let getCameraType = () => {
|
|
681
|
+
return cameraType
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
let setCameraType = (c) => {
|
|
685
|
+
cameraType = c
|
|
686
|
+
disposeCamera() //camera無dispose
|
|
687
|
+
createCamera()
|
|
688
|
+
//因controls須由camera產生, 故變更camera也得要重產controls
|
|
689
|
+
disposeControls()
|
|
690
|
+
createControls()
|
|
691
|
+
render()
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// let setCameraPos = (pos) => { //不提供直接修改camera position, 外部改變視角須改變azimuthAngle或polarAngle
|
|
695
|
+
// cameraPos = pos
|
|
696
|
+
// setCameraPosCore(pos)
|
|
697
|
+
// render()
|
|
698
|
+
// }
|
|
699
|
+
|
|
700
|
+
let setCameraFov = (r) => {
|
|
701
|
+
cameraFov = r
|
|
702
|
+
camera.fov = r
|
|
703
|
+
camera.updateProjectionMatrix()
|
|
704
|
+
render()
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
let setCameraNear = (r) => {
|
|
708
|
+
cameraNear = r
|
|
709
|
+
camera.near = r
|
|
710
|
+
camera.updateProjectionMatrix()
|
|
711
|
+
render()
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
let setCameraFar = (r) => {
|
|
715
|
+
cameraFar = r
|
|
716
|
+
camera.far = r
|
|
717
|
+
camera.updateProjectionMatrix()
|
|
718
|
+
render()
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
let setCameraOrthographicRatio = (r) => {
|
|
722
|
+
cameraOrthographicRatio = r
|
|
723
|
+
disposeCamera() //camera無dispose
|
|
724
|
+
createCamera()
|
|
725
|
+
//因controls須由camera產生, 故變更camera也得要重產controls
|
|
726
|
+
disposeControls()
|
|
727
|
+
createControls()
|
|
728
|
+
render()
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
//renderer
|
|
732
|
+
let renderer = new THREE.WebGLRenderer({
|
|
733
|
+
antialias: true,
|
|
734
|
+
})
|
|
735
|
+
renderer.setSize(rendererWidth, rendererHeight)
|
|
736
|
+
// renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
737
|
+
// renderer.toneMappingExposure = 2.2;
|
|
738
|
+
// renderer.physicallyCorrectLights = true;
|
|
739
|
+
// renderer.outputEncoding = THREE.sRGBEncoding;
|
|
740
|
+
domPanel.appendChild(renderer.domElement)
|
|
741
|
+
|
|
742
|
+
//rendererLabels
|
|
743
|
+
let rendererLabels = new CSS2DRenderer()
|
|
744
|
+
rendererLabels.setSize(rendererWidth, rendererHeight)
|
|
745
|
+
rendererLabels.domElement.style.position = 'absolute'
|
|
746
|
+
rendererLabels.domElement.style.top = '0px'
|
|
747
|
+
rendererLabels.domElement.style.left = '0px'
|
|
748
|
+
domPanel.appendChild(rendererLabels.domElement)
|
|
749
|
+
|
|
750
|
+
//controls
|
|
751
|
+
CameraControls.install({ THREE })
|
|
752
|
+
let controls = null
|
|
753
|
+
let createControls = () => {
|
|
754
|
+
|
|
755
|
+
//CameraControls
|
|
756
|
+
controls = new CameraControls(camera, rendererLabels.domElement)
|
|
757
|
+
|
|
758
|
+
//controls
|
|
759
|
+
// // controls.target.set( 0, 0, -0.1 )
|
|
760
|
+
// // controls.enableDamping = true
|
|
761
|
+
// controls.enablePan=true //平移
|
|
762
|
+
// controls.enableRotate=true //旋轉
|
|
763
|
+
// controls.enableZoom=true //縮放
|
|
764
|
+
// // controls.autoRotate=true //自動旋轉
|
|
765
|
+
// // controls.screenSpacePanning=false
|
|
766
|
+
// controls.zoomToCursor=true //針對滑鼠位置zoom
|
|
767
|
+
controls.mouseButtons = { //PAN ROTATE DOLLY
|
|
768
|
+
|
|
769
|
+
//鍵名大寫為OrbitControls使用
|
|
770
|
+
// LEFT: THREE.MOUSE.PAN,
|
|
771
|
+
// MIDDLE: THREE.MOUSE.DOLLY,
|
|
772
|
+
// RIGHT: THREE.MOUSE.ROTATE,
|
|
773
|
+
|
|
774
|
+
//鍵名小寫為CameraControls使用
|
|
775
|
+
left: CameraControls.ACTION.ROTATE,
|
|
776
|
+
middle: CameraControls.ACTION.DOLLY,
|
|
777
|
+
right: CameraControls.ACTION.OFFSET,
|
|
778
|
+
wheel: CameraControls.ACTION.ZOOM,
|
|
779
|
+
|
|
780
|
+
}
|
|
781
|
+
controls.touches = {
|
|
782
|
+
|
|
783
|
+
//鍵名小寫為CameraControls使用
|
|
784
|
+
one: CameraControls.ACTION.TOUCH_ROTATE,
|
|
785
|
+
two: CameraControls.ACTION.TOUCH_DOLLY_OFFSET,
|
|
786
|
+
three: CameraControls.ACTION.TOUCH_OFFSET,
|
|
787
|
+
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
}
|
|
791
|
+
let disposeControls = () => {
|
|
792
|
+
controls = null
|
|
793
|
+
}
|
|
794
|
+
createControls()
|
|
795
|
+
|
|
796
|
+
let getCameraViewAngle = () => {
|
|
797
|
+
let az = get(controls, 'azimuthAngle')
|
|
798
|
+
let polar = get(controls, 'polarAngle')
|
|
799
|
+
return {
|
|
800
|
+
azimuthAngle: az * toDeg,
|
|
801
|
+
polarAngle: polar * toDeg,
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
let setCameraViewAngle = (az, polar) => {
|
|
806
|
+
set(controls, 'azimuthAngle', az * toRad)
|
|
807
|
+
set(controls, 'polarAngle', polar * toRad)
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
//dollyTo( distance, enableTransition )
|
|
811
|
+
//zoomTo( zoom, enableTransition )
|
|
812
|
+
|
|
813
|
+
let iniCameraViewAngle = () => {
|
|
814
|
+
setCameraViewAngle(cameraAzimuthAngle, cameraPolarAngle)
|
|
815
|
+
}
|
|
816
|
+
iniCameraViewAngle()
|
|
817
|
+
|
|
818
|
+
let setCameraAzimuthAngle = (r) => {
|
|
819
|
+
cameraAzimuthAngle = r
|
|
820
|
+
setCameraViewAngle(cameraAzimuthAngle, cameraPolarAngle)
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
let setCameraPolarAngle = (r) => {
|
|
824
|
+
cameraPolarAngle = r
|
|
825
|
+
setCameraViewAngle(cameraAzimuthAngle, cameraPolarAngle)
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
let _viewAngle = null //前次viewAngle
|
|
829
|
+
let timer = setInterval(() => { //timer偵測
|
|
830
|
+
let viewAngle = getCameraViewAngle()
|
|
831
|
+
if (!isEqual(viewAngle, _viewAngle)) {
|
|
832
|
+
_viewAngle = viewAngle
|
|
833
|
+
ev.emit('change-view-angle', viewAngle)
|
|
834
|
+
}
|
|
835
|
+
}, 50)
|
|
836
|
+
|
|
837
|
+
//group
|
|
838
|
+
let group = null
|
|
839
|
+
let createGroup = () => {
|
|
840
|
+
group = new THREE.Group()
|
|
841
|
+
// each(meshs, (mesh) => {
|
|
842
|
+
// group.add(mesh)
|
|
843
|
+
// })
|
|
844
|
+
// console.log('group',group)
|
|
845
|
+
scene.add(group)
|
|
846
|
+
}
|
|
847
|
+
let disposeGroup = () => {
|
|
848
|
+
group.traverse(function(obj) {
|
|
849
|
+
if (obj.isMesh) {
|
|
850
|
+
obj.geometry.dispose()
|
|
851
|
+
obj.material.dispose()
|
|
852
|
+
}
|
|
853
|
+
})
|
|
854
|
+
scene.remove(group)
|
|
855
|
+
group = null
|
|
856
|
+
}
|
|
857
|
+
createGroup()
|
|
858
|
+
|
|
859
|
+
//meshs
|
|
860
|
+
let meshs = []
|
|
861
|
+
|
|
862
|
+
let addMeshCore = async (v) => {
|
|
863
|
+
|
|
864
|
+
//type
|
|
865
|
+
let type = get(v, 'type', '')
|
|
866
|
+
if (!isestr(type)) {
|
|
867
|
+
type = getFileNameExt(v.url)
|
|
868
|
+
}
|
|
869
|
+
if (type !== 'stl') {
|
|
870
|
+
throw new Error(`現在僅支援stl檔`)
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
//gc, a
|
|
874
|
+
let color = get(v, 'color', '')
|
|
875
|
+
let c = oc.toRgba(color)
|
|
876
|
+
let gc = oc.toRgbString(c)
|
|
877
|
+
let a = c.a
|
|
878
|
+
// console.log('addStl before', c, gc, a)
|
|
879
|
+
|
|
880
|
+
//load
|
|
881
|
+
let mesh = await addStl(ev, v.url, {
|
|
882
|
+
color: gc,
|
|
883
|
+
opacity: a,
|
|
884
|
+
})
|
|
885
|
+
|
|
886
|
+
//add name and color
|
|
887
|
+
mesh.name = v.name
|
|
888
|
+
mesh.color = color
|
|
889
|
+
// console.log('mesh', mesh)
|
|
890
|
+
|
|
891
|
+
//push
|
|
892
|
+
meshs.push(mesh)
|
|
893
|
+
|
|
894
|
+
//add
|
|
895
|
+
group.add(mesh)
|
|
896
|
+
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
let addMeshsCore = async (vs) => {
|
|
900
|
+
await pmSeries(vs, async(v) => {
|
|
901
|
+
await addMeshCore(v)
|
|
902
|
+
})
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
await addMeshsCore(items)
|
|
906
|
+
// console.log('first addMeshsCore')
|
|
907
|
+
|
|
908
|
+
let addMesh = async (v) => {
|
|
909
|
+
resetTransform()
|
|
910
|
+
disposeLabel()
|
|
911
|
+
await addMeshCore(v)
|
|
912
|
+
rdr()
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
let addMeshs = async (vs) => {
|
|
916
|
+
resetTransform()
|
|
917
|
+
disposeLabel()
|
|
918
|
+
await addMeshsCore(vs)
|
|
919
|
+
rdr()
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
let getMeshsInfor = () => {
|
|
923
|
+
let rs = map(meshs, (v, ind) => {
|
|
924
|
+
// console.log('ind', v)
|
|
925
|
+
let color = get(v, 'color', '')
|
|
926
|
+
let label = get(labels, ind)
|
|
927
|
+
let labelText = get(label, 'textContent', '')
|
|
928
|
+
let labelTextColor = get(label, 'style.color', '')
|
|
929
|
+
let labelTextFontSize = get(label, 'style.fontSize', '')
|
|
930
|
+
let labelTextFontFamily = get(label, 'style.fontFamily', '')
|
|
931
|
+
return {
|
|
932
|
+
visible: v.visible,
|
|
933
|
+
color,
|
|
934
|
+
labelText,
|
|
935
|
+
labelTextColor,
|
|
936
|
+
labelTextFontSize,
|
|
937
|
+
labelTextFontFamily,
|
|
938
|
+
}
|
|
939
|
+
})
|
|
940
|
+
return rs
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
let setMeshVisibleCore = (ind, visible) => {
|
|
944
|
+
let mesh = get(meshs, ind)
|
|
945
|
+
if (!iseobj(mesh)) {
|
|
946
|
+
return null
|
|
947
|
+
}
|
|
948
|
+
try {
|
|
949
|
+
meshs[ind].visible = visible
|
|
950
|
+
}
|
|
951
|
+
catch (err) {
|
|
952
|
+
console.log(err)
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
let setMeshVisible = (ind, visible) => {
|
|
957
|
+
setMeshVisibleCore(ind, visible)
|
|
958
|
+
setMeshLabelVisibleCore(ind, visible)
|
|
959
|
+
render()
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
let setMeshColor = (ind, color) => {
|
|
963
|
+
let mesh = get(meshs, ind)
|
|
964
|
+
if (!iseobj(mesh)) {
|
|
965
|
+
return null
|
|
966
|
+
}
|
|
967
|
+
try {
|
|
968
|
+
let c = oc.toRgba(color)
|
|
969
|
+
// console.log('color', color)
|
|
970
|
+
// console.log('c', c)
|
|
971
|
+
let gc = oc.toRgbString(c)
|
|
972
|
+
let a = c.a
|
|
973
|
+
// console.log('gc', gc)
|
|
974
|
+
// console.log('a', a)
|
|
975
|
+
meshs[ind].material.color = new THREE.Color(gc)
|
|
976
|
+
meshs[ind].material.opacity = a
|
|
977
|
+
meshs[ind].color = color
|
|
978
|
+
}
|
|
979
|
+
catch (err) {
|
|
980
|
+
console.log(err)
|
|
981
|
+
}
|
|
982
|
+
render()
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
//csr
|
|
986
|
+
let csr = {}
|
|
987
|
+
let calcCsr = () => {
|
|
988
|
+
|
|
989
|
+
//csrd
|
|
990
|
+
let csrd = getCsrdFromMeshs(meshs)
|
|
991
|
+
// console.log('csrd', csrd)
|
|
992
|
+
|
|
993
|
+
//cs, r
|
|
994
|
+
let cs = csrd.cs
|
|
995
|
+
let r = 1
|
|
996
|
+
if (csrd.rd > 0) {
|
|
997
|
+
r = 1 / csrd.rd
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
//csr
|
|
1001
|
+
csr = {
|
|
1002
|
+
...cs,
|
|
1003
|
+
r,
|
|
1004
|
+
}
|
|
1005
|
+
// console.log('csr', csr)
|
|
1006
|
+
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
let calcTransform = () => {
|
|
1010
|
+
each(meshs, (mesh) => {
|
|
1011
|
+
// console.log('mesh',mesh)
|
|
1012
|
+
let geometry = mesh.geometry
|
|
1013
|
+
geometry.translate(-csr.x, -csr.y, -csr.z) //先平移
|
|
1014
|
+
geometry.scale(csr.r, csr.r, csr.r) //再縮放
|
|
1015
|
+
})
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
let resetTransform = () => {
|
|
1019
|
+
each(meshs, (mesh) => {
|
|
1020
|
+
// console.log('mesh',mesh)
|
|
1021
|
+
let geometry = mesh.geometry
|
|
1022
|
+
let r = 1 / csr.r
|
|
1023
|
+
geometry.scale(r, r, r) //先恢復縮放
|
|
1024
|
+
geometry.translate(csr.x, csr.y, csr.z) //再恢復平移
|
|
1025
|
+
})
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
//labels
|
|
1029
|
+
let labels = []
|
|
1030
|
+
let createLabels = () => {
|
|
1031
|
+
each(meshs, (mesh) => {
|
|
1032
|
+
|
|
1033
|
+
//ele
|
|
1034
|
+
let ele = document.createElement('div')
|
|
1035
|
+
ele.textContent = mesh.name
|
|
1036
|
+
ele.style.color = labelTextColor
|
|
1037
|
+
ele.style.fontSize = labelTextFontSize
|
|
1038
|
+
ele.style.fontFamily = labelTextFontFamily
|
|
1039
|
+
// ele.style.display = 'none' //無效
|
|
1040
|
+
ele.style.visibility = 'visible' //改用visibility控制顯隱, visible, hidden
|
|
1041
|
+
// console.log('ele', ele)
|
|
1042
|
+
|
|
1043
|
+
//cso
|
|
1044
|
+
let cso = new CSS2DObject(ele)
|
|
1045
|
+
let c = mesh.geometry.boundingSphere.center //get(mesh, 'geometry.boundingSphere.center')
|
|
1046
|
+
cso.position.set(c.x, c.y, c.z)
|
|
1047
|
+
// console.log('cso',cso)
|
|
1048
|
+
|
|
1049
|
+
//push
|
|
1050
|
+
labels.push(ele)
|
|
1051
|
+
|
|
1052
|
+
//add
|
|
1053
|
+
mesh.add(cso)
|
|
1054
|
+
|
|
1055
|
+
})
|
|
1056
|
+
}
|
|
1057
|
+
let disposeLabel = () => {
|
|
1058
|
+
each(labels, (ele) => {
|
|
1059
|
+
domRemove(ele)
|
|
1060
|
+
})
|
|
1061
|
+
labels = []
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
let rdr = async () => {
|
|
1065
|
+
|
|
1066
|
+
//初始渲染
|
|
1067
|
+
render()
|
|
1068
|
+
|
|
1069
|
+
await delay(1)
|
|
1070
|
+
|
|
1071
|
+
//須先等初始渲染後才能取得csr
|
|
1072
|
+
calcCsr()
|
|
1073
|
+
|
|
1074
|
+
//須有csr各mesh才能translate與scale
|
|
1075
|
+
calcTransform()
|
|
1076
|
+
|
|
1077
|
+
//須mesh已translate與scale才能取得center並給予label座標
|
|
1078
|
+
createLabels()
|
|
1079
|
+
|
|
1080
|
+
//更新平移與縮放後渲染
|
|
1081
|
+
render()
|
|
1082
|
+
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
let setMeshLabelVisibleCore = (ind, visible) => {
|
|
1086
|
+
let label = get(labels, ind)
|
|
1087
|
+
if (!isEle(label)) {
|
|
1088
|
+
return null
|
|
1089
|
+
}
|
|
1090
|
+
try {
|
|
1091
|
+
//無法用display控制顯隱
|
|
1092
|
+
let visibility = 'hidden'
|
|
1093
|
+
if (visible === true) {
|
|
1094
|
+
visibility = 'visible'
|
|
1095
|
+
}
|
|
1096
|
+
labels[ind].style.visibility = visibility
|
|
1097
|
+
}
|
|
1098
|
+
catch (err) {
|
|
1099
|
+
console.log(err)
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
let setMeshLabelVisible = (ind, visible) => {
|
|
1104
|
+
setMeshLabelVisibleCore(ind, visible)
|
|
1105
|
+
render()
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
let setMeshLabelText = (ind, text) => {
|
|
1109
|
+
let label = get(labels, ind)
|
|
1110
|
+
if (!isEle(label)) {
|
|
1111
|
+
return null
|
|
1112
|
+
}
|
|
1113
|
+
try {
|
|
1114
|
+
labels[ind].textContent = text
|
|
1115
|
+
}
|
|
1116
|
+
catch (err) {
|
|
1117
|
+
console.log(err)
|
|
1118
|
+
}
|
|
1119
|
+
render()
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
let setMeshLabelTextColor = (ind, color) => {
|
|
1123
|
+
let label = get(labels, ind)
|
|
1124
|
+
if (!isEle(label)) {
|
|
1125
|
+
return null
|
|
1126
|
+
}
|
|
1127
|
+
try {
|
|
1128
|
+
labels[ind].style.color = color
|
|
1129
|
+
}
|
|
1130
|
+
catch (err) {
|
|
1131
|
+
console.log(err)
|
|
1132
|
+
}
|
|
1133
|
+
render()
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
let setMeshLabelTextFontSize = (ind, fontSize) => {
|
|
1137
|
+
let label = get(labels, ind)
|
|
1138
|
+
if (!isEle(label)) {
|
|
1139
|
+
return null
|
|
1140
|
+
}
|
|
1141
|
+
try {
|
|
1142
|
+
labels[ind].style.fontSize = fontSize
|
|
1143
|
+
}
|
|
1144
|
+
catch (err) {
|
|
1145
|
+
console.log(err)
|
|
1146
|
+
}
|
|
1147
|
+
render()
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
let setMeshLabelTextFontFamily = (ind, fontFamily) => {
|
|
1151
|
+
let label = get(labels, ind)
|
|
1152
|
+
if (!isEle(label)) {
|
|
1153
|
+
return null
|
|
1154
|
+
}
|
|
1155
|
+
try {
|
|
1156
|
+
labels[ind].style.fontFamily = fontFamily
|
|
1157
|
+
}
|
|
1158
|
+
catch (err) {
|
|
1159
|
+
console.log(err)
|
|
1160
|
+
}
|
|
1161
|
+
render()
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
let cleanMeshs = () => {
|
|
1165
|
+
each(meshs, (mesh) => {
|
|
1166
|
+
group.remove(mesh)
|
|
1167
|
+
})
|
|
1168
|
+
disposeGroup()
|
|
1169
|
+
meshs = []
|
|
1170
|
+
createGroup()
|
|
1171
|
+
disposeLabel()
|
|
1172
|
+
render()
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
// let iRender = 0
|
|
1176
|
+
let render = () => {
|
|
1177
|
+
// iRender++
|
|
1178
|
+
// console.log('render', iRender)
|
|
1179
|
+
try {
|
|
1180
|
+
renderer.render(scene, camera)
|
|
1181
|
+
rendererLabels.render(scene, camera)
|
|
1182
|
+
}
|
|
1183
|
+
catch (err) {
|
|
1184
|
+
console.log(err)
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
let resize = () => {
|
|
1189
|
+
// console.log('resize')
|
|
1190
|
+
|
|
1191
|
+
//rendererWidth, rendererHeight, cameraAspect
|
|
1192
|
+
let rwh = gs(domPanel)
|
|
1193
|
+
rendererWidth = rwh.w
|
|
1194
|
+
rendererHeight = rwh.h
|
|
1195
|
+
cameraAspect = gasp(rendererWidth, rendererHeight)
|
|
1196
|
+
// console.log('resize rendererWidth', rendererWidth)
|
|
1197
|
+
// console.log('resize rendererHeight', rendererHeight)
|
|
1198
|
+
// console.log('resize cameraAspect', cameraAspect)
|
|
1199
|
+
|
|
1200
|
+
//update camera
|
|
1201
|
+
camera.aspect = cameraAspect
|
|
1202
|
+
camera.updateProjectionMatrix()
|
|
1203
|
+
|
|
1204
|
+
//viewCenter
|
|
1205
|
+
viewCenter()
|
|
1206
|
+
|
|
1207
|
+
//update renderer
|
|
1208
|
+
renderer.setSize(rendererWidth, rendererHeight)
|
|
1209
|
+
rendererLabels.setSize(rendererWidth, rendererHeight)
|
|
1210
|
+
|
|
1211
|
+
//render
|
|
1212
|
+
render()
|
|
1213
|
+
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
//第1次渲染
|
|
1217
|
+
rdr() //非同步驅動, 故不能用await等待
|
|
1218
|
+
.then(() => {
|
|
1219
|
+
ev.emit('init')
|
|
1220
|
+
})
|
|
1221
|
+
|
|
1222
|
+
//stop
|
|
1223
|
+
let stop = false
|
|
1224
|
+
|
|
1225
|
+
// let iAnimate = 0
|
|
1226
|
+
let animate = () => {
|
|
1227
|
+
// iAnimate++
|
|
1228
|
+
// console.log('animate', iAnimate)
|
|
1229
|
+
if (stop) {
|
|
1230
|
+
// console.log('animate stop')
|
|
1231
|
+
return
|
|
1232
|
+
}
|
|
1233
|
+
try {
|
|
1234
|
+
|
|
1235
|
+
//delta
|
|
1236
|
+
let delta = clock.getDelta()
|
|
1237
|
+
// console.log('delta',delta)
|
|
1238
|
+
|
|
1239
|
+
//hasControlsUpdated
|
|
1240
|
+
let hasControlsUpdated = controls.update(delta)
|
|
1241
|
+
// console.log('hasControlsUpdated',hasControlsUpdated)
|
|
1242
|
+
|
|
1243
|
+
//useAutoRotate
|
|
1244
|
+
if (useAutoRotate) {
|
|
1245
|
+
let az = -autoRotateDeg * toRad * delta
|
|
1246
|
+
// console.log('az', az)
|
|
1247
|
+
controls.azimuthAngle += az
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
//requestAnimationFrame
|
|
1251
|
+
requestAnimationFrame(animate)
|
|
1252
|
+
|
|
1253
|
+
//check
|
|
1254
|
+
if (hasControlsUpdated) {
|
|
1255
|
+
// console.log('hasControlsUpdated and render')
|
|
1256
|
+
render()
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
catch (err) {
|
|
1260
|
+
console.log(err)
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
//animate
|
|
1265
|
+
animate()
|
|
1266
|
+
|
|
1267
|
+
let disposeAll = () => {
|
|
1268
|
+
// console.log('disposeAll')
|
|
1269
|
+
|
|
1270
|
+
//emit
|
|
1271
|
+
ev.emit('dispose')
|
|
1272
|
+
|
|
1273
|
+
//clearInterval
|
|
1274
|
+
clearInterval(timer)
|
|
1275
|
+
|
|
1276
|
+
//stop
|
|
1277
|
+
stop = true
|
|
1278
|
+
|
|
1279
|
+
//disposeGroup
|
|
1280
|
+
disposeGroup()
|
|
1281
|
+
|
|
1282
|
+
//disposeHelperAxes
|
|
1283
|
+
disposeHelperAxes()
|
|
1284
|
+
|
|
1285
|
+
//disposeHelperGrid
|
|
1286
|
+
disposeHelperGrid()
|
|
1287
|
+
|
|
1288
|
+
//disposeLightAmbient
|
|
1289
|
+
disposeLightAmbient()
|
|
1290
|
+
|
|
1291
|
+
//disposeLightPoints
|
|
1292
|
+
disposeLightPoints()
|
|
1293
|
+
|
|
1294
|
+
//disposeLightDirection
|
|
1295
|
+
disposeLightDirection()
|
|
1296
|
+
|
|
1297
|
+
// labelDiv=document.querySelector('#labelDiv'); // same beginning
|
|
1298
|
+
// allLabelsToDelete=document.querySelectorAll('#labelDiv .label') // takes children of class "label" like in moon-earth example
|
|
1299
|
+
// forEach (elem in allLabelsToDelete ) {
|
|
1300
|
+
// labelDiv.removeChild(elem)
|
|
1301
|
+
// }
|
|
1302
|
+
|
|
1303
|
+
//disposeLabel
|
|
1304
|
+
disposeLabel()
|
|
1305
|
+
|
|
1306
|
+
//disposeScene
|
|
1307
|
+
disposeScene()
|
|
1308
|
+
|
|
1309
|
+
//remove
|
|
1310
|
+
// console.log('renderer.domElement',renderer.domElement)
|
|
1311
|
+
// console.log('rendererLabels.domElement',rendererLabels.domElement)
|
|
1312
|
+
// document.body.remove(renderer.domElement)
|
|
1313
|
+
// document.body.remove(rendererLabels.domElement)
|
|
1314
|
+
// renderer.domElement.remove()
|
|
1315
|
+
// rendererLabels.domElement.remove()
|
|
1316
|
+
domRemove(renderer.domElement)
|
|
1317
|
+
domRemove(rendererLabels.domElement)
|
|
1318
|
+
|
|
1319
|
+
//dispose & free renderer
|
|
1320
|
+
renderer.dispose()
|
|
1321
|
+
// rendererLabels.dispose()
|
|
1322
|
+
renderer = null
|
|
1323
|
+
rendererLabels = null
|
|
1324
|
+
|
|
1325
|
+
//free clock
|
|
1326
|
+
// clock.dispose()
|
|
1327
|
+
clock = null
|
|
1328
|
+
|
|
1329
|
+
//disposeControls
|
|
1330
|
+
disposeControls()
|
|
1331
|
+
|
|
1332
|
+
//disposeCamera
|
|
1333
|
+
disposeCamera()
|
|
1334
|
+
|
|
1335
|
+
//free scene
|
|
1336
|
+
// scene.dispose()
|
|
1337
|
+
scene = null
|
|
1338
|
+
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
//save
|
|
1342
|
+
ev.render = render
|
|
1343
|
+
ev.resize = resize
|
|
1344
|
+
ev.dispose = disposeAll
|
|
1345
|
+
|
|
1346
|
+
ev.getUseAutoRotate = getUseAutoRotate
|
|
1347
|
+
ev.setUseAutoRotate = setUseAutoRotate
|
|
1348
|
+
ev.setAutoRotateDeg = setAutoRotateDeg
|
|
1349
|
+
|
|
1350
|
+
ev.setCameraViewAngle = setCameraViewAngle
|
|
1351
|
+
ev.getCameraViewAngle = getCameraViewAngle
|
|
1352
|
+
ev.setCameraAzimuthAngle = setCameraAzimuthAngle
|
|
1353
|
+
ev.setCameraPolarAngle = setCameraPolarAngle
|
|
1354
|
+
|
|
1355
|
+
ev.setBackgroundColor = setBackgroundColor
|
|
1356
|
+
|
|
1357
|
+
ev.getUseHelperAxes = getUseHelperAxes
|
|
1358
|
+
ev.setUseHelperAxes = setUseHelperAxes
|
|
1359
|
+
ev.setHelperAxesLengthRatio = setHelperAxesLengthRatio
|
|
1360
|
+
|
|
1361
|
+
ev.getUseHelperGrid = getUseHelperGrid
|
|
1362
|
+
ev.setUseHelperGrid = setUseHelperGrid
|
|
1363
|
+
|
|
1364
|
+
ev.setHelperGridLengthRatio = setHelperGridLengthRatio
|
|
1365
|
+
ev.setHelperGridDensity = setHelperGridDensity
|
|
1366
|
+
ev.setHelperGridPositionRatioZ = setHelperGridPositionRatioZ
|
|
1367
|
+
|
|
1368
|
+
ev.setUseLightAmbient = setUseLightAmbient
|
|
1369
|
+
ev.setLightAmbientColor = setLightAmbientColor
|
|
1370
|
+
|
|
1371
|
+
ev.setUseLightPoint = setUseLightPoint
|
|
1372
|
+
ev.setLightPointPoss = setLightPointPoss
|
|
1373
|
+
ev.setLightPointColor = setLightPointColor
|
|
1374
|
+
ev.setLightPointIntensity = setLightPointIntensity
|
|
1375
|
+
ev.setLightPointDistance = setLightPointDistance
|
|
1376
|
+
ev.setLightPointDecay = setLightPointDecay
|
|
1377
|
+
|
|
1378
|
+
ev.setUseLightDirection = setUseLightDirection
|
|
1379
|
+
ev.setLightDirectionColor = setLightDirectionColor
|
|
1380
|
+
ev.setLightDirectionIntensity = setLightDirectionIntensity
|
|
1381
|
+
ev.setLightDirectionPos = setLightDirectionPos
|
|
1382
|
+
|
|
1383
|
+
ev.getCameraType = getCameraType
|
|
1384
|
+
ev.setCameraType = setCameraType
|
|
1385
|
+
// ev.setCameraPos = setCameraPos
|
|
1386
|
+
ev.setCameraFov = setCameraFov
|
|
1387
|
+
ev.setCameraNear = setCameraNear
|
|
1388
|
+
ev.setCameraFar = setCameraFar
|
|
1389
|
+
ev.setCameraOrthographicRatio = setCameraOrthographicRatio
|
|
1390
|
+
|
|
1391
|
+
ev.addMesh = addMesh
|
|
1392
|
+
ev.addMeshs = addMeshs
|
|
1393
|
+
ev.getMeshsInfor = getMeshsInfor
|
|
1394
|
+
ev.setMeshVisible = setMeshVisible
|
|
1395
|
+
ev.setMeshColor = setMeshColor
|
|
1396
|
+
ev.setMeshLabelVisible = setMeshLabelVisible
|
|
1397
|
+
ev.setMeshLabelText = setMeshLabelText
|
|
1398
|
+
ev.setMeshLabelTextColor = setMeshLabelTextColor
|
|
1399
|
+
ev.setMeshLabelTextFontSize = setMeshLabelTextFontSize
|
|
1400
|
+
ev.setMeshLabelTextFontFamily = setMeshLabelTextFontFamily
|
|
1401
|
+
ev.cleanMeshs = cleanMeshs
|
|
1402
|
+
|
|
1403
|
+
return ev
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
|
|
1407
|
+
export default plot3d
|